Skip to content

Commit 1044435

Browse files
committed
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.
1 parent d2fea23 commit 1044435

8 files changed

+16
-27
lines changed

bfd/elf32-bfin.c

+2-5
Original file line numberDiff line numberDiff line change
@@ -5049,11 +5049,8 @@ bfin_adjust_dynamic_symbol (struct bfd_link_info *info,
50495049

50505050
/* Apply the required alignment. */
50515051
s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
5052-
if (power_of_two > bfd_section_alignment (s))
5053-
{
5054-
if (!bfd_set_section_alignment (s, power_of_two))
5055-
return false;
5056-
}
5052+
if (!bfd_link_align_section (s, power_of_two))
5053+
return false;
50575054

50585055
/* Define the symbol as being at this point in the section. */
50595056
h->root.u.def.section = s;

bfd/elf32-hppa.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -2216,12 +2216,10 @@ elf32_hppa_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
22162216
section. We want this stub right at the end, up
22172217
against the .got section. */
22182218
int gotalign = bfd_section_alignment (htab->etab.sgot);
2219-
int pltalign = bfd_section_alignment (sec);
22202219
int align = gotalign > 3 ? gotalign : 3;
22212220
bfd_size_type mask;
22222221

2223-
if (align > pltalign)
2224-
bfd_set_section_alignment (sec, align);
2222+
(void) bfd_link_align_section (sec, align);
22252223
mask = ((bfd_size_type) 1 << gotalign) - 1;
22262224
sec->size = (sec->size + sizeof (plt_stub) + mask) & ~mask;
22272225
}

bfd/elf32-microblaze.c

+2-5
Original file line numberDiff line numberDiff line change
@@ -2743,11 +2743,8 @@ microblaze_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
27432743

27442744
/* Apply the required alignment. */
27452745
s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
2746-
if (power_of_two > s->alignment_power)
2747-
{
2748-
if (!bfd_set_section_alignment (s, power_of_two))
2749-
return false;
2750-
}
2746+
if (!bfd_link_align_section (s, power_of_two))
2747+
return false;
27512748

27522749
/* Define the symbol as being at this point in the section. */
27532750
h->root.u.def.section = s;

bfd/elf32-nds32.c

+2-5
Original file line numberDiff line numberDiff line change
@@ -4058,11 +4058,8 @@ nds32_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
40584058

40594059
/* Apply the required alignment. */
40604060
s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
4061-
if (power_of_two > bfd_section_alignment (s))
4062-
{
4063-
if (!bfd_set_section_alignment (s, power_of_two))
4064-
return false;
4065-
}
4061+
if (!bfd_link_align_section (s, power_of_two))
4062+
return false;
40664063

40674064
/* Define the symbol as being at this point in the section. */
40684065
h->root.u.def.section = s;

bfd/elf64-ppc.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -10207,8 +10207,8 @@ size_global_entry_stubs (struct elf_link_hash_entry *h, void *inf)
1020710207
non-empty. Otherwise the .text output section will be
1020810208
aligned at least to plt_stub_align even when no global
1020910209
entry stubs are needed. */
10210-
if (s->alignment_power < align_power)
10211-
s->alignment_power = align_power;
10210+
if (!bfd_link_align_section (s, align_power))
10211+
return false;
1021210212
stub_align = (bfd_vma) 1 << align_power;
1021310213
if (htab->params->plt_stub_align >= 0
1021410214
|| ((((stub_off + stub_size - 1) & -stub_align)

bfd/elflink.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3606,7 +3606,7 @@ _bfd_elf_tls_setup (bfd *obfd, struct bfd_link_info *info)
36063606
/* Ensure the alignment of the first section (usually .tdata) is the largest
36073607
alignment, so that the tls segment starts aligned. */
36083608
if (tls != NULL)
3609-
tls->alignment_power = align;
3609+
(void) bfd_link_align_section (tls, align);
36103610

36113611
return tls;
36123612
}

bfd/elfxx-mips.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -1946,7 +1946,7 @@ mips_elf_add_la25_intro (struct mips_elf_la25_stub *stub,
19461946

19471947
/* Make sure that any padding goes before the stub. */
19481948
align = input_section->alignment_power;
1949-
if (!bfd_set_section_alignment (s, align))
1949+
if (!bfd_link_align_section (s, align))
19501950
return false;
19511951
if (align > 3)
19521952
s->size = (1 << align) - 8;
@@ -1983,7 +1983,7 @@ mips_elf_add_la25_trampoline (struct mips_elf_la25_stub *stub,
19831983
asection *input_section = stub->h->root.root.u.def.section;
19841984
s = htab->add_stub_section (".text", NULL,
19851985
input_section->output_section);
1986-
if (s == NULL || !bfd_set_section_alignment (s, 4))
1986+
if (s == NULL || !bfd_link_align_section (s, 4))
19871987
return false;
19881988
htab->strampoline = s;
19891989
}
@@ -9447,13 +9447,13 @@ _bfd_mips_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
94479447
Encourage better cache usage by aligning. We do this
94489448
lazily to avoid pessimizing traditional objects. */
94499449
if (htab->root.target_os != is_vxworks
9450-
&& !bfd_set_section_alignment (htab->root.splt, 5))
9450+
&& !bfd_link_align_section (htab->root.splt, 5))
94519451
return false;
94529452

94539453
/* Make sure that .got.plt is word-aligned. We do this lazily
94549454
for the same reason as above. */
9455-
if (!bfd_set_section_alignment (htab->root.sgotplt,
9456-
MIPS_ELF_LOG_FILE_ALIGN (dynobj)))
9455+
if (!bfd_link_align_section (htab->root.sgotplt,
9456+
MIPS_ELF_LOG_FILE_ALIGN (dynobj)))
94579457
return false;
94589458

94599459
/* On non-VxWorks targets, the first two entries in .got.plt

bfd/elfxx-x86.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2666,7 +2666,7 @@ _bfd_x86_elf_late_size_sections (bfd *output_bfd,
26662666
it is empty. Update its section alignment now since it
26672667
is non-empty. */
26682668
if (s == htab->elf.iplt
2669-
&& !bfd_set_section_alignment (s, htab->plt.iplt_alignment))
2669+
&& !bfd_link_align_section (s, htab->plt.iplt_alignment))
26702670
abort ();
26712671

26722672
/* Allocate memory for the section contents. We use bfd_zalloc

0 commit comments

Comments
 (0)