Damage of .debug_macro by --gc-sections when an unused object file is linked
Simon Kirby
sim@simulated.ca
Wed Sep 10 07:12:15 GMT 2025
Hello!
I would like to report and/or fix an issue I am experiencing, but I am
not entirely sure what is at fault.
The short of it is that when using gcc to build (with -g3) and then link
several simple .o files together (with -Wl,--gc-sections), the resulting
.debug_macro section is corrupted (*) in a way that causes invalid macro
definition information to be printed by GDB if an unused (entirely
gc-able) object file is included, but is fine if not.
(*): "readelf --debug-dump=macro" outputs multiple "offset : 0" lines
I believe GDB is overwriting data at offset 0 depending on the order in
which the .debug_macro is combined.
I have created a minimized testcast that shows the issue including the
resulting output from GDB, which is probably small enough to inline,
but in any event: https://github.com/sim-/debug_macro_vs_gc_sections
Thanks,
Simon-
More information about the Binutils
mailing list