This is an archive of the discontinued LLVM Phabricator instance.

Build libFuzzer with -fPIC
AbandonedPublic

Authored by george.karpenkov on Aug 25 2017, 6:34 PM.

Details

Reviewers
kcc
kubamracek
Summary

Strangely enough, otherwise we get the following linker error only on Linux only when using Swift:

...
/usr/bin/ld.gold: error: /home/buildnode/jenkins/workspace/swift-PR-Linux-smoke-test@2/branch-master-next/buildbot_linux/swift-linux-x86_64/lib/swift/clang/lib/linux/libclang_rt.fuzzer-x86_64.a(FuzzerDriver.cpp.o): requires unsupported dynamic reloc 11; recompile with -fPIC
/usr/bin/ld.gold: error: /home/buildnode/jenkins/workspace/swift-PR-Linux-smoke-test@2/branch-master-next/buildbot_linux/swift-linux-x86_64/lib/swift/clang/lib/linux/libclang_rt.fuzzer-x86_64.a(FuzzerDriver.cpp.o): requires unsupported dynamic reloc 11; recompile with -fPIC
/usr/bin/ld.gold: error: /home/buildnode/jenkins/workspace/swift-PR-Linux-smoke-test@2/branch-master-next/buildbot_linux/swift-linux-x86_64/lib/swift/clang/lib/linux/libclang_rt.fuzzer-x86_64.a(FuzzerDriver.cpp.o): requires dynamic R_X86_64_PC32 reloc against '_Znwm' which may overflow at runtime; recompile with -fPIC
/usr/bin/ld.gold: error: /home/buildnode/jenkins/workspace/swift-PR-Linux-smoke-test@2/branch-master-next/buildbot_linux/swift-linux-x86_64/lib/swift/clang/lib/linux/libclang_rt.fuzzer-x86_64.a(FuzzerDriver.cpp.o): requires dynamic R_X86_64_PC32 reloc against '_ZdlPv' which may overflow at runtime; recompile with -fPIC
/usr/bin/ld.gold: error: /home/buildnode/jenkins/workspace/swift-PR-Linux-smoke-test@2/branch-master-next/buildbot_linux/swift-linux-x86_64/lib/swift/clang/lib/linux/libclang_rt.fuzzer-x86_64.a(FuzzerDriver.cpp.o): requires dynamic R_X86_64_PC32 reloc against '_ZdlPv' which may overflow at runtime; recompile with -fPIC
/usr/bin/ld.gold: error: /home/buildnode/jenkins/workspace/swift-PR-Linux-smoke-test@2/branch-master-next/buildbot_linux/swift-linux-x86_64/lib/swift/clang/lib/linux/libclang_rt.fuzzer-x86_64.a(FuzzerDriver.cpp.o): requires dynamic R_X86_64_32 reloc against '_ZTSSt19_Sp_make_shared_tag' which may overflow at runtime; recompile with -fPIC
...

Diff Detail

Event Timeline

kcc edited edge metadata.Aug 25 2017, 10:08 PM

of course. :)

Please add a lit test that builds a puzzle with "-fPIC -pie", such test should fail w/o this change.
The change itself LGTM, thanks!

@kcc I can't get the test to fail without this option: -fPIC -pie does not seem to be enough.

kcc added a comment.Aug 27 2017, 9:44 PM

Actually, running ninja -v on linux gives me this command line:
clang++ -D_DEBUG -D_GNU_SOURCE -DSTDC_CONSTANT_MACROS -DSTDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Iprojects/compiler-rt/lib/fuzzer -I/usr/local/google/home/kcc/llvm/projects/compiler-rt/lib/fuzzer -I/usr/include/libxml2 -Iinclude -I/usr/local/google/home/kcc/llvm/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wstring-conversion -fcolor-diagnostics -ffunction-sections -fdata-sections -Wall -std=c++11 -Wno-unused-parameter -O3 -UNDEBUG -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wstring-conversion -fcolor-diagnostics -ffunction-sections -fdata-sections -Wall -std=c++11 -Wno-unused-parameter -m64 -MMD -MT projects/compiler-rt/lib/fuzzer/CMakeFiles/RTfuzzer.x86_64.dir/FuzzerLoop.cpp.o -MF projects/compiler-rt/lib/fuzzer/CMakeFiles/RTfuzzer.x86_64.dir/FuzzerLoop.cpp.o.d -o projects/compiler-rt/lib/fuzzer/CMakeFiles/RTfuzzer.x86_64.dir/FuzzerLoop.cpp.o -c /usr/local/google/home/kcc/llvm/projects/compiler-rt/lib/fuzzer/FuzzerLoop.cpp

I.e. -fPIC is already there.
No surprise you can't make a test fail.
But it *is* is surprise why this change fixes anything.

kcc accepted this revision.Aug 28 2017, 11:26 AM

LGTM

This revision is now accepted and ready to land.Aug 28 2017, 11:26 AM