Merge tag 'kbuild-fixes-v5.10-2' of git://git.kernel.org/pub/scm/linux/kernel/git...
authorLinus Torvalds <torvalds@linux-foundation.org>
Sun, 6 Dec 2020 18:31:39 +0000 (10:31 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sun, 6 Dec 2020 18:31:39 +0000 (10:31 -0800)
Pull Kbuild fixes from Masahiro Yamada:

 - Move -Wcast-align to W=3, which tends to be false-positive and there
   is no tree-wide solution.

 - Pass -fmacro-prefix-map to KBUILD_CPPFLAGS because it is a
   preprocessor option and makes sense for .S files as well.

 - Disable -gdwarf-2 for Clang's integrated assembler to avoid warnings.

 - Disable --orphan-handling=warn for LLD 10.0.1 to avoid warnings.

 - Fix undesirable line breaks in *.mod files.

* tag 'kbuild-fixes-v5.10-2' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild:
  kbuild: avoid split lines in .mod files
  kbuild: Disable CONFIG_LD_ORPHAN_WARN for ld.lld 10.0.1
  kbuild: Hoist '--orphan-handling' into Kconfig
  Kbuild: do not emit debug info for assembly with LLVM_IAS=1
  kbuild: use -fmacro-prefix-map for .S sources
  Makefile.extrawarn: move -Wcast-align to W=3

17 files changed:
MAINTAINERS
Makefile
arch/Kconfig
arch/arm/Kconfig
arch/arm/Makefile
arch/arm/boot/compressed/Makefile
arch/arm64/Kconfig
arch/arm64/Makefile
arch/powerpc/Kconfig
arch/powerpc/Makefile
arch/x86/Kconfig
arch/x86/Makefile
arch/x86/boot/compressed/Makefile
init/Kconfig
scripts/Makefile.build
scripts/Makefile.extrawarn
scripts/lld-version.sh [new file with mode: 0755]

index ebe4829cdd4d8086b2096f7ad331047f83d99336..1b29ee566ca39c3af992a5aa54c1aab45b509a4c 100644 (file)
@@ -4287,6 +4287,7 @@ B:        https://github.com/ClangBuiltLinux/linux/issues
 C:     irc://chat.freenode.net/clangbuiltlinux
 F:     Documentation/kbuild/llvm.rst
 F:     scripts/clang-tools/
+F:     scripts/lld-version.sh
 K:     \b(?i:clang|llvm)\b
 
 CLEANCACHE API
index 43ecedeb3f0214f6adfcd0ba105928cd2b0f5334..a2ded5029084d3f4d757305aca7d8ea0f697a351 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -826,7 +826,9 @@ else
 DEBUG_CFLAGS   += -g
 endif
 
+ifneq ($(LLVM_IAS),1)
 KBUILD_AFLAGS  += -Wa,-gdwarf-2
+endif
 
 ifdef CONFIG_DEBUG_INFO_DWARF4
 DEBUG_CFLAGS   += -gdwarf-4
@@ -944,7 +946,7 @@ KBUILD_CFLAGS   += $(call cc-option,-Werror=incompatible-pointer-types)
 KBUILD_CFLAGS   += $(call cc-option,-Werror=designated-init)
 
 # change __FILE__ to the relative path from the srctree
-KBUILD_CFLAGS  += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
+KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
 
 # ensure -fcf-protection is disabled when using retpoline as it is
 # incompatible with -mindirect-branch=thunk-extern
@@ -982,6 +984,12 @@ ifeq ($(CONFIG_RELR),y)
 LDFLAGS_vmlinux        += --pack-dyn-relocs=relr
 endif
 
+# We never want expected sections to be placed heuristically by the
+# linker. All sections should be explicitly named in the linker script.
+ifdef CONFIG_LD_ORPHAN_WARN
+LDFLAGS_vmlinux += --orphan-handling=warn
+endif
+
 # Align the bit size of userspace programs with the kernel
 KBUILD_USERCFLAGS  += $(filter -m32 -m64 --target=%, $(KBUILD_CFLAGS))
 KBUILD_USERLDFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CFLAGS))
