llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Profile Instrumentation and linker (gnu) garbage collection

Open david-xl opened this issue 11 years ago • 0 comments

Bugzilla Link 25286
Version unspecified
OS Linux
CC @vns-mn

Extended Description

If you use the latest clang to build an instrumented executable or shared library with garbage collection turned on, you will get a linker error if the linker is gnu ld:

clang -fprofile-instr-generate -fdata-sections -ffunction-sections -Wl,--gc-sections t.c

The affected platform is Linux and FreeBSD. This is basically a gnu linker bug:

https://sourceware.org/bugzilla/show_bug.cgi?id=19161

It is possible to workaround this by changing clang driver, but the solution is hacky and temporary, so not desirable.

If you hit the problem, here are three solutions:

  1. update the gnu linker (when the fix is released)
  2. use gold linker: -fuse-ld=gold
  3. use the following linker script -- name it prf_data.x
SECTIONS {
__llvm_prf_data : { KEEP(*(__llvm_prf_data)) }
}

and add the following link option: -Wl,-T,prf_data.x

Keep this bug open as a place holder to document the issue.

david-xl avatar Oct 22 '15 20:10 david-xl