FS#40515 - [gcc] ld.gold fails to link tcmalloc properly with -Wl,--as-needed
Attached to Project:
Arch Linux
Opened by Dave Reisner (falconindy) - Friday, 23 May 2014, 23:52 GMT
Last edited by Allan McRae (Allan) - Saturday, 20 February 2016, 02:25 GMT
Opened by Dave Reisner (falconindy) - Friday, 23 May 2014, 23:52 GMT
Last edited by Allan McRae (Allan) - Saturday, 20 February 2016, 02:25 GMT
|
Details
With gcc 4.9, gold seems to be a bit too aggressive in its
use of -Wl,--as-needed. tcmalloc is interesting since it's
employed essentially via linking, and doesn't actually
require calling any symbols in the library directly.
Here's a minimal example: $ echo 'int main() { void *x = malloc(10); return 0; }' | gcc -include stdlib.h -x c - -Wl,--as-needed -fuse-ld=gold -ltcmalloc $ objdump -p a.out | grep NEEDED NEEDED libc.so.6 Removing one of "-Wl,--as-needed" or "-fuse-ld=gold" will result in libtcmalloc being linked. You can further tell that libtcmalloc is in use because valgrind will always report 0 heap usage for said binary. |
This task depends upon
I'd suggest putting the -ltcmalloc in front of the -Wl,--as-needed to ensure it is linked.
tcmalloc redefines symbol names like malloc, so it isn't like there aren't any references. The real compile commandline includes flags "-fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free" as well, but I'm not sure what real effect this has within gcc.