[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>
This commit is contained in:
Michael Brown
2013-07-16 00:08:50 +02:00
parent 9978e2cb37
commit ca319873bf
7 changed files with 31 additions and 13 deletions

View File

@@ -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,$<)),\