Skip to content

Commit b8321ed

Browse files
committed
Merge tag 'kbuild-v5.18-v2' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild
Pull Kbuild updates from Masahiro Yamada: - Add new environment variables, USERCFLAGS and USERLDFLAGS to allow additional flags to be passed to user-space programs. - Fix missing fflush() bugs in Kconfig and fixdep - Fix a minor bug in the comment format of the .config file - Make kallsyms ignore llvm's local labels, .L* - Fix UAPI compile-test for cross-compiling with Clang - Extend the LLVM= syntax to support LLVM=<suffix> form for using a particular version of LLVm, and LLVM=<prefix> form for using custom LLVM in a particular directory path. - Clean up Makefiles * tag 'kbuild-v5.18-v2' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild: kbuild: Make $(LLVM) more flexible kbuild: add --target to correctly cross-compile UAPI headers with Clang fixdep: use fflush() and ferror() to ensure successful write to files arch: syscalls: simplify uapi/kapi directory creation usr/include: replace extra-y with always-y certs: simplify empty certs creation in certs/Makefile certs: include certs/signing_key.x509 unconditionally kallsyms: ignore all local labels prefixed by '.L' kconfig: fix missing '# end of' for empty menu kconfig: add fflush() before ferror() check kbuild: replace $(if A,A,B) with $(or A,B) kbuild: Add environment variables for userprogs flags kbuild: unify cmd_copy and cmd_shipped
2 parents f87cbd0 + e9c2819 commit b8321ed

File tree

51 files changed

+189
-175
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+189
-175
lines changed

Documentation/kbuild/kbuild.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ HOSTLDLIBS
7777
----------
7878
Additional libraries to link against when building host programs.
7979

80+
.. _userkbuildflags:
81+
82+
USERCFLAGS
83+
----------
84+
Additional options used for $(CC) when compiling userprogs.
85+
86+
USERLDFLAGS
87+
-----------
88+
Additional options used for $(LD) when linking userprogs. userprogs are linked
89+
with CC, so $(USERLDFLAGS) should include "-Wl," prefix as applicable.
90+
8091
KBUILD_KCONFIG
8192
--------------
8293
Set the top-level Kconfig file to the value of this environment

Documentation/kbuild/llvm.rst

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,36 @@ example: ::
4949
LLVM Utilities
5050
--------------
5151

52-
LLVM has substitutes for GNU binutils utilities. Kbuild supports ``LLVM=1``
53-
to enable them. ::
54-
55-
make LLVM=1
56-
57-
They can be enabled individually. The full list of the parameters: ::
52+
LLVM has substitutes for GNU binutils utilities. They can be enabled individually.
53+
The full list of supported make variables::
5854

5955
make CC=clang LD=ld.lld AR=llvm-ar NM=llvm-nm STRIP=llvm-strip \
6056
OBJCOPY=llvm-objcopy OBJDUMP=llvm-objdump READELF=llvm-readelf \
6157
HOSTCC=clang HOSTCXX=clang++ HOSTAR=llvm-ar HOSTLD=ld.lld
6258

59+
To simplify the above command, Kbuild supports the ``LLVM`` variable::
60+
61+
make LLVM=1
62+
63+
If your LLVM tools are not available in your PATH, you can supply their
64+
location using the LLVM variable with a trailing slash::
65+
66+
make LLVM=/path/to/llvm/
67+
68+
which will use ``/path/to/llvm/clang``, ``/path/to/llvm/ld.lld``, etc.
69+
70+
If your LLVM tools have a version suffix and you want to test with that
71+
explicit version rather than the unsuffixed executables like ``LLVM=1``, you
72+
can pass the suffix using the ``LLVM`` variable::
73+
74+
make LLVM=-14
75+
76+
which will use ``clang-14``, ``ld.lld-14``, etc.
77+
78+
``LLVM=0`` is not the same as omitting ``LLVM`` altogether, it will behave like
79+
``LLVM=1``. If you only wish to use certain LLVM utilities, use their respective
80+
make variables.
81+
6382
The integrated assembler is enabled by default. You can pass ``LLVM_IAS=0`` to
6483
disable it.
6584

Documentation/kbuild/makefiles.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,8 @@ The syntax is quite similar. The difference is to use "userprogs" instead of
982982

983983
When linking bpfilter_umh, it will be passed the extra option -static.
984984

