aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2025-02-18 11:11:09 +1030
committerAlan Modra <amodra@gmail.com>2025-02-18 11:26:55 +1030
commit104443510ad1238d6f30d446bd7070a523d0e9ab (patch)
treead42b9f92d3a74a6e6bcb1a40920a47545a2e848
parentd2fea23a4a39f235c9e11849857b1aeb095719ab (diff)
downloadbinutils-104443510ad1238d6f30d446bd7070a523d0e9ab.zip
binutils-104443510ad1238d6f30d446bd7070a523d0e9ab.tar.gz
binutils-104443510ad1238d6f30d446bd7070a523d0e9ab.tar.bz2
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.
-rw-r--r--bfd/elf32-bfin.c7
-rw-r--r--bfd/elf32-hppa.c4
-rw-r--r--bfd/elf32-microblaze.c7
-rw-r--r--bfd/elf32-nds32.c7
-rw-r--r--bfd/elf64-ppc.c4
-rw-r--r--bfd/elflink.c2
-rw-r--r--bfd/elfxx-mips.c10
-rw-r--r--bfd/elfxx-x86.c2
8 files changed, 16 insertions, 27 deletions
diff --git a/bfd/elf32-bfin.c b/bfd/elf32-bfin.c
index 547661a..7ac95a0 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 01c0fc4..759912d 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 fb86b3e..57c37c5 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 9db95e8..e240c31 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 c3f22f6..3e768dc 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 7046057..0df1976 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 e428ae2..ace1d4b 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 3b25f83..d6433ed 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