Skip to content

Commit ee3e46b

Browse files
committed
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 9c2af1c ("kbuild: add .DELETE_ON_ERROR special target"). Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
1 parent 4317ee3 commit ee3e46b

File tree

1 file changed

+17
-37
lines changed

1 file changed

+17
-37
lines changed

scripts/Makefile.build

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -154,35 +154,30 @@ $(obj)/%.ll: $(src)/%.c FORCE
154154
# (See cmd_cc_o_c + relevant part of rule_cc_o_c)
155155

156156
quiet_cmd_cc_o_c = CC $(quiet_modtag) $@
157+
cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
157158

158-
ifndef CONFIG_MODVERSIONS
159-
cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
160-
161-
else
159+
ifdef CONFIG_MODVERSIONS
162160
# 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.
167164
# o otherwise, we calculate symbol versions using the good old
168165
# genksyms on the preprocessed source and postprocess them in a way
169166
# 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
171168
# replace the unresolved symbols __crc_exported_symbol with
172169
# 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
175171

176172
cmd_modversions_c = \
177-
if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \
173+
if $(OBJDUMP) -h $@ | grep -q __ksymtab; then \
178174
$(call cmd_gensymtypes_c,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \
179175
> $(@D)/.tmp_$(@F:.o=.ver); \
180176
\
181-
$(LD) $(KBUILD_LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \
177+
$(LD) $(KBUILD_LDFLAGS) -r -o $(@D)/.tmp_$(@F) $@ \
182178
-T $(@D)/.tmp_$(@F:.o=.ver); \
183-
rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=.ver); \
184-
else \
185179
mv -f $(@D)/.tmp_$(@F) $@; \
180+
rm -f $(@D)/.tmp_$(@F:.o=.ver); \
186181
fi;
187182
endif
188183

@@ -241,19 +236,12 @@ ifneq ($(RETPOLINE_CFLAGS),)
241236
endif
242237
endif
243238

244-
245-
ifdef CONFIG_MODVERSIONS
246-
objtool_o = $(@D)/.tmp_$(@F)
247-
else
248-
objtool_o = $(@)
249-
endif
250-
251239
# 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory
252240
# 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
253241
# 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
254242
cmd_objtool = $(if $(patsubst y%,, \
255243
$(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \
256-
$(__objtool_obj) $(objtool_args) "$(objtool_o)";)
244+
$(__objtool_obj) $(objtool_args) $@;)
257245
objtool_obj = $(if $(patsubst y%,, \
258246
$(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n), \
259247
$(__objtool_obj))
@@ -357,34 +345,26 @@ $(obj)/%.s: $(src)/%.S FORCE
357345
$(call if_changed_dep,cpp_s_S)
358346

359347
quiet_cmd_as_o_S = AS $(quiet_modtag) $@
348+
cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
360349

361-
ifndef CONFIG_MODVERSIONS
362-
cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
363-
364-
else
350+
ifdef CONFIG_MODVERSIONS
365351

366352
ASM_PROTOTYPES := $(wildcard $(srctree)/arch/$(SRCARCH)/include/asm/asm-prototypes.h)
367353

368-
ifeq ($(ASM_PROTOTYPES),)
369-
cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
370-
371-
else
354+
ifneq ($(ASM_PROTOTYPES),)
372355

373356
# versioning matches the C process described above, with difference that
374357
# we parse asm-prototypes.h C header to get function definitions.
375358

376-
cmd_as_o_S = $(CC) $(a_flags) -c -o $(@D)/.tmp_$(@F) $<
377-
378359
cmd_modversions_S = \
379-
if $(OBJDUMP) -h $(@D)/.tmp_$(@F) | grep -q __ksymtab; then \
360+
if $(OBJDUMP) -h $@ | grep -q __ksymtab; then \
380361
$(call cmd_gensymtypes_S,$(KBUILD_SYMTYPES),$(@:.o=.symtypes)) \
381362
> $(@D)/.tmp_$(@F:.o=.ver); \
382363
\
383-
$(LD) $(KBUILD_LDFLAGS) -r -o $@ $(@D)/.tmp_$(@F) \
364+
$(LD) $(KBUILD_LDFLAGS) -r -o $(@D)/.tmp_$(@F) $@ \
384365
-T $(@D)/.tmp_$(@F:.o=.ver); \
385-
rm -f $(@D)/.tmp_$(@F) $(@D)/.tmp_$(@F:.o=.ver); \
386-
else \
387366
mv -f $(@D)/.tmp_$(@F) $@; \
367+
rm -f $(@D)/.tmp_$(@F:.o=.ver); \
388368
fi;
389369
endif
390370
endif

0 commit comments

Comments
 (0)