bug-binutils
[Top][All Lists]
Advanced

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

Re: relocation information disappears


From: Jim Wilson
Subject: Re: relocation information disappears
Date: Fri, 7 Apr 2017 14:19:08 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

On 04/06/2017 04:20 AM, Katsuya TANAKA wrote:
# ~/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-gcc
-march=armv7-a -o w w.c
~/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-readelf -r
w
There is no "debug_f" symbol.
Why not?

The value of a weak symbol is evaluated at static link time. If a symbol is found, then that symbol address is used. If a symbol is not found, then the address is set to zero.

In this testcase, there is no debug_f symbol, so the address is forced to zero at link time, and hence no relocs are necessary.

# ~/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-gcc
-march=armv7-a -o w2 w2.c

There is a debug_info symbol.
Variable is not good.

In this case, debug_info is a function call, and function calls always go through the PLT, so there will be a PLT reloc for the function, even though we know the address is zero at link time.

The address check however gets forced to zero, and has no relocs, because none is necessary.

Note that weak symbols are not very useful with shared libraries. They are primarily intended for use with static linking. If you are trying to do something with a shared library, then don't use weak. Put a default definition of the symbol in the shared library, and then if you want to override it in the main program, just put a local definition in one of the source files linked into the main program.

Jim




reply via email to

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