How to sort mixed DWARF32 and DWARF64 .debug_*

Nick Clifton
Fri Nov 13 11:49:14 GMT 2020

Hi Fangrui,

> Let me rephrase the problem:
> If a .debug_* output section S can be larger than 32-bit and its section
> offset is referenced by a DWARF32 input section of itself or another
> .debug_* output section,
> the relocation may be subject to 32-bit relocation overflow.

But in this case using DWARF32 is the wrong thing to do.  The producers
should be generating DWARF64.  Mitigation is all very well, but it will
not solve the overall problem, nor will it guarantee good debug info.

> (We can imagine that for a known large project, most compilation units
> are DWARF64.
> Some archives may have DWARF32 debug info and may be difficult to rebuild.
> This partition scheme can solve the problems.)

Ok, although I still think that the onus should be on the library maintainers
to rebuild their binaries.  But I take your point that this might not always
be practical.

> Does such an option --dwarf32-before-dwarf64 look good to binutils folks?

Would this result in multiple copies of the same section ?  Eg would the
output file contain say two .debug_info sections, one for 32-bit dwarf
and one for 64-bit dwarf, and the second one would be further down in the
memory map ?

I do not actually have any objections to the idea, although it does occur
to me that maybe it should be extended to cover other types of section as
well.  (Eg 32-bits vs 64-bit notes).

Hmmm - maybe this would be better expressed in the linker script, rather
than as a command line option.  For example:

   .debug_info     0 : { *(.debug_info${RELOCATING+ .gnu.linkonce.wi.*}) }
   .debug_abbrev   0 : { *(.debug_abbrev) }
   .debug_line     0 : { *(.debug_line${RELOCATING+ .debug_line.* .debug_line_end}) }

Could be replaced by:

   .debug_info     0 : { IS_32BIT(*(.debug_info${RELOCATING+ .gnu.linkonce.wi.*})) }
   .debug_abbrev   0 : { IS_32BIT(*(.debug_abbrev)) }
   .debug_line     0 : { IS_32BIT(*(.debug_line${RELOCATING+ .debug_line.* .debug_line_end})) }
   [...and then later on....]
   .debug_info     0 : { IS_64BIT(*(.debug_info${RELOCATING+ .gnu.linkonce.wi.*})) }
   .debug_abbrev   0 : { IS_64BIT(*(.debug_abbrev)) }
   .debug_line     0 : { IS_64BIT(*(.debug_line${RELOCATING+ .debug_line.* .debug_line_end})) }

This would work for any section types that come in 32-bit and 64-bit flavours...

> I'd be happy to act as a bridge communicating thoughts from both sides:)

Are you volunteering to write a patch as well ? :-)  Not to worry, I will
have a go myself as long as we can agree on a solution that works for both
the binutils and lld communities.


More information about the Binutils mailing list