From fbc4ba4b4ed13cc86cb8fdea0bac6c3be0164ed5 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Wed, 4 Mar 2015 18:48:19 +0000 Subject: [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 --- src/arch/i386/include/bits/compiler.h | 3 +++ src/arch/i386/interface/pxe/pxe_call.c | 1 + src/arch/i386/prefix/kkkpxeprefix.S | 1 + src/arch/i386/prefix/romprefix.S | 3 +++ src/arch/i386/transitions/librm_test.c | 1 + src/arch/x86/drivers/hyperv/hyperv.c | 3 +++ src/arch/x86/drivers/xen/hvm.c | 3 +++ src/arch/x86_64/include/bits/compiler.h | 3 +++ 8 files changed, 18 insertions(+) (limited to 'src/arch') diff --git a/src/arch/i386/include/bits/compiler.h b/src/arch/i386/include/bits/compiler.h index db512dbd3..87201135f 100644 --- a/src/arch/i386/include/bits/compiler.h +++ b/src/arch/i386/include/bits/compiler.h @@ -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 */ diff --git a/src/arch/i386/interface/pxe/pxe_call.c b/src/arch/i386/interface/pxe/pxe_call.c index 9703733c1..104313666 100644 --- a/src/arch/i386/interface/pxe/pxe_call.c +++ b/src/arch/i386/interface/pxe/pxe_call.c @@ -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 ); diff --git a/src/arch/i386/prefix/kkkpxeprefix.S b/src/arch/i386/prefix/kkkpxeprefix.S index 999fe1bf5..6e43cd26a 100644 --- a/src/arch/i386/prefix/kkkpxeprefix.S +++ b/src/arch/i386/prefix/kkkpxeprefix.S @@ -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 diff --git a/src/arch/i386/prefix/romprefix.S b/src/arch/i386/prefix/romprefix.S index 08fcf73b1..777b9e042 100644 --- a/src/arch/i386/prefix/romprefix.S +++ b/src/arch/i386/prefix/romprefix.S @@ -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 ) diff --git a/src/arch/i386/transitions/librm_test.c b/src/arch/i386/transitions/librm_test.c index af7f0470d..f1a517eda 100644 --- a/src/arch/i386/transitions/librm_test.c +++ b/src/arch/i386/transitions/librm_test.c @@ -118,4 +118,5 @@ struct self_test librm_test __self_test = { .exec = librm_test_exec, }; +REQUIRING_SYMBOL ( librm_test ); REQUIRE_OBJECT ( test ); diff --git a/src/arch/x86/drivers/hyperv/hyperv.c b/src/arch/x86/drivers/hyperv/hyperv.c index c3c0e86c0..f73829bd5 100644 --- a/src/arch/x86/drivers/hyperv/hyperv.c +++ b/src/arch/x86/drivers/hyperv/hyperv.c @@ -590,5 +590,8 @@ struct root_device hv_root_device __root_device = { .driver = &hv_root_driver, }; +/* Drag in objects via hv_root_device */ +REQUIRING_SYMBOL ( hv_root_device ); + /* Drag in netvsc driver */ REQUIRE_OBJECT ( netvsc ); diff --git a/src/arch/x86/drivers/xen/hvm.c b/src/arch/x86/drivers/xen/hvm.c index 6f3be8e2e..7ac32d54c 100644 --- a/src/arch/x86/drivers/xen/hvm.c +++ b/src/arch/x86/drivers/xen/hvm.c @@ -496,5 +496,8 @@ struct pci_driver hvm_driver __pci_driver = { .remove = hvm_remove, }; +/* Drag in objects via hvm_driver */ +REQUIRING_SYMBOL ( hvm_driver ); + /* Drag in netfront driver */ REQUIRE_OBJECT ( netfront ); diff --git a/src/arch/x86_64/include/bits/compiler.h b/src/arch/x86_64/include/bits/compiler.h index 51a7eaae2..f70b2e517 100644 --- a/src/arch/x86_64/include/bits/compiler.h +++ b/src/arch/x86_64/include/bits/compiler.h @@ -1,6 +1,9 @@ #ifndef _BITS_COMPILER_H #define _BITS_COMPILER_H +/** Dummy relocation type */ +#define RELOC_TYPE_NONE R_X86_64_NONE + #ifndef ASSEMBLY /** Declare a function with standard calling conventions */ -- cgit v1.2.3-55-g7522