index 56b6ccc0e32d396af496541a8fc31809020d6691..ba4e966484ab571b0f541336f8c2b212cca4493a 100644 (file)
@@ -1028,6 +1028,15 @@ config HAVE_STATIC_CALL_INLINE
        bool
        depends on HAVE_STATIC_CALL
 
+config ARCH_WANT_LD_ORPHAN_WARN
+       bool
+       help
+         An arch should select this symbol once all linker sections are explicitly
+         included, size-asserted, or discarded in the linker scripts. This is
+         important because we never want expected sections to be placed heuristically
+         by the linker, since the locations of such sections can change between linker
+         versions.
+
 source "kernel/gcov/Kconfig"
 
 source "scripts/gcc-plugins/Kconfig"
index fe2f17eb2b505ace1720741f7cd550d6eeb6f356..002e0cf025f59b364ac14bc922fd970dcfe93f98 100644 (file)
@@ -35,6 +35,7 @@ config ARM
        select ARCH_USE_CMPXCHG_LOCKREF
        select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU
        select ARCH_WANT_IPC_PARSE_VERSION
+       select ARCH_WANT_LD_ORPHAN_WARN
        select BINFMT_FLAT_ARGVP_ENVP_ON_STACK
        select BUILDTIME_TABLE_SORT if MMU
        select CLONE_BACKWARDS
index 4d76eab2b22d761618a4c36c9b906af0fa3d4bf6..e15f76ca2887cbd7fe3ecfcb0c214682d75f2484 100644 (file)
@@ -16,10 +16,6 @@ LDFLAGS_vmlinux      += --be8
 KBUILD_LDFLAGS_MODULE  += --be8
 endif
 
-# We never want expected sections to be placed heuristically by the
-# linker. All sections should be explicitly named in the linker script.
-LDFLAGS_vmlinux += $(call ld-option, --orphan-handling=warn)
-
 GZFLAGS                :=-9
 #KBUILD_CFLAGS +=-pipe
 
index 47f001ca5499dd929f3e440e6d06dcb18c909bc9..e1567418a2b149583f130faa13eb15183b1e6324 100644 (file)
@@ -129,7 +129,9 @@ LDFLAGS_vmlinux += --no-undefined
 # Delete all temporary local symbols
 LDFLAGS_vmlinux += -X
 # Report orphan sections
-LDFLAGS_vmlinux += $(call ld-option, --orphan-handling=warn)
+ifdef CONFIG_LD_ORPHAN_WARN
+LDFLAGS_vmlinux += --orphan-handling=warn
+endif
 # Next argument is a linker script
 LDFLAGS_vmlinux += -T
 
index 1515f6f153a0dc9a3ebc4220442686138a9f7859..a6b5b7ef40aea08f036e58d2684f87f378773644 100644 (file)
@@ -81,6 +81,7 @@ config ARM64
        select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT
        select ARCH_WANT_FRAME_POINTERS
        select ARCH_WANT_HUGE_PMD_SHARE if ARM64_4K_PAGES || (ARM64_16K_PAGES && !ARM64_VA_BITS_36)
+       select ARCH_WANT_LD_ORPHAN_WARN
        select ARCH_HAS_UBSAN_SANITIZE_ALL
        select ARM_AMBA
        select ARM_ARCH_TIMER
index 5789c2d18d43910ed0a03f6d6f112ac04cf71858..6a87d592bd001fb1b7735b1924d12fe926087759 100644 (file)
@@ -28,10 +28,6 @@ LDFLAGS_vmlinux      += --fix-cortex-a53-843419
   endif
 endif
 
-# We never want expected sections to be placed heuristically by the
-# linker. All sections should be explicitly named in the linker script.
-LDFLAGS_vmlinux += $(call ld-option, --orphan-handling=warn)
-
 ifeq ($(CONFIG_ARM64_USE_LSE_ATOMICS), y)
   ifneq ($(CONFIG_ARM64_LSE_ATOMICS), y)
 $(warning LSE atomics not supported by binutils)
