[binutils-gdb] Use bfd_link_align_section in a few more places

Alan Modra amodra@sourceware.org
Tue Feb 18 03:03:41 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=104443510ad1238d6f30d446bd7070a523d0e9ab

commit 104443510ad1238d6f30d446bd7070a523d0e9ab
Author: Alan Modra <amodra@gmail.com>
Date:   Tue Feb 18 11:11:09 2025 +1030

    Use bfd_link_align_section in a few more places
    
    Some of these aren't relevant to the relro bug.  Some are.  They all
    matter if early estimation of section layout needs to be good.
    
            PR ld/32690
            * elf32-bfin.c (bfin_adjust_dynamic_symbol),
            * elf32-hppa.c (elf32_hppa_late_size_sections),
            * elf32-microblaze.c (microblaze_elf_adjust_dynamic_symbol),
            * elf32-nds32.c (nds32_elf_adjust_dynamic_symbol),
            * elf64-ppc.c (size_global_entry_stubs),
            * elflink.c (_bfd_elf_tls_setup),
            * elfxx-mips.c (mips_elf_add_la25_intro),
            (mips_elf_add_la25_trampoline),
            (_bfd_mips_elf_adjust_dynamic_symbol),
            * elfxx-x86.c (_bfd_x86_elf_late_size_sections): Use
            bfd_link_align_section to ensure correct output section
            alignment.

Diff:
---
 bfd/elf32-bfin.c       |  7 ++-----
 bfd/elf32-hppa.c       |  4 +---
 bfd/elf32-microblaze.c |  7 ++-----
 bfd/elf32-nds32.c      |  7 ++-----
 bfd/elf64-ppc.c        |  4 ++--
 bfd/elflink.c          |  2 +-
 bfd/elfxx-mips.c       | 10 +++++-----
 bfd/elfxx-x86.c        |  2 +-
 8 files changed, 16 insertions(+), 27 deletions(-)

diff --git a/bfd/elf32-bfin.c b/bfd/elf32-bfin.c
index 547661a3098..7ac95a0634e 100644
--- a/bfd/elf32-bfin.c
+++ b/bfd/elf32-bfin.c
@@ -5049,11 +5049,8 @@ bfin_adjust_dynamic_symbol (struct bfd_link_info *info,
 
   /* Apply the required alignment.  */
   s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
-  if (power_of_two > bfd_section_alignment (s))
-    {
-      if (!bfd_set_section_alignment (s, power_of_two))
-	return false;
-    }
+  if (!bfd_link_align_section (s, power_of_two))
+    return false;
 
   /* Define the symbol as being at this point in the section.  */
   h->root.u.def.section = s;
diff --git a/bfd/elf32-hppa.c b/bfd/elf32-hppa.c
index 01c0fc4658e..759912d74ad 100644
--- a/bfd/elf32-hppa.c
+++ b/bfd/elf32-hppa.c
@@ -2216,12 +2216,10 @@ elf32_hppa_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 		 section.  We want this stub right at the end, up
 		 against the .got section.  */
 	      int gotalign = bfd_section_alignment (htab->etab.sgot);
-	      int pltalign = bfd_section_alignment (sec);
 	      int align = gotalign > 3 ? gotalign : 3;
 	      bfd_size_type mask;
 
-	      if (align > pltalign)
-		bfd_set_section_alignment (sec, align);
+	      (void) bfd_link_align_section (sec, align);
 	      mask = ((bfd_size_type) 1 << gotalign) - 1;
 	      sec->size = (sec->size + sizeof (plt_stub) + mask) & ~mask;
 	    }
diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c
index fb86b3e4bcf..57c37c53074 100644
--- a/bfd/elf32-microblaze.c
+++ b/bfd/elf32-microblaze.c
@@ -2743,11 +2743,8 @@ microblaze_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
 
   /* Apply the required alignment.  */
   s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
-  if (power_of_two > s->alignment_power)
-    {
-      if (!bfd_set_section_alignment (s, power_of_two))
-	return false;
-    }
+  if (!bfd_link_align_section (s, power_of_two))
+    return false;
 
   /* Define the symbol as being at this point in the section.  */
   h->root.u.def.section = s;
