This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Return error status from bfd_elf_discard_info


This tidy came about from looking into whether we could run
bfd_elf_discard_info earlier, in order to avoid R_*_NONE dynamic
relocations when not using relative encoding for personality
functions.  It turns out that bfd_elf_discard_info indeed can be run
before elf_backend_size_dynamic_sections (which is where we allocate
dynamic relocs), but then those backends that emit PLT .eh_frame info
won't have their PLT CIEs merged.  You can't emit the PLT .eh_frame
earlier than elf_backend_size_dynamic_sections because that's where
the backend decides whether a PLT is used.  So we'd need to feed the
PLT .eh_frame into _bfd_elf_parse_eh_frame and
_bfd_elf_discard_section_eh_frame later.  Reasonable easy to do I
think, but well, I haven't written it yet.

bfd/
	* elflink.c (bfd_elf_discard_info): Return int error status.
	* stabs.c (_bfd_discard_section_stabs): Comment typo fix.
	* bfd-in.h (bfd_elf_discard_info): Updata prototype.
	* bfd-in2.h: Regenerate.
ld/
	* emultempl/aarch64elf.em (gld${EMULATION_NAME}_after_allocation):
	Handle error status from bfd_elf_discard_info.
	* emultempl/armelf.em: Likewise.
	* emultempl/elf32.em: Likewise.
	* emultempl/hppaelf.em: Likewise.
	* emultempl/metagelf.em: Likewise.
	* emultempl/nios2elf.em: Likewise.
	* emultempl/ppc64elf.em: Likewise.
	* emultempl/tic6xdsbt.em: Likewise.
	* emultempl/vms.em: Likewise.

diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h
index 83f125b..bcb9fdc 100644
--- a/bfd/bfd-in.h
+++ b/bfd/bfd-in.h
@@ -658,7 +658,7 @@ extern int bfd_elf_get_dyn_lib_class
   (bfd *);
 extern struct bfd_link_needed_list *bfd_elf_get_runpath_list
   (bfd *, struct bfd_link_info *);
-extern bfd_boolean bfd_elf_discard_info
+extern int bfd_elf_discard_info
   (bfd *, struct bfd_link_info *);
 extern unsigned int _bfd_elf_default_action_discarded
   (struct bfd_section *);
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 5e5af32..d20f357 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -12629,21 +12629,21 @@ bfd_elf_reloc_symbol_deleted_p (bfd_vma offset, void *cookie)
 }
 
 /* Discard unneeded references to discarded sections.
-   Returns TRUE if any section's size was changed.  */
-/* This function assumes that the relocations are in sorted order,
-   which is true for all known assemblers.  */
+   Returns -1 on error, 1 if any section's size was changed, 0 if
+   nothing changed.  This function assumes that the relocations are in
+   sorted order, which is true for all known assemblers.  */
 
-bfd_boolean
+int
 bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
 {
   struct elf_reloc_cookie cookie;
   asection *o;
   bfd *abfd;
-  bfd_boolean ret = FALSE;
+  int changed = 0;
 
   if (info->traditional_format
       || !is_elf_hash_table (info->hash))
-    return FALSE;
+    return 0;
 
   o = bfd_get_section_by_name (output_bfd, ".stab");
   if (o != NULL)
@@ -12662,13 +12662,13 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
 	    continue;
 
 	  if (!init_reloc_cookie_for_section (&cookie, info, i))
-	    return FALSE;
+	    return -1;
 
 	  if (_bfd_discard_section_stabs (abfd, i,
 					  elf_section_data (i)->sec_info,
 					  bfd_elf_reloc_symbol_deleted_p,
 					  &cookie))
-	    ret = TRUE;
+	    changed = 1;
 
 	  fini_reloc_cookie_for_section (&cookie, i);
 	}
@@ -12692,13 +12692,13 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
 	    continue;
 
 	  if (!init_reloc_cookie_for_section (&cookie, info, i))
-	    return FALSE;
+	    return -1;
 
 	  _bfd_elf_parse_eh_frame (abfd, info, i, &cookie);
 	  if (_bfd_elf_discard_section_eh_frame (abfd, info, i,
 						 bfd_elf_reloc_symbol_deleted_p,
 						 &cookie))
-	    ret = TRUE;
+	    changed = 1;
 
 	  fini_reloc_cookie_for_section (&cookie, i);
 	}
@@ -12717,10 +12717,10 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
       if (bed->elf_backend_discard_info != NULL)
 	{
 	  if (!init_reloc_cookie (&cookie, info, abfd))
-	    return FALSE;
+	    return -1;
 
 	  if ((*bed->elf_backend_discard_info) (abfd, &cookie, info))
-	    ret = TRUE;
+	    changed = 1;
 
 	  fini_reloc_cookie (&cookie, abfd);
 	}
@@ -12729,9 +12729,9 @@ bfd_elf_discard_info (bfd *output_bfd, struct bfd_link_info *info)
   if (info->eh_frame_hdr
       && !info->relocatable
       && _bfd_elf_discard_section_eh_frame_hdr (output_bfd, info))
-    ret = TRUE;
+    changed = 1;
 
-  return ret;
+  return changed;
 }
 
 bfd_boolean
diff --git a/bfd/stabs.c b/bfd/stabs.c
index 784eb97..e6526c5 100644
--- a/bfd/stabs.c
+++ b/bfd/stabs.c
@@ -536,7 +536,7 @@ _bfd_discard_section_stabs (bfd *abfd,
        link, so we should just ignore them.  */
     return FALSE;
 
-  /* We should have initialized our data in _bfd_link_stab_sections.
+  /* We should have initialized our data in _bfd_link_section_stabs.
      If there was some bizarre error reading the string sections, though,
      we might not have.  Bail rather than asserting.  */
   if (psecinfo == NULL)
diff --git a/ld/emultempl/aarch64elf.em b/ld/emultempl/aarch64elf.em
index 6134855..bb58901 100644
--- a/ld/emultempl/aarch64elf.em
+++ b/ld/emultempl/aarch64elf.em
@@ -219,20 +219,27 @@ build_section_lists (lang_statement_union_type *statement)
 static void
 gld${EMULATION_NAME}_after_allocation (void)
 {
+  int ret;
+
   /* bfd_elf32_discard_info just plays with debugging sections,
      ie. doesn't affect any code, so we can delay resizing the
      sections.  It's likely we'll resize everything in the process of
      adding stubs.  */
-  if (bfd_elf_discard_info (link_info.output_bfd, & link_info))
+  ret = bfd_elf_discard_info (link_info.output_bfd, & link_info);
+  if (ret < 0)
+    {
+      einfo ("%X%P: .eh_frame/.stab edit: %E\n");
+      return;
+    }
+  else if (ret > 0)
     need_laying_out = 1;
 
   /* If generating a relocatable output file, then we don't
      have to examine the relocs.  */
   if (stub_file != NULL && !link_info.relocatable)
     {
-      int ret = elf${ELFSIZE}_aarch64_setup_section_lists (link_info.output_bfd,
-						   & link_info);
-
+      ret = elf${ELFSIZE}_aarch64_setup_section_lists (link_info.output_bfd,
+						       &link_info);
       if (ret != 0)
 	{
 	  if (ret < 0)
diff --git a/ld/emultempl/armelf.em b/ld/emultempl/armelf.em
index 34028ee..371b440 100644
--- a/ld/emultempl/armelf.em
+++ b/ld/emultempl/armelf.em
@@ -271,6 +271,8 @@ compare_output_sec_vma (const void *a, const void *b)
 static void
 gld${EMULATION_NAME}_after_allocation (void)
 {
+  int ret;
+
   if (!link_info.relocatable)
     {
       /* Build a sorted list of input text sections, then use that to process
@@ -325,15 +327,20 @@ gld${EMULATION_NAME}_after_allocation (void)
      ie. doesn't affect any code, so we can delay resizing the
      sections.  It's likely we'll resize everything in the process of
      adding stubs.  */
-  if (bfd_elf_discard_info (link_info.output_bfd, & link_info))
+  ret = bfd_elf_discard_info (link_info.output_bfd, & link_info);
+  if (ret < 0)
+    {
+      einfo ("%X%P: .eh_frame/.stab edit: %E\n");
+      return;
+    }
+  else if (ret > 0)
     need_laying_out = 1;
 
   /* If generating a relocatable output file, then we don't
      have to examine the relocs.  */
   if (stub_file != NULL && !link_info.relocatable)
     {
-      int  ret = elf32_arm_setup_section_lists (link_info.output_bfd, & link_info);
-
+      ret = elf32_arm_setup_section_lists (link_info.output_bfd, &link_info);
       if (ret != 0)
 	{
 	  if (ret < 0)
diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em
index 39b4ccd..67c437d 100644
--- a/ld/emultempl/elf32.em
+++ b/ld/emultempl/elf32.em
@@ -1942,9 +1942,12 @@ fragment <<EOF
 static void
 gld${EMULATION_NAME}_after_allocation (void)
 {
-  bfd_boolean need_layout = bfd_elf_discard_info (link_info.output_bfd,
-						  &link_info);
-  gld${EMULATION_NAME}_map_segments (need_layout);
+  int need_layout = bfd_elf_discard_info (link_info.output_bfd, &link_info);
+
+  if (need_layout < 0)
+    einfo ("%X%P: .eh_frame/.stab edit: %E\n");
+  else
+    gld${EMULATION_NAME}_map_segments (need_layout);
 }
 EOF
 fi
diff --git a/ld/emultempl/hppaelf.em b/ld/emultempl/hppaelf.em
index 7cb4537..6955796 100644
--- a/ld/emultempl/hppaelf.em
+++ b/ld/emultempl/hppaelf.em
@@ -242,20 +242,26 @@ build_section_lists (lang_statement_union_type *statement)
 static void
 gld${EMULATION_NAME}_after_allocation (void)
 {
+  int ret;
+
   /* bfd_elf_discard_info just plays with data and debugging sections,
      ie. doesn't affect code size, so we can delay resizing the
      sections.  It's likely we'll resize everything in the process of
      adding stubs.  */
-  if (bfd_elf_discard_info (link_info.output_bfd, &link_info))
+  ret = bfd_elf_discard_info (link_info.output_bfd, &link_info);
+  if (ret < 0)
+    {
+      einfo ("%X%P: .eh_frame/.stab edit: %E\n");
+      return;
+    }
+  else if (ret > 0)
     need_laying_out = 1;
 
   /* If generating a relocatable output file, then we don't
      have to examine the relocs.  */
   if (stub_file != NULL && !link_info.relocatable)
     {
-      int ret = elf32_hppa_setup_section_lists (link_info.output_bfd,
-						&link_info);
-
+      ret = elf32_hppa_setup_section_lists (link_info.output_bfd, &link_info);
       if (ret != 0)
 	{
 	  if (ret < 0)
diff --git a/ld/emultempl/metagelf.em b/ld/emultempl/metagelf.em
index 1f77ecd..97739dc 100644
--- a/ld/emultempl/metagelf.em
+++ b/ld/emultempl/metagelf.em
@@ -219,20 +219,26 @@ build_section_lists (lang_statement_union_type *statement)
 static void
 gld${EMULATION_NAME}_after_allocation (void)
 {
+  int ret;
+
   /* bfd_elf_discard_info just plays with data and debugging sections,
      ie. doesn't affect code size, so we can delay resizing the
      sections.  It's likely we'll resize everything in the process of
      adding stubs.  */
-  if (bfd_elf_discard_info (link_info.output_bfd, &link_info))
+  ret = bfd_elf_discard_info (link_info.output_bfd, &link_info);
+  if (ret < 0)
+    {
+      einfo ("%X%P: .eh_frame/.stab edit: %E\n");
+      return;
+    }
+  else if (ret > 0)
     need_laying_out = 1;
 
   /* If generating a relocatable output file, then we don't
      have to examine the relocs.  */
   if (stub_file != NULL && !link_info.relocatable)
     {
-      int ret = elf_metag_setup_section_lists (link_info.output_bfd,
-					       &link_info);
-
+      ret = elf_metag_setup_section_lists (link_info.output_bfd, &link_info);
       if (ret != 0)
 	{
 	  if (ret < 0)
diff --git a/ld/emultempl/nios2elf.em b/ld/emultempl/nios2elf.em
index 991a11b..bdf54a3 100644
--- a/ld/emultempl/nios2elf.em
+++ b/ld/emultempl/nios2elf.em
@@ -236,20 +236,26 @@ build_section_lists (lang_statement_union_type *statement)
 static void
 gld${EMULATION_NAME}_after_allocation (void)
 {
+  int ret;
+
   /* bfd_elf_discard_info just plays with data and debugging sections,
      ie. doesn't affect code size, so we can delay resizing the
      sections.  It's likely we'll resize everything in the process of
      adding stubs.  */
-  if (bfd_elf_discard_info (link_info.output_bfd, &link_info))
+  ret = bfd_elf_discard_info (link_info.output_bfd, &link_info);
+  if (ret < 0)
+    {
+      einfo ("%X%P: .eh_frame/.stab edit: %E\n");
+      return;
+    }
+  else if (ret > 0)
     need_laying_out = 1;
 
   /* If generating a relocatable output file, then we don't
      have to examine the relocs.  */
   if (stub_file != NULL && !link_info.relocatable && RELAXATION_ENABLED)
     {
-      int ret = nios2_elf32_setup_section_lists (link_info.output_bfd,
-						 &link_info);
-
+      ret = nios2_elf32_setup_section_lists (link_info.output_bfd, &link_info);
       if (ret != 0)
 	{
 	  if (ret < 0)
diff --git a/ld/emultempl/ppc64elf.em b/ld/emultempl/ppc64elf.em
index d45fdac..3e316af 100644
--- a/ld/emultempl/ppc64elf.em
+++ b/ld/emultempl/ppc64elf.em
@@ -458,18 +458,26 @@ build_section_lists (lang_statement_union_type *statement)
 static void
 gld${EMULATION_NAME}_after_allocation (void)
 {
+  int ret;
+
   /* bfd_elf_discard_info just plays with data and debugging sections,
      ie. doesn't affect code size, so we can delay resizing the
      sections.  It's likely we'll resize everything in the process of
      adding stubs.  */
-  if (bfd_elf_discard_info (link_info.output_bfd, &link_info))
+  ret = bfd_elf_discard_info (link_info.output_bfd, &link_info);
+  if (ret < 0)
+    {
+      einfo ("%X%P: .eh_frame/.stab edit: %E\n");
+      return;
+    }
+  else if (ret > 0)
     need_laying_out = 1;
 
   /* If generating a relocatable output file, then we don't have any
      stubs.  */
   if (stub_file != NULL && !link_info.relocatable)
     {
-      int ret = ppc64_elf_setup_section_lists (&link_info);
+      ret = ppc64_elf_setup_section_lists (&link_info);
       if (ret < 0)
 	einfo ("%X%P: can not size stub section: %E\n");
       else if (ret > 0)
diff --git a/ld/emultempl/tic6xdsbt.em b/ld/emultempl/tic6xdsbt.em
index ca957c4..ff591f1 100644
--- a/ld/emultempl/tic6xdsbt.em
+++ b/ld/emultempl/tic6xdsbt.em
@@ -95,6 +95,7 @@ static void
 gld${EMULATION_NAME}_after_allocation (void)
 {
   int layout_changed = 0;
+  int ret;
 
   if (!link_info.relocatable)
     {
@@ -149,7 +150,13 @@ gld${EMULATION_NAME}_after_allocation (void)
   /* bfd_elf32_discard_info just plays with debugging sections,
      ie. doesn't affect any code, so we can delay resizing the
      sections.  */
-  if (bfd_elf_discard_info (link_info.output_bfd, & link_info))
+  ret = bfd_elf_discard_info (link_info.output_bfd, & link_info);
+  if (ret < 0)
+    {
+      einfo ("%X%P: .eh_frame/.stab edit: %E\n");
+      return;
+    }
+  else if (ret > 0)
     layout_changed = 1;
 
   gld${EMULATION_NAME}_map_segments (layout_changed);
diff --git a/ld/emultempl/vms.em b/ld/emultempl/vms.em
index b1f61d5..40be66d 100644
--- a/ld/emultempl/vms.em
+++ b/ld/emultempl/vms.em
@@ -207,9 +207,12 @@ gld${EMULATION_NAME}_before_allocation (void)
 static void
 gld${EMULATION_NAME}_after_allocation (void)
 {
-  bfd_boolean need_layout = bfd_elf_discard_info (link_info.output_bfd,
-						  &link_info);
-  gld${EMULATION_NAME}_map_segments (need_layout);
+  int need_layout = bfd_elf_discard_info (link_info.output_bfd, &link_info);
+
+  if (need_layout < 0)
+    einfo ("%X%P: .eh_frame/.stab edit: %E\n");
+  else
+    gld${EMULATION_NAME}_map_segments (need_layout);
 }
 
 static void

-- 
Alan Modra
Australia Development Lab, IBM


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]