Parcourir la source

[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 il y a 11 ans
Parent
révision
ca319873bf

+ 8
- 3
src/Makefile.housekeeping Voir le fichier

1011
 # Get licensing verdict for the specified target
1011
 # Get licensing verdict for the specified target
1012
 #
1012
 #
1013
 define licensable_deps_list
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
 endef
1017
 endef
1016
 define unlicensed_deps_list
1018
 define unlicensed_deps_list
1017
 	$(shell grep -L FILE_LICENCE $(call licensable_deps_list,$(1)))
1019
 	$(shell grep -L FILE_LICENCE $(call licensable_deps_list,$(1)))
1018
 endef
1020
 endef
1019
 define licence_list
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
 endef
1025
 endef
1026
+$(BIN)/%.licence_list : $(BIN)/%.tmp
1027
+	$(Q)$(ECHO) $(call licence_list,$<)
1023
 $(BIN)/%.licence : $(BIN)/%.tmp
1028
 $(BIN)/%.licence : $(BIN)/%.tmp
1024
 	$(QM)$(ECHO) "  [LICENCE] $@"
1029
 	$(QM)$(ECHO) "  [LICENCE] $@"
1025
 	$(Q)$(if $(strip $(call unlicensed_deps_list,$<)),\
1030
 	$(Q)$(if $(strip $(call unlicensed_deps_list,$<)),\

+ 2
- 0
src/arch/i386/scripts/i386-kir.lds Voir le fichier

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

+ 2
- 0
src/arch/i386/scripts/i386.lds Voir le fichier

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

+ 2
- 0
src/arch/i386/scripts/linux.lds Voir le fichier

53
 		*(.data)
53
 		*(.data)
54
 		*(.data.*)
54
 		*(.data.*)
55
 		KEEP(*(SORT(.tbl.*)))
55
 		KEEP(*(SORT(.tbl.*)))
56
+		KEEP(*(.provided))
57
+		KEEP(*(.provided.*))
56
 		_edata = .;
58
 		_edata = .;
57
 	}
59
 	}
58
 
60
 

+ 2
- 0
src/arch/x86/scripts/efi.lds Voir le fichier

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

+ 2
- 0
src/arch/x86_64/scripts/linux.lds Voir le fichier

53
 		*(.data)
53
 		*(.data)
54
 		*(.data.*)
54
 		*(.data.*)
55
 		KEEP(*(SORT(.tbl.*)))
55
 		KEEP(*(SORT(.tbl.*)))
56
+		KEEP(*(.provided))
57
+		KEEP(*(.provided.*))
56
 		_edata = .;
58
 		_edata = .;
57
 	}
59
 	}
58
 
60
 

+ 13
- 10
src/include/compiler.h Voir le fichier

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

Chargement…
Annuler
Enregistrer