Gold complains about relocations from note sections to discarded sections

Cary Coutant ccoutant@gmail.com
Fri Jul 13 22:20:00 GMT 2018


I wonder if we shouldn't handle these relocations the same as for
debug info -- with CB_PRETEND, which tries to map the reference to the
corresponding kept section (in the case of a COMDAT group). For gc'ed
sections, it would be equivalent to CB_IGNORE.

We've got a few options: (1) look for specific section names (ick, but
that's what we're doing currently), (2) look for SHT_NOTE sections, or
(3) look for !SHF_ALLOC sections. The third choice would take care of
both debug and note sections with a single condition.

There are also SHT_NOTE + SHF_ALLOC sections. I'm not sure if any of
them would be expected to have such relocations in them, and if so,
what we should do about them.

What does ld.bfd do?

-cary


On Fri, Jul 13, 2018 at 2:33 AM, Nick Clifton <nickc@redhat.com> wrote:
> Hi Ian, Hi Cary,
>
>   Gold will complain if there is a relocation in a note section
>   that references a symbol in a discarded section.  For example:
>
>   % cat note.s
>         .section        .text.unused
>         .word 1
>
>   % as --generate-missing-build-notes=yes note.s -o note.o
>   % gold --gc-sections note.o
>   note.o(.gnu.build.attributes+0x14): error: relocation refers to local symbol "" [1], which is defined in a discarded section
>   note.o(.gnu.build.attributes+0x1c): error: relocation refers to local symbol "" [1], which is defined in a discarded section
>   note.o(.gnu.build.attributes+0x38): error: relocation refers to local symbol "" [4], which is defined in a discarded section
>   note.o(.gnu.build.attributes+0x40): error: relocation refers to local symbol "" [4], which is defined in a discarded section
>
>   I have a small patch (see below) which handles this specific case, but
>   I really think that gold ought to be ignoring any relocs in note
>   sections (or maybe any non-ALLOC section) that are against discarded
>   sections.
>
>   What do you think ?
>
> Cheers
>   Nick
>
> diff --git a/gold/target-reloc.h b/gold/target-reloc.h
> index 6bde51dc31..3b4decf262 100644
> --- a/gold/target-reloc.h
> +++ b/gold/target-reloc.h
> @@ -136,6 +136,7 @@ class Default_comdat_behavior
>      if (Layout::is_debug_info_section(name))
>        return CB_PRETEND;
>      if (strcmp(name, ".eh_frame") == 0
> +       || strcmp(name, ".gnu.build.attributes") == 0   // FIXME: We should really be checking the section type for ST_NOTE...
>         || strcmp(name, ".gcc_except_table") == 0)
>        return CB_IGNORE;
>      return CB_ERROR;



More information about the Binutils mailing list