This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Question on LD Linker providing low 2 bytes of address as a constant
Hi,
Miller, Doreen schrieb:
If I put the address of the table I wanted stored in HdlrTbl in my
pre-initializer, the compiler reports "error: initializer element is not
constant". If I change HdlrTbl from 2 bytes to 4 bytes and leave the
pre-initilizer the way it was, it compiles fine. So it looks like I
need a way to tell the compiler and linker that I only want the lowest 2
bytes of the address (which is identical to the address since the 2 high
bytes are 0).
ld should accept storing a two byte value in a two byte field.
I just tested with the assembler source
.word foo
.long foo
bar:
.globl bar
and the linker script
SECTIONS {
.text 0x12345678 : {
*(.text)
}
foo = ABSOLUTE(bar) & 0xffff;
}
and I get an image that indeed reads
12345678 7e 56 7e 56 00 00
1234567e
So it is certainly possible on the linker side. The problem with gcc is
that there is no legal way to express this in C -- cast expressions
cannot be "constant-expression"s, and pointers cannot be mixed with
integers in a binary &.
Depending on the size of the tables, it might just make sense to create
them with .word directives in the assembler. The linker script stuff is
a lot simpler if the values don't have to be computed (i.e. the linker
sees that the addresses are below 0x10000), as the linker will check the
size of the relocation only when it is applied to the final output image.
Simon