https://bugs.llvm.org/show_bug.cgi?id=44278

            Bug ID: 44278
           Summary: Default --gc-sections breaks cmake test
           Product: lld
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: wasm
          Assignee: unassignedb...@nondot.org
          Reporter: b...@pepin.io
                CC: llvm-bugs@lists.llvm.org, s...@chromium.org

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
https://github.com/Kitware/CMake/blob/master/Modules/CMakeCompilerABI.h

/* 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 */
};

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to