diff options
author | Jan Beulich <jbeulich@novell.com> | 2008-12-16 06:28:14 -0500 |
---|---|---|
committer | Sam Ravnborg <sam@ravnborg.org> | 2008-12-19 16:41:15 -0500 |
commit | ad7a953c522ceb496611d127e51e278bfe0ff483 (patch) | |
tree | f51a18ab282bb77244fc02ad33359a92b6b36eb9 /scripts/Makefile.build | |
parent | 37a8d9f67f18de1e2cbc7387311ce22d4dbff518 (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/Makefile.build')
-rw-r--r-- | scripts/Makefile.build | 55 |
1 files changed, 35 insertions, 20 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 | ||
154 | cmd_gensymtypes = \ | 154 | cmd_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 | ||
160 | quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@ | 160 | quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@ |
161 | cmd_cc_symtypes_c = \ | 161 | cmd_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 | ||
178 | else | 178 | else |
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. |
190 | s_file = $(@D)/.tmp_$(@F:.o=.s) | ||
191 | v_file = $(@D)/.tmp_$(@F:.o=.v) | ||
192 | tmp_o_file = $(@D)/.tmp_$(@F) | ||
193 | no_g_c_flags = $(filter-out -g%,$(c_flags)) | ||
194 | |||
195 | cmd_cc_o_c = $(CC) $(c_flags) -S -o $(s_file) $< | ||
190 | 196 | ||
191 | cmd_cc_o_c = $(CC) $(c_flags) -c -o $(@D)/.tmp_$(@F) $< | ||
192 | cmd_modversions = \ | 197 | cmd_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; |
203 | endif | 213 | endif |
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 |
226 | endef | 241 | endef |
227 | 242 | ||