| Issue |
240535
|
| Summary |
[lldb] Universal Darwin build (CMAKE_OSX_ARCHITECTURES="arm64;x86_64") fails to link liblldb.dylib with LLDB_ENABLE_DYNAMIC_SCRIPTINTERPRETERS=ON
|
| Labels |
lldb
|
| Assignees |
|
| Reporter |
nickdesaulniers
|
After 119e57630281 (#201392) and b6888f0b0873 (#204015), building LLDB as a universal binary on an arm64 macOS host fails when linking the x86_64 slice of liblldb.dylib:
```
Undefined symbols for architecture x86_64:
"lldb_private::NativeFileBase::PrintfVarArg(char const*, char*)", referenced from:
<initial-undefines>
"lldb_private::File::PrintfVarArg(char const*, char*)", referenced from:
<initial-undefines>
ld: symbol(s) not found for architecture x86_64
```
Reproducer (arm64 macOS host):
```
$ cmake -G Ninja -B build -DLLVM_ENABLE_PROJECTS="clang;lldb" \
-DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -DLLDB_ENABLE_PYTHON=ON \
-DLLDB_ENABLE_DYNAMIC_SCRIPTINTERPRETERS=ON llvm
$ ninja -C build liblldb
```
Root cause:
1. lldb_record_dynamic_script_interpreter_exports (lldb/cmake/modules/AddLLDB.cmake) and lldb/scripts/extract-dynamic-script-interpreter-exports.py run llvm-nm on the plugin objects without --arch.
2. With CMAKE_OSX_ARCHITECTURES="arm64;x86_64" the .o files are fat Mach-O. Without --arch, llvm-nm dumps only the slice matching the host (dumpMachOUniversalBinaryMatchHost in llvm/tools/llvm-nm/llvm-nm.cpp).
3. va_list mangles as char* (Pc) on arm64 but __va_list_tag* (P13__va_list_tag) on x86_64, so the exports file gets the arm64-only _ZN12lldb_private4File12PrintfVarArgEPKcPc.
4. add_llvm_symbol_exports passes -Wl,-exported_symbols_list to the universal link; ld64 treats literal names as <initial-undefines> in every slice, so the x86_64 slice fails.
Suggested fix:
Extract symbols per architecture (llvm-nm --arch=<arch> for each entry in CMAKE_OSX_ARCHITECTURES). Note a single union list fails each slice on the other arch's mangling, and an intersection leaves PrintfVarArg unexported. So either generate per-arch export lists and pass them via -Xarch_<arch> -Wl,-exported_symbols_list,<file>, or use wildcard patterns for arch-divergent symbols in the merged list.
cc @llvm/android-maintainers @JDevlieghere
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs