]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Use bfd_link_align_section in a few more places
authorAlan Modra <amodra@gmail.com>
Tue, 18 Feb 2025 00:41:09 +0000 (11:11 +1030)
committerAlan Modra <amodra@gmail.com>
Tue, 18 Feb 2025 00:56:55 +0000 (11:26 +1030)
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.

bfd/elf32-bfin.c
bfd/elf32-hppa.c
bfd/elf32-microblaze.c
bfd/elf32-nds32.c
bfd/elf64-ppc.c
bfd/elflink.c
bfd/elfxx-mips.c
bfd/elfxx-x86.c

index 547661a3098e7f4bc8169c8cd794fda1b4e21718..7ac95a0634e3bd331625aa70f39e89c937b95178 100644 (file)
@@ -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;
index 01c0fc4658eb1fd711cd93bddc8667515b05631a..759912d74adc9527fcb4dac2c04c0ea48da456c8 100644 (file)
@@ -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;
            }
index fb86b3e4bcfa3599afe3959d0bbc0718e4f6366d..57c37c530746e630be5690abf839c5d912d9f2f8 100644 (file)
@@ -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;
index 9db95e87ec63b37acf200aeb9a86537e886f0df5..e240c3118412859dee3358ec144183da7decf1c4 100644 (file)
@@ -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;
index c3f22f6ba9892acc87cefde2a08f2a7cfcda9e29..3e768dca8d6081cfe3c6166feb76728ce2a7a16a 100644 (file)
@@ -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)
index 70460573522e05af766738270a158e93052e6a60..0df19769483620a3190064a3997303c12bb4748f 100644 (file)
@@ -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;
 }
index e428ae278ba6a0d82117ea210a44fac50fd62a75..ace1d4b1e07ebd0cd83be27b2cb292e4f010d326 100644 (file)
@@ -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
index 3b25f832a9da2c89a565dc8df28cabcf4474be37..d6433ed790b3d9282cec66178c7d1efad6cd8333 100644 (file)
@@ -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