RFH: Assignments folded too early

Hans-Peter Nilsson hp@bitrange.com
Wed Apr 7 22:14:00 GMT 2010


On Wed, 7 Apr 2010, Daniel Jacobowitz wrote:
> In the ld manual there's an example that's just perfect for the
> problem I'm working on:
>
> `DEFINED(SYMBOL)'
>      Return 1 if SYMBOL is in the linker global symbol table and is
>      defined before the statement using DEFINED in the script, otherwise
>      return 0.  You can use this function to provide default values for
>      symbols.

> And this linker script:
>
> SECTIONS
> {
>   .text :
>   {
>     *(.text)
>     *(.text1)
>     begin = DEFINED(begin) ? begin : fallback ;
>   }
> }
>
> Works fine:

> But move the assignment higher, and it blows up:
>
> SECTIONS
> {
>   .text :
>   {
>     *(.text)
>     begin = DEFINED(begin) ? begin : fallback ;
>     *(.text1)
>   }
> }
>
> 0000000000000004 T begin
> 0000000000000008 T fallback
> 0000000000000000 t padding
>
> See how begin has moved into the middle of the .text input section?

Yes, and I also see that it isn't "defined *before* the
statement using DEFINED in the script" any more (my emphasis),
but it seems you read those words differently from how I do?

I remember this being sanitized some time ago, from some
semantics that tried to cater to the symbol being defined
*anywhere* in the program or if it included the current
assignment (I don't remember).  If you're trying to do that,
please add something with a different name, like
DEFINED_ANYWHERE, so you don't change semantics of the existing
DEFINED.

brgds, H-P



More information about the Binutils mailing list