https://bugs.llvm.org/show_bug.cgi?id=51390
Bug ID: 51390
Summary: -nodefaultlibs flag CMake check always fails
Product: compiler-rt
Version: unspecified
Hardware: PC
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: compiler-rt
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected], [email protected],
[email protected], [email protected]
All runtimes check if `-nodefaultlibs` flag is supported by the compiler, see
for example
https://github.com/llvm/llvm-project/blob/c120edc7b3e1907127c3107b30e2667f1fde1ee2/compiler-rt/cmake/config-ix.cmake#L28
I found out recently that these checks don't work as intended. The problem is
that `-nodefaultlibs` is not a compiler but a linker flag. The solution is to
replace check_c_compiler_flag with check_linker_flag but that leads to the
check failure because the simple program that CMake tries to link fails with
undefined reference to C library symbols (since `-lc` is no longer included
when `-nodefaultlibs` is set).
To make that check succeed, we need to include `-lc` and `-lgcc` (or builtins
if those are being used) in `CMAKE_REQUIRED_LIBRARIES`, but currently these
libraries are only included if `-nodefaultlibs` checks succeeds, see
https://github.com/llvm/llvm-project/blob/c120edc7b3e1907127c3107b30e2667f1fde1ee2/compiler-rt/cmake/config-ix.cmake#L29.
This is the opposite order from what we want.
We'll likely need to reorganize this logic by first speculatively adding `-lc`
and `-lgcc` to `CMAKE_REQUIRED_LIBRARIES`, then performing the `-nodefaultlibs`
check, and if it fails, removing the libraries we added earlier.
Since that logic is going to be duplicated across libunwind, libc++abi, libc++
and compiler-rt, it might be worth extracting it to a shared function.
--
You are receiving this mail because:
You are on the CC list for the bug._______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs