diff options
author | Michael Brown <mcb30@ipxe.org> | 2013-07-16 00:08:50 +0200 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2013-07-16 00:50:54 +0200 |
commit | ca319873bf43d5d955cc3d8770b5b2415798907d (patch) | |
tree | 8168679666b92de3de4ab5f4453c8383b22bc103 /src | |
parent | 9978e2cb3725c716169ade674c18376b1a401219 (diff) | |
download | ipxe-ca319873bf43d5d955cc3d8770b5b2415798907d.tar.gz |
[build] Fix %.licence build target
Our use of --gc-sections causes the linker to discard the symbols
defined by FILE_LICENCE(), meaning that the resulting licence
determination is incomplete.
We must use the KEEP() directive in the linker script to force the
linker to not discard the licence symbols. Using KEEP(*(COMMON))
would be undesirable, since there are some symbols in COMMON which we
may wish to discard.
Fix by placing symbols defined by PROVIDE_SYMBOL() (which is used by
FILE_LICENCE()) into a special ".provided" section, which we then mark
with KEEP(). All such symbols are zero-length, so there is no cost in
terms of the final binary size.
Since the symbols are no longer in COMMON, the linker will reject
symbols with the same name coming from multiple objects. We therefore
append the object name to the licence symbol, to ensure that it is
unique.
Reported-by: Marin Hannache <git@mareo.fr>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.housekeeping | 11 | ||||
-rw-r--r-- | src/arch/i386/scripts/i386-kir.lds | 2 | ||||
-rw-r--r-- | src/arch/i386/scripts/i386.lds | 2 | ||||
-rw-r--r-- | src/arch/i386/scripts/linux.lds | 2 | ||||
-rw-r--r-- | src/arch/x86/scripts/efi.lds | 2 | ||||
-rw-r--r-- | src/arch/x86_64/scripts/linux.lds | 2 | ||||
-rw-r--r-- | src/include/compiler.h | 23 |
7 files changed, 31 insertions, 13 deletions
diff --git a/src/Makefile.housekeeping b/src/Makefile.housekeeping index 80b70f5cd..8603bfd61 100644 --- a/src/Makefile.housekeeping +++ b/src/Makefile.housekeeping @@ -1011,15 +1011,20 @@ $(BIN)/%.nodeps : $(BIN)/%.tmp # Get licensing verdict for the specified target # define licensable_deps_list - $(filter-out config/local/%.h,$(call deps_list,$(1))) + $(filter-out config/local/%.h,\ + $(filter-out $(BIN)/.%.list,\ + $(call deps_list,$(1)))) endef define unlicensed_deps_list $(shell grep -L FILE_LICENCE $(call licensable_deps_list,$(1))) endef define licence_list - $(patsubst __licence_%,%,\ - $(filter __licence_%,$(shell $(NM) $(1) | cut -d" " -f3))) + $(sort $(foreach LICENCE,\ + $(filter __licence__%,$(shell $(NM) $(1) | cut -d" " -f3)),\ + $(word 2,$(subst __, ,$(LICENCE))))) endef +$(BIN)/%.licence_list : $(BIN)/%.tmp + $(Q)$(ECHO) $(call licence_list,$<) $(BIN)/%.licence : $(BIN)/%.tmp $(QM)$(ECHO) " [LICENCE] $@" $(Q)$(if $(strip $(call unlicensed_deps_list,$<)),\ diff --git a/src/arch/i386/scripts/i386-kir.lds b/src/arch/i386/scripts/i386-kir.lds index 338d6ee87..66bf804e6 100644 --- a/src/arch/i386/scripts/i386-kir.lds +++ b/src/arch/i386/scripts/i386-kir.lds @@ -98,6 +98,8 @@ SECTIONS { *(.data) *(.data.*) KEEP(*(SORT(.tbl.*))) /* Various tables. See include/tables.h */ + KEEP(*(.provided)) + KEEP(*(.provided.*)) _edata16_progbits = .; } .bss16 : AT ( _data16_load_offset + __bss16 ) { diff --git a/src/arch/i386/scripts/i386.lds b/src/arch/i386/scripts/i386.lds index fb763656c..98f95cb23 100644 --- a/src/arch/i386/scripts/i386.lds +++ b/src/arch/i386/scripts/i386.lds @@ -109,6 +109,8 @@ SECTIONS { *(.data) *(.data.*) KEEP(*(SORT(.tbl.*))) /* Various tables. See include/tables.h */ + KEEP(*(.provided)) + KEEP(*(.provided.*)) _mtextdata = .; } .bss.textdata (NOLOAD) : AT ( _end_lma ) { *(.bss) diff --git a/src/arch/i386/scripts/linux.lds b/src/arch/i386/scripts/linux.lds index 64c9b97fd..9f2eeaf3c 100644 --- a/src/arch/i386/scripts/linux.lds +++ b/src/arch/i386/scripts/linux.lds @@ -53,6 +53,8 @@ SECTIONS { *(.data) *(.data.*) KEEP(*(SORT(.tbl.*))) + KEEP(*(.provided)) + KEEP(*(.provided.*)) _edata = .; } diff --git a/src/arch/x86/scripts/efi.lds b/src/arch/x86/scripts/efi.lds index 1a16c29bd..f1049f24b 100644 --- a/src/arch/x86/scripts/efi.lds +++ b/src/arch/x86/scripts/efi.lds @@ -55,6 +55,8 @@ SECTIONS { *(.data) *(.data.*) KEEP(*(SORT(.tbl.*))) /* Various tables. See include/tables.h */ + KEEP(*(.provided)) + KEEP(*(.provided.*)) _edata = .; } diff --git a/src/arch/x86_64/scripts/linux.lds b/src/arch/x86_64/scripts/linux.lds index 85e548ffe..47db21745 100644 --- a/src/arch/x86_64/scripts/linux.lds +++ b/src/arch/x86_64/scripts/linux.lds @@ -53,6 +53,8 @@ SECTIONS { *(.data) *(.data.*) KEEP(*(SORT(.tbl.*))) + KEEP(*(.provided)) + KEEP(*(.provided.*)) _edata = .; } diff --git a/src/include/compiler.h b/src/include/compiler.h index e55592456..132793b5d 100644 --- a/src/include/compiler.h +++ b/src/include/compiler.h @@ -60,12 +60,15 @@ /** Provide a symbol within this object file */ #ifdef ASSEMBLY #define PROVIDE_SYMBOL( _sym ) \ + .section ".provided", "a", @nobits ; \ + .hidden _sym ; \ .globl _sym ; \ - .comm _sym, 0 + _sym: ; \ + .previous #else /* ASSEMBLY */ #define PROVIDE_SYMBOL( _sym ) \ - extern char _sym[]; \ - char _sym[0] + char _sym[0] \ + __attribute__ (( section ( ".provided" ) )) #endif /* ASSEMBLY */ /** Require a symbol within this object file @@ -652,7 +655,7 @@ int __debug_disable; * be in the public domain. */ #define FILE_LICENCE_PUBLIC_DOMAIN \ - PROVIDE_SYMBOL ( __licence_public_domain ) + PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__public_domain__ ) ) /** Declare a file as being under version 2 (or later) of the GNU GPL * @@ -661,7 +664,7 @@ int __debug_disable; * (at your option) any later version". */ #define FILE_LICENCE_GPL2_OR_LATER \ - PROVIDE_SYMBOL ( __licence_gpl2_or_later ) + PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__gpl2_or_later__ ) ) /** Declare a file as being under version 2 of the GNU GPL * @@ -670,7 +673,7 @@ int __debug_disable; * "or, at your option, any later version" clause. */ #define FILE_LICENCE_GPL2_ONLY \ - PROVIDE_SYMBOL ( __licence_gpl2_only ) + PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__gpl2_only__ ) ) /** Declare a file as being under any version of the GNU GPL * @@ -682,7 +685,7 @@ int __debug_disable; * version ever published by the Free Software Foundation". */ #define FILE_LICENCE_GPL_ANY \ - PROVIDE_SYMBOL ( __licence_gpl_any ) + PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__gpl_any__ ) ) /** Declare a file as being under the three-clause BSD licence * @@ -707,7 +710,7 @@ int __debug_disable; * functionally equivalent to the standard three-clause BSD licence. */ #define FILE_LICENCE_BSD3 \ - PROVIDE_SYMBOL ( __licence_bsd3 ) + PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__bsd3__ ) ) /** Declare a file as being under the two-clause BSD licence * @@ -728,7 +731,7 @@ int __debug_disable; * functionally equivalent to the standard two-clause BSD licence. */ #define FILE_LICENCE_BSD2 \ - PROVIDE_SYMBOL ( __licence_bsd2 ) + PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__bsd2__ ) ) /** Declare a file as being under the one-clause MIT-style licence * @@ -738,7 +741,7 @@ int __debug_disable; * permission notice appear in all copies. */ #define FILE_LICENCE_MIT \ - PROVIDE_SYMBOL ( __licence_mit ) + PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__mit__ ) ) /** Declare a particular licence as applying to a file */ #define FILE_LICENCE( _licence ) FILE_LICENCE_ ## _licence |