This is an archive of the discontinued LLVM Phabricator instance.

[libFuzzer] Use the compiler to link the relocatable object
ClosedPublic

Authored by phosek on Jun 14 2022, 11:59 PM.

Details

Summary

Rather than invoking the linker directly, let the compiler driver
handle it. This ensures that we use the correct linker in the case
of cross-compiling.

Diff Detail

Event Timeline

phosek created this revision.Jun 14 2022, 11:59 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 14 2022, 11:59 PM
Herald added subscribers: Enna1, mgorny. · View Herald Transcript
phosek requested review of this revision.Jun 14 2022, 11:59 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 14 2022, 11:59 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript
haowei accepted this revision.Jun 15 2022, 12:02 AM
This revision is now accepted and ready to land.Jun 15 2022, 12:02 AM
This revision was landed with ongoing or failed builds.Jun 15 2022, 12:16 AM
This revision was automatically updated to reflect the committed changes.
glandium added inline comments.
compiler-rt/lib/fuzzer/CMakeLists.txt
149

This ensures that we use the correct linker in the case of cross-compiling.

When you ensured you were using the correct linker by setting CMAKE_LINKER to lld, ironically, this breaks your setup because now CMAKE_CXX_COMPILER is using plain ld, which isn't the correct linker.

phosek added inline comments.Jun 16 2022, 12:58 AM
compiler-rt/lib/fuzzer/CMakeLists.txt
149

Which linker is going to be used depends on the target and your build configuration (that is the value of CLANG_DEFAULT_LINKER). Furthermore, we shouldn't be relying on any LLD-specific feature here so even BFD ld or gold should work fine.

glandium added inline comments.Jun 16 2022, 1:53 AM
compiler-rt/lib/fuzzer/CMakeLists.txt
149

Not when BFD ld doesn't support the target. In my case, I'm also setting various CMAKE_*_LINKER_FLAGS to include -fuse-ld=lld, but obviously, that doesn't end up here.

149

Not when BFD ld doesn't support the target.

More precisely, when the BFD ld you have available doesn't have the support for the target compiled in.