]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix implementation of SUBALIGN.
authorVladislav Belov <vladislav.belov@syntacore.com>
Wed, 28 Feb 2024 16:36:37 +0000 (16:36 +0000)
committerNick Clifton <nickc@redhat.com>
Wed, 28 Feb 2024 16:36:37 +0000 (16:36 +0000)
ld/ldlang.c
ld/testsuite/ld-scripts/align.exp
ld/testsuite/ld-scripts/subalign.d [new file with mode: 0644]
ld/testsuite/ld-scripts/subalign.s [new file with mode: 0644]
ld/testsuite/ld-scripts/subalign.t [new file with mode: 0644]

index 229401c83420e3f2fbbec7cd35742a0c91a2a0b1..54d1af62ebe4b7b2043c86ddde31e30f6664f41a 100644 (file)
@@ -5468,13 +5468,16 @@ size_input_section
       /* 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;
index ea0500d4f531743e07b3f98bc3b211c941a0ac4a..e34825ec3da2314ca3d84efd33556a570894ef0b 100644 (file)
@@ -48,6 +48,14 @@ if ![is_aout_format] {
     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] } {
diff --git a/ld/testsuite/ld-scripts/subalign.d b/ld/testsuite/ld-scripts/subalign.d
new file mode 100644 (file)
index 0000000..37483a3
--- /dev/null
@@ -0,0 +1,12 @@
+# 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].*
+#...
diff --git a/ld/testsuite/ld-scripts/subalign.s b/ld/testsuite/ld-scripts/subalign.s
new file mode 100644 (file)
index 0000000..5589570
--- /dev/null
@@ -0,0 +1,20 @@
+       .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
+
diff --git a/ld/testsuite/ld-scripts/subalign.t b/ld/testsuite/ld-scripts/subalign.t
new file mode 100644 (file)
index 0000000..36ee259
--- /dev/null
@@ -0,0 +1,20 @@
+SECTIONS
+{
+    . = 0x10024;
+
+    .mysection1 : SUBALIGN(4) {
+        *(.mysection1)
+    }
+
+    .mysection2 : ALIGN(16) {
+        *(.mysection2)
+    }
+  
+    .mysection3 : {
+        *(.mysection3)
+    }
+  
+    /DISCARD/ : {
+      *(*)
+    }
+}