<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - -nodefaultlibs flag CMake check always fails"
href="https://bugs.llvm.org/show_bug.cgi?id=51390">51390</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>-nodefaultlibs flag CMake check always fails
</td>
</tr>
<tr>
<th>Product</th>
<td>compiler-rt
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>compiler-rt
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>phosek@chromium.org
</td>
</tr>
<tr>
<th>CC</th>
<td>chris.bieneman@me.com, ldionne@apple.com, llvm-bugs@lists.llvm.org, smeenai@fb.com
</td>
</tr></table>
<p>
<div>
<pre>All runtimes check if `-nodefaultlibs` flag is supported by the compiler, see
for example
<a href="https://github.com/llvm/llvm-project/blob/c120edc7b3e1907127c3107b30e2667f1fde1ee2/compiler-rt/cmake/config-ix.cmake#L28">https://github.com/llvm/llvm-project/blob/c120edc7b3e1907127c3107b30e2667f1fde1ee2/compiler-rt/cmake/config-ix.cmake#L28</a>
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
<a href="https://github.com/llvm/llvm-project/blob/c120edc7b3e1907127c3107b30e2667f1fde1ee2/compiler-rt/cmake/config-ix.cmake#L29">https://github.com/llvm/llvm-project/blob/c120edc7b3e1907127c3107b30e2667f1fde1ee2/compiler-rt/cmake/config-ix.cmake#L29</a>.
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.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>