* [PATCH] changed ld subalign priority
@ 2024-02-27 8:15 vb-sc
2024-02-28 16:36 ` Nick Clifton
0 siblings, 1 reply; 2+ messages in thread
From: vb-sc @ 2024-02-27 8:15 UTC (permalink / raw)
To: binutils; +Cc: vb-sc
Hi,
According to the GNU LD documentation:
<<You 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.>>
However, let's consider the behaviour of GNU ld
Suppose we have the following test:
$ cat one.c
char a_one __attribute__((__aligned__(8))) __attribute__((section(".mysection"))) = 0;
and the following linker script:
$ cat foo.lds
SECTIONS
{
. = 0x10024;
.mysection : SUBALIGN(4) {
*(.mysection)
}
.note.gnu.property ALIGN(8) : {
*(.note.gnu.property)
*(.comment)
}
}
We suppose that the section .mysection would be aligned by 4 despite of alignment attribute 8 in source code.
However, after linking object file "one.o" __ with gnu ld linker the symbol .mysection is aligned by 8
$ gcc -c one.c
$ ld -T foo.lds one.o -o foo.out
$ objdump -h foo.out
foo2.out: file format elf64-x86-64Sections:
Idx Name Size VMA LMA File off Algn
0 .mysection 00000001 0000000000010028 0000000000010028 00001028 2**3
CONTENTS, ALLOC, LOAD, DATA
1 .note.gnu.property 0000004b 0000000000010030 0000000000010030 00001030 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
It seems like this is contrary to documented behavior.
Below you can see the patch fixed this problem.
---
Best regards,
Vladislav
---
ld/ldlang.c | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/ld/ldlang.c b/ld/ldlang.c
index df4c43ce9f4..0ab59daccb4 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -5349,17 +5349,22 @@ size_input_section
bfd_size_type alignment_needed;
/* 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. */
-
- if (output_section_statement->subsection_alignment != NULL)
- i->alignment_power
- = exp_get_power (output_section_statement->subsection_alignment,
- "subsection alignment");
+ 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.
+ 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,
+ "subsection alignment");
+ o->alignment_power = i->alignment_power;
+ }
- if (o->alignment_power < i->alignment_power)
- o->alignment_power = i->alignment_power;
+ else if (o->alignment_power < i->alignment_power)
+ o->alignment_power = i->alignment_power;
alignment_needed = align_power (dot, i->alignment_power) - dot;
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] changed ld subalign priority
2024-02-27 8:15 [PATCH] changed ld subalign priority vb-sc
@ 2024-02-28 16:36 ` Nick Clifton
0 siblings, 0 replies; 2+ messages in thread
From: Nick Clifton @ 2024-02-28 16:36 UTC (permalink / raw)
To: vb-sc; +Cc: Binutils
Hi Vladislav,
Thanks for reporting this problem.
In the future, please could I ask that you use the binutils bug
reporting system, as this allows us to keep track of problems and
to reference them in comments:
https://sourceware.org/bugzilla/
> Below you can see the patch fixed this problem.
Thank you. I have applied a simplified version of your patch
and added your example code as a new test in the linker testsuite.
Cheers
Nick
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-02-28 16:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-27 8:15 [PATCH] changed ld subalign priority vb-sc
2024-02-28 16:36 ` Nick Clifton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).