]> git.ipfire.org Git - thirdparty/ipxe.git/commit
[build] Formalise mechanism for accessing absolute symbols
authorMichael Brown <mcb30@ipxe.org>
Fri, 9 May 2025 13:25:59 +0000 (14:25 +0100)
committerMichael Brown <mcb30@ipxe.org>
Fri, 9 May 2025 14:14:03 +0000 (15:14 +0100)
commit134d76379e22d1554476cac3ef7baee14a3c27d3
treed8fa3f5724066ee7eb0b6fcd8fb2d5c4f481ea69
parent1d58d928fe97e9095e7e91b727ea36fcea9d2567
[build] Formalise mechanism for accessing absolute symbols

In a position-dependent executable, where all addresses are fixed
at link time, we can use the standard technique as documented by
GNU ld to get the value of an absolute symbol, e.g.:

    extern char _my_symbol[];

    printf ( "Absolute symbol value is %x\n", ( ( int ) _my_symbol ) );

This technique may not work in a position-independent executable.
When dynamic relocations are applied, the runtime addresses will no
longer be equal to the link-time addresses.  If the code to obtain the
address of _my_symbol uses PC-relative addressing, then it will
calculate the runtime "address" of the absolute symbol, which will no
longer be equal the the link-time "address" (i.e. the correct value)
of the absolute symbol.

Define macros ABS_SYMBOL(), ABS_VALUE_INIT(), and ABS_VALUE() that
provide access to the correct values of absolute symbols even in
position-independent code, and use these macros wherever absolute
symbols are accessed.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/x86/include/librm.h
src/arch/x86/interface/pcbios/hidemem.c
src/arch/x86/interface/pxe/pxe_call.c
src/arch/x86/transitions/librm_mgmt.c
src/core/version.c
src/crypto/certstore.c
src/crypto/privkey.c
src/image/embedded.c
src/include/compiler.h