This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [RFC] PR ld/13621
- From: Alan Modra <amodra at gmail dot com>
- To: "H.J. Lu" <hjl dot tools at gmail dot com>
- Cc: Richard Henderson <rth at redhat dot com>, binutils at sourceware dot org, Mark Wielaard <mjw at redhat dot com>
- Date: Mon, 7 May 2012 15:50:11 +0930
- Subject: Re: [RFC] PR ld/13621
- References: <4F25EAD1.7040601@redhat.com> <CAMe9rOq4gJkZPhbFqJ3T=O52Yqd5-Ud0eUdMHkhkf0xGc-=SsQ@mail.gmail.com>
On Sat, May 05, 2012 at 07:42:40AM -0700, H.J. Lu wrote:
> On Sun, Jan 29, 2012 at 4:56 PM, Richard Henderson <rth@redhat.com> wrote:
> > This PR is about elflint warning about symbols outside of the section
> > with which they are associated.
> >
> > The problem can be seen with just about any zero-sized section, nearly
> > all of which are removed by strip_excluded_output_sections. ?Then, the
> > symbols are relocated to a "near by" section by _bfd_fix_excluded_sec_syms.
> >
> > This elflint warning will affect essentially all binaries built with
> > gcc4.7 because of the crt symbol __TMC_END__, present in the normally
> > empty section .tm_clone_table. ?Thus it seems worthwhile to fix this.
> >
> > At first I attempted to SEC_KEEP any section with global symbols. ?But
> > this ran into all sorts of testsuite failures re .got. ?In those cases
> > the _GLOBAL_OFFSET_TABLE_ symbol still exists, which causes .got to
> > be kept instead of removed as unused later in the link.
> >
> > A second best solution would seem to be to merely move the offending
> > symbols to the ABS section rather than associate them with some random
> > section.
> >
> > Thoughts?
> >
>
> This patch has been reverted. Here is a different patch to keep
> empty section if a definition uses it.
As Richard said, this results in testsuite failures. If you or anyone
else wants this patch, you get to fix the testsuite.. Here's another
idea. Put symbols that don't belong in any of the usual sections into
a non-alloc section that elflint can recognise and so silence the
dubious warning.
I'm not really enthusiastic about the following, but it does seem to
work.
Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.552
diff -u -p -r1.552 elf.c
--- bfd/elf.c 24 Apr 2012 05:12:30 -0000 1.552
+++ bfd/elf.c 7 May 2012 04:38:55 -0000
@@ -2620,7 +2620,8 @@ elf_fake_sections (bfd *abfd, asection *
else
sh_type = bfd_elf_get_default_section_type (asect->flags);
- if (this_hdr->sh_type == SHT_NULL)
+ if (this_hdr->sh_type == SHT_NULL
+ && asect->name[0] != 0)
this_hdr->sh_type = sh_type;
else if (this_hdr->sh_type == SHT_NOBITS
&& sh_type == SHT_PROGBITS
@@ -2640,15 +2641,6 @@ elf_fake_sections (bfd *abfd, asection *
default:
break;
- case SHT_STRTAB:
- case SHT_INIT_ARRAY:
- case SHT_FINI_ARRAY:
- case SHT_PREINIT_ARRAY:
- case SHT_NOTE:
- case SHT_NOBITS:
- case SHT_PROGBITS:
- break;
-
case SHT_HASH:
this_hdr->sh_entsize = bed->s->sizeof_hash_entry;
break;
@@ -2951,7 +2943,8 @@ assign_section_numbers (bfd *abfd, struc
{
d = elf_section_data (sec);
- if (d->this_hdr.sh_type != SHT_GROUP)
+ if (d->this_hdr.sh_type != SHT_GROUP
+ && d->this_hdr.sh_type != SHT_NULL)
d->this_idx = section_number++;
_bfd_elf_strtab_addref (elf_shstrtab (abfd), d->this_hdr.sh_name);
if (d->rel.hdr)
@@ -2999,6 +2992,17 @@ assign_section_numbers (bfd *abfd, struc
_bfd_elf_strtab_finalize (elf_shstrtab (abfd));
t->shstrtab_hdr.sh_size = _bfd_elf_strtab_size (elf_shstrtab (abfd));
+ sec = bfd_get_section_by_name (abfd, "");
+ if (sec != NULL)
+ {
+ d = elf_section_data (sec);
+
+ /* This chooses .symtab for the section we've used for symbols
+ that belong in no other section. */
+ if (d->this_hdr.sh_type == SHT_NULL)
+ d->this_idx = section_number - 2;
+ }
+
elf_numsections (abfd) = section_number;
elf_elfheader (abfd)->e_shnum = section_number;
@@ -3039,7 +3043,8 @@ assign_section_numbers (bfd *abfd, struc
d = elf_section_data (sec);
- i_shdrp[d->this_idx] = &d->this_hdr;
+ if (d->this_hdr.sh_type != SHT_NULL)
+ i_shdrp[d->this_idx] = &d->this_hdr;
if (d->rel.idx != 0)
i_shdrp[d->rel.idx] = d->rel.hdr;
if (d->rela.idx != 0)
Index: bfd/linker.c
===================================================================
RCS file: /cvs/src/src/bfd/linker.c,v
retrieving revision 1.95
diff -u -p -r1.95 linker.c
--- bfd/linker.c 5 May 2012 04:51:15 -0000 1.95
+++ bfd/linker.c 7 May 2012 04:39:09 -0000
@@ -3161,10 +3160,7 @@ _bfd_nearby_section (bfd *obfd, asection
as S would have been if it was kept. */
best = next;
if (prev == NULL)
- {
- if (next == NULL)
- best = bfd_abs_section_ptr;
- }
+ ;
else if (next == NULL)
best = prev;
else if (((prev->flags ^ next->flags)
@@ -3198,6 +3194,28 @@ _bfd_nearby_section (bfd *obfd, asection
best = prev;
}
+ if (bfd_get_flavour (obfd) == bfd_target_elf_flavour)
+ {
+ if (best == NULL
+ || addr < best->vma
+ || addr > best->vma + best->size)
+ {
+ /* For ELF, if symbols don't belong in one of the normal
+ sections, don't put them in the absolute section as this
+ will result in SHN_ABS symbols. Instead, we'll make them
+ belong to the .symtab section via this dummy section
+ (which will not be output). */
+ best = bfd_get_section_by_name (obfd, "");
+ if (best == NULL)
+ {
+ best = bfd_make_section_anyway_with_flags (obfd, "", SEC_READONLY);
+ best->output_section = best;
+ }
+ }
+ }
+ else if (best == NULL)
+ best = bfd_abs_section_ptr;
+
return best;
}
--
Alan Modra
Australia Development Lab, IBM