mirror of https://gitee.com/openkylin/linux.git
kbuild: link $(real-obj-y) instead of $(obj-y) into built-in.a
In Kbuild, Makefiles can add the same object to obj-y multiple times. So, obj-y += foo.o obj-y += foo.o is fine. However, this is not true when the same object is added multiple times via composite objects. For example, obj-y += foo.o bar.o foo-objs := foo-bar-common.o foo-only.o bar-objs := foo-bar-common.o bar-only.o causes build error because two instances of foo-bar-common.o are linked into the vmlinux. Makefiles tend to invent ugly work-around, for example - lib/zstd/Makefile - drivers/net/ethernet/cavium/liquidio/Makefile The technique used in Kbuild to avoid the multiple definition error is to use $(filter $(obj-y), $^). Here, $^ lists the names of all the prerequisites with duplicated names removed. By replacing it with $(filter $(real-obj-y), $^) we can do likewise for composite objects. For built-in objects, we do not need to keep the composite object structure. We can simply expand them, and link $(real-obj-y) to built-in.a. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
This commit is contained in:
parent
f5f336812c
commit
f98fe47ce5
|
@ -73,10 +73,10 @@ endif
|
||||||
|
|
||||||
ifneq ($(strip $(lib-y) $(lib-m) $(lib-)),)
|
ifneq ($(strip $(lib-y) $(lib-m) $(lib-)),)
|
||||||
lib-target := $(obj)/lib.a
|
lib-target := $(obj)/lib.a
|
||||||
obj-y += $(obj)/lib-ksyms.o
|
real-obj-y += $(obj)/lib-ksyms.o
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq ($(strip $(obj-y) $(need-builtin)),)
|
ifneq ($(strip $(real-obj-y) $(need-builtin)),)
|
||||||
builtin-target := $(obj)/built-in.a
|
builtin-target := $(obj)/built-in.a
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -412,7 +412,7 @@ endif
|
||||||
$(obj)/%.o: $(src)/%.S $(objtool_dep) FORCE
|
$(obj)/%.o: $(src)/%.S $(objtool_dep) FORCE
|
||||||
$(call if_changed_rule,as_o_S)
|
$(call if_changed_rule,as_o_S)
|
||||||
|
|
||||||
targets += $(real-obj-y) $(real-obj-m) $(lib-y)
|
targets += $(filter-out $(subdir-obj-y), $(real-obj-y)) $(real-obj-m) $(lib-y)
|
||||||
targets += $(extra-y) $(MAKECMDGOALS) $(always)
|
targets += $(extra-y) $(MAKECMDGOALS) $(always)
|
||||||
|
|
||||||
# Linker scripts preprocessor (.lds.S -> .lds)
|
# Linker scripts preprocessor (.lds.S -> .lds)
|
||||||
|
@ -455,12 +455,12 @@ cmd_make_empty_builtin = rm -f $@; $(AR) rcSTP$(KBUILD_ARFLAGS)
|
||||||
quiet_cmd_link_o_target = AR $@
|
quiet_cmd_link_o_target = AR $@
|
||||||
|
|
||||||
# If the list of objects to link is empty, just create an empty built-in.a
|
# If the list of objects to link is empty, just create an empty built-in.a
|
||||||
cmd_link_o_target = $(if $(strip $(obj-y)),\
|
cmd_link_o_target = $(if $(strip $(real-obj-y)),\
|
||||||
$(cmd_make_builtin) $@ $(filter $(obj-y), $^) \
|
$(cmd_make_builtin) $@ $(filter $(real-obj-y), $^) \
|
||||||
$(cmd_secanalysis),\
|
$(cmd_secanalysis),\
|
||||||
$(cmd_make_empty_builtin) $@)
|
$(cmd_make_empty_builtin) $@)
|
||||||
|
|
||||||
$(builtin-target): $(obj-y) FORCE
|
$(builtin-target): $(real-obj-y) FORCE
|
||||||
$(call if_changed,link_o_target)
|
$(call if_changed,link_o_target)
|
||||||
|
|
||||||
targets += $(builtin-target)
|
targets += $(builtin-target)
|
||||||
|
@ -534,23 +534,16 @@ $($(subst $(obj)/,,$(@:.o=-m)))), $^)
|
||||||
|
|
||||||
cmd_link_multi-link = $(LD) $(ld_flags) -r -o $@ $(link_multi_deps) $(cmd_secanalysis)
|
cmd_link_multi-link = $(LD) $(ld_flags) -r -o $@ $(link_multi_deps) $(cmd_secanalysis)
|
||||||
|
|
||||||
quiet_cmd_link_multi-y = AR $@
|
|
||||||
cmd_link_multi-y = rm -f $@; $(AR) rcSTP$(KBUILD_ARFLAGS) $@ $(link_multi_deps)
|
|
||||||
|
|
||||||
quiet_cmd_link_multi-m = LD [M] $@
|
quiet_cmd_link_multi-m = LD [M] $@
|
||||||
cmd_link_multi-m = $(cmd_link_multi-link)
|
cmd_link_multi-m = $(cmd_link_multi-link)
|
||||||
|
|
||||||
$(multi-used-y): FORCE
|
|
||||||
$(call if_changed,link_multi-y)
|
|
||||||
$(call multi_depend, $(multi-used-y), .o, -objs -y)
|
|
||||||
|
|
||||||
$(multi-used-m): FORCE
|
$(multi-used-m): FORCE
|
||||||
$(call if_changed,link_multi-m)
|
$(call if_changed,link_multi-m)
|
||||||
@{ echo $(@:.o=.ko); echo $(link_multi_deps); \
|
@{ echo $(@:.o=.ko); echo $(link_multi_deps); \
|
||||||
$(cmd_undef_syms); } > $(MODVERDIR)/$(@F:.o=.mod)
|
$(cmd_undef_syms); } > $(MODVERDIR)/$(@F:.o=.mod)
|
||||||
$(call multi_depend, $(multi-used-m), .o, -objs -y -m)
|
$(call multi_depend, $(multi-used-m), .o, -objs -y -m)
|
||||||
|
|
||||||
targets += $(multi-used-y) $(multi-used-m)
|
targets += $(multi-used-m)
|
||||||
targets := $(filter-out $(PHONY), $(targets))
|
targets := $(filter-out $(PHONY), $(targets))
|
||||||
|
|
||||||
# Descending
|
# Descending
|
||||||
|
|
|
@ -51,8 +51,9 @@ single-used-m := $(sort $(filter-out $(multi-used-m),$(obj-m)))
|
||||||
# tell kbuild to descend
|
# tell kbuild to descend
|
||||||
subdir-obj-y := $(filter %/built-in.a, $(obj-y))
|
subdir-obj-y := $(filter %/built-in.a, $(obj-y))
|
||||||
|
|
||||||
# Replace multi-part objects by their individual parts, look at local dir only
|
# Replace multi-part objects by their individual parts,
|
||||||
real-obj-y := $(foreach m, $(filter-out $(subdir-obj-y), $(obj-y)), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m)))
|
# including built-in.a from subdirectories
|
||||||
|
real-obj-y := $(foreach m, $(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m)))
|
||||||
real-obj-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m)),$(m)))
|
real-obj-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m)),$(m)))
|
||||||
|
|
||||||
# DTB
|
# DTB
|
||||||
|
@ -66,14 +67,12 @@ extra-y := $(addprefix $(obj)/,$(extra-y))
|
||||||
always := $(addprefix $(obj)/,$(always))
|
always := $(addprefix $(obj)/,$(always))
|
||||||
targets := $(addprefix $(obj)/,$(targets))
|
targets := $(addprefix $(obj)/,$(targets))
|
||||||
modorder := $(addprefix $(obj)/,$(modorder))
|
modorder := $(addprefix $(obj)/,$(modorder))
|
||||||
obj-y := $(addprefix $(obj)/,$(obj-y))
|
|
||||||
obj-m := $(addprefix $(obj)/,$(obj-m))
|
obj-m := $(addprefix $(obj)/,$(obj-m))
|
||||||
lib-y := $(addprefix $(obj)/,$(lib-y))
|
lib-y := $(addprefix $(obj)/,$(lib-y))
|
||||||
subdir-obj-y := $(addprefix $(obj)/,$(subdir-obj-y))
|
subdir-obj-y := $(addprefix $(obj)/,$(subdir-obj-y))
|
||||||
real-obj-y := $(addprefix $(obj)/,$(real-obj-y))
|
real-obj-y := $(addprefix $(obj)/,$(real-obj-y))
|
||||||
real-obj-m := $(addprefix $(obj)/,$(real-obj-m))
|
real-obj-m := $(addprefix $(obj)/,$(real-obj-m))
|
||||||
single-used-m := $(addprefix $(obj)/,$(single-used-m))
|
single-used-m := $(addprefix $(obj)/,$(single-used-m))
|
||||||
multi-used-y := $(addprefix $(obj)/,$(multi-used-y))
|
|
||||||
multi-used-m := $(addprefix $(obj)/,$(multi-used-m))
|
multi-used-m := $(addprefix $(obj)/,$(multi-used-m))
|
||||||
subdir-ym := $(addprefix $(obj)/,$(subdir-ym))
|
subdir-ym := $(addprefix $(obj)/,$(subdir-ym))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue