This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[Patch] AIX/ld fix section alignment in linker script
- From: Tristan Gingold <gingold at adacore dot com>
- To: "binutils at sourceware dot org Development" <binutils at sourceware dot org>
- Cc: Richard Sandiford <rdsandiford at googlemail dot com>
- Date: Fri, 21 Oct 2011 13:06:27 +0200
- Subject: [Patch] AIX/ld fix section alignment in linker script
Hi,
currently the default AIX linker script uses PPC segment boundary to align .text and .data
In fact, this is never used as is, because gcc specs always adds -bpT:0x10000000 -bpD:0x20000000 to the linker command.
As a result, the SIZEOF_HEADERS will be added to the via of .text (see aix.em):
etree_type *t;
t = exp_binop ('+',
exp_intop (val),
exp_nameop (SIZEOF_HEADERS, NULL));
t = exp_binop ('&',
exp_binop ('+', t, exp_intop (31)),
exp_intop (~(bfd_vma) 31));
lang_section_start (".text", t, NULL);
and the vma of .text will match its file offset (modulo the page size).
So why not making that by default too ?
Things are going worse for .data, because although aix.em tries to keep the file offset in the vma:
t = exp_binop ('+',
exp_intop (val),
exp_binop ('&',
exp_nameop (NAME, "."),
exp_intop (0xfff)));
t = exp_binop ('&',
exp_binop ('+', t, exp_intop (31)),
exp_intop (~(bfd_vma) 31));
lang_section_start (".data", t, NULL);
it doesn't work because of '. = ALIGN (0x10000000)'. As a result the file offset is forgotten, contrary to the native linker.
(This issue was somewhat difficult to find because the AIX kernel still accept such image. I have no idea of the performance impact of these badly offsetted images)
Ok for trunk ?
Tristan.
ld/
2011-10-21 Tristan Gingold <gingold@adacore.com>
* scripttempl/aix.sc: Consider header size for .text and .data
alignment.
diff --git a/ld/scripttempl/aix.sc b/ld/scripttempl/aix.sc
index d592dbe..adc5de6 100644
--- a/ld/scripttempl/aix.sc
+++ b/ld/scripttempl/aix.sc
@@ -11,7 +11,7 @@ SECTIONS
{
.pad 0 : { *(.pad) }
- . = 0x10000000;
+ . = ALIGN (0x10000000 + SIZEOF_HEADERS, 32);
.text ${RELOCATING-0} : {
${RELOCATING+PROVIDE (_text = .);}
*(.text)
@@ -24,7 +24,8 @@ SECTIONS
*(.tb)
${RELOCATING+PROVIDE (_etext = .);}
}
- . = ALIGN (0x10000000);
+
+ . = ALIGN (ALIGN (0x10000000) + (. & 0xfff), 32);
.data . : {
${RELOCATING+PROVIDE (_data = .);}
*(.data)