[binutils-gdb] bfin, frv, m68k, vax: got creation in check_relocs

Alan Modra via Binutils-cvs <[email protected]>
Newsgroups gmane.comp.gnu.binutils.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=72f3042bdc70668e2153f4d3bb5c5afe8aba80be

commit 72f3042bdc70668e2153f4d3bb5c5afe8aba80be
Author: Alan Modra <[email protected]>
Date:   Thu Aug 6 11:14:10 2026 +0930

    bfin, frv, m68k, vax: got creation in check_relocs
    
    It isn't obvious that it is correct to call the various create got
    section functions inside a !dynobj test, ie. somebody reading the code
    is left wondering whether the got might not be be created.  I think it
    is always created but I'd rather not need to dig even a little.
    
            * elf32-bfin.c (bfin_check_relocs): Move call creating
            got section outside dynobj test.
            (bfinfdpic_check_relocs): Likewise.
            * elf32-frv.c (elf32_frv_check_relocs): Likewise.
            * elf32-m68k.c (elf_m68k_check_relocs): Likewise.
            * elf32-vax.c (elf_vax_check_relocs): Likewise.

Diff:
---
 bfd/elf32-bfin.c | 19 +++++++++----------
 bfd/elf32-frv.c  | 10 ++++------
 bfd/elf32-m68k.c | 10 ++++------
 bfd/elf32-vax.c  | 10 ++++------
 4 files changed, 21 insertions(+), 28 deletions(-)

diff --git a/bfd/elf32-bfin.c b/bfd/elf32-bfin.c
index 8be69ead976..82025e6b242 100644
--- a/bfd/elf32-bfin.c
+++ b/bfd/elf32-bfin.c
@@ -1226,12 +1226,10 @@ bfin_check_relocs (bfd * abfd,
 	  /* Fall through.  */
 
 	  if (dynobj == NULL)
-	    {
-	      /* Create the .got section.  */
-	      elf_hash_table (info)->dynobj = dynobj = abfd;
-	      if (!_bfd_elf_create_got_section (dynobj, info))
-		return false;
-	    }
+	    elf_hash_table (info)->dynobj = dynobj = abfd;
+
+	  if (!_bfd_elf_create_got_section (dynobj, info))
+	    return false;
 
 	  sgot = elf_hash_table (info)->sgot;
 	  srelgot = elf_hash_table (info)->srelgot;
@@ -4558,13 +4556,14 @@ bfinfdpic_check_relocs (bfd *abfd, struct bfd_link_info *info,
 	case R_BFIN_PCREL24:
 	case R_BFIN_PCREL24_JUMP_L:
 	case R_BFIN_BYTE4_DATA:
-	  if (IS_FDPIC (abfd) && ! dynobj)
+	  if (IS_FDPIC (abfd))
 	    {
-	      elf_hash_table (info)->dynobj = dynobj = abfd;
-	      if (! _bfin_create_got_section (abfd, info))
+	      if (dynobj == NULL)
+		elf_hash_table (info)->dynobj = dynobj = abfd;
+	      if (!_bfin_create_got_section (dynobj, info))
 		return false;
 	    }
-	  if (! IS_FDPIC (abfd))
+	  else
 	    {
 	      picrel = NULL;
 	      break;
diff --git a/bfd/elf32-frv.c b/bfd/elf32-frv.c
index 183a78f6049..d19bb5a1499 100644
--- a/bfd/elf32-frv.c
+++ b/bfd/elf32-frv.c
@@ -6071,12 +6071,10 @@ elf32_frv_check_relocs (bfd *abfd,
 	case R_FRV_GPRELLO:
 	case R_FRV_LABEL24:
 	case R_FRV_32:
-	  if (! dynobj)
-	    {
-	      elf_hash_table (info)->dynobj = dynobj = abfd;
-	      if (! _frv_create_got_section (abfd, info))
-		return false;
-	    }
+	  if (dynobj == NULL)
+	    elf_hash_table (info)->dynobj = dynobj = abfd;
+	  if (!_frv_create_got_section (dynobj, info))
+	    return false;
 	  if (! IS_FDPIC (abfd))
 	    {
 	      picrel = NULL;
diff --git a/bfd/elf32-m68k.c b/bfd/elf32-m68k.c
index 8ed7640ddf8..541ff670110 100644
--- a/bfd/elf32-m68k.c
+++ b/bfd/elf32-m68k.c
@@ -2637,12 +2637,10 @@ elf_m68k_check_relocs (bfd *abfd,
 	  /* This symbol requires a global offset table entry.  */
 
 	  if (dynobj == NULL)
-	    {
-	      /* Create the .got section.  */
-	      elf_hash_table (info)->dynobj = dynobj = abfd;
-	      if (!_bfd_elf_create_got_section (dynobj, info))
-		return false;
-	    }
+	    elf_hash_table (info)->dynobj = dynobj = abfd;
+
+	  if (!_bfd_elf_create_got_section (dynobj, info))
+	    return false;
 
 	  if (got == NULL)
 	    {
diff --git a/bfd/elf32-vax.c b/bfd/elf32-vax.c
index 5d103caab93..b49a4837c04 100644
--- a/bfd/elf32-vax.c
+++ b/bfd/elf32-vax.c
@@ -594,12 +594,10 @@ elf_vax_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
 	  /* This symbol requires a global offset table entry.  */
 
 	  if (dynobj == NULL)
-	    {
-	      /* Create the .got section.  */
-	      elf_hash_table (info)->dynobj = dynobj = abfd;
-	      if (!_bfd_elf_create_got_section (dynobj, info))
-		return false;
-	    }
+	    elf_hash_table (info)->dynobj = dynobj = abfd;
+
+	  if (!_bfd_elf_create_got_section (dynobj, info))
+	    return false;
 
 	  if (h != NULL)
 	    {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.