kbuild: fix CONFIG_CC_CAN_LINK(_STATIC) for cross-compilation with Clang
PATCH v2 1/2 kbuild: fix CONFIG_CC_CAN_LINK(_STATIC) for cross-compilation with Clang
scripts/cc-can-link.sh tests if the compiler can link userspace programs.
When $(CC) is GCC, it is checked against the target architecture because the toolchain prefix is specified as a part of $(CC).
When $(CC) is Clang, it is checked against the host architecture because --target option is missing.
Pass $(CLANG_FLAGS) to scripts/cc-can-link.sh to evaluate the link capability for the target architecture.
---
Changes in v2:
- New patch
init/Kconfig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
init/Kconfig +4 -4
@@ -49,13 +49,13 @@ config CLANG_VERSION config CC_CAN_LINK bool - default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(m64-flag)) if 64BIT - default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(m32-flag)) + default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) $(m64-flag)) if 64BIT + default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) $(m32-flag)) config CC_CAN_LINK_STATIC bool - default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) -static $(m64-flag)) if 64BIT - default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) -static $(m32-flag)) + default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) -static $(m64-flag)) if 64BIT + default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) -static $(m32-flag)) config CC_HAS_ASM_GOTO def_bool $(success,$(srctree)/scripts/gcc-goto.sh $(CC))
Signature · 1 line
2.25.1
PATCH v2 2/2 kbuild: make Clang build userprogs for target architecture
Programs added 'userprogs' should be compiled for the target architecture i.e. the same architecture as the kernel.
GCC does this correctly since the target architecture is implied by the toolchain prefix.
Clang builds userspace programs always for the host architecture because the target triple is currently missing.
Fix this.
---
(no changes since v1)
Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Makefile +2 -2
@@ -970,8 +970,8 @@ LDFLAGS_vmlinux += --pack-dyn-relocs=relr endif # Align the bit size of userspace programs with the kernel -KBUILD_USERCFLAGS += $(filter -m32 -m64, $(KBUILD_CFLAGS)) -KBUILD_USERLDFLAGS += $(filter -m32 -m64, $(KBUILD_CFLAGS)) +KBUILD_USERCFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CFLAGS)) +KBUILD_USERLDFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CFLAGS)) # make the checker run with the right architecture CHECKFLAGS += --arch=$(ARCH)
Signature · 1 line
2.25.1
Re: [PATCH v2 2/2] kbuild: make Clang build userprogs for target architecture
Quoted 6 lines · Masahiro Yamada
Programs added 'userprogs' should be compiled for the target architecture i.e. the same architecture as the kernel.
GCC does this correctly since the target architecture is implied by the toolchain prefix.
Quoted 8 lines
Clang builds userspace programs always for the host architecture because the target triple is currently missing.
Fix this.
Fixes 7f3a59db274c ("kbuild: add infrastructure to build userspace programs")Signed-off-by Masahiro Yamada <[email protected]>Reviewed-by Nick Desaulniers <[email protected]>
Quoted 24 lines
---
(no changes since v1)
Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)Makefile +2
-2@@ -970,8 +970,8 @@ LDFLAGS_vmlinux += --pack-dyn-relocs=relr endif # Align the bit size of userspace programs with the kernel -KBUILD_USERCFLAGS += $(filter -m32 -m64, $(KBUILD_CFLAGS)) -KBUILD_USERLDFLAGS += $(filter -m32 -m64, $(KBUILD_CFLAGS)) +KBUILD_USERCFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CFLAGS)) +KBUILD_USERLDFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CFLAGS)) # make the checker run with the right architecture CHECKFLAGS += --arch=$(ARCH)Signature · 1 line
2.25.1
Quoted 6 lines · Masahiro Yamada
scripts/cc-can-link.shtests if the compiler can link userspace programs.When $(CC) is GCC, it is checked against the target architecture because the toolchain prefix is specified as a part of $(CC).
Quoted 7 lines
When $(CC) is Clang, it is checked against the host architecture because --target option is missing.
Pass $(CLANG_FLAGS) to
scripts/cc-can-link.shto evaluate the link capability for the target architecture.Signed-off-by Masahiro Yamada <[email protected]>
Quoted 33 lines
---
Changes in v2:
- New patchinit/Kconfig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)init/Kconfig +4
-4@@ -49,13 +49,13 @@ config CLANG_VERSION config CC_CAN_LINK bool - default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(m64-flag)) if 64BIT - default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(m32-flag)) + default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) $(m64-flag)) if 64BIT + default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) $(m32-flag)) config CC_CAN_LINK_STATIC bool - default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) -static $(m64-flag)) if 64BIT - default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) -static $(m32-flag)) + default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) -static $(m64-flag)) if 64BIT + default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) -static $(m32-flag)) config CC_HAS_ASM_GOTO def_bool $(success,$(srctree)/scripts/gcc-goto.sh $(CC))Signature · 1 line
2.25.1