You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit e88fd04
Browse filesBrowse the repository at this point in the historyBrowse files
Qualcomm AI Engine Direct - Fix backend register issue on Windows (pytorch#20053)
## Background
On Linux, `qnn_executorch_backend.so` is a shared library that links
`executorch_core.a` statically. This produces a `.so` that embeds its
own copy of `register_backend`, `registered_backends`, and
`num_registered_backends`. But those symbols are **ELF global
(non-hidden) symbols**. When the runner exe also links
`executorch_core.a`, it too has copies of those symbols — but **ELF's
symbol interposition rule** says:
> When the dynamic linker resolves a symbol at runtime, the executable's
definition takes priority over any .so's definition.
Even though the `.so` physically contains its own `register_backend`
code, at runtime all calls to `register_backend` — including the static
initializer inside the `.so` — **are redirected to the exe's copy by the
dynamic linker**.
## Why it breaks on Windows?
Windows has no symbol interposition. Each module — the .dll and the .exe
— resolves all statically linked symbols independently, and each carries
a completely private copy of any data that came from statically archived
code.
## The fix for Windows (compatible with Linux)
**The solution is to explicitly bridge the address-space split by
passing the exe's own `register_backend` function pointer across the DLL
boundary.**
The exe's registering function address is passed as `void*` to the DLL's
`QnnExecuTorchBackendRegister`. Inside the DLL, the function pointer is
a direct address into the exe's code. When the DLL executes
`reinterpret_cast<RegisterFn>(register_fn)(backend_msvc)`, the CPU jumps
into the exe's `register_backend` function, which writes into the exe's
own `registered_backends[]`.
---------
Co-authored-by: chenweng <chenweng@qti.qualcomm.com>
0 commit comments