bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: binutils-doc 2.15-5: glitches in ld.info


From: Ian Lance Taylor
Subject: Re: binutils-doc 2.15-5: glitches in ld.info
Date: 24 Jan 2005 14:02:36 -0500
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3

Edward Welbourne <address@hidden> writes:

> and I've been interpreting (ld) Assignments and (ld) Simple
> Assignments as saying that assignments work like they do in C - that
> is, if the linker script says
>        SYMBOL = EXPRESSION
> then C code compiled into one of the objects being linked (c.f. the
> example you assure me is correct) can use SYMBOL as an lvalue and
> thereby get the value of EXPRESSION; while &SYMBOL will get a memory
> address at which this value is being held.  I conclude that this is
> not how it works.

You are correct that that is not how it works.  In a linker script,
assigning to SYMBOL just affects the symbol table.

> If I have understood what you are saying correctly, then a linker
> script assignment actually creates an alias - an assignment
>        SYMBOL = EXPRESSION
> causes my C code to be able to reference &SYMBOL to get the value of
> EXPRESSION, and my C code won't be able to reference the place where
> that value is stored.

Well, it depends upon how you write your C code.  If you want to play
with this kind of thing in linker scripts, you need to understand the
interaction between C code and the linker symbol table.

First I'll note that from the point of view of the program there is no
"place where that value is stored."  The value is stored in the symbol
table, but the symbol table is not (normally) loaded into memory at
runtime.

If you write
    extern int VAR;
then in the simple case C code will expect the symbol VAR to be
defined in the symbol table.  The value that VAR will have in the
symbol table is the address of the location where the variable's value
will be stored.  So if in your linker script you write "VAR = VAL"
then you are in essence saying that the address where the value of the
C variable VAR will be stored is VAL.  So if your C code wants to get
VAL, you need to write "&VAR".

Or, you can write
    extern int VAR[];
Once again, in the simple case, C code will expect VAR to be defined
in the symbol table, and to be the address of the array.  However,
know if you simply write VAR in C, you will get VAL, because in C
a simple reference to an array is the same as a reference to the
address of the first element, which is VAR.

> If such is really the case, either (ld) Assignments or possibly "Basic
> Linker Script Concepts" should explain it - since the naive C/C++
> programmer will be apt to make the same mistake as I did in
> understanding the meaning of assignment.  Alternatively, if in fact my
> initial reading of how assignments work is correct, then there are
> problems with the (ld) Overlay Description text quoted above.

Documentation updates are always welcome.

Ian




reply via email to

[Prev in Thread] Current Thread [Next in Thread]