985+
From command line, :ref:`USERCFLAGS and USERLDFLAGS <userkbuildflags>` will also be used.
986+
985987
5.4 When userspace programs are actually built
986988
----------------------------------------------
987989

Makefile

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -424,34 +424,41 @@ HOST_LFS_LDFLAGS := $(shell getconf LFS_LDFLAGS 2>/dev/null)
424424
HOST_LFS_LIBS := $(shell getconf LFS_LIBS 2>/dev/null)
425425

426426
ifneq ($(LLVM),)
427-
HOSTCC = clang
428-
HOSTCXX = clang++
427+
ifneq ($(filter %/,$(LLVM)),)
428+
LLVM_PREFIX := $(LLVM)
429+
else ifneq ($(filter -%,$(LLVM)),)
430+
LLVM_SUFFIX := $(LLVM)
431+
endif
432+
433+
HOSTCC = $(LLVM_PREFIX)clang$(LLVM_SUFFIX)
434+
HOSTCXX = $(LLVM_PREFIX)clang++$(LLVM_SUFFIX)
429435
else
430436
HOSTCC = gcc
431437
HOSTCXX = g++
432438
endif
433439

434-
export KBUILD_USERCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
435-
-O2 -fomit-frame-pointer -std=gnu11 \
436-
-Wdeclaration-after-statement
437-
export KBUILD_USERLDFLAGS :=
440+
KBUILD_USERHOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
441+
-O2 -fomit-frame-pointer -std=gnu11 \
442+
-Wdeclaration-after-statement
443+
KBUILD_USERCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(USERCFLAGS)
444+
KBUILD_USERLDFLAGS := $(USERLDFLAGS)
438445

439-
KBUILD_HOSTCFLAGS := $(KBUILD_USERCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
446+
KBUILD_HOSTCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
440447
KBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS)
441448
KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS)
442449
KBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS)
443450

444451
# Make variables (CC, etc...)
445452
CPP = $(CC) -E
446453
ifneq ($(LLVM),)
447-
CC = clang
448-
LD = ld.lld
449-
AR = llvm-ar
450-
NM = llvm-nm
451-
OBJCOPY = llvm-objcopy
452-
OBJDUMP = llvm-objdump
453-
READELF = llvm-readelf
454-
STRIP = llvm-strip
454+
CC = $(LLVM_PREFIX)clang$(LLVM_SUFFIX)
455+
LD = $(LLVM_PREFIX)ld.lld$(LLVM_SUFFIX)
456+
AR = $(LLVM_PREFIX)llvm-ar$(LLVM_SUFFIX)
457+
NM = $(LLVM_PREFIX)llvm-nm$(LLVM_SUFFIX)
458+
OBJCOPY = $(LLVM_PREFIX)llvm-objcopy$(LLVM_SUFFIX)
459+
OBJDUMP = $(LLVM_PREFIX)llvm-objdump$(LLVM_SUFFIX)
460+
READELF = $(LLVM_PREFIX)llvm-readelf$(LLVM_SUFFIX)
461+
STRIP = $(LLVM_PREFIX)llvm-strip$(LLVM_SUFFIX)
455462
else
456463
CC = $(CROSS_COMPILE)gcc
457464
LD = $(CROSS_COMPILE)ld
@@ -531,6 +538,7 @@ export CPP AR NM STRIP OBJCOPY OBJDUMP READELF PAHOLE RESOLVE_BTFIDS LEX YACC AW
531538
export PERL PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX
532539
export KGZIP KBZIP2 KLZOP LZMA LZ4 XZ ZSTD
533540
export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE
541+
export KBUILD_USERCFLAGS KBUILD_USERLDFLAGS
534542

535543
export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS
536544
export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
@@ -1237,8 +1245,8 @@ define filechk_version.h
12371245
echo \#define LINUX_VERSION_SUBLEVEL $(SUBLEVEL)
12381246
endef
12391247

1240-
$(version_h): PATCHLEVEL := $(if $(PATCHLEVEL), $(PATCHLEVEL), 0)
1241-
$(version_h): SUBLEVEL := $(if $(SUBLEVEL), $(SUBLEVEL), 0)
1248+
$(version_h): PATCHLEVEL := $(or $(PATCHLEVEL), 0)
1249+
$(version_h): SUBLEVEL := $(or $(SUBLEVEL), 0)
12421250
$(version_h): FORCE
12431251
$(call filechk,version.h)
12441252

