[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:
Michael Brown
2015-03-04 18:48:19 +00:00
parent 86ae6e6c18
commit fbc4ba4b4e
37 changed files with 185 additions and 46 deletions

View File

@@ -3,6 +3,9 @@
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** Dummy relocation type */
#define RELOC_TYPE_NONE R_386_NONE
#ifndef ASSEMBLY
/** Declare a function with standard calling conventions */

View File

@@ -346,6 +346,7 @@ int pxe_start_nbp ( void ) {
return 0;
}
REQUIRING_SYMBOL ( pxe_api_call );
REQUIRE_OBJECT ( pxe_preboot );
REQUIRE_OBJECT ( pxe_undi );
REQUIRE_OBJECT ( pxe_udp );

View File

@@ -8,6 +8,7 @@
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )
/* Provide the PXENV_FILE_EXIT_HOOK API call */
REQUIRING_SYMBOL ( _kkkpxe_start )
REQUIRE_OBJECT ( pxe_exit_hook )
#define PXELOADER_KEEP_UNDI

View File

@@ -875,5 +875,8 @@ wait_for_tick:
ret
.size wait_for_tick, . - wait_for_tick
/* Drag in objects via _rom_start */
REQUIRING_SYMBOL ( _rom_start )
/* Drag in ROM configuration */
REQUIRE_OBJECT ( config_romprefix )

View File

@@ -118,4 +118,5 @@ struct self_test librm_test __self_test = {
.exec = librm_test_exec,
};
REQUIRING_SYMBOL ( librm_test );
REQUIRE_OBJECT ( test );