Commit e88fd04
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>1 parent cf77ba8 commit e88fd04
4 files changed
Lines changed: 61 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 | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
95 | 111 | | |
96 | 112 | | |
97 | 113 | | |
| 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 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 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