diff --git a/bfd/elf32-nds32.c b/bfd/elf32-nds32.c
index 9db95e87ec6..e240c311841 100644
--- a/bfd/elf32-nds32.c
+++ b/bfd/elf32-nds32.c
@@ -4058,11 +4058,8 @@ nds32_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
 
   /* Apply the required alignment.  */
   s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
-  if (power_of_two > bfd_section_alignment (s))
-    {
-      if (!bfd_set_section_alignment (s, power_of_two))
-	return false;
-    }
+  if (!bfd_link_align_section (s, power_of_two))
+    return false;
 
   /* Define the symbol as being at this point in the section.  */
   h->root.u.def.section = s;
diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c
index c3f22f6ba98..3e768dca8d6 100644
--- a/bfd/elf64-ppc.c
+++ b/bfd/elf64-ppc.c
@@ -10207,8 +10207,8 @@ size_global_entry_stubs (struct elf_link_hash_entry *h, void *inf)
 	   non-empty.  Otherwise the .text output section will be
 	   aligned at least to plt_stub_align even when no global
 	   entry stubs are needed.  */
-	if (s->alignment_power < align_power)
-	  s->alignment_power = align_power;
+	if (!bfd_link_align_section (s, align_power))
+	  return false;
 	stub_align = (bfd_vma) 1 << align_power;
 	if (htab->params->plt_stub_align >= 0
 	    || ((((stub_off + stub_size - 1) & -stub_align)
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 70460573522..0df19769483 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -3606,7 +3606,7 @@ _bfd_elf_tls_setup (bfd *obfd, struct bfd_link_info *info)
   /* Ensure the alignment of the first section (usually .tdata) is the largest
      alignment, so that the tls segment starts aligned.  */
   if (tls != NULL)
-    tls->alignment_power = align;
+    (void) bfd_link_align_section (tls, align);
 
   return tls;
 }
diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
index e428ae278ba..ace1d4b1e07 100644
--- a/bfd/elfxx-mips.c
+++ b/bfd/elfxx-mips.c
@@ -1946,7 +1946,7 @@ mips_elf_add_la25_intro (struct mips_elf_la25_stub *stub,
 
   /* Make sure that any padding goes before the stub.  */
   align = input_section->alignment_power;
-  if (!bfd_set_section_alignment (s, align))
+  if (!bfd_link_align_section (s, align))
     return false;
   if (align > 3)
     s->size = (1 << align) - 8;
@@ -1983,7 +1983,7 @@ mips_elf_add_la25_trampoline (struct mips_elf_la25_stub *stub,
       asection *input_section = stub->h->root.root.u.def.section;
       s = htab->add_stub_section (".text", NULL,
 				  input_section->output_section);
-      if (s == NULL || !bfd_set_section_alignment (s, 4))
+      if (s == NULL || !bfd_link_align_section (s, 4))
 	return false;
       htab->strampoline = s;
     }
@@ -9447,13 +9447,13 @@ _bfd_mips_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
 	     Encourage better cache usage by aligning.  We do this
 	     lazily to avoid pessimizing traditional objects.  */
 	  if (htab->root.target_os != is_vxworks
-	      && !bfd_set_section_alignment (htab->root.splt, 5))
+	      && !bfd_link_align_section (htab->root.splt, 5))
 	    return false;
 
 	  /* Make sure that .got.plt is word-aligned.  We do this lazily
 	     for the same reason as above.  */
-	  if (!bfd_set_section_alignment (htab->root.sgotplt,
-					  MIPS_ELF_LOG_FILE_ALIGN (dynobj)))
+	  if (!bfd_link_align_section (htab->root.sgotplt,
+				       MIPS_ELF_LOG_FILE_ALIGN (dynobj)))
 	    return false;
 
 	  /* On non-VxWorks targets, the first two entries in .got.plt
diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
index 3b25f832a9d..d6433ed790b 100644
--- a/bfd/elfxx-x86.c
+++ b/bfd/elfxx-x86.c
@@ -2666,7 +2666,7 @@ _bfd_x86_elf_late_size_sections (bfd *output_bfd,
 	 it is empty.  Update its section alignment now since it
 	 is non-empty.  */
       if (s == htab->elf.iplt
-	  && !bfd_set_section_alignment (s, htab->plt.iplt_alignment))
+	  && !bfd_link_align_section (s, htab->plt.iplt_alignment))
 	abort ();
 
       /* Allocate memory for the section contents.  We use bfd_zalloc


More information about the Binutils-cvs mailing list