llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.32k stars 12.11k forks source link

lld/mac-linked clang crashes at runtime #51769

Open nico opened 3 years ago

nico commented 3 years ago
Bugzilla Link 52427
Version unspecified
OS All
CC @gkmhub,@int3,@smeenai

Extended Description

Repro file for linking clang: https://drive.google.com/file/d/1uoZnBDRWrG6HQUsPzXsG5yA6t-I0zAoL/view?usp=sharing

This is a clang that was built with -DLLVM_BUILD_INSTRUMENTED=IR.

Linking clang with the repro file with lld.ld64 and then running bin/clang++ -target x86_64-unknown-unknown -O2 -g -std=c++14 -fno-exceptions -fno-rtti -w -c pgo_training-1.ii pgo_training-1.ii makes clang crash after ~25s.

clang doesn't crash if it's linked with ld64 (it succeeds after ~31s).

You can obtain pgo_training-1.ii by running curl -L -O https://commondatastorage.googleapis.com/chromium-browser-clang/pgo_training-1.ii.

1: Full cmake invocation for producing the .o files:

 Running cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=OFF '-DLLVM_ENABLE_PROJECTS=clang;compiler-rt;lld;clang-tools-extra;libcxx' '-DLLVM_TARGETS_TO_BUILD=AArch64;ARM;Mips;PowerPC;SystemZ;WebAssembly;X86' -DLLVM_ENABLE_PIC=OFF -DLLVM_ENABLE_UNWIND_TABLES=OFF -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_ENABLE_Z3_SOLVER=OFF -DCLANG_PLUGIN_SUPPORT=OFF -DCLANG_ENABLE_STATIC_ANALYZER=OFF -DCLANG_ENABLE_ARCMT=OFF '-DBUG_REPORT_URL=https://crbug.com and run tools/clang/scripts/process_crashreports.py (only works inside Google) which will upload a report' -DLLVM_INCLUDE_GO_TESTS=OFF -DENABLE_X86_RELAX_RELOCATIONS=NO -DLLVM_ENABLE_DIA_SDK=OFF '-DCOMPILER_RT_SANITIZERS_TO_BUILD=asan;dfsan;msan;hwasan;tsan;cfi' -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF -DLIBCXX_ENABLE_SHARED=OFF -DLIBCXX_ENABLE_STATIC=OFF -DLIBCXX_INCLUDE_TESTS=OFF -DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=OFF -DLLVM_ENABLE_LIBXML2=FORCE_ON -DLLVM_ENABLE_LLD=ON '-DLLVM_ENABLE_PROJECTS=clang;libcxx;compiler-rt' -DCMAKE_C_FLAGS= -DCMAKE_CXX_FLAGS= -DCMAKE_EXE_LINKER_FLAGS= -DCMAKE_SHARED_LINKER_FLAGS= -DCMAKE_MODULE_LINKER_FLAGS= -DLLVM_BUILD_INSTRUMENTED=IR -DCMAKE_C_COMPILER=/Users/thakis/src/chrome/src/third_party/llvm-bootstrap-install/bin/clang -DCMAKE_CXX_COMPILER=/Users/thakis/src/chrome/src/third_party/llvm-bootstrap-install/bin/clang++ /Users/thakis/src/chrome/src/third_party/llvm/llvm

This is with a "normally" built clang as stage0 compiler, but it might repro when just using system clang as host compiler.

nico commented 3 years ago

https://reviews.llvm.org/rG317e00dc54c74a2e0fd0c62bdc6a6d68b0d2ca7e is somewhat related.

nico commented 3 years ago

Now that I'm actually trying this with the repro file, you need to do the following to get it to actually repro:

mkdir bin mv clang-14 bin # Update response.txt to write to here directly mkdir -p lib/clang/14.0.0 ln -s ~/src/llvm-project/clang/lib/Headers lib/clang/14.0.0/include

And then to get the crash:

bin/clang-14 -target x86_64-unknown-unknown -O2 -g -std=c++14 -fno-exceptions -fno-rtti -w -c pgo_training-1.ii pgo_training-1.ii

(See comment 0 for where to get the .ii file.)

nico commented 3 years ago

https://bugs.chromium.org/p/chromium/issues/detail?id=1267227 comment 0 has full stack. (It's pretty long.)

Still happens without -dead_strip.