Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kbuild: refactor modversions build rules

Let $(CC) compile objects into normal files *.o instead of .tmp_*.o
whether CONFIG_MODVERSIONS is enabled or not. With this, the input
file for objtool is always *.o so objtool_o can go away.

I guess the reason of using .tmp_*.o for intermediate objects was
to avoid leaving incomplete *.o file (, whose timestamp says it is
up-to-date) when the genksyms tool failed for some reasons.

It no longer matters because any targets are deleted on errors since
commit 9c2af1c7377a ("kbuild: add .DELETE_ON_ERROR special target").

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

+17 -37
+17 -37
scripts/Makefile.build
··· 154 154 # (See cmd_cc_o_c + relevant part of rule_cc_o_c) 155 155 156 156 quiet_cmd_cc_o_c = CC $(quiet_modtag) $@ 157 + cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< 157 158 158 - ifndef CONFIG_MODVERSIONS 159 - cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< 160 - 161 - else 159 + ifdef CONFIG_MODVERSIONS 162 160 # When module versioning is enabled the following steps are executed: 163 - # o compile a .tmp_<file>.o from <file>.c 164 - # o if .tmp_<file>.o doesn't contain a __ksymtab version, i.e. does 165 - # not export symbols, we just rename .tmp_<file>.o to <file>.o and 166 - # are done. 161 + # o compile a <file>.o from <file>.c 162 + # o if <file>.o doesn't contain a __ksymtab version, i.e. does 163 + # not export symbols, it's done. 167 164 # o otherwise, we calculate symbol versions using the good old 168 165 # genksyms on the preprocessed source and postprocess them in a way 169 166 # that they are usable as a linker script 170 - # o generate <file>.o from .tmp_<file>.o using the linker to 167 + # o generate .tmp_<file>.o from <file>.o using the linker to 171 168 # replace the unresolved symbols __crc_exported_symbol with 172 169 # the actual value of the checksum generated by genksyms 173 - 174 - cmd_cc_o_c = $(CC) $(c_flags) -c -o $(@D)/.tmp_$(@F) $< 170 + # o remove .tmp_<file>.o to <file>.o 175 171 176 172 cmd_modversions_c = \ 177 - if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \ 173 + if $(OBJDUMP) -h $@ | grep -q __ksymtab; then \ 178 174 $(call cmd_gensymtypes_c,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \ 179 175 > $(@D)/.tmp_$(@F:.o=.ver); \ 180 176 \ 181 - $(LD) $(KBUILD_LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \ 177 + $(LD) $(KBUILD_LDFLAGS) -r -o $(@D)/.tmp_$(@F) $@ \ 182 178 -T $(@D)/.tmp_$(@F:.o=.ver); \ 183 - rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=.ver); \ 184 - else \ 185 179 mv -f $(@D)/.tmp_$(@F) $@; \ 180 + rm -f $(@D)/.tmp_$(@F:.o=.ver); \ 186 181 fi; 187 182 endif 188 183 ··· 236 241 endif 237 242 endif 238 243 239 - 240 - ifdef CONFIG_MODVERSIONS 241 - objtool_o = $(@D)/.tmp_$(@F) 242 - else 243 - objtool_o = $(@) 244 - endif 245 - 246 244 # 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory 247 245 # 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file 248 246 # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file 249 247 cmd_objtool = $(if $(patsubst y%,, \ 250 248 $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \ 251 - $(__objtool_obj) $(objtool_args) "$(objtool_o)";) 249 + $(__objtool_obj) $(objtool_args) $@;) 252 250 objtool_obj = $(if $(patsubst y%,, \ 253 251 $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \ 254 252 $(__objtool_obj)) ··· 345 357 $(call if_changed_dep,cpp_s_S) 346 358 347 359 quiet_cmd_as_o_S = AS $(quiet_modtag) $@ 360 + cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $< 348 361 349 - ifndef CONFIG_MODVERSIONS 350 - cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $< 351 - 352 - else 362 + ifdef CONFIG_MODVERSIONS 353 363 354 364 ASM_PROTOTYPES := $(wildcard $(srctree)/arch/$(SRCARCH)/include/asm/asm-prototypes.h) 355 365 356 - ifeq ($(ASM_PROTOTYPES),) 357 - cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $< 358 - 359 - else 366 + ifneq ($(ASM_PROTOTYPES),) 360 367 361 368 # versioning matches the C process described above, with difference that 362 369 # we parse asm-prototypes.h C header to get function definitions. 363 370 364 - cmd_as_o_S = $(CC) $(a_flags) -c -o $(@D)/.tmp_$(@F) $< 365 - 366 371 cmd_modversions_S = \ 367 - if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \ 372 + if $(OBJDUMP) -h $@ | grep -q __ksymtab; then \ 368 373 $(call cmd_gensymtypes_S,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \ 369 374 > $(@D)/.tmp_$(@F:.o=.ver); \ 370 375 \ 371 - $(LD) $(KBUILD_LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \ 376 + $(LD) $(KBUILD_LDFLAGS) -r -o $(@D)/.tmp_$(@F) $@ \ 372 377 -T $(@D)/.tmp_$(@F:.o=.ver); \ 373 - rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=.ver); \ 374 - else \ 375 378 mv -f $(@D)/.tmp_$(@F) $@; \ 379 + rm -f $(@D)/.tmp_$(@F:.o=.ver); \ 376 380 fi; 377 381 endif 378 382 endif