@@ -1621,7 +1629,7 @@ help:
16211629
@$(MAKE) -f $(srctree)/Documentation/Makefile dochelp
16221630
@echo ''
16231631
@echo 'Architecture specific targets ($(SRCARCH)):'
1624-
@$(if $(archhelp),$(archhelp),\
1632+
@$(or $(archhelp),\
16251633
echo ' No architecture specific help defined for $(SRCARCH)')
16261634
@echo ''
16271635
@$(if $(boards), \
@@ -1838,7 +1846,7 @@ $(clean-dirs):
18381846

18391847
clean: $(clean-dirs)
18401848
$(call cmd,rmfiles)
1841-
@find $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \
1849+
@find $(or $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \
18421850
\( -name '*.[aios]' -o -name '*.ko' -o -name '.*.cmd' \
18431851
-o -name '*.ko.*' \
18441852
-o -name '*.dtb' -o -name '*.dtbo' -o -name '*.dtb.S' -o -name '*.dt.yaml' \

arch/alpha/kernel/syscalls/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
kapi := arch/$(SRCARCH)/include/generated/asm
33
uapi := arch/$(SRCARCH)/include/generated/uapi/asm
44

5-
_dummy := $(shell [ -d '$(uapi)' ] || mkdir -p '$(uapi)') \
6-
$(shell [ -d '$(kapi)' ] || mkdir -p '$(kapi)')
5+
$(shell mkdir -p $(uapi) $(kapi))
76

87
syscall := $(src)/syscall.tbl
98
syshdr := $(srctree)/scripts/syscallhdr.sh

arch/arm/tools/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ kapi: $(kapi-hdrs-y) $(gen-y)
2929
uapi: $(uapi-hdrs-y)
3030

3131
# Create output directory if not already present
32-
_dummy := $(shell [ -d '$(kapi)' ] || mkdir -p '$(kapi)') \
33-
$(shell [ -d '$(uapi)' ] || mkdir -p '$(uapi)')
32+
$(shell mkdir -p $(kapi) $(uapi))
3433

3534
quiet_cmd_gen_mach = GEN $@
3635
cmd_gen_mach = $(AWK) -f $(real-prereqs) > $@

arch/ia64/kernel/syscalls/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
kapi := arch/$(SRCARCH)/include/generated/asm
33
uapi := arch/$(SRCARCH)/include/generated/uapi/asm
44

5-
_dummy := $(shell [ -d '$(uapi)' ] || mkdir -p '$(uapi)') \
6-
$(shell [ -d '$(kapi)' ] || mkdir -p '$(kapi)')
5+
$(shell mkdir -p $(uapi) $(kapi))
76

87
syscall := $(src)/syscall.tbl
98
syshdr := $(srctree)/scripts/syscallhdr.sh

arch/m68k/kernel/syscalls/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
kapi := arch/$(SRCARCH)/include/generated/asm
33
uapi := arch/$(SRCARCH)/include/generated/uapi/asm
44

5-
_dummy := $(shell [ -d '$(uapi)' ] || mkdir -p '$(uapi)') \
6-
$(shell [ -d '$(kapi)' ] || mkdir -p '$(kapi)')
5+
$(shell mkdir -p $(uapi) $(kapi))
76

87
syscall := $(src)/syscall.tbl
98
syshdr := $(srctree)/scripts/syscallhdr.sh

arch/microblaze/boot/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ $(obj)/simpleImage.$(DTB).ub: $(obj)/simpleImage.$(DTB) FORCE
2929
$(call if_changed,uimage)
3030

3131
$(obj)/simpleImage.$(DTB).unstrip: vmlinux FORCE
32-
$(call if_changed,shipped)
32+
$(call if_changed,copy)
3333

3434
$(obj)/simpleImage.$(DTB).strip: vmlinux FORCE
3535
$(call if_changed,strip)

arch/microblaze/boot/dts/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ $(obj)/linked_dtb.o: $(obj)/system.dtb
1212
# Generate system.dtb from $(DTB).dtb
1313
ifneq ($(DTB),system)
1414
$(obj)/system.dtb: $(obj)/$(DTB).dtb
15-
$(call if_changed,shipped)
15+
$(call if_changed,copy)
1616
endif
1717
endif
1818

0 commit comments

Comments
 (0)