Skip to content

Commit deab487

Browse files
t-8chNicolas Schier
authored andcommitted
kbuild: allow architectures to override CC_CAN_LINK
The generic test for CC_CAN_LINK assumes that all architectures use -m32 and -m64 to switch between 32-bit and 64-bit compilation. This is overly simplistic. Architectures may use other flags (-mabi, -m31, etc.) or may also require byte order handling (-mlittle-endian, -EL). Expressing all of the different possibilities will be very complicated and brittle. Instead allow architectures to supply their own logic which will be easy to understand and evolve. Both the boolean ARCH_HAS_CC_CAN_LINK and the string ARCH_USERFLAGS need to be implemented as kconfig does not allow the reuse of string options. Signed-off-by: Thomas Weißschuh <[email protected]> Reviewed-by: Nicolas Schier <[email protected]> Reviewed-by: Nathan Chancellor <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Nicolas Schier <[email protected]>
1 parent 80623f2 commit deab487

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Makefile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,8 +1137,17 @@ ifneq ($(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS),)
11371137
LDFLAGS_vmlinux += --emit-relocs --discard-none
11381138
endif
11391139

1140-
# Align the bit size of userspace programs with the kernel
1141-
USERFLAGS_FROM_KERNEL := -m32 -m64 --target=%
1140+
# Align the architecture of userspace programs with the kernel
1141+
USERFLAGS_FROM_KERNEL := --target=%
1142+
1143+
ifdef CONFIG_ARCH_USERFLAGS
1144+
KBUILD_USERCFLAGS += $(CONFIG_ARCH_USERFLAGS)
1145+
KBUILD_USERLDFLAGS += $(CONFIG_ARCH_USERFLAGS)
1146+
else
1147+
# If not overridden also inherit the bit size
1148+
USERFLAGS_FROM_KERNEL += -m32 -m64
1149+
endif
1150+
11421151
KBUILD_USERCFLAGS += $(filter $(USERFLAGS_FROM_KERNEL), $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))
11431152
KBUILD_USERLDFLAGS += $(filter $(USERFLAGS_FROM_KERNEL), $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))
11441153

init/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,12 @@ config RUSTC_LLVM_VERSION
8282
int
8383
default $(rustc-llvm-version)
8484

85+
config ARCH_HAS_CC_CAN_LINK
86+
bool
87+
8588
config CC_CAN_LINK
8689
bool
90+
default ARCH_CC_CAN_LINK if ARCH_HAS_CC_CAN_LINK
8791
default $(cc_can_link_user,$(m64-flag)) if 64BIT
8892
default $(cc_can_link_user,$(m32-flag))
8993

0 commit comments

Comments
 (0)