<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 - Default --gc-sections breaks cmake test"
href="https://bugs.llvm.org/show_bug.cgi?id=44278">44278</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Default --gc-sections breaks cmake test
</td>
</tr>
<tr>
<th>Product</th>
<td>lld
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>wasm
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>bob@pepin.io
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, sbc@chromium.org
</td>
</tr></table>
<p>
<div>
<pre>This could be addressed either on the lld or the cmake side, I'll let you
coordinate with the cmake maintainers if necessary.
The cmake CMAKE_SIZEOF_VOID_P macro compiles a temporary file with the size of
a pointer encoded in a string in one of the sections of the binary (see below).
It then tries to extract the result from the compiler output. However, with
--gc-sections enabled, the section containing the string in question is garbage
collected by the linker.
This breaks in particular the compilation of LLVM compiler-rt with wasm32 and
the default linker options.
To reproduce:
CMakeLists.txt:
message("CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P}")
toolchain.cmake:
set(CMAKE_SYSTEM_NAME WASM32)
set(CMAKE_SYSTEM_VERSION 1.0)
set(CMAKE_SYSTEM_PROCESSOR unknown)
set(triple wasm32)
set(CMAKE_C_COMPILER /usr/local/opt/llvm/bin/clang)
set(CMAKE_C_COMPILER_TARGET ${triple})
set(CMAKE_CXX_COMPILER /usr/local/opt/llvm/bin/clang++)
set(CMAKE_CXX_COMPILER_TARGET ${triple})
# This gives CMAKE_SIZEOF_VOID_P 4
#set(CMAKE_EXE_LINKER_FLAGS_INIT "-nostdlib -Wl,--no-entry
-Wl,--no-gc-sections")
# This gives an empty CMAKE_SIZEOF_VOID_P
set(CMAKE_EXE_LINKER_FLAGS_INIT "-nostdlib -Wl,--no-entry")
The cmake code in question is at the top of
<a href="https://github.com/Kitware/CMake/blob/master/Modules/CMakeCompilerABI.h">https://github.com/Kitware/CMake/blob/master/Modules/CMakeCompilerABI.h</a>
/* Size of a pointer-to-data in bytes. */
#define SIZEOF_DPTR (sizeof(void*))
const char info_sizeof_dptr[] = {
/* clang-format off */
'I', 'N', 'F', 'O', ':', 's', 'i', 'z', 'e', 'o', 'f', '_', 'd', 'p', 't',
'r', '[', ('0' + ((SIZEOF_DPTR / 10) % 10)), ('0' + (SIZEOF_DPTR % 10)), ']',
'\0'
/* clang-format on */
};</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>