Przeglądaj źródła

[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>
tags/v1.20.1
Michael Brown 11 lat temu
rodzic
commit
ca319873bf

+ 8
- 3
src/Makefile.housekeeping Wyświetl plik

@@ -1011,15 +1011,20 @@ $(BIN)/%.nodeps : $(BIN)/%.tmp
1011 1011
 # Get licensing verdict for the specified target
1012 1012
 #
1013 1013
 define licensable_deps_list
1014
-	$(filter-out config/local/%.h,$(call deps_list,$(1)))
1014
+	$(filter-out config/local/%.h,\
1015
+	  $(filter-out $(BIN)/.%.list,\
1016
+	    $(call deps_list,$(1))))
1015 1017
 endef
1016 1018
 define unlicensed_deps_list
1017 1019
 	$(shell grep -L FILE_LICENCE $(call licensable_deps_list,$(1)))
1018 1020
 endef
1019 1021
 define licence_list
1020
-	$(patsubst __licence_%,%,\
1021
-	  $(filter __licence_%,$(shell $(NM) $(1) | cut -d" " -f3)))
1022
+	$(sort $(foreach LICENCE,\
1023
+		 $(filter __licence__%,$(shell $(NM) $(1) | cut -d" " -f3)),\
1024
+		 $(word 2,$(subst __, ,$(LICENCE)))))
1022 1025
 endef
1026
+$(BIN)/%.licence_list : $(BIN)/%.tmp
1027
+	$(Q)$(ECHO) $(call licence_list,$<)
1023 1028
 $(BIN)/%.licence : $(BIN)/%.tmp
1024 1029
 	$(QM)$(ECHO) "  [LICENCE] $@"
1025 1030
 	$(Q)$(if $(strip $(call unlicensed_deps_list,$<)),\

+ 2
- 0
src/arch/i386/scripts/i386-kir.lds Wyświetl plik

@@ -98,6 +98,8 @@ SECTIONS {
98 98
 	*(.data)
99 99
 	*(.data.*)
100 100
 	KEEP(*(SORT(.tbl.*)))	/* Various tables.  See include/tables.h */
101
+	KEEP(*(.provided))
102
+	KEEP(*(.provided.*))
101 103
 	_edata16_progbits = .;
102 104
     }
103 105
     .bss16 : AT ( _data16_load_offset + __bss16 ) {

+ 2
- 0
src/arch/i386/scripts/i386.lds Wyświetl plik

@@ -109,6 +109,8 @@ SECTIONS {
109 109
 	*(.data)
110 110
 	*(.data.*)
111 111
 	KEEP(*(SORT(.tbl.*)))	/* Various tables.  See include/tables.h */
112
+	KEEP(*(.provided))
113
+	KEEP(*(.provided.*))
112 114
 	_mtextdata = .;
113 115
     } .bss.textdata (NOLOAD) : AT ( _end_lma ) {
114 116
 	*(.bss)

+ 2
- 0
src/arch/i386/scripts/linux.lds Wyświetl plik

@@ -53,6 +53,8 @@ SECTIONS {
53 53
 		*(.data)
54 54
 		*(.data.*)
55 55
 		KEEP(*(SORT(.tbl.*)))
56
+		KEEP(*(.provided))
57
+		KEEP(*(.provided.*))
56 58
 		_edata = .;
57 59
 	}
58 60
 

+ 2
- 0
src/arch/x86/scripts/efi.lds Wyświetl plik

@@ -55,6 +55,8 @@ SECTIONS {
55 55
 	*(.data)
56 56
 	*(.data.*)
57 57
 	KEEP(*(SORT(.tbl.*)))	/* Various tables.  See include/tables.h */
58
+	KEEP(*(.provided))
59
+	KEEP(*(.provided.*))
58 60
 	_edata = .;
59 61
     }
60 62
 

+ 2
- 0
src/arch/x86_64/scripts/linux.lds Wyświetl plik

@@ -53,6 +53,8 @@ SECTIONS {
53 53
 		*(.data)
54 54
 		*(.data.*)
55 55
 		KEEP(*(SORT(.tbl.*)))
56
+		KEEP(*(.provided))
57
+		KEEP(*(.provided.*))
56 58
 		_edata = .;
57 59
 	}
58 60
 

+ 13
- 10
src/include/compiler.h Wyświetl plik

@@ -60,12 +60,15 @@
60 60
 /** Provide a symbol within this object file */
61 61
 #ifdef ASSEMBLY
62 62
 #define PROVIDE_SYMBOL( _sym )				\
63
+	.section ".provided", "a", @nobits ;		\
64
+	.hidden _sym ;					\
63 65
 	.globl	_sym ;					\
64
-	.comm	_sym, 0
66
+	_sym: ;						\
67
+	.previous
65 68
 #else /* ASSEMBLY */
66 69
 #define PROVIDE_SYMBOL( _sym )				\
67
-	extern char _sym[];				\
68
-	char _sym[0]
70
+	char _sym[0]					\
71
+	  __attribute__ (( section ( ".provided" ) ))
69 72
 #endif /* ASSEMBLY */
70 73
 
71 74
 /** Require a symbol within this object file
@@ -652,7 +655,7 @@ int __debug_disable;
652 655
  * be in the public domain.
653 656
  */
654 657
 #define FILE_LICENCE_PUBLIC_DOMAIN \
655
-	PROVIDE_SYMBOL ( __licence_public_domain )
658
+	PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__public_domain__ ) )
656 659
 
657 660
 /** Declare a file as being under version 2 (or later) of the GNU GPL
658 661
  *
@@ -661,7 +664,7 @@ int __debug_disable;
661 664
  * (at your option) any later version".
662 665
  */
663 666
 #define FILE_LICENCE_GPL2_OR_LATER \
664
-	PROVIDE_SYMBOL ( __licence_gpl2_or_later )
667
+	PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__gpl2_or_later__ ) )
665 668
 
