Skip to content

Commit

Permalink
Merge tag 'kbuild-v6.1' of git://git.kernel.org/pub/scm/linux/kernel/…
Browse files Browse the repository at this point in the history
…git/masahiroy/linux-kbuild

Pull Kbuild updates from Masahiro Yamada:

 - Remove potentially incomplete targets when Kbuid is interrupted by
   SIGINT etc in case GNU Make may miss to do that when stderr is piped
   to another program.

 - Rewrite the single target build so it works more correctly.

 - Fix rpm-pkg builds with V=1.

 - List top-level subdirectories in ./Kbuild.

 - Ignore auto-generated __kstrtab_* and __kstrtabns_* symbols in
   kallsyms.

 - Avoid two different modules in lib/zstd/ having shared code, which
   potentially causes building the common code as build-in and modular
   back-and-forth.

 - Unify two modpost invocations to optimize the build process.

 - Remove head-y syntax in favor of linker scripts for placing
   particular sections in the head of vmlinux.

 - Bump the minimal GNU Make version to 3.82.

 - Clean up misc Makefiles and scripts.

* tag 'kbuild-v6.1' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild: (41 commits)
  docs: bump minimal GNU Make version to 3.82
  ia64: simplify esi object addition in Makefile
  Revert "kbuild: Check if linker supports the -X option"
  kbuild: rebuild .vmlinux.export.o when its prerequisite is updated
  kbuild: move modules.builtin(.modinfo) rules to Makefile.vmlinux_o
  zstd: Fixing mixed module-builtin objects
  kallsyms: ignore __kstrtab_* and __kstrtabns_* symbols
  kallsyms: take the input file instead of reading stdin
  kallsyms: drop duplicated ignore patterns from kallsyms.c
  kbuild: reuse mksysmap output for kallsyms
  mksysmap: update comment about __crc_*
  kbuild: remove head-y syntax
  kbuild: use obj-y instead extra-y for objects placed at the head
  kbuild: hide error checker logs for V=1 builds
  kbuild: re-run modpost when it is updated
  kbuild: unify two modpost invocations
  kbuild: move vmlinux.o rule to the top Makefile
  kbuild: move .vmlinux.objs rule to Makefile.modpost
  kbuild: list sub-directories in ./Kbuild
  Makefile.compiler: replace cc-ifversion with compiler-specific macros
  ...
  • Loading branch information
torvalds committed Oct 10, 2022
2 parents 4de65c5 + 0715fdb commit 8afc66e
Show file tree
Hide file tree
Showing 87 changed files with 729 additions and 763 deletions.
56 changes: 23 additions & 33 deletions Documentation/kbuild/makefiles.rst
Original file line number Diff line number Diff line change
Expand Up @@ -341,30 +341,14 @@ more details, with real examples.

Examples are:

1) head objects

Some objects must be placed at the head of vmlinux. They are
directly linked to vmlinux without going through built-in.a
A typical use-case is an object that contains the entry point.

arch/$(SRCARCH)/Makefile should specify such objects as head-y.

Discussion:
Given that we can control the section order in the linker script,
why do we need head-y?

2) vmlinux linker script
1) vmlinux linker script

The linker script for vmlinux is located at
arch/$(SRCARCH)/kernel/vmlinux.lds

Example::

# arch/x86/kernel/Makefile
extra-y := head_$(BITS).o
extra-y += head$(BITS).o
extra-y += ebda.o
extra-y += platform-quirks.o
extra-y += vmlinux.lds

$(extra-y) should only contain targets needed for vmlinux.
Expand Down Expand Up @@ -683,22 +667,27 @@ more details, with real examples.
In the above example, -Wno-unused-but-set-variable will be added to
KBUILD_CFLAGS only if gcc really accepts it.

cc-ifversion
cc-ifversion tests the version of $(CC) and equals the fourth parameter
if version expression is true, or the fifth (if given) if the version
expression is false.
gcc-min-version
gcc-min-version tests if the value of $(CONFIG_GCC_VERSION) is greater than
or equal to the provided value and evaluates to y if so.

Example::

cflags-$(call gcc-min-version, 70100) := -foo

In this example, cflags-y will be assigned the value -foo if $(CC) is gcc and
$(CONFIG_GCC_VERSION) is >= 7.1.

clang-min-version
clang-min-version tests if the value of $(CONFIG_CLANG_VERSION) is greater
than or equal to the provided value and evaluates to y if so.

Example::

#fs/reiserfs/Makefile
ccflags-y := $(call cc-ifversion, -lt, 0402, -O1)
cflags-$(call clang-min-version, 110000) := -foo

In this example, ccflags-y will be assigned the value -O1 if the
$(CC) version is less than 4.2.
cc-ifversion takes all the shell operators:
-eq, -ne, -lt, -le, -gt, and -ge
The third parameter may be a text as in this example, but it may also
be an expanded variable or a macro.
In this example, cflags-y will be assigned the value -foo if $(CC) is clang
and $(CONFIG_CLANG_VERSION) is >= 11.0.0.

cc-cross-prefix
cc-cross-prefix is used to check if there exists a $(CC) in path with
Expand Down Expand Up @@ -1099,8 +1088,7 @@ When kbuild executes, the following steps are followed (roughly):
- The values of the above variables are expanded in arch/$(SRCARCH)/Makefile.
5) All object files are then linked and the resulting file vmlinux is
located at the root of the obj tree.
The very first objects linked are listed in head-y, assigned by
arch/$(SRCARCH)/Makefile.
The very first objects linked are listed in scripts/head-object-list.txt.
6) Finally, the architecture-specific part does any required post processing
and builds the final bootimage.
- This includes building boot records
Expand Down Expand Up @@ -1272,6 +1260,9 @@ When kbuild executes, the following steps are followed (roughly):
All object files for vmlinux. They are linked to vmlinux in the same
order as listed in KBUILD_VMLINUX_OBJS.

The objects listed in scripts/head-object-list.txt are exceptions;
they are placed before the other objects.

KBUILD_VMLINUX_LIBS

All .a "lib" files for vmlinux. KBUILD_VMLINUX_OBJS and
Expand Down Expand Up @@ -1315,8 +1306,7 @@ When kbuild executes, the following steps are followed (roughly):
machinery is all architecture-independent.


head-y, core-y, libs-y, drivers-y
$(head-y) lists objects to be linked first in vmlinux.
core-y, libs-y, drivers-y

$(libs-y) lists directories where a lib.a archive can be located.

Expand Down
4 changes: 2 additions & 2 deletions Documentation/process/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ GNU C 5.1 gcc --version
Clang/LLVM (optional) 11.0.0 clang --version
Rust (optional) 1.62.0 rustc --version
bindgen (optional) 0.56.0 bindgen --version
GNU make 3.81 make --version
GNU make 3.82 make --version
bash 4.2 bash --version
binutils 2.23 ld -v
flex 2.5.35 flex --version
Expand Down Expand Up @@ -108,7 +108,7 @@ It depends on ``libclang``.
Make
----

You will need GNU make 3.81 or later to build the kernel.
You will need GNU make 3.82 or later to build the kernel.

Bash
----
Expand Down
78 changes: 59 additions & 19 deletions Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
#
# Kbuild for top-level directory of the kernel

#####
# Prepare global headers and check sanity before descending into sub-directories
# ---------------------------------------------------------------------------

# Generate bounds.h

bounds-file := include/generated/bounds.h

always-y := $(bounds-file)
targets := kernel/bounds.s

$(bounds-file): kernel/bounds.s FORCE
$(call filechk,offsets,__LINUX_BOUNDS_H__)

#####
# Generate timeconst.h

timeconst-file := include/generated/timeconst.h
Expand All @@ -23,37 +23,77 @@ filechk_gentimeconst = echo $(CONFIG_HZ) | bc -q $<
$(timeconst-file): kernel/time/timeconst.bc FORCE
$(call filechk,gentimeconst)

#####
# Generate asm-offsets.h

offsets-file := include/generated/asm-offsets.h

always-y += $(offsets-file)
targets += arch/$(SRCARCH)/kernel/asm-offsets.s

arch/$(SRCARCH)/kernel/asm-offsets.s: $(timeconst-file) $(bounds-file)

$(offsets-file): arch/$(SRCARCH)/kernel/asm-offsets.s FORCE
$(call filechk,offsets,__ASM_OFFSETS_H__)

#####
# Check for missing system calls

always-y += missing-syscalls

quiet_cmd_syscalls = CALL $<
cmd_syscalls = $(CONFIG_SHELL) $< $(CC) $(c_flags) $(missing_syscalls_flags)

missing-syscalls: scripts/checksyscalls.sh $(offsets-file) FORCE
PHONY += missing-syscalls
missing-syscalls: scripts/checksyscalls.sh $(offsets-file)
$(call cmd,syscalls)

#####
# Check atomic headers are up-to-date

always-y += old-atomics

quiet_cmd_atomics = CALL $<
cmd_atomics = $(CONFIG_SHELL) $<

old-atomics: scripts/atomic/check-atomics.sh FORCE
$(call cmd,atomics)
# Check the manual modification of atomic headers

quiet_cmd_check_sha1 = CHKSHA1 $<
cmd_check_sha1 = \
if ! command -v sha1sum >/dev/null; then \
echo "warning: cannot check the header due to sha1sum missing"; \
exit 0; \
fi; \
if [ "$$(sed -n '$$s:// ::p' $<)" != \
"$$(sed '$$d' $< | sha1sum | sed 's/ .*//')" ]; then \
echo "error: $< has been modified." >&2; \
exit 1; \
fi; \
touch $@

atomic-checks += $(addprefix $(obj)/.checked-, \
atomic-arch-fallback.h \
atomic-instrumented.h \
atomic-long.h)

targets += $(atomic-checks)
$(atomic-checks): $(obj)/.checked-%: include/linux/atomic/% FORCE
$(call if_changed,check_sha1)

# A phony target that depends on all the preparation targets

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-$(CONFIG_RUST) += rust/
obj-y += $(ARCH_LIB)
obj-y += drivers/
obj-y += sound/
obj-$(CONFIG_SAMPLES) += samples/
obj-$(CONFIG_NET) += net/
obj-y += virt/
obj-y += $(ARCH_DRIVERS)
Loading

0 comments on commit 8afc66e

Please sign in to comment.