index e9f13fe084929bd9ad322c432d9a59f1674d9ecd..5181872f94523c9e0e9259797e8176cc83b21112 100644 (file)
@@ -152,6 +152,7 @@ config PPC
        select ARCH_USE_QUEUED_SPINLOCKS        if PPC_QUEUED_SPINLOCKS
        select ARCH_WANT_IPC_PARSE_VERSION
        select ARCH_WANT_IRQS_OFF_ACTIVATE_MM
+       select ARCH_WANT_LD_ORPHAN_WARN
        select ARCH_WEAK_RELEASE_ACQUIRE
        select BINFMT_ELF
        select BUILDTIME_TABLE_SORT
index 16b8336f91dda417161a28ed5458cf2822c09b36..5c8c06215dd4ba7c6efefe1e948620ba6e4f4095 100644 (file)
@@ -123,7 +123,6 @@ endif
 LDFLAGS_vmlinux-y := -Bstatic
 LDFLAGS_vmlinux-$(CONFIG_RELOCATABLE) := -pie
 LDFLAGS_vmlinux        := $(LDFLAGS_vmlinux-y)
-LDFLAGS_vmlinux += $(call ld-option,--orphan-handling=warn)
 
 ifdef CONFIG_PPC64
 ifeq ($(call cc-option-yn,-mcmodel=medium),y)
index f6946b81f74a95da92bce9f483dcbd6ca6aa7cff..fbf26e0f7a6a9be1066c9a60348903a401b6050b 100644 (file)
@@ -100,6 +100,7 @@ config X86
        select ARCH_WANT_DEFAULT_BPF_JIT        if X86_64
        select ARCH_WANTS_DYNAMIC_TASK_STRUCT
        select ARCH_WANT_HUGE_PMD_SHARE
+       select ARCH_WANT_LD_ORPHAN_WARN
        select ARCH_WANTS_THP_SWAP              if X86_64
        select BUILDTIME_TABLE_SORT
        select CLKEVT_I8253
index 154259f18b8b960b9aee729fb2e1ddc1e7538634..1bf21746f4cea13fedcd1fd562d70f9121f82454 100644 (file)
@@ -209,9 +209,6 @@ ifdef CONFIG_X86_64
 LDFLAGS_vmlinux += -z max-page-size=0x200000
 endif
 
-# We never want expected sections to be placed heuristically by the
-# linker. All sections should be explicitly named in the linker script.
-LDFLAGS_vmlinux += $(call ld-option, --orphan-handling=warn)
 
 archscripts: scripts_basic
        $(Q)$(MAKE) $(build)=arch/x86/tools relocs
index ee249088cbfe2ff46f2b7e2c76252b1f9001bc9f..40b8fd375d522052f5359040c862ab9ba102e69c 100644 (file)
@@ -61,7 +61,9 @@ KBUILD_LDFLAGS += $(call ld-option,--no-ld-generated-unwind-info)
 # Compressed kernel should be built as PIE since it may be loaded at any
 # address by the bootloader.
 LDFLAGS_vmlinux := -pie $(call ld-option, --no-dynamic-linker)
-LDFLAGS_vmlinux += $(call ld-option, --orphan-handling=warn)
+ifdef CONFIG_LD_ORPHAN_WARN
+LDFLAGS_vmlinux += --orphan-handling=warn
+endif
 LDFLAGS_vmlinux += -T
 
 hostprogs      := mkpiggy
index 02d13ae27abb907972e8446387decb72c782d7df..0872a5a2e7590c0ade132f624af8d6e39de61544 100644 (file)
@@ -47,6 +47,10 @@ config CLANG_VERSION
        int
        default $(shell,$(srctree)/scripts/clang-version.sh $(CC))
 
+config LLD_VERSION
+       int
+       default $(shell,$(srctree)/scripts/lld-version.sh $(LD))
+
 config CC_CAN_LINK
        bool
        default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) $(m64-flag)) if 64BIT
@@ -1348,6 +1352,12 @@ config LD_DEAD_CODE_DATA_ELIMINATION
          present. This option is not well tested yet, so use at your
          own risk.
 
+config LD_ORPHAN_WARN
+       def_bool y
+       depends on ARCH_WANT_LD_ORPHAN_WARN
+       depends on !LD_IS_LLD || LLD_VERSION >= 110000
+       depends on $(ld-option,--orphan-handling=warn)
+
 config SYSCTL
        bool
 
index ae647379b57953d4b291b850f4712a5926d4400f..4c058f12dd73cb6d2d3832788f25daa9d2b413d6 100644 (file)
@@ -252,6 +252,9 @@ objtool_dep = $(objtool_obj)                                        \
 ifdef CONFIG_TRIM_UNUSED_KSYMS
 cmd_gen_ksymdeps = \
        $(CONFIG_SHELL) $(srctree)/scripts/gen_ksymdeps.sh $@ >> $(dot-target).cmd
+
+# List module undefined symbols
+undefined_syms = $(NM) $< | $(AWK) '$$1 == "U" { printf("%s%s", x++ ? " " : "", $$2) }';
 endif
 
 define rule_cc_o_c
@@ -271,13 +274,6 @@ define rule_as_o_S
        $(call cmd,modversions_S)
 endef
 
-# List module undefined symbols (or empty line if not enabled)
-ifdef CONFIG_TRIM_UNUSED_KSYMS
-cmd_undef_syms = $(NM) $< | sed -n 's/^  *U //p' | xargs echo
-else
-cmd_undef_syms = echo
-endif
-
 # Built-in and composite module parts
 $(obj)/%.o: $(src)/%.c $(recordmcount_source) $(objtool_dep) FORCE
        $(call if_changed_rule,cc_o_c)
@@ -285,7 +281,7 @@ $(obj)/%.o: $(src)/%.c $(recordmcount_source) $(objtool_dep) FORCE
 
 cmd_mod = { \
        echo $(if $($*-objs)$($*-y)$($*-m), $(addprefix $(obj)/, $($*-objs) $($*-y) $($*-m)), $(@:.mod=.o)); \
-       $(cmd_undef_syms); \
+       $(undefined_syms) echo; \
        } > $@
 
 $(obj)/%.mod: $(obj)/%.o FORCE
index 95e4cdb94fe9f7bfc99f49646c447df98caf23b8..6baee1200615d53ec7d783108a456825b385d5e0 100644 (file)
@@ -60,7 +60,6 @@ endif
 #
 ifneq ($(findstring 2, $(KBUILD_EXTRA_WARN)),)
 
-KBUILD_CFLAGS += -Wcast-align
 KBUILD_CFLAGS += -Wdisabled-optimization
 KBUILD_CFLAGS += -Wnested-externs
 KBUILD_CFLAGS += -Wshadow
@@ -80,6 +79,7 @@ endif
 ifneq ($(findstring 3, $(KBUILD_EXTRA_WARN)),)
 
 KBUILD_CFLAGS += -Wbad-function-cast
+KBUILD_CFLAGS += -Wcast-align
 KBUILD_CFLAGS += -Wcast-qual
 KBUILD_CFLAGS += -Wconversion
 KBUILD_CFLAGS += -Wpacked
diff --git a/scripts/lld-version.sh b/scripts/lld-version.sh
new file mode 100755 (executable)
index 0000000..d70edb4
--- /dev/null
@@ -0,0 +1,20 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+#
+# Usage: $ ./scripts/lld-version.sh ld.lld
+#
+# Print the linker version of `ld.lld' in a 5 or 6-digit form
+# such as `100001' for ld.lld 10.0.1 etc.
+
+linker_string="$($* --version)"
+
+if ! ( echo $linker_string | grep -q LLD ); then
+       echo 0
+       exit 1
+fi
+
+VERSION=$(echo $linker_string | cut -d ' ' -f 2)
+MAJOR=$(echo $VERSION | cut -d . -f 1)
+MINOR=$(echo $VERSION | cut -d . -f 2)
+PATCHLEVEL=$(echo $VERSION | cut -d . -f 3)
+printf "%d%02d%02d\\n" $MAJOR $MINOR $PATCHLEVEL