-
Notifications
You must be signed in to change notification settings - Fork 16.2k
Description
| Bugzilla Link | 34636 |
| Version | unspecified |
| OS | Linux |
| CC | @compnerd,@efriedma-quic,@eugenis,@froydnj,@bogner,@glandium,@Dor1s,@pcc,@vedantk,@yuanfang-chen |
Extended Description
[discussed previously at http://lists.llvm.org/pipermail/llvm-dev/2017-September/117315.html]
On linux we have two problems with -fsanitize=fuzzer and -ffunction-sections -Wl,-gc-sections
Test for these: projects/compiler-rt/test/fuzzer/GcSectionsTest.cpp
First problem:
% clang -std=c++11 -ffunction-sections -Wl,-gc-sections -fsanitize=fuzzer GcSectionsTest.cpp
/tmp/GcSectionsTest-065286.o: In function sancov.module_ctor': GcSectionsTest.cpp:(.text.sancov.module_ctor[sancov.module_ctor]+0x22): undefined reference to __start___sancov_pcs'
GcSectionsTest.cpp:(.text.sancov.module_ctor[sancov.module_ctor]+0x2c): undefined reference to `__stop___sancov_pcs'
Here, the table produced by -fsanitize-coverage=pc-table __sancov_pcs gets dropped by the bfd linker (on Ubuntu 14.04).
With a better linker (-fuse-ld=gold or -fuse-ld=lld) this doesn't happen,
but we still may need to find a workaround suitable for old ld. Or maybe not.
Second:
% clang -std=c++11 -ffunction-sections -Wl,-gc-sections -fsanitize=fuzzer GcSectionsTest.cpp -fuse-ld=lld && nm a.out | grep Unused
000000000023f590 t UnusedFunctionShouldBeRemovedByLinker
here, gc-sections is essentially disabled because -fsanitize-coverage=pc-table makes all functions used.
eugenis@ suggests that all we need here is to use https://llvm.org/docs/LangRef.html#associated-metadata to mark the pc-table as associated with it's function.
This is important, we need gc-sections to work.
But once we fix it, we'll need a test (in test/fuzzer/gc-sections.test)
but the test won't work with bfd linker, see above.