diff options
| author | Michael Brown | 2025-05-09 15:25:59 +0200 |
|---|---|---|
| committer | Michael Brown | 2025-05-09 16:14:03 +0200 |
| commit | 134d76379e22d1554476cac3ef7baee14a3c27d3 (patch) | |
| tree | d8fa3f5724066ee7eb0b6fcd8fb2d5c4f481ea69 /src/image | |
| parent | [libc] Display assertion failure message before incrementing counter (diff) | |
| download | ipxe-134d76379e22d1554476cac3ef7baee14a3c27d3.tar.gz ipxe-134d76379e22d1554476cac3ef7baee14a3c27d3.tar.xz ipxe-134d76379e22d1554476cac3ef7baee14a3c27d3.zip | |
[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>
Diffstat (limited to 'src/image')
| -rw-r--r-- | src/image/embedded.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/image/embedded.c b/src/image/embedded.c index 76d256c9b..2934d4ee7 100644 --- a/src/image/embedded.c +++ b/src/image/embedded.c @@ -16,7 +16,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #undef EMBED #define EMBED( _index, _path, _name ) \ extern char embedded_image_ ## _index ## _data[]; \ - extern char embedded_image_ ## _index ## _len[]; \ + extern size_t ABS_SYMBOL ( embedded_image_ ## _index ## _len ); \ __asm__ ( ".section \".data\", \"aw\", " PROGBITS "\n\t" \ "\nembedded_image_" #_index "_data:\n\t" \ ".incbin \"" _path "\"\n\t" \ @@ -34,7 +34,7 @@ EMBED_ALL .name = _name, \ .flags = ( IMAGE_STATIC | IMAGE_STATIC_NAME ), \ .rwdata = embedded_image_ ## _index ## _data, \ - .len = ( size_t ) embedded_image_ ## _index ## _len, \ + .len = ABS_VALUE_INIT ( embedded_image_ ## _index ## _len ), \ }, static struct image embedded_images[] = { EMBED_ALL |
