Q: Weak symbol defaulting to an other symbol?

Jan Beulich jbeulich@suse.com
Mon Nov 24 07:52:45 GMT 2025


On 23.11.2025 12:54, Georg-Johann Lay via Binutils wrote:
> In an assembler module, I would like to introduce a weak symbol like in:
> 
>      .weak my_symbol
>      my_symbol = __heap_start
>      ;; use my_symbol...
> 
> where __heap_start is defined in the linker script as
> 
>      PROVIDE (__heap_start = .)
> 
> The code will be part of a static library.
> 
> The generated code when linking against the static lib is as
> expected.  Though what doesn't work is to let the user adjust
> my_symbol when they don't like the default, e.g. by
>      --defsym my_symbol=0x12324
> or by code like
> 
>      .global my_symbol
>      my_symbol = 0x12345
> 
> in some module.
> 
> Binutils version is 2.45.  So I already found out that overriding
> the default doesn't work, and that's likely on purpose.
> 
> In order to get a better understanding, I'd like to ask why this
> doesn't work, and what's the thinko in my intended design? Having
> a user-adjustable symbol that defaults to some symbol value seems
> to be a useful feature.

The problem is the use of an equate in combination with an undefined
(external) symbol. The assembler resolves the equate, as you will be
able to see when you dump the generated object. The recorded relocation
references __heap_start instead. See also how e.g. gcc's "alias"
attribute is only specified to work with defined symbols. (The test in
the doc says "declared", but really means "defined", as can be easily
checked by converting the function definition of __f() in the example
to a function declaration.)

Jan


More information about the Binutils mailing list