666 669
 /** Declare a file as being under version 2 of the GNU GPL
667 670
  *
@@ -670,7 +673,7 @@ int __debug_disable;
670 673
  * "or, at your option, any later version" clause.
671 674
  */
672 675
 #define FILE_LICENCE_GPL2_ONLY \
673
-	PROVIDE_SYMBOL ( __licence_gpl2_only )
676
+	PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__gpl2_only__ ) )
674 677
 
675 678
 /** Declare a file as being under any version of the GNU GPL
676 679
  *
@@ -682,7 +685,7 @@ int __debug_disable;
682 685
  * version ever published by the Free Software Foundation".
683 686
  */
684 687
 #define FILE_LICENCE_GPL_ANY \
685
-	PROVIDE_SYMBOL ( __licence_gpl_any )
688
+	PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__gpl_any__ ) )
686 689
 
687 690
 /** Declare a file as being under the three-clause BSD licence
688 691
  *
@@ -707,7 +710,7 @@ int __debug_disable;
707 710
  * functionally equivalent to the standard three-clause BSD licence.
708 711
  */
709 712
 #define FILE_LICENCE_BSD3 \
710
-	PROVIDE_SYMBOL ( __licence_bsd3 )
713
+	PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__bsd3__ ) )
711 714
 
712 715
 /** Declare a file as being under the two-clause BSD licence
713 716
  *
@@ -728,7 +731,7 @@ int __debug_disable;
728 731
  * functionally equivalent to the standard two-clause BSD licence.
729 732
  */
730 733
 #define FILE_LICENCE_BSD2 \
731
-	PROVIDE_SYMBOL ( __licence_bsd2 )
734
+	PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__bsd2__ ) )
732 735
 
733 736
 /** Declare a file as being under the one-clause MIT-style licence
734 737
  *
@@ -738,7 +741,7 @@ int __debug_disable;
738 741
  * permission notice appear in all copies.
739 742
  */
740 743
 #define FILE_LICENCE_MIT \
741
-	PROVIDE_SYMBOL ( __licence_mit )
744
+	PROVIDE_SYMBOL ( PREFIX_OBJECT ( __licence__mit__ ) )
742 745
 
743 746
 /** Declare a particular licence as applying to a file */
744 747
 #define FILE_LICENCE( _licence ) FILE_LICENCE_ ## _licence

Ładowanie…
Anuluj
Zapisz