Arch Linux

Please read this before reporting a bug:
https://wiki.archlinux.org/title/Bug_reporting_guidelines

Do NOT report bugs when a package is just outdated, or it is in the AUR. Use the 'flag out of date' link on the package page, or the Mailing List.

REPEAT: Do NOT report bugs for outdated packages!
Tasklist

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
Task Type Bug Report
Category Packages: Core
Status Closed
Assigned To Allan McRae (Allan)
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

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

Closed by  Allan McRae (Allan)
Saturday, 20 February 2016, 02:25 GMT
Reason for closing:  Upstream
Comment by Allan McRae (Allan) - Thursday, 12 June 2014, 14:15 GMT
I'm not sure this is actually a bug... libtcmalloc is not needed as malloc is already provided by libc. So I guess there is a bug in ld.bfd.

I'd suggest putting the -ltcmalloc in front of the -Wl,--as-needed to ensure it is linked.
Comment by Dave Reisner (falconindy) - Thursday, 12 June 2014, 14:23 GMT
Well, it's a rather distinct and inconsistent change in behavior, so I figured it was worth reporting. Feel free to do what you want with this as far as upstream goes.

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.
Comment by Dave Reisner (falconindy) - Thursday, 12 June 2014, 19:28 GMT Comment by Allan McRae (Allan) - Thursday, 12 June 2014, 21:21 GMT
Not really related - that happened in 2011.
Comment by Daniel Micay (thestinger) - Thursday, 12 June 2014, 21:30 GMT
It's related in the sense that the alternative to the weak symbols was deprecated in favour of them, so it seems like it was expected to behave as ld.bfd does. I'm not sure which is the correct behaviour, but it should definitely be consistent between the two linkers.
Comment by Allan McRae (Allan) - Wednesday, 17 September 2014, 22:07 GMT Comment by Allan McRae (Allan) - Saturday, 20 February 2016, 02:25 GMT
Not much that can be done here - gold does not treat the --as-needed option correctly. Closing as upstream bug. Use link above to track.

Loading...