This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Aligning .text segments
- From: Nicholas Clifton <nickc at redhat dot com>
- To: K Jski <bielsk1 at vt dot edu>, Binutils <binutils at sourceware dot org>
- Date: Tue, 23 Dec 2014 08:46:28 +0000
- Subject: Re: Aligning .text segments
- Authentication-results: sourceware.org; auth=none
- References: <CAH=yU0a2YO7R-opvtu-zCNkWBhTDwhVcNywOwFkpC7ZSQ=DPsQ at mail dot gmail dot com>
Hi K Jski,
foo at 0x40000010
bar at 0x400000c9
main in at 0x40000400
so I just would want the following to happen
foo to be aligned at 0x40000050
bar to be aligned at 0x40000100
main stays at 0x40000400
I have an attempt at a linker script (I never worked on linkers in my
life) that I feed gold as an arg "myscript.x". (source below) what
happens when gold produces a binary is that it creates another .text
section and inserts them at the designated addresses.
So, are you saying that the functions get aligned as you wanted, but
that the program itself does not run ?
myscript.x
SECTIONS{
.text:
{
. = ALIGN(0x50);
*(.text.foo)
. = ALIGN(0x50);
*(.text.bar)
}
}
That script should work, assuming that you compiled your code with the
-ffunction-sections command line option enabled, although you are
missing the catch-all line to catch the other text sections (eg the one
containing main):
.text:
{
. = ALIGN(0x50);
*(.text.foo)
. = ALIGN(0x50);
*(.text.bar)
. = ALIGN(0x50);
*(.text .text.*)
}
Also - this script is just a fragment - a full script would also need to
specify the locations of other sections like .data, .bss and so on.
Your best bet is to take the linker's builtin default script (shown when
you run "gold --verbose") and modify that to suit your needs.
Cheers
Nick