Commit 1fe030b
Add --exclude-libs=ALL to libIREECompiler.so shared library (#23574)
When building `libIREECompiler.so` in `TheRock` I hit the following
error when trying to load the library:
```
LLVM ERROR: Option 'pbqp' already exists!
```
I'll put the full claude generated description of what happened below
but the long and the short of it is `libIREECompiler.so` seems to be
exporting quite a few symbols when linking LLVM's static `.a`'s. In my
case, `TheRock` has another library that loads `libLLVM.so`, and when
loaded it
[interposes](https://maskray.me/blog/2021-05-16-elf-interposition-and-bsymbolic)
some of the global command line registration machinery. Because of the
interposition, `libIREECompiler.so`'s command line registration got
routed to `libLLVM.so`'s; luckily, rather than some incredibly hard to
diagnose error, the double command line registration crashes on startup.
`--exclude-libs,ALL` hides symbols from static libraries when linking
the final `libIREECompiler.so`, preventing LLVM's symbols from being
exported and therefore being interposable.
---
Claude generated description
```
Add --exclude-libs=ALL to libIREECompiler.so shared library
libIREECompiler.so statically links LLVM/MLIR but exports ~175K internal
symbols via its version script (api_version.ld uses `global: *`). The
visibility design assumes LLVM is compiled with -fvisibility=hidden, but
LLVM's own CMake build only applies -fvisibility-inlines-hidden — not
-fvisibility=hidden — to the vast majority of its compilation units
(2250/2720 LLVM files, 1049/1145 MLIR files lack the flag). This means
all non-inline LLVM symbols default to visibility("default") and leak
through the version script.
When libIREECompiler.so is loaded via dlopen(RTLD_LOCAL) into a process
that already has libLLVM.so in the global scope (e.g. via HIP runtime's
libamd_comgr.so → libLLVM.so.22.0git), the ELF dynamic linker searches
the global scope first when resolving relocations. LLVM function calls
in libIREECompiler.so that go through the PLT/GOT resolve to
libLLVM.so's copies rather than the compiler's own static LLVM. This
causes LLVM cl::Option static initializers to register duplicate options
into libLLVM.so's global registry, crashing with:
LLVM ERROR: Option 'pbqp' already exists!
The fix adds --exclude-libs=ALL to the SharedImpl linker options, which
forces all symbols from static archives (.a files) to hidden visibility
at link time. Only symbols from object files (.o) compiled with explicit
__attribute__((visibility("default"))) annotations — i.e. the IREE and
MLIR C API functions marked with IREE_EMBED_EXPORTED / MLIR_CAPI_EXPORTED
— remain visible. This reduces exported dynamic symbols from ~274K to
~2.9K.
This matches the pattern already used by MLIR's own MLIR-C shared
library (mlir/lib/CAPI/CMakeLists.txt):
target_link_options(MLIR-C PRIVATE "-Wl,-exclude-libs,ALL")
```
ci-extra: all
---------
Signed-off-by: Bangtian Liu <liubangtian@gmail.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Bangtian Liu <liubangtian@gmail.com>1 parent b082090 commit 1fe030b
File tree
5 files changed
+9
-0
lines changed- build_tools/cmake
- compiler
- bindings/python
- src/iree/compiler/API
- tests/e2e/regression
5 files changed
+9
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
214 | 214 | | |
215 | 215 | | |
216 | 216 | | |
| 217 | + | |
| 218 | + | |
217 | 219 | | |
218 | 220 | | |
219 | 221 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
171 | 175 | | |
172 | 176 | | |
173 | 177 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| 89 | + | |
89 | 90 | | |
90 | 91 | | |
91 | 92 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| 84 | + | |
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
| |||
0 commit comments