This is an archive of the discontinued LLVM Phabricator instance.

[clang][Driver] Don't hardcode --as-needed/--no-as-needed on Illumos
ClosedPublic

Authored by ro on Jul 23 2020, 7:44 AM.

Details

Summary

ninja check-all currently fails on Illumos:

[84/716] Generating default/Asan-i386-inline-Test
FAILED: projects/compiler-rt/lib/asan/tests/default/Asan-i386-inline-Test
cd /var/llvm/dist-amd64-release/projects/compiler-rt/lib/asan/tests && /var/llvm/dist-amd64-release/./bin/clang ASAN_INST_TEST_OBJECTS.gtest-all.cc.i386-inline.o ASAN_INST_TEST_OBJECTS.asan_globals_test.cpp.i386-inline.o ASAN_INST_TEST_OBJECTS.asan_interface_test.cpp.i386-inline.o ASAN_INST_TEST_OBJECTS.asan_internal_interface_test.cpp.i386-inline.o ASAN_INST_TEST_OBJECTS.asan_test.cpp.i386-inline.o ASAN_INST_TEST_OBJECTS.asan_oob_test.cpp.i386-inline.o ASAN_INST_TEST_OBJECTS.asan_mem_test.cpp.i386-inline.o ASAN_INST_TEST_OBJECTS.asan_str_test.cpp.i386-inline.o ASAN_INST_TEST_OBJECTS.asan_test_main.cpp.i386-inline.o -o /var/llvm/dist-amd64-release/projects/compiler-rt/lib/asan/tests/default/./Asan-i386-inline-Test -g --driver-mode=g++ -fsanitize=address -m32
ld: fatal: unrecognized option '--no-as-needed'
ld: fatal: use the -z help option for usage information
clang-11: error: linker command failed with exit code 1 (use -v to see invocation)

clang unconditionally passes --as-needed/--no-as-needed to the linker. This works
on Solaris 11.[34] which added a couple of option aliases to the native linker to improve
compatibility with GNU ld. Illumos ld didn't do this, so one needs to use the corresponding
native options -z ignore/-z record instead.

Because this works on both Solaris and Illumos, the current patch always passes the
native options on Solaris. This isn't fully correct, however: when using GNU ld on
Solaris (not yet supported; I'm working on that), one still needs --as-needed instead.

I'm hardcoding this decision because a generic detection via a cmake test is hard:
many systems have their own implementation of getDefaultLinker and cmake would
have to duplicate the information encoded there. Besides, it would still break when
-fuse-ld is used.

Tested on amd64-pc-solaris2.11 (Solaris 11.4 and OpenIndiana 2020.04), sparcv9-sun-solaris2.11, and
x86_64-pc-linux-gnu.

Diff Detail

Event Timeline

ro created this revision.Jul 23 2020, 7:44 AM
ro added a reviewer: MaskRay.Aug 4 2020, 1:17 AM

Ping? It's been two weeks now.

#clang does not have many people. You might need to add people explicitly..

clang/lib/Driver/ToolChains/CommonArgs.cpp
633

ignore seems strange. How about start?

634

Can you improve the comment to mention that this is to work around illumnos ld?

636

I'll assume that -zignore has semantics similar to --as-needed.

ro updated this revision to Diff 283232.Aug 5 2020, 7:20 AM

Incorporate review comments: clarify comment and arg name.

ro marked 3 inline comments as done.Aug 5 2020, 7:27 AM

#clang does not have many people. You might need to add people explicitly..

I always found finding reviewers sort of a black art: sometimes the people from the CODE_OWNERS.TXT files work, sometimes people that
recently reviewed changes to the same files are willing to do so again, while at others only repeated nagging works...

clang/lib/Driver/ToolChains/CommonArgs.cpp
633

I'd used ignore based no the description of the option in the ld man page:

-z ignore | record
--as-needed | --no-as-needed

    Ignores, or records, shared object dependencies that are not refer-
    enced as part  of  the  link-edit.  These  options  are  positional

start doesn't tell me much either, so I've gone for as_needed.

634

I hope it's better now. I've removed the GNU ld reference.
You can see my current hack to make clang work with gld on Solaris in D85309.

636

Right: the two are identical semantically.

MaskRay accepted this revision.Aug 5 2020, 7:02 PM

LGTM.

This revision is now accepted and ready to land.Aug 5 2020, 7:02 PM
This revision was automatically updated to reflect the committed changes.
ro marked 3 inline comments as done.