This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Linker script, start address of "subsection" and alignment
- From: Nick Clifton <nickc at redhat dot com>
- To: Mike Hommey <mh at glandium dot org>, binutils at sourceware dot org
- Date: Wed, 18 Jul 2018 10:58:25 +0100
- Subject: Re: Linker script, start address of "subsection" and alignment
- References: <20180626042028.qgjjsdbohz2zr3no@glandium.org>
Hi Mike,
> SECTIONS {
> .data : {
> __foo = .;
> But this doesn't actually work because of the alignment. That is, `__foo`
> gets its value pre-alignment. This is what -print-map says about .data:
> 0x0000000000201028 __foo = .
> *(.foo)
> *fill* 0x0000000000201028 0x18
> .foo 0x0000000000201040 0x8 /tmp/ccEGZYAm.o
> but that doesn't seem very satisfactory. ALIGNOF doesn't allow to get
> the alignment requirement from some input. Am I missing something or
> is it not possible to do this "generically"?
You could add an alignment attribute to the declaration of the .data section
so that it starts on a 32-byte boundary.
SECTIONS {
.data : ALIGN(32) {
Although this still requires that you know the alignment requirements in advance.
You could try the ALIGN_WITH_INPUT attribute instead. I am not exactly sure what
this is supposed to do, but it might work:
SECTIONS {
.data : ALIGN_WITH_INPUT {
Alternatively you could sort the entries in the section by alignment. This will
put the largest alignment entries first, which I think will also bring the start
of the section to the largest alignment boundary needed.
SECTIONS {
.data : {
__foo = . ;
SORT_BY_ALIGNMENT (*(.foo))
Cheers
Nick