_bfd_elf_create_got_section .rela.got

Alan Modra amodra@gmail.com
Mon May 11 05:11:35 GMT 2026


_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.

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;
 }
 


More information about the Binutils mailing list