This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Linker script, start address of "subsection" and alignment
- From: Mike Hommey <mh at glandium dot org>
- To: binutils at sourceware dot org
- Date: Tue, 26 Jun 2018 13:20:28 +0900
- Subject: Linker script, start address of "subsection" and alignment
Hi,
Consider the following C source:
```
__attribute__((aligned(32), section(".foo")))
long foo = 0;
```
And the following linker script:
```
SECTIONS {
.data : {
__foo = .;
*(.foo)
}
}
```
The goal being to have the `__foo` symbol point at the first thing that
was originally in the `.foo` section.
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:
```
.data 0x0000000000201020 0x28
*(.data .data.* .gnu.linkonce.d.*)
.data 0x0000000000201020 0x0 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crti.o
.data 0x0000000000201020 0x0 /usr/lib/gcc/x86_64-linux-gnu/7/crtbeginS.o
.data.rel.local
0x0000000000201020 0x8 /usr/lib/gcc/x86_64-linux-gnu/7/crtbeginS.o
0x0000000000201020 __dso_handle
.data 0x0000000000201028 0x0 /tmp/ccEGZYAm.o
.data 0x0000000000201028 0x0 /usr/lib/gcc/x86_64-linux-gnu/7/crtendS.o
.data 0x0000000000201028 0x0 /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/crtn.o
0x0000000000201028 __foo = .
*(.foo)
*fill* 0x0000000000201028 0x18
.foo 0x0000000000201040 0x8 /tmp/ccEGZYAm.o
0x0000000000201040 foo
```
It is somehow possible to align by adding the following before the
symbol assignment in the linker script:
```
. = ALIGN(32)
```
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"?
Mike