Don't attach linker created section to --just-syms bfd
authorAlan Modra <amodra@gmail.com>
Sun, 25 Jun 2017 23:40:22 +0000 (09:10 +0930)
committerAlan Modra <amodra@gmail.com>
Sun, 25 Jun 2017 23:40:22 +0000 (09:10 +0930)
All sections on a --just-syms bfd are discarded from the output, so
attaching linker created sections to such a bfd results in errors.
In other cases, like the .note.GNU-stack check, it's wrong to have a
--just-syms object potentially affect the output.

bfd/
* elflink.c (_bfd_elf_link_create_dynstrtab): Don't make dynobj
a --just-syms bfd.
(_bfd_elf_size_group_sections): Skip --just-syms bfds.
(bfd_elf_size_dynamic_sections): Ignore .note.GNU-stack and
.preinit_array on --just-syms bfds.
(_bfd_elf_gc_mark_extra_sections): Skip --just-syms bfds.
(elf_gc_sweep, bfd_elf_parse_eh_frame_entries): Likewise.
(bfd_elf_gc_sections, bfd_elf_discard_info): Likewise.
ld/
* emultempl/elf32.em (gld${EMULATION_NAME}_after_open): Skip
--just-syms bfds when looking for a place to attach .note.gnu.build-id
and .eh_frame_hdr sections.  Delete dead code.

bfd/ChangeLog
bfd/elflink.c
ld/ChangeLog
ld/emultempl/elf32.em

index 945cb68..c5f1f23 100644 (file)
@@ -1,3 +1,14 @@
+2017-06-26  Alan Modra  <amodra@gmail.com>
+
+       * elflink.c (_bfd_elf_link_create_dynstrtab): Don't make dynobj
+       a --just-syms bfd.
+       (_bfd_elf_size_group_sections): Skip --just-syms bfds.
+       (bfd_elf_size_dynamic_sections): Ignore .note.GNU-stack and
+       .preinit_array on --just-syms bfds.
+       (_bfd_elf_gc_mark_extra_sections): Skip --just-syms bfds.
+       (elf_gc_sweep, bfd_elf_parse_eh_frame_entries): Likewise.
+       (bfd_elf_gc_sections, bfd_elf_discard_info): Likewise.
+
 2017-06-25  Sergei Trofimovich  <slyfox@gentoo.org>
 
        * elf.c (find_link): Bounds check "hint".
index e35ec63..471e8ad 100644 (file)
@@ -218,9 +218,13 @@ _bfd_elf_link_create_dynstrtab (bfd *abfd, struct bfd_link_info *info)
       if ((abfd->flags & (DYNAMIC | BFD_PLUGIN)) != 0)
        {
          bfd *ibfd;
+         asection *s;
          for (ibfd = info->input_bfds; ibfd; ibfd = ibfd->link.next)
            if ((ibfd->flags
-                & (DYNAMIC | BFD_LINKER_CREATED | BFD_PLUGIN)) == 0)
+                & (DYNAMIC | BFD_LINKER_CREATED | BFD_PLUGIN)) == 0
+               && bfd_get_flavour (ibfd) == bfd_target_elf_flavour
+               && !((s = ibfd->sections) != NULL
+                    && s->sec_info_type == SEC_INFO_TYPE_JUST_SYMS))
              {
                abfd = ibfd;
                break;
@@ -5861,9 +5865,12 @@ bfd_boolean
 _bfd_elf_size_group_sections (struct bfd_link_info *info)
 {
   bfd *ibfd;
+  asection *s;
 
   for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
     if (bfd_get_flavour (ibfd) == bfd_target_elf_flavour
+       && (s = ibfd->sections) != NULL
+       && s->sec_info_type != SEC_INFO_TYPE_JUST_SYMS
        && !_bfd_elf_fixup_group_sections (ibfd, bfd_abs_section_ptr))
       return FALSE;
   return TRUE;
@@ -6511,6 +6518,10 @@ bfd_elf_size_dynamic_sections (bfd *output_bfd,
          if (inputobj->flags
              & (DYNAMIC | EXEC_P | BFD_PLUGIN | BFD_LINKER_CREATED))
            continue;
+         s = inputobj->sections;
+         if (s == NULL || s->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
+           continue;
+
          s = bfd_get_section_by_name (inputobj, ".note.GNU-stack");
          if (s)
            {
@@ -6660,9 +6671,10 @@ bfd_elf_size_dynamic_sections (bfd *output_bfd,
              bfd *sub;
              asection *o;
 
-             for (sub = info->input_bfds; sub != NULL;
-                  sub = sub->link.next)
-               if (bfd_get_flavour (sub) == bfd_target_elf_flavour)
+             for (sub = info->input_bfds; sub != NULL; sub = sub->link.next)
+               if (bfd_get_flavour (sub) == bfd_target_elf_flavour
+                   && (o = sub->sections) != NULL
+                   && o->sec_info_type != SEC_INFO_TYPE_JUST_SYMS)
                  for (o = sub->sections; o != NULL; o = o->next)
                    if (elf_section_data (o)->this_hdr.sh_type
                        == SHT_PREINIT_ARRAY)
@@ -12911,6 +12923,9 @@ _bfd_elf_gc_mark_extra_sections (struct bfd_link_info *info,
 
       if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
        continue;
+      isec = ibfd->sections;
+      if (isec == NULL || isec->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
+       continue;
 
       /* Ensure all linker created sections are kept,
         see if any other section is already marked,
@@ -13016,6 +13031,9 @@ elf_gc_sweep (bfd *abfd, struct bfd_link_info *info)
       if (bfd_get_flavour (sub) != bfd_target_elf_flavour
          || !(*bed->relocs_compatible) (sub->xvec, abfd->xvec))
        continue;
+      o = sub->sections;
+      if (o == NULL || o->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
+       continue;
 
       for (o = sub->sections; o != NULL; o = o->next)
        {
@@ -13253,6 +13271,9 @@ bfd_elf_parse_eh_frame_entries (bfd *abfd ATTRIBUTE_UNUSED,
 
       if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
        continue;
+      sec = ibfd->sections;
+      if (sec == NULL || sec->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
+       continue;
 
       if (!init_reloc_cookie (&cookie, info, ibfd))
        return FALSE;
@@ -13300,6 +13321,9 @@ bfd_elf_gc_sections (bfd *abfd, struct bfd_link_info *info)
       asection *sec;
       struct elf_reloc_cookie cookie;
 
+      sec = sub->sections;
+      if (sec == NULL || sec->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
+       continue;
       sec = bfd_get_section_by_name (sub, ".eh_frame");
       while (sec && init_reloc_cookie_for_section (&cookie, info, sec))
        {
@@ -13336,6 +13360,10 @@ bfd_elf_gc_sections (bfd *abfd, struct bfd_link_info *info)
          || !(*bed->relocs_compatible) (sub->xvec, abfd->xvec))
        continue;
 
+      o = sub->sections;
+      if (o == NULL || o->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
+       continue;
+
       /* Start at sections marked with SEC_KEEP (ref _bfd_elf_gc_keep).
         Also treat note sections as a root, if the section is not part
         of a group.  */
@@ -13840,9 +13868,13 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
   for (abfd = info->input_bfds; abfd != NULL; abfd = abfd->link.next)
     {
       const struct elf_backend_data *bed;
+      asection *s;
 
       if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
        continue;
+      s = abfd->sections;
+      if (s == NULL || s->sec_info_type == SEC_INFO_TYPE_JUST_SYMS)
+       continue;
 
       bed = get_elf_backend_data (abfd);
 
index bd21ad6..1db5afa 100644 (file)
@@ -1,3 +1,9 @@
+2017-06-26  Alan Modra  <amodra@gmail.com>
+
+       * emultempl/elf32.em (gld${EMULATION_NAME}_after_open): Skip
+       --just-syms bfds when looking for a place to attach .note.gnu.build-id
+       and .eh_frame_hdr sections.  Delete dead code.
+
 2017-06-24  Thomas Preud'homme  <thomas.preudhomme@arm.com>
 
        * testsuite/ld-arm/arm-elf.exp (EABI attribute merging 11): New test.
index 325d847..d2551b6 100644 (file)
@@ -1245,7 +1245,8 @@ gld${EMULATION_NAME}_after_open (void)
       for (abfd = link_info.input_bfds;
           abfd != (bfd *) NULL; abfd = abfd->link.next)
        if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
-           && bfd_count_sections (abfd) != 0)
+           && bfd_count_sections (abfd) != 0
+           && !((lang_input_statement_type *) abfd->usrdata)->flags.just_syms)
          break;
 
       /* PR 10555: If there are no ELF input files do not try to
@@ -1285,6 +1286,10 @@ gld${EMULATION_NAME}_after_open (void)
       for (abfd = link_info.input_bfds; abfd; abfd = abfd->link.next)
        {
          int type = 0;
+
+         if (((lang_input_statement_type *) abfd->usrdata)->flags.just_syms)
+           continue;
+
          for (s = abfd->sections; s && type < COMPACT_EH_HDR; s = s->next)
            {
              const char *name = bfd_get_section_name (abfd, s);
@@ -1323,9 +1328,6 @@ gld${EMULATION_NAME}_after_open (void)
 
          if (seen_type == COMPACT_EH_HDR)
            link_info.eh_frame_hdr_type = COMPACT_EH_HDR;
-
-         if (bfd_count_sections (abfd) == 0)
-           continue;
        }
       if (elfbfd)
        {