Re: Range lists, zero-length functions, linker gc

Mark Wielaard
2020-05-31T22:30:08Z

Hi,

On Sun, May 31, 2020 at 01:49:12PM -0700, David Blaikie wrote:
> On Sun, May 31, 2020 at 1:41 PM Mark Wielaard <mark@klomp.org> wrote:
> > On Sun, May 31, 2020 at 11:55:06AM -0700, Fangrui Song via Elfutils-devel wrote:
> > > I am eager to know what you think
> > > of the ideas from binutils/gdb/elfutils's perspective.
> >
> > I think this is a producer problem. If a (code) section can be totally
> > dropped then the associated (.debug) sections should have been
> > generated together with that (code) section in a COMDAT group. That
> > way when the linker drops that section, all the associated sections in
> > that COMDAT group will get dropped with it. If you don't do that, then
> > the DWARF is malformed and there is not much a consumer can do about
> > it.
> >
> > Said otherwise, I don't think it is correct for the linker (with
> > --gc-sections) to drop any sections that have references to it
> > (through relocation symbols) from other (.debug) sections.
>
> That's probably not practical for at least some users - the
> easiest/most thorough counter-example is Split DWARF - the DWARF is in
> another file the linker can't see. All the linker sees is a list of
> addresses (debug_addr).

I might be missing something, but I think this works fine with Split
DWARF. As long as you make sure that the .dwo files/sections are
separated along the same lines as the ELF section groups are. That
means each section group either gets its own .dwo file, or you
generate the .dwo sections in the same section group in the same
object file using the SHF_EXCLUDED trick. That way each .debug.dwo
uses their own index into the separate .debug_addr tables. If that
group, with the .debug_addr table, gets discarded, then the reference
to the .dwo also disappears and it simply won't be used.

Cheers,

Mark