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 Doreen,
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).
Tricky. There are several possibilities, none of them easy:
1. Don't do this.
You are trying to play tricks on the compiler and linker and they
are doing their best to prevent you.
2. Do not use static initialization.
If you initialised your StructTbl structure at run time rather
than at compile time (or at link time or at load time) then you
could do pretty much whatever you want.
3. Invent a new M68K relocation type and a new assembler directive.
Some architectures support a %lo() assembler directive which places
the low 16-bits of a 32-bit word into the appropriate field in an
instruction. (eg the IQ2000). You could add such a directive to
the M68K assembler, along with a new reloc to support and new linker
code to implement it and then access this directive from your source
code. Of course you would then be using a custom toolchain to build
your app.
4. Hard code the addresses of your HdlrTbl structures.
You would have to make sure that you use a low memory area that is not
going to be used by anything else and use two versions of the address,
one 16-bit and the other 32-bit.
Cheers
Nick