/* Align this section first to the input sections requirement,
then to the output section's requirement. If this alignment
is greater than any seen before, then record it too. Perform
- the alignment by inserting a magic 'padding' statement. */
+ the alignment by inserting a magic 'padding' statement.
+ We can force input section alignment within an output section
+ by using SUBALIGN. The value specified overrides any alignment
+ given by input sections, whether larger or smaller. */
if (output_section_statement->subsection_alignment != NULL)
- i->alignment_power
- = exp_get_power (output_section_statement->subsection_alignment,
- output_section_statement,
- "subsection alignment");
+ o->alignment_power = i->alignment_power =
+ exp_get_power (output_section_statement->subsection_alignment,
+ output_section_statement,
+ "subsection alignment");
if (o->alignment_power < i->alignment_power)
o->alignment_power = i->alignment_power;
run_dump_test align5
}
run_dump_test align2c
+
+if { [is_elf_format] } {
+ # FIXME: Currently this test is only run for ELF targets as other formats
+ # do not necessarily support these large alignments. It could be tweaked
+ # to work with other formats.
+ run_dump_test subalign
+}
+
set LDFLAGS "$saved_LDFLAGS"
if { [is_elf_format] && ![uses_genelf] } {
--- /dev/null
+# ld: -T subalign.t --no-error-rwx-segments -e 0
+# objdump: -h --wide
+# Ensure that SUBALIGN fixes the alignment of the output section.
+# Check that ALIGN provides a minimum alignment, although allow the target to require a larger value.
+
+#...
+ . .mysection1.*2\*\*2.*
+#...
+ . .mysection2.*2\*\*[4-9].*
+#...
+ . .mysection3.*2\*\*[3-9].*
+#...
--- /dev/null
+ .file "subalign.c"
+ .text
+ .globl a_one
+ .section .mysection1,"aw"
+ .align 8
+a_one:
+ .zero 1
+
+ .globl b_one
+ .section .mysection2,"aw"
+ .align 8
+b_one:
+ .zero 1
+
+ .globl c_one
+ .section .mysection3,"aw"
+ .align 8
+c_one:
+ .zero 1
+