aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorJan Beulich <jbeulich@novell.com>2008-12-16 06:28:14 -0500
committerSam Ravnborg <sam@ravnborg.org>2008-12-19 16:41:15 -0500
commitad7a953c522ceb496611d127e51e278bfe0ff483 (patch)
treef51a18ab282bb77244fc02ad33359a92b6b36eb9 /scripts
parent37a8d9f67f18de1e2cbc7387311ce22d4dbff518 (diff)
kbuild: strip generated symbols from *.ko
This patch changes the way __crc_ symbols are being resolved from using ld to do so to using the assembler, thus allowing these symbols to be marked local (the linker creates then as global ones) and hence allow stripping (for modules) or ignoring (for vmlinux) them. While at this, also strip other generated symbols during module installation. One potentially debatable point is the handling of the flags passeed to gcc when translating the intermediate assembly file into an object: passing $(c_flags) unchanged doesn't work as gcc passes --gdwarf2 to gas whenever is sees any -g* option, even for -g0, and despite the fact that the compiler would have already produced all necessary debug info in the C->assembly translation phase. I took the approach of just filtering out all -g* options, but an alternative to such negative filtering might be to have a positive filter which might, in the ideal case allow just all the -Wa,* options to pass through. Signed-off-by: Jan Beulich <jbeulich@novell.com> Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/Makefile.build55
-rw-r--r--scripts/Makefile.modinst3
-rw-r--r--scripts/genksyms/genksyms.c21
-rw-r--r--scripts/mksysmap7
-rw-r--r--scripts/strip-symbols22
5 files changed, 76 insertions, 32 deletions
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index c1da14b9f59d..6a2153891592 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -151,16 +151,16 @@ cmd_cc_i_c = $(CPP) $(c_flags) -o $@ $<
151$(obj)/%.i: $(src)/%.c FORCE 151$(obj)/%.i: $(src)/%.c FORCE
152 $(call if_changed_dep,cc_i_c) 152 $(call if_changed_dep,cc_i_c)
153 153
154cmd_gensymtypes = \ 154cmd_genksyms = \
155 $(CPP) -D__GENKSYMS__ $(c_flags) $< | \ 155 $(CPP) -D__GENKSYMS__ $(c_flags) $< | \
156 $(GENKSYMS) -T $@ -a $(ARCH) \ 156 $(GENKSYMS) -T $@ -A -a $(ARCH) \
157 $(if $(KBUILD_PRESERVE),-p) \ 157 $(if $(KBUILD_PRESERVE),-p) \
158 $(if $(1),-r $(firstword $(wildcard $(@:.symtypes=.symref) /dev/null))) 158 $(if $(1),-r $(firstword $(wildcard $(@:.symtypes=.symref) /dev/null)))
159 159
160quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@ 160quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@
161cmd_cc_symtypes_c = \ 161cmd_cc_symtypes_c = \
162 set -e; \ 162 set -e; \
163 $(call cmd_gensymtypes, true) >/dev/null; \ 163 $(call cmd_genksyms, true) >/dev/null; \
164 test -s $@ || rm -f $@ 164 test -s $@ || rm -f $@
165 165
166$(obj)/%.symtypes : $(src)/%.c FORCE 166$(obj)/%.symtypes : $(src)/%.c FORCE
@@ -177,28 +177,38 @@ cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
177 177
178else 178else
179# When module versioning is enabled the following steps are executed: 179# When module versioning is enabled the following steps are executed:
180# o compile a .tmp_<file>.o from <file>.c 180# o compile a .tmp_<file>.s from <file>.c
181# o if .tmp_<file>.o doesn't contain a __ksymtab version, i.e. does 181# o if .tmp_<file>.s doesn't contain a __ksymtab version, i.e. does
182# not export symbols, we just rename .tmp_<file>.o to <file>.o and 182# not export symbols, we just assemble .tmp_<file>.s to <file>.o and
183# are done. 183# are done.
184# o otherwise, we calculate symbol versions using the good old 184# o otherwise, we calculate symbol versions using the good old
185# genksyms on the preprocessed source and postprocess them in a way 185# genksyms on the preprocessed source and postprocess them in a way
186# that they are usable as a linker script 186# that they are usable as assembly source
187# o generate <file>.o from .tmp_<file>.o using the linker to 187# o assemble <file>.o from .tmp_<file>.s forcing inclusion of directives
188# replace the unresolved symbols __crc_exported_symbol with 188# defining the actual values of __crc_*, followed by objcopy-ing them
189# the actual value of the checksum generated by genksyms 189# to force these symbols to be local to permit stripping them later.
190s_file = $(@D)/.tmp_$(@F:.o=.s)
191v_file = $(@D)/.tmp_$(@F:.o=.v)
192tmp_o_file = $(@D)/.tmp_$(@F)
193no_g_c_flags = $(filter-out -g%,$(c_flags))
194
195cmd_cc_o_c = $(CC) $(c_flags) -S -o $(s_file) $<
190 196
191cmd_cc_o_c = $(CC) $(c_flags) -c -o $(@D)/.tmp_$(@F) $<
192cmd_modversions = \ 197cmd_modversions = \
193 if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \ 198 if grep -q __ksymtab $(s_file); then \
194 $(call cmd_gensymtypes, $(KBUILD_SYMTYPES)) \ 199 if $(call cmd_genksyms, $(KBUILD_SYMTYPES)) > $(v_file) \
195 > $(@D)/.tmp_$(@F:.o=.ver); \ 200 && $(CC) $(no_g_c_flags) -c -Wa,$(v_file) \
196 \ 201 -o $(tmp_o_file) $(s_file) \
197 $(LD) $(LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \ 202 && $(OBJCOPY) -L '__crc_*' -L '___crc_*' -w \
198 -T $(@D)/.tmp_$(@F:.o=.ver); \ 203 $(tmp_o_file) $@; \
199 rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=.ver); \ 204 then \
205 : ; \
206 else \
207 rm -f $@; exit 1; \
208 fi; \
200 else \ 209 else \
201 mv -f $(@D)/.tmp_$(@F) $@; \ 210 rm -f $(v_file); \
211 $(CC) $(no_g_c_flags) -c -o $@ $(s_file); \
202 fi; 212 fi;
203endif 213endif
204 214
@@ -221,7 +231,12 @@ define rule_cc_o_c
221 $(cmd_record_mcount) \ 231 $(cmd_record_mcount) \
222 scripts/basic/fixdep $(depfile) $@ '$(call make-cmd,cc_o_c)' > \ 232 scripts/basic/fixdep $(depfile) $@ '$(call make-cmd,cc_o_c)' > \
223 $(dot-target).tmp; \ 233 $(dot-target).tmp; \
224 rm -f $(depfile); \ 234 if [ -r $(@D)/.tmp_$(@F:.o=.v) ]; then \
235 echo >> $(dot-target).tmp; \
236 echo '$@: $(GENKSYMS)' >> $(dot-target).tmp; \
237 echo '$(GENKSYMS):: ;' >> $(dot-target).tmp; \
238 fi; \
239 rm -f $(depfile) $(@D)/.tmp_$(@F:.o=.?); \
225 mv -f $(dot-target).tmp $(dot-target).cmd 240 mv -f $(dot-target).tmp $(dot-target).cmd
226endef 241endef
227 242
diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst
index efa5d940e632..a5122dce1264 100644
--- a/scripts/Makefile.modinst
+++ b/scripts/Makefile.modinst
@@ -17,7 +17,8 @@ __modinst: $(modules)
17 @: 17 @:
18 18
19quiet_cmd_modules_install = INSTALL $@ 19quiet_cmd_modules_install = INSTALL $@
20 cmd_modules_install = mkdir -p $(2); cp $@ $(2) ; $(mod_strip_cmd) $(2)/$(notdir $@) 20 cmd_modules_install = mkdir -p $(2); \
21 $(mod_strip_cmd) $@ $(2)/$(notdir $@) || cp $@ $(2)
21 22
22# Modules built outside the kernel source tree go into extra by default 23# Modules built outside the kernel source tree go into extra by default
23INSTALL_MOD_DIR ?= extra 24INSTALL_MOD_DIR ?= extra
diff --git a/scripts/genksyms/genksyms.c b/scripts/genksyms/genksyms.c
index 3a8297b5184c..f8bb4cabd62d 100644
--- a/scripts/genksyms/genksyms.c
+++ b/scripts/genksyms/genksyms.c
@@ -43,7 +43,7 @@ int cur_line = 1;
43char *cur_filename; 43char *cur_filename;
44 44
45static int flag_debug, flag_dump_defs, flag_reference, flag_dump_types, 45static int flag_debug, flag_dump_defs, flag_reference, flag_dump_types,
46 flag_preserve, flag_warnings; 46 flag_preserve, flag_warnings, flag_asm;
47static const char *arch = ""; 47static const char *arch = "";
48static const char *mod_prefix = ""; 48static const char *mod_prefix = "";
49 49
@@ -610,8 +610,11 @@ void export_symbol(const char *name)
610 if (flag_dump_defs) 610 if (flag_dump_defs)
611 fputs(">\n", debugfile); 611 fputs(">\n", debugfile);
612 612
613 /* Used as a linker script. */ 613 /* Used as assembly source or a linker script. */
614 printf("%s__crc_%s = 0x%08lx ;\n", mod_prefix, name, crc); 614 printf(flag_asm
615 ? ".equiv %s__crc_%s, %#08lx\n"
616 : "%s__crc_%s = %#08lx ;\n",
617 mod_prefix, name, crc);
615 } 618 }
616} 619}
617 620
@@ -648,9 +651,10 @@ void error_with_pos(const char *fmt, ...)
648 651
649static void genksyms_usage(void) 652static void genksyms_usage(void)
650{ 653{
651 fputs("Usage:\n" "genksyms [-adDTwqhV] > /path/to/.tmp_obj.ver\n" "\n" 654 fputs("Usage:\n" "genksyms [-aAdDTwqhV] > /path/to/.tmp_obj.ver\n" "\n"
652#ifdef __GNU_LIBRARY__ 655#ifdef __GNU_LIBRARY__
653 " -a, --arch Select architecture\n" 656 " -a, --arch Select architecture\n"
657 " -A, --asm Generate assembly rather than linker script\n"
654 " -d, --debug Increment the debug level (repeatable)\n" 658 " -d, --debug Increment the debug level (repeatable)\n"
655 " -D, --dump Dump expanded symbol defs (for debugging only)\n" 659 " -D, --dump Dump expanded symbol defs (for debugging only)\n"
656 " -r, --reference file Read reference symbols from a file\n" 660 " -r, --reference file Read reference symbols from a file\n"
@@ -662,6 +666,7 @@ static void genksyms_usage(void)
662 " -V, --version Print the release version\n" 666 " -V, --version Print the release version\n"
663#else /* __GNU_LIBRARY__ */ 667#else /* __GNU_LIBRARY__ */
664 " -a Select architecture\n" 668 " -a Select architecture\n"
669 " -A Generate assembly rather than linker script\n"
665 " -d Increment the debug level (repeatable)\n" 670 " -d Increment the debug level (repeatable)\n"
666 " -D Dump expanded symbol defs (for debugging only)\n" 671 " -D Dump expanded symbol defs (for debugging only)\n"
667 " -r file Read reference symbols from a file\n" 672 " -r file Read reference symbols from a file\n"
@@ -683,6 +688,7 @@ int main(int argc, char **argv)
683#ifdef __GNU_LIBRARY__ 688#ifdef __GNU_LIBRARY__
684 struct option long_opts[] = { 689 struct option long_opts[] = {
685 {"arch", 1, 0, 'a'}, 690 {"arch", 1, 0, 'a'},
691 {"asm", 0, 0, 'A'},
686 {"debug", 0, 0, 'd'}, 692 {"debug", 0, 0, 'd'},
687 {"warnings", 0, 0, 'w'}, 693 {"warnings", 0, 0, 'w'},
688 {"quiet", 0, 0, 'q'}, 694 {"quiet", 0, 0, 'q'},
@@ -695,10 +701,10 @@ int main(int argc, char **argv)
695 {0, 0, 0, 0} 701 {0, 0, 0, 0}
696 }; 702 };
697 703
698 while ((o = getopt_long(argc, argv, "a:dwqVDr:T:ph", 704 while ((o = getopt_long(argc, argv, "a:dwqVADr:T:ph",
699 &long_opts[0], NULL)) != EOF) 705 &long_opts[0], NULL)) != EOF)
700#else /* __GNU_LIBRARY__ */ 706#else /* __GNU_LIBRARY__ */
701 while ((o = getopt(argc, argv, "a:dwqVDr:T:ph")) != EOF) 707 while ((o = getopt(argc, argv, "a:dwqVADr:T:ph")) != EOF)
702#endif /* __GNU_LIBRARY__ */ 708#endif /* __GNU_LIBRARY__ */
703 switch (o) { 709 switch (o) {
704 case 'a': 710 case 'a':
@@ -716,6 +722,9 @@ int main(int argc, char **argv)
716 case 'V': 722 case 'V':
717 fputs("genksyms version 2.5.60\n", stderr); 723 fputs("genksyms version 2.5.60\n", stderr);
718 break; 724 break;
725 case 'A':
726 flag_asm = 1;
727 break;
719 case 'D': 728 case 'D':
720 flag_dump_defs = 1; 729 flag_dump_defs = 1;
721 break; 730 break;
diff --git a/scripts/mksysmap b/scripts/mksysmap
index 6e133a0bae7a..1db316a3712b 100644
--- a/scripts/mksysmap
+++ b/scripts/mksysmap
@@ -37,9 +37,6 @@
37 37
38# readprofile starts reading symbols when _stext is found, and 38# readprofile starts reading symbols when _stext is found, and
39# continue until it finds a symbol which is not either of 'T', 't', 39# continue until it finds a symbol which is not either of 'T', 't',
40# 'W' or 'w'. __crc_ are 'A' and placed in the middle 40# 'W' or 'w'.
41# so we just ignore them to let readprofile continue to work.
42# (At least sparc64 has __crc_ in the middle).
43
44$NM -n $1 | grep -v '\( [aNUw] \)\|\(__crc_\)\|\( \$[adt]\)' > $2
45 41
42$NM -n $1 | grep -v '\( [aNUw] \)\|\( \$[adt]\)' > $2
diff --git a/scripts/strip-symbols b/scripts/strip-symbols
new file mode 100644
index 000000000000..29ee8c1a014b
--- /dev/null
+++ b/scripts/strip-symbols
@@ -0,0 +1,22 @@
1<*>
2*.h
3__compound_literal[$.][0-9]*
4__crc_[a-zA-Z_]*
5__exitcall_[a-zA-Z_]*
6__func__[$.][0-9]*
7__FUNCTION__[$.][0-9]*
8gcc[0-9]_compiled[$.]
9__initcall_[a-zA-Z_]*
10__kcrctab_[a-zA-Z_]*
11__kstrtab_[a-zA-Z_]*
12__ksymtab_[a-zA-Z_]*
13__mod_[a-zA-Z_]*[0-9]
14__module_depends
15__param_[a-zA-Z_]*
16__pci_fixup_*PCI_ANY_IDPCI_ANY_ID*
17__pci_fixup_*PCI_ANY_IDPCI_DEVICE_ID_*
18__pci_fixup_*PCI_VENDOR_ID_*PCI_ANY_ID*
19__pci_fixup_*PCI_VENDOR_ID_*PCI_DEVICE_ID_*
20__PRETTY_FUNCTION__[$.][0-9]*
21__setup_[a-zA-Z_]*
22____versions