Bug 27990 - ld --trace: Print the symbol which leads to archive extraction
Summary: ld --trace: Print the symbol which leads to archive extraction
Status: UNCONFIRMED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-06-16 23:38 UTC by Fangrui Song
Modified: 2021-06-17 07:58 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fangrui Song 2021-06-16 23:38:28 UTC
% gcc a.c -static -fuse-ld=bfd -Wl,-t
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crt1.o
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crti.o
/usr/lib/gcc/x86_64-linux-gnu/10/crtbeginT.o
/tmp/ccczCGoq.o
/usr/lib/gcc/x86_64-linux-gnu/10/libgcc.a
/usr/lib/gcc/x86_64-linux-gnu/10/libgcc_eh.a
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libc.a
/usr/lib/gcc/x86_64-linux-gnu/10/libgcc.a
/usr/lib/gcc/x86_64-linux-gnu/10/libgcc_eh.a
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libc.a
/usr/lib/gcc/x86_64-linux-gnu/10/libgcc.a
/usr/lib/gcc/x86_64-linux-gnu/10/libgcc_eh.a
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libc.a
/usr/lib/gcc/x86_64-linux-gnu/10/crtend.o
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crtn.o

gold's includes archive member names, which is IMHO more useful

% gcc a.c -static -fuse-ld=gold -Wl,-t
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crt1.o
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crti.o
/usr/lib/gcc/x86_64-linux-gnu/10/crtbeginT.o
/tmp/ccX5yMOZ.o
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libc.a(libc-start.o)
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libc.a(check_fds.o)
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libc.a(libc-tls.o)
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libc.a(elf-init.o)
...

When debugging multiple definition errors, we sometimes want to know the origin symbols.
I think including the symbol causing archive member extraction in --trace can be useful, e.g.

```
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crt1.o
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crti.o
/usr/lib/gcc/x86_64-linux-gnu/10/crtbeginT.o
/tmp/ccX5yMOZ.o
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libc.a(libc-start.o)\txxx
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libc.a(check_fds.o)\tyyy
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libc.a(libc-tls.o)\tzzz
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libc.a(elf-init.o)\twww
```
Comment 1 Fangrui Song 2021-06-16 23:40:54 UTC
I'll add a comment that on Mach-O, ld64 -why_live gives you clue why a symbol is defined (via a potentially long archive member extraction chain).

The --trace feature can make some other debugging tasks convenient.
Comment 2 Andreas Schwab 2021-06-17 07:58:49 UTC
That information is already part of the map file, including the symbol which has triggered the inclusion.