Commit 3d3ee36
committed
Qualcomm AI Engine Direct - Fix backend register issue on Windows
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**.
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 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[]`.1 parent a6f0cf1 commit 3d3ee36
4 files changed
Lines changed: 46 additions & 0 deletions
File tree
- backends/qualcomm/runtime
- examples/qualcomm
- executor_runner
- oss_scripts/whisper
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
40 | 50 | | |
41 | 51 | | |
42 | 52 | | |
| |||
92 | 102 | | |
93 | 103 | | |
94 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
95 | 108 | | |
96 | 109 | | |
97 | 110 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
351 | 351 | | |
352 | 352 | | |
353 | 353 | | |
| 354 | + | |
354 | 355 | | |
355 | 356 | | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
356 | 360 | | |
| 361 | + | |
357 | 362 | | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
358 | 369 | | |
359 | 370 | | |
360 | 371 | | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
| 211 | + | |
| 212 | + | |
211 | 213 | | |
212 | 214 | | |
213 | 215 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
| |||
95 | 97 | | |
96 | 98 | | |
97 | 99 | | |
| 100 | + | |
| 101 | + | |
98 | 102 | | |
99 | 103 | | |
100 | 104 | | |
| |||
0 commit comments