mirror of
https://github.com/ipxe/ipxe
synced 2025-12-27 18:12:36 +03:00
[build] Fix the REQUIRE_SYMBOL mechanism
At some point in the past few years, binutils became more aggressive at removing unused symbols. To function as a symbol requirement, a relocation record must now be in a section marked with @progbits and must not be in a section which gets discarded during the link (either via --gc-sections or via /DISCARD/). Update REQUIRE_SYMBOL() to generate relocation records meeting these criteria. To minimise the impact upon the final binary size, we use existing symbols (specified via the REQUIRING_SYMBOL() macro) as the relocation targets where possible. We use R_386_NONE or R_X86_64_NONE relocation types to prevent any actual unwanted relocation taking place. Where no suitable symbol exists for REQUIRING_SYMBOL() (such as in config.c), the macro PROVIDE_REQUIRING_SYMBOL() can be used to generate a one-byte-long symbol to act as the relocation target. If there are versions of binutils for which this approach fails, then the fallback will probably involve killing off REQUEST_SYMBOL(), redefining REQUIRE_SYMBOL() to use the current definition of REQUEST_SYMBOL(), and postprocessing the linked ELF file with something along the lines of "nm -u | wc -l" to check that there are no undefined symbols remaining. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -478,6 +478,9 @@ static void process_reloc ( bfd *bfd __attribute__ (( unused )),
|
||||
/* Skip absolute symbols; the symbol value won't
|
||||
* change when the object is loaded.
|
||||
*/
|
||||
} else if ( ( strcmp ( howto->name, "R_386_NONE" ) == 0 ) ||
|
||||
( strcmp ( howto->name, "R_X86_64_NONE" ) == 0 ) ) {
|
||||
/* Ignore dummy relocations used by REQUIRE_SYMBOL() */
|
||||
} else if ( strcmp ( howto->name, "R_X86_64_64" ) == 0 ) {
|
||||
/* Generate an 8-byte PE relocation */
|
||||
generate_pe_reloc ( pe_reltab, offset, 8 );
|
||||
|
||||
Reference in New Issue
Block a user