Skip to content

Commit

Permalink
kbuild: move core-y and drivers-y to ./Kbuild
Browse files Browse the repository at this point in the history
Use the ordinary obj-y to list subdirectories.

Note1:
GNU Make seems to transform './.modules.order' to '.modules.order'
before matching it against the target pattern. Split ./.modules.order
to a dedicated rule to avoid "doesn't match the target pattern"
warning. [1]

Note2:
Previously, the link order of lib-y depended on CONFIG_MODULES; lib-y
was linked before drivers-y when CONFIG_MODULES=y, otherwise after
drivers-y. This was a bug of commit 7273ad2 ("kbuild: link lib-y
objects to vmlinux forcibly when CONFIG_MODULES=y"), but it was not a
big deal after all. Now, libs-y (all objects that come from lib/ and
arch/*/lib/) is linked last, irrespective of CONFIG_MODULES.

Note3:
Now, the single target build in arch/*/lib/ works correctly. There was
a bug report about this. [2]

  $ make ARCH=arm arch/arm/lib/findbit.o
    CALL    scripts/checksyscalls.sh
    AS      arch/arm/lib/findbit.o

[1]: https://lists.gnu.org/archive/html/bug-make/2022-08/msg00059.html
[2]: https://lore.kernel.org/linux-kbuild/YvUQOwL6lD4%2F5%2FU6@shell.armlinux.org.uk/

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
  • Loading branch information
masahir0y authored and intel-lab-lkp committed Sep 6, 2022
1 parent f3e8257 commit 9349fbf
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
23 changes: 23 additions & 0 deletions Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,26 @@ $(atomic-checks): $(obj)/.checked-%: include/linux/atomic/% FORCE
PHONY += prepare
prepare: $(offsets-file) missing-syscalls $(atomic-checks)
@:

# Ordinary directory descending
# ---------------------------------------------------------------------------

obj-y += init/
obj-y += usr/
obj-y += arch/$(SRCARCH)/
obj-y += $(ARCH_CORE)
obj-y += kernel/
obj-y += certs/
obj-y += mm/
obj-y += fs/
obj-y += ipc/
obj-y += security/
obj-y += crypto/
obj-$(CONFIG_BLOCK) += block/
obj-$(CONFIG_IO_URING) += io_uring/
obj-y += drivers/
obj-y += sound/
obj-$(CONFIG_SAMPLES) += samples/
obj-$(CONFIG_NET) += net/
obj-y += virt/
obj-y += $(ARCH_DRIVERS)
29 changes: 13 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -676,11 +676,8 @@ endif

ifeq ($(KBUILD_EXTMOD),)
# Objects we will link into vmlinux / subdirs we need to visit
core-y := init/ usr/ arch/$(SRCARCH)/
drivers-y := drivers/ sound/
drivers-$(CONFIG_SAMPLES) += samples/
drivers-$(CONFIG_NET) += net/
drivers-y += virt/
core-y :=
drivers-y :=
libs-y := lib/
endif # KBUILD_EXTMOD

Expand Down Expand Up @@ -1101,31 +1098,27 @@ export MODORDER := $(extmod_prefix)modules.order
export MODULES_NSDEPS := $(extmod_prefix)modules.nsdeps

ifeq ($(KBUILD_EXTMOD),)
core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/
core-$(CONFIG_BLOCK) += block/
core-$(CONFIG_IO_URING) += io_uring/

vmlinux-dirs := $(patsubst %/,%,$(filter %/, \
$(core-y) $(core-m) $(drivers-y) $(drivers-m) \
$(libs-y) $(libs-m)))
vmlinux-dirs := . $(patsubst %/,%,$(filter %/, $(libs-y) $(libs-m)))

vmlinux-alldirs := $(sort $(vmlinux-dirs) Documentation . \
vmlinux-alldirs := $(sort $(vmlinux-dirs) Documentation \
$(patsubst %/,%,$(filter %/, $(core-) \
$(drivers-) $(libs-))))

build-dirs := $(vmlinux-dirs)
clean-dirs := $(vmlinux-alldirs)

export ARCH_CORE := $(core-y)
export ARCH_DRIVERS := $(drivers-y)
# Externally visible symbols (used by link-vmlinux.sh)
KBUILD_VMLINUX_OBJS := $(head-y) $(patsubst %/,%/built-in.a, $(core-y))
KBUILD_VMLINUX_OBJS := $(head-y) ./built-in.a
KBUILD_VMLINUX_OBJS += $(addsuffix built-in.a, $(filter %/, $(libs-y)))
ifdef CONFIG_MODULES
KBUILD_VMLINUX_OBJS += $(patsubst %/, %/lib.a, $(filter %/, $(libs-y)))
KBUILD_VMLINUX_LIBS := $(filter-out %/, $(libs-y))
else
KBUILD_VMLINUX_LIBS := $(patsubst %/,%/lib.a, $(libs-y))
endif
KBUILD_VMLINUX_OBJS += $(patsubst %/,%/built-in.a, $(drivers-y))

export KBUILD_VMLINUX_OBJS KBUILD_VMLINUX_LIBS
export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds
Expand Down Expand Up @@ -1752,7 +1745,10 @@ ifdef CONFIG_MODULES

subdir-modorder := $(addsuffix /.modules.order, $(build-dirs))

$(sort $(subdir-modorder)): %/.modules.order: % ;
# Split ./.modules.order into a dedicate target to avoid
# "doesn't match the target pattern" warning
./.modules.order: . ;
$(sort $(filter-out ./.modules.order, $(subdir-modorder))): %/.modules.order: % ;

cmd_modules_order = cat $(real-prereqs) > $@

Expand Down Expand Up @@ -1823,7 +1819,8 @@ single_modpost: $(single-no-ko) modules_prepare
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
$(Q)rm -f $(MODORDER)

single-goals := $(addprefix $(extmod_prefix), $(single-no-ko))
single-goals := $(foreach x, $(addprefix $(extmod_prefix), $(single-no-ko)), \
$(if $(filter $(addsuffix /%, $(build-dirs)), $x),,./)$x)

# trim unrelated directories
build-dirs := $(foreach d, $(build-dirs), \
Expand Down
2 changes: 2 additions & 0 deletions scripts/Makefile.lib
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ always-y += $(dtb-y)

# Add subdir path

ifneq ($(obj),.)
extra-y := $(addprefix $(obj)/,$(extra-y))
always-y := $(addprefix $(obj)/,$(always-y))
targets := $(addprefix $(obj)/,$(targets))
Expand All @@ -100,6 +101,7 @@ multi-obj-m := $(addprefix $(obj)/, $(multi-obj-m))
multi-dtb-y := $(addprefix $(obj)/, $(multi-dtb-y))
real-dtb-y := $(addprefix $(obj)/, $(real-dtb-y))
subdir-ym := $(addprefix $(obj)/,$(subdir-ym))
endif

# Finds the multi-part object the current object will be linked into.
# If the object belongs to two or more multi-part objects, list them all.
Expand Down

0 comments on commit 9349fbf

Please sign in to comment.