This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt][cmake] Don't pass --version-script to Illumos ld
ClosedPublic

Authored by ro on Jul 24 2020, 2:59 PM.

Details

Summary

Neither the Illumos ld nor the Solaris 11.3 one support the --version-script and
z gnu-linker-script-compat options, which breaks the compiler-rt build.

This patch checks for both options instead of hardcoding their use.

Tested on amd-pc-solaris2.11 (all of Solaris 11.4, 11.3, and Illumos).

It should be possible to remove the UNIX resp. FUCHSIA OR UNIX conditions in
compiler-rt/lib/asan/CMakeLists.txt and compiler-rt/lib/ubsan/CMakeLists.txt.
However, until this has been tested on a wider range of platforms, I've kept them to
be safe.

Diff Detail

Event Timeline

ro created this revision.Jul 24 2020, 2:59 PM
ro added a comment.Jul 24 2020, 3:00 PM

I forgot: also tested on x86_64-pc-linux-gnu.

vitalybuka added inline comments.
compiler-rt/lib/asan/CMakeLists.txt
227

Not sure who is going to test this.
I'd suggested to try and see that is broken

compiler-rt/lib/ubsan/CMakeLists.txt
203

same

vitalybuka accepted this revision.Jul 28 2020, 12:15 AM

feel free to move suggested changes into a separate patch

This revision is now accepted and ready to land.Jul 28 2020, 12:15 AM
ro added a comment.Jul 28 2020, 3:35 AM

feel free to move suggested changes into a separate patch

Will do: this allows to quickly revert just this part in case there's fallout. What's the best way to handle this? Create a new patch in Phabricator
or just commit it separately with "Differential Revision: " set to this one?

This revision was automatically updated to reflect the committed changes.

I'm seeing
ld.lld: error: unknown -z value: gnu-version-script-compat
for a build with -DLLVM_ENABLE_LLD=On
and
/usr/bin/ld: warning: -z gnu-version-script-compat ignored
in a build without one.
$ ninja lib/clang/12.0.0/lib/linux/libclang_rt.ubsan_standalone-i386.so

ro added a subscriber: MaskRay.Jul 29 2020, 3:27 AM

I'm seeing
ld.lld: error: unknown -z value: gnu-version-script-compat
for a build with -DLLVM_ENABLE_LLD=On

So far I cannot reproduce this: in a build with -DLLVM_ENABLE_LLD=On and clang-10 as the build compiler, COMPILER_RT_HAS_VERSION_SCRIPT is 1 in CMakeCache.txt while COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT is
empty, just as expected.

/usr/bin/ld: warning: -z gnu-version-script-compat ignored
in a build without one.

While ugly, this one is expected. I consider gld no-so-silently accepting unknown -z options a serious bug: it has no way of knowing if the
unknown option is crucial to the link or can be ignored without causing harm. However, this seems to date back to binutils 2.22 from 2011,
so is unlikely to change.

$ ninja lib/clang/12.0.0/lib/linux/libclang_rt.ubsan_standalone-i386.so

Works for me just fine. I even tried a 2-stage build with -DLLVM_ENABLE_LLD=On in CLANG_BOOTSTRAP_PASSTHROUGH, but that
consistently fails during the stage 2 cmake run:

CMake Error at cmake/modules/HandleLLVMOptions.cmake:277 (message):
  Host compiler does not support '-fuse-ld=lld'

The stage 2 CMakeFiles/CMakeError.log has

Performing C++ SOURCE FILE Test CXX_SUPPORTS_CUSTOM_LINKER failed with the following output:
Change Dir: /var/llvm/local-x86_64-release-stage2-lld/tools/clang/stage2-bins/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/ninja-build cmTC_1d566 && [1/2] Building CXX object CMakeFiles/cmTC_1d566.dir/src.cxx.o
clang-12: warning: argument unused during compilation: '-fuse-ld=lld' [-Wunused-command-line-argument]
[2/2] Linking CXX executable cmTC_1d566
FAILED: cmTC_1d566
: && /var/llvm/local-x86_64-release-stage2-lld/./bin/clang++  -DCXX_SUPPORTS_CUSTOM_LINKER  -Werror=unguarded-availability-new -fuse-ld=lld   CMakeFiles/cmTC_1d566.dir/src.cxx.o  -o cmTC_1d566  -lm && :
clang-12: error: invalid linker name in argument '-fuse-ld=lld'
ninja: build stopped: subcommand failed.

which is really weird given that the same command works just fine if repeated manually. This might be related to @MaskRay 's recent
-fuse-ld changes.

ro added a comment.Jul 29 2020, 3:40 AM

Could you check your CMakeFiles/CMake{Output,Error}.log files for the -z gnu-version-script-compat test? In mine it fails as expected:

FAILED: cmTC_2dc7b
: && /vol/llvm-10.0/bin/clang++  -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wstring-conversion -fdiagnostics-color -ffunction-sections -fdata-sections -DCOMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT  -Werror=unguarded-availability-new -nodefaultlibs -Wl,-z,gnu-version-script-compat  -fuse-ld=lld -Wl,--color-diagnostics -Wl,-allow-shlib-undefined CMakeFiles/cmTC_2dc7b.dir/src.cxx.o  -o cmTC_2dc7b  -lm  -lc  -lgcc_s && :
ld.lld: error: unknown -z value: gnu-version-script-compat
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
ro added a comment.Jul 29 2020, 4:56 AM
In D84559#2181226, @ro wrote:

Works for me just fine. I even tried a 2-stage build with -DLLVM_ENABLE_LLD=On in CLANG_BOOTSTRAP_PASSTHROUGH, but that
consistently fails during the stage 2 cmake run:

[...]

which is really weird given that the same command works just fine if repeated manually. This might be related to @MaskRay 's recent
-fuse-ld changes.

Scratch that: pilot error. I didn't have lld in system paths and the script I use to run llvm builds didn't include the full llvm-10 bin directory
in PATH.

I killed everything and started again from scratch, seems like it's not an issue anymore. Might be CMake caching not working well between CMake changes?
Sorry for the false alarm.

ro added a comment.Jul 30 2020, 1:20 AM

I killed everything and started again from scratch, seems like it's not an issue anymore. Might be CMake caching not working well between CMake changes?
Sorry for the false alarm.

No worries: glad it wasn't my fault. I've always been wary of rebuilds correctly picking up configuration changes, both in the cmake and autotools worlds.