Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8f91869

Browse files
Matthias KaehlckeIngo Molnar
Matthias Kaehlcke
authored and
Ingo Molnar
committedAug 17, 2017
x86/build: Fix stack alignment for CLang
Commit: d77698d ("x86/build: Specify stack alignment for clang") intended to use the same stack alignment for clang as with gcc. The two compilers use different options to configure the stack alignment (gcc: -mpreferred-stack-boundary=n, clang: -mstack-alignment=n). The above commit assumes that the clang option uses the same parameter type as gcc, i.e. that the alignment is specified as 2^n. However clang interprets the value of this option literally to use an alignment of n, in consequence the stack remains misaligned. Change the values used with -mstack-alignment to be the actual alignment instead of a power of two. cc-option isn't used here with the typical pattern of KBUILD_CFLAGS += $(call cc-option ...). The reason is that older gcc versions don't support the -mpreferred-stack-boundary option, since cc-option doesn't verify whether the alternative option is valid it would incorrectly select the clang option -mstack-alignment.. Signed-off-by: Matthias Kaehlcke <mka@chromium.org> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Bernhard.Rosenkranzer@linaro.org Cc: Greg Hackmann <ghackmann@google.com> Cc: Kees Cook <keescook@chromium.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Masahiro Yamada <yamada.masahiro@socionext.com> Cc: Michael Davidson <md@google.com> Cc: Nick Desaulniers <ndesaulniers@google.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephen Hines <srhines@google.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: dianders@chromium.org Link: http://lkml.kernel.org/r/20170817004740.170588-1-mka@chromium.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent e20f7e5 commit 8f91869

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed
 

‎arch/x86/Makefile

+8-6
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ endif
1414
# For gcc stack alignment is specified with -mpreferred-stack-boundary,
1515
# clang has the option -mstack-alignment for that purpose.
1616
ifneq ($(call cc-option, -mpreferred-stack-boundary=4),)
17-
cc_stack_align_opt := -mpreferred-stack-boundary
18-
else ifneq ($(call cc-option, -mstack-alignment=4),)
19-
cc_stack_align_opt := -mstack-alignment
17+
cc_stack_align4 := -mpreferred-stack-boundary=2
18+
cc_stack_align8 := -mpreferred-stack-boundary=3
19+
else ifneq ($(call cc-option, -mstack-alignment=16),)
20+
cc_stack_align4 := -mstack-alignment=4
21+
cc_stack_align8 := -mstack-alignment=8
2022
endif
2123

2224
# How to compile the 16-bit code. Note we always compile for -march=i386;
@@ -36,7 +38,7 @@ REALMODE_CFLAGS := $(M16_CFLAGS) -g -Os -D__KERNEL__ \
3638

3739
REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -ffreestanding)
3840
REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), -fno-stack-protector)
39-
REALMODE_CFLAGS += $(call __cc-option, $(CC), $(REALMODE_CFLAGS), $(cc_stack_align_opt)=2)
41+
REALMODE_CFLAGS += $(cc_stack_align4)
4042
export REALMODE_CFLAGS
4143

4244
# BITS is used as extension for files which are available in a 32 bit
@@ -76,7 +78,7 @@ ifeq ($(CONFIG_X86_32),y)
7678
# Align the stack to the register width instead of using the default
7779
# alignment of 16 bytes. This reduces stack usage and the number of
7880
# alignment instructions.
79-
KBUILD_CFLAGS += $(call cc-option,$(cc_stack_align_opt)=2)
81+
KBUILD_CFLAGS += $(cc_stack_align4)
8082

8183
# Disable unit-at-a-time mode on pre-gcc-4.0 compilers, it makes gcc use
8284
# a lot more stack due to the lack of sharing of stacklots:
@@ -115,7 +117,7 @@ else
115117
# default alignment which keep the stack *mis*aligned.
116118
# Furthermore an alignment to the register width reduces stack usage
117119
# and the number of alignment instructions.
118-
KBUILD_CFLAGS += $(call cc-option,$(cc_stack_align_opt)=3)
120+
KBUILD_CFLAGS += $(cc_stack_align8)
119121

120122
# Use -mskip-rax-setup if supported.
121123
KBUILD_CFLAGS += $(call cc-option,-mskip-rax-setup)

0 commit comments

Comments
 (0)
Failed to load comments.