[PATCH] D107627: [CMake] Check the builtins library value first

Petr Hosek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 6 10:29:49 PDT 2021


phosek added a comment.

This was discovered after D107501 <https://reviews.llvm.org/D107501> broke our build, which uncovered several CMake check failures:

  Performing C++ SOURCE FILE Test COMPILER_RT_HAS_G_FLAG failed with the following output:
  Change Dir: /Users/phosek/llvm/build/fuchsia/runtimes/runtimes-bins/CMakeFiles/CMakeTmp
  
  Run Build Command(s):/Users/phosek/.brew/bin/ninja cmTC_85a84 && [1/2] Building CXX object CMakeFiles/cmTC_85a84.dir/src.cxx.o
  [2/2] Linking CXX executable cmTC_85a84
  FAILED: cmTC_85a84
  : && /Users/phosek/llvm/build/fuchsia/./bin/clang++ --target=x86_64-apple-darwin20.6.0 -stdlib=libc++ -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -Wmisleading-indentation -fdiagnostics-color -ffile-prefix-map=/Users/phosek/llvm/build/fuchsia/runtimes/runtimes-bins=../build/fuchsia/runtimes/runtimes-bins -ffile-prefix-map=/Users/phosek/llvm/llvm-project/= -no-canonical-prefixes  -nostdinc++ -nostdlib++ -nodefaultlibs -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names -stdlib=libc++ CMakeFiles/cmTC_85a84.dir/src.cxx.o -o cmTC_85a84  -lc  -lNOTFOUND && :
  clang++: warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
  ld: library not found for -lNOTFOUND
  clang++: error: linker command failed with exit code 1 (use -v to see invocation)
  ninja: build stopped: subcommand failed.

The problem is that find_compiler_rt_library <https://github.com/llvm/llvm-project/blob/772d2093fc30b545df61c25d3b05a90ed2909e92/compiler-rt/cmake/config-ix.cmake#L19> we use to find builtins fails on Darwin because the library isn't called `libclang_rt.builtins.a` there, rather it's called `libclang_rt.$os.a` where `$os` can be `osx`, `ios`, etc. Therefore, `find_compiler_rt_library` returns `NOTFOUND` but we don't validate the result before appending it to CMAKE_REQUIRED_LIBRARIES <https://github.com/llvm/llvm-project/blob/772d2093fc30b545df61c25d3b05a90ed2909e92/compiler-rt/cmake/config-ix.cmake#L35>.

This is a latent bug that was just uncovered by D107501 <https://reviews.llvm.org/D107501>. The reason why this hasn't caused issues before is because the `-nodefaultlibs` flag check is also broken so we never include that flag in `CMAKE_REQUIRED_FLAGS` and the compiler always uses the default builtins library.

I agree with you, we should report an error when user sets `-DCOMPILER_RT_USE_BUILTINS_LIBRARY=YES` and we fail to find builtins, but before we can do that, we also need to fix `find_compiler_rt_library` on Darwin and the `-nodefaultlibs` check. I'm looking into all of these issues, but addressing them is going to take a bit longer so I was hoping to unbreak our build with this (hopefully temporary) workaround.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107627/new/

https://reviews.llvm.org/D107627



More information about the llvm-commits mailing list