[llvm-bugs] [Bug 51390] New: -nodefaultlibs flag CMake check always fails

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Aug 6 10:53:02 PDT 2021


            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: unassignedbugs at nondot.org
          Reporter: phosek at chromium.org
                CC: chris.bieneman at me.com, ldionne at apple.com,
                    llvm-bugs at lists.llvm.org, smeenai at fb.com

All runtimes check if `-nodefaultlibs` flag is supported by the compiler, see
for example

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
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210806/d0b59772/attachment.html>

More information about the llvm-bugs mailing list