Skip to content

Commit 0024430

Browse files
nathanchanceIngo Molnar
authored andcommitted
x86/build: Fix location of '-plugin-opt=' flags
Commit b33fff0 ("x86, build: allow LTO to be selected") added a couple of '-plugin-opt=' flags to KBUILD_LDFLAGS because the code model and stack alignment are not stored in LLVM bitcode. However, these flags were added to KBUILD_LDFLAGS prior to the emulation flag assignment, which uses ':=', so they were overwritten and never added to $(LD) invocations. The absence of these flags caused misalignment issues in the AMDGPU driver when compiling with CONFIG_LTO_CLANG, resulting in general protection faults. Shuffle the assignment below the initial one so that the flags are properly passed along and all of the linker flags stay together. At the same time, avoid any future issues with clobbering flags by changing the emulation flag assignment to '+=' since KBUILD_LDFLAGS is already defined with ':=' in the main Makefile before being exported for modification here as a result of commit: ce99d0b ("kbuild: clear LDFLAGS in the top Makefile") Fixes: b33fff0 ("x86, build: allow LTO to be selected") Reported-by: Anthony Ruhier <[email protected]> Signed-off-by: Nathan Chancellor <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Tested-by: Anthony Ruhier <[email protected]> Cc: [email protected] Link: ClangBuiltLinux#1374 Link: https://lore.kernel.org/r/[email protected]
1 parent a50c5be commit 0024430

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

arch/x86/Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,6 @@ ifeq ($(ACCUMULATE_OUTGOING_ARGS), 1)
178178
KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args,)
179179
endif
180180

181-
ifdef CONFIG_LTO_CLANG
182-
KBUILD_LDFLAGS += -plugin-opt=-code-model=kernel \
183-
-plugin-opt=-stack-alignment=$(if $(CONFIG_X86_32),4,8)
184-
endif
185-
186181
# Workaround for a gcc prelease that unfortunately was shipped in a suse release
187182
KBUILD_CFLAGS += -Wno-sign-compare
188183
#
@@ -202,7 +197,12 @@ ifdef CONFIG_RETPOLINE
202197
endif
203198
endif
204199

205-
KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE)
200+
KBUILD_LDFLAGS += -m elf_$(UTS_MACHINE)
201+
202+
ifdef CONFIG_LTO_CLANG
203+
KBUILD_LDFLAGS += -plugin-opt=-code-model=kernel \
204+
-plugin-opt=-stack-alignment=$(if $(CONFIG_X86_32),4,8)
205+
endif
206206

207207
ifdef CONFIG_X86_NEED_RELOCS
208208
LDFLAGS_vmlinux := --emit-relocs --discard-none

0 commit comments

Comments
 (0)