llvm / llvm-project

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

[compiler-rt lsan] lipo error when building llvm 16.0.4 from source #63085

Open susugagalala opened 1 year ago

susugagalala commented 1 year ago

I encountered the following build error when building LLVM 16.0.4 on a macOS x86_64 host. The source code was taken from here:

https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-16.0.4.tar.gz

fatal error: /Library/Developer/CommandLineTools/usr/bin/lipo: /var/folders/gn/s0ng0p2x0lvcknxk20tp3nsc0000gp/T/lsan-0f8184/lsan-x86_64.out and /var/folders/gn/s0ng0p2x0lvcknxk20tp3nsc0000gp/T/lsan-2300a3/lsan-x86_64h.out have the same architectures (x86_64) and can't be in the same fat output file
clang++: error: lipo command failed with exit code 1 (use -v to see invocation)
make[2]: *** [lib/clang/16/lib/darwin/libclang_rt.lsan_osx_dynamic.dylib] Error 1
make[1]: *** [projects/compiler-rt/lib/lsan/CMakeFiles/clang_rt.lsan_osx_dynamic.dir/all] Error 2
make: *** [all] Error 2
hoyhoy commented 1 year ago

I just hit a similar problem using 16.0.6 to compile llvm 17 with XCode 15's lipo. Is there some way to turn off x86_64h? I don't need it.

sanitizer_allocator-x86_64.out and /var/folders/sg/by4ymb_1491658nz5rdt1k940000gn/T/sanitizer_allocator-06ef06/sanitizer_allocator-x86_64h.out have the same architectures (x86_64) and can't be in the same fat output file
clang-16: error: lipo command failed with exit code 1 (use -v to see invocation)
[3439/6947] Building CXX object projects/compiler-rt/lib/lsan/CMakeFiles/RTLSanCommon.osx.dir/lsan_common.cpp.o
ninja: build stopped: subcommand failed.
gbaraldi commented 12 months ago

Did any of you folks figure this out? I see this with ubsan as well, when crosscompiling to x86_64-darwin with clang+lld

hoyhoy commented 12 months ago

Did any of you folks figure this out? I see this with ubsan as well, when crosscompiling to x86_64-darwin with clang+lld

I ended up using the latest XCode to compile Clang 17.0.1 on macOS 14 and that worked for me. I just recompiled Clang 17.0.3 with Clang 17.0.1 and that worked as well.

DavidSpickett commented 12 months ago

I have used the CMake setting COMPILER_RT_DEFAULT_TARGET_ONLY in the past, to disable building 32 and 64 bit on x86 machines that didn't have 32 bit libraries.

That might work here, since x86_64h seems to be treated as an architecture variant.

hoyhoy commented 9 months ago

Just hit this again. COMPILER_RT_DEFAULT_TARGET_ONLY doesn't disable x86_64h. You have to manually remove it from builtin-config-ix.cmake.

lvm-lipo: error: /var/folders/sg/by4ymb_1491658nz5rdt1k940000gn/T/sanitizer_allocator-4d45c0/sanitizer_allocator-x86_64.out and /var/folders/sg/by4ymb_1491658nz5rdt1k940000gn/T/sanitizer_allocator-a6fe88/sanitizer_allocator-x86_64h.out have the same architecture x86_64 and therefore cannot be in the same universal binary
clang++: error: lipo command failed with exit code 1 (use -v to see invocation)
sztomi commented 6 months ago

You have to manually remove it from builtin-config-ix.cmake

I'm also hitting this, but I don't think removing x86_64h is the right move. If anything, removing x86_64 makes more sense. No Apple hardware since 2013 is sold without haswell extensions and it's highly unlikely that your developers would use such hardware for work.

sztomi commented 6 months ago

For what its worth, I just verified that commenting out the x86_64 arch (and leaving only x86_64h) works fine. I'm confused why this happens in the first place because both the logic for this error in lipo (and llvm-lipo) is old code, and so is the CMake script selecting the architectures. The sample 2-stage Apple CMake caches don't produce these errors, but they aren't using PGO either. I'm certain that the issue can be worked out by minimizing the CMake flags until it no longer repros, but I'm OK with this workaround.

hoyhoy commented 6 months ago

It's still a problem in 18.1.3. Thanks for the recommendation on X86_64h. I'm actually getting a crash in lldb as well. Now I'm wondering if it's because I'm using the old X86_64 architecture flag.

sztomi commented 6 months ago

@hoyhoy that's unlikely, code that's not using the haswell instructions will run just fine on haswell and later CPUs.

hoyhoy commented 6 months ago

So, I tried building with just x86_64h, but conan actually doesn't support that. If I try to build my entire app and dependencies with x86_64h, conan attempts to build certain dependencies as 32-bit since it tries an exact match for "x86_64".

Why is this additional architecture string needed for the runtimes? uname on macOS lists the system as x86_64, not x86_64h. When I use clang directly, it knows the CPU is "penryn" which is later than haswell.

theoparis commented 1 month ago

I received this error on a M2 mbp running MacOS 15.1 beta... not sure why it's trying to use x86_64h on aarch64

.../darwin/libclang_rt.tsan_osx_dynamic.dylib
clang++: warning: argument unused during compilation: '-stdlib=libc++' [-Wunused-command-line-argument]
llvm-lipo: error: /var/folders/s7/5dn5m1jx42g6jjn5hq96fwvr0000gn/T/interception_linux-x86_64-c3967e.out and /var/folders/s7/5dn5m1jx42g6jjn5hq96fwvr0000gn/T/interception_linux-x86_64h-b2170c.out have the same architecture x86_64 and therefore cannot be in the same universal binary
clang++: error: lipo command failed with exit code 1 (use -v to see invocation)
[1623/1673] Building CXX object compiler-rt/lib/orc/CMakeFiles/RTOrc.osx.dir/macho_platform.cpp.o
complyue commented 2 weeks ago

Removed x86_64 and kept only x86_64h, it works fine but should I worry about these warnings?

[188/3913] Linking CXX executable bin/llvm-min-tblgen
ld64.lld: warning: /xxx/llvm-project/build-x86_64-Darwin/lib/clang/18/lib/darwin/libclang_rt.osx.a: ignoring file because it is universal (x86_64h) but does not contain the x86_64 architecture
[1069/3913] Linking CXX executable bin/llvm-tblgen
ld64.lld: warning: /xxx/llvm-project/build-x86_64-Darwin/lib/clang/18/lib/darwin/libclang_rt.osx.a: ignoring file because it is universal (x86_64h) but does not contain the x86_64 architecture
[1922/3913] Linking CXX shared library lib/libLLVM.dylib
ld64.lld: warning: /xxx/llvm-project/build-x86_64-Darwin/lib/clang/18/lib/darwin/libclang_rt.osx.a: ignoring file because it is universal (x86_64h) but does not contain the x86_64 architecture
[2166/3913] Linking CXX executable bin/clang-tblgen
ld64.lld: warning: /xxx/llvm-project/build-x86_64-Darwin/lib/clang/18/lib/darwin/libclang_rt.osx.a: ignoring file because it is universal (x86_64h) but does not contain the x86_64 architecture
[3139/3913] Linking CXX shared library lib/libclang-cpp.dylib
ld64.lld: warning: /xxx/llvm-project/build-x86_64-Darwin/lib/clang/18/lib/darwin/libclang_rt.osx.a: ignoring file because it is universal (x86_64h) but does not contain the x86_64 architecture
[3225/3913] Linking CXX executable bin/llvm-ar
ld64.lld: warning: /xxx/llvm-project/build-x86_64-Darwin/lib/clang/18/lib/darwin/libclang_rt.osx.a: ignoring file because it is universal (x86_64h) but does not contain the x86_64 architecture
[3227/3913] Linking CXX executable bin/clang-18
ld64.lld: warning: /xxx/llvm-project/build-x86_64-Darwin/lib/clang/18/lib/darwin/libclang_rt.osx.a: ignoring file because it is universal (x86_64h) but does not contain the x86_64 architecture
[3254/3913] Linking CXX executable bin/llvm-libtool-darwin
ld64.lld: warning: /xxx/llvm-project/build-x86_64-Darwin/lib/clang/18/lib/darwin/libclang_rt.osx.a: ignoring file because it is universal (x86_64h) but does not contain the x86_64 architecture
[3263/3913] Linking CXX executable bin/llvm-lipo
ld64.lld: warning: /xxx/llvm-project/build-x86_64-Darwin/lib/clang/18/lib/darwin/libclang_rt.osx.a: ignoring file because it is universal (x86_64h) but does not contain the x86_64 architecture
[3283/3913] Linking CXX executable bin/llvm-nm
ld64.lld: warning: /xxx/llvm-project/build-x86_64-Darwin/lib/clang/18/lib/darwin/libclang_rt.osx.a: ignoring file because it is universal (x86_64h) but does not contain the x86_64 architecture
[3286/3913] Linking CXX executable bin/lld
ld64.lld: warning: /xxx/llvm-project/build-x86_64-Darwin/lib/clang/18/lib/darwin/libclang_rt.osx.a: ignoring file because it is universal (x86_64h) but does not contain the x86_64 architecture
[3288/3913] Linking CXX executable bin/llvm-config
ld64.lld: warning: /xxx/llvm-project/build-x86_64-Darwin/lib/clang/18/lib/darwin/libclang_rt.osx.a: ignoring file because it is universal (x86_64h) but does not contain the x86_64 architecture
[3304/3913] Linking CXX executable bin/llvm-objdump
ld64.lld: warning: /xxx/llvm-project/build-x86_64-Darwin/lib/clang/18/lib/darwin/libclang_rt.osx.a: ignoring file because it is universal (x86_64h) but does not contain the x86_64 architecture
[3309/3913] Performing configure step for 'builtins'