_bfd_elf_create_got_section .rela.got

Message ID 293e97d4e22c10e75f60c11fad0312352cfabec3.1778457849.git.amodra@gmail.com
State New
Headers
Series _bfd_elf_create_got_section .rela.got |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Test passed

Commit Message

Alan Modra May 11, 2026, 5:11 a.m. UTC
  _bfd_elf_create_got_section creates .rela.got or .rel.got before it
creates .got.  This normally isn't a problem, but in some tests that
use a script to map uninteresting sections to a .junk section, if it
happens to be the first section so mapped then .junk becomes RELA
rather than the usual PROGBITS.  Using a linker created dynobj makes
this more likely as the linker created bfd is put first on
link_info.input_bfds.

	* elflink.c (_bfd_elf_create_got_section): Create .rela.got/
	.rel.got later.
  

Patch

diff --git a/bfd/elflink.c b/bfd/elflink.c
index 6540184ed23..100f13227c8 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -240,15 +240,6 @@  _bfd_elf_create_got_section (bfd *abfd, struct bfd_link_info *info)
 
   flags = bed->dynamic_sec_flags;
 
-  s = bfd_make_section_anyway_with_flags (abfd,
-					  (bed->rela_plts_and_copies_p
-					   ? ".rela.got" : ".rel.got"),
-					  flags | SEC_READONLY);
-  if (s == NULL
-      || !bfd_set_section_alignment (s, bed->s->log_file_align))
-    return false;
-  htab->srelgot = s;
-
   s = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
   if (s == NULL
       || !bfd_set_section_alignment (s, bed->s->log_file_align))
@@ -280,6 +271,15 @@  _bfd_elf_create_got_section (bfd *abfd, struct bfd_link_info *info)
 	return false;
     }
 
+  s = bfd_make_section_anyway_with_flags (abfd,
+					  (bed->rela_plts_and_copies_p
+					   ? ".rela.got" : ".rel.got"),
+					  flags | SEC_READONLY);
+  if (s == NULL
+      || !bfd_set_section_alignment (s, bed->s->log_file_align))
+    return false;
+  htab->srelgot = s;
+
   return true;
 }