Confusion about value stored in linker script

Sergei Organov osv@javad.com
Thu Nov 1 19:19:00 GMT 2007


"Dave Korn" <dave.korn@artimi.com> writes:
> On 01 November 2007 19:02, Rick Mann wrote:
[...]
>   They aren't pointers and they aren't variables.  They are just numbers.  Try
> this instead: tell the compiler that these are references to a single byte of
> memory by pretending they are 'char' variables:
>
> extern char gVectorsStart, gVectorsEnd;
>
>   Then take the address of those variables:
>
> extern UInt32 *pgVectorsStart = &gVectorsStart;
> extern UInt32 *pgVectorsEnd = &gVectorsEnd;

Beware, this may not work for some architectures[1]. Safer bet is:

extern UInt32 gVectorStart[], gVectorEnd[];
extern UInt32 *pgVectorsStart = gVectorsStart;
extern UInt32 *pgVectorsEnd = gVectorsEnd;


[1] E.g., for archs where there is "small .data" or "small .bss"
section, compiler will expect simple "char" variables are in the small
section and do wrong thing when you try to take their address. It won't
expect this when you declare these virtual variables as arrays of
unknown size though.

-- 
Sergei.



More information about the Binutils mailing list