]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Detect .eh_frame_hdr earlier for SIZEOF_HEADERS
authorAlan Modra <amodra@gmail.com>
Fri, 4 Feb 2022 09:00:47 +0000 (19:30 +1030)
committerAlan Modra <amodra@gmail.com>
Sat, 5 Feb 2022 06:15:38 +0000 (16:45 +1030)
Current code detects the need for PT_GNU_EH_FRAME using a field set by
_bfd_elf_discard_section_eh_frame_hdr, which is called fairly late in
the linking process.  Use the elf hash table eh_info instead, which is
set up earlier by size_dynamic_sections.

* elf-bfd.h (struct output_elf_obj_tdata): Delete eh_frame_hdr.
(elf_eh_frame_hdr): Don't define.
(_bfd_elf_discard_section_eh_frame_hdr): Update prototype.
* elf-eh-frame.c (_bfd_elf_discard_section_eh_frame_hdr): Delete
abfd parameter.  Don't set elf_eh_frame_hdr.
* elf.c (elf_eh_frame_hdr): New function.
(get_program_header_size): Adjust elf_eh_frame_hdr call.
(_bfd_elf_map_sections_to_segments): Likewise.

bfd/elf-bfd.h
bfd/elf-eh-frame.c
bfd/elf.c
bfd/elflink.c

index 138ef46791b2622f5979b90e3bdc2fe5dee7998e..1d3ae76339aa90dfcb300fe5eb3a1f26b52ec252 100644 (file)
@@ -1909,10 +1909,6 @@ struct output_elf_obj_tdata
   /* STT_SECTION symbols for each section */
   asymbol **section_syms;
 
-  /* Used to determine if PT_GNU_EH_FRAME segment header should be
-     created.  */
-  asection *eh_frame_hdr;
-
   /* NT_GNU_BUILD_ID note type info.  */
   struct
   {
@@ -2116,7 +2112,6 @@ struct elf_obj_tdata
 #define elf_seg_map(bfd)       (elf_tdata(bfd) -> o->seg_map)
 #define elf_link_info(bfd)     (elf_tdata(bfd) -> o->link_info)
 #define elf_next_file_pos(bfd) (elf_tdata(bfd) -> o->next_file_pos)
-#define elf_eh_frame_hdr(bfd)  (elf_tdata(bfd) -> o->eh_frame_hdr)
 #define elf_stack_flags(bfd)   (elf_tdata(bfd) -> o->stack_flags)
 #define elf_shstrtab(bfd)      (elf_tdata(bfd) -> o->strtab_ptr)
 #define elf_onesymtab(bfd)     (elf_tdata(bfd) -> symtab_section)
@@ -2412,7 +2407,7 @@ extern bool _bfd_elf_discard_section_eh_frame
 extern bool _bfd_elf_adjust_eh_frame_global_symbol
   (struct elf_link_hash_entry *, void *);
 extern bool _bfd_elf_discard_section_eh_frame_hdr
-  (bfd *, struct bfd_link_info *);
+  (struct bfd_link_info *);
 extern bfd_vma _bfd_elf_eh_frame_section_offset
   (bfd *, struct bfd_link_info *, asection *, bfd_vma);
 extern bool _bfd_elf_write_section_eh_frame
index a621fedbee86d4b5b2bf5c05688e85bbf93c4fd9..2e22d0c92158da5a53fb9e6ef60954ab92272f99 100644 (file)
@@ -1612,7 +1612,7 @@ _bfd_elf_discard_section_eh_frame
    input sections.  It finalizes the size of .eh_frame_hdr section.  */
 
 bool
-_bfd_elf_discard_section_eh_frame_hdr (bfd *abfd, struct bfd_link_info *info)
+_bfd_elf_discard_section_eh_frame_hdr (struct bfd_link_info *info)
 {
   struct elf_link_hash_table *htab;
   struct eh_frame_hdr_info *hdr_info;
@@ -1644,7 +1644,6 @@ _bfd_elf_discard_section_eh_frame_hdr (bfd *abfd, struct bfd_link_info *info)
        sec->size += 4 + hdr_info->u.dwarf.fde_count * 8;
     }
 
-  elf_eh_frame_hdr (abfd) = sec;
   return true;
 }
 
index 14c2c7ba734d4d0e5ccec7a637597aae08a97777..79f71aa81e2c74ad6fe79fa3c679c07958cf319f 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -4343,6 +4343,20 @@ _bfd_elf_compute_section_file_positions (bfd *abfd,
   return true;
 }
 
+/* Retrieve .eh_frame_hdr.  Prior to size_dynamic_sections the
+   function effectively returns whether --eh-frame-hdr is given on the
+   command line.  After size_dynamic_sections the result reflects
+   whether .eh_frame_hdr will actually be output (sizing isn't done
+   until ldemul_after_allocation).  */
+
+static asection *
+elf_eh_frame_hdr (const struct bfd_link_info *info)
+{
+  if (info != NULL && is_elf_hash_table (info->hash))
+    return elf_hash_table (info)->eh_info.hdr_sec;
+  return NULL;
+}
+
 /* Make an initial estimate of the size of the program header.  If we
    get the number wrong here, we'll redo section placement.  */
 
@@ -4379,7 +4393,7 @@ get_program_header_size (bfd *abfd, struct bfd_link_info *info)
       ++segs;
     }
 
-  if (elf_eh_frame_hdr (abfd))
+  if (elf_eh_frame_hdr (info))
     {
       /* We need a PT_GNU_EH_FRAME segment.  */
       ++segs;
@@ -5134,7 +5148,7 @@ _bfd_elf_map_sections_to_segments (bfd *abfd,
 
       /* If there is a .eh_frame_hdr section, throw in a PT_GNU_EH_FRAME
         segment.  */
-      eh_frame_hdr = elf_eh_frame_hdr (abfd);
+      eh_frame_hdr = elf_eh_frame_hdr (info);
       if (eh_frame_hdr != NULL
          && (eh_frame_hdr->output_section->flags & SEC_LOAD) != 0)
        {
index 2677561478dd1ff9bc9d6e495c06948f2d22f049..6fa18d9200798338ecc51e652909009ac5bcac40 100644 (file)
@@ -14888,7 +14888,7 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
 
   if (info->eh_frame_hdr_type
       && !bfd_link_relocatable (info)
-      && _bfd_elf_discard_section_eh_frame_hdr (output_bfd, info))
+      && _bfd_elf_discard_section_eh_frame_hdr (info))
     changed = 1;
 
   return changed;