[PATCH] drm/amd/display: Explicitly set stack size to 4
Kazlauskas, Nicholas
nicholas.kazlauskas at amd.com
Tue Jul 21 16:08:46 UTC 2020
On 2020-07-21 12:03 p.m., Felix Kuehling wrote:
> Am 2020-07-21 um 11:38 a.m. schrieb Kent Russell:
>> In certain kernels using GCC 8.2, we get compilation errors saying:
>> -mpreferred-stack-boundary=3 is not between 4 and 12
>> Explicitly set -mpreferred-stack-boundary=4 in the Display Makefiles,
>> even when SSE2 is enabled
>
> As I understand it, -mpreferred-stack-boundary does not affect the stack
> size, but the alignment of the stack frame.
>
> The GCC manpage explains that mixing different stack boundary settings
> can lead to errors when functions compiled with stack-boundary=3 call
> functions with stack-boundary=4. That sounds like setting a different
> stack boundary explicitly in only some parts of the code is probably a
> bad idea.
>
> Quote from the gcc mangage:
>
>> Warning: When generating code for the x86-64 architecture
>> with SSE
>> extensions disabled, -mpreferred-stack-boundary=3 can be
>> used to
>> keep the stack boundary aligned to 8 byte boundary. Since
>> x86-64
>> ABI require 16 byte stack alignment, this is ABI
>> incompatible and
>> intended to be used in controlled environment where stack
>> space is
>> important limitation. This option leads to wrong code when
>> functions compiled with 16 byte stack alignment (such as
>> functions
>> from a standard library) are called with misaligned stack.
>> In this
>> case, SSE instructions may lead to misaligned memory access
>> traps.
>> In addition, variable arguments are handled incorrectly for
>> 16 byte
>> aligned objects (including x87 long double and __int128),
>> leading
>> to wrong results. You must build all modules with
>> -mpreferred-stack-boundary=3, including any libraries. This
>> includes the system libraries and startup modules.
>
> Regards,
> Felix
Oh right, I remember that this issue was brought up before.
https://github.com/ClangBuiltLinux/linux/issues/735
I don't think we want to be mixing alignment then. Maybe let's hold off
on this change for now and figure out if we still need this flag set at
all for GCC 8.2 onward.
like
#ifndef GCC82
ccflags += -mpreferred-stack-boundary=3
#endif
Regards,
Nicholas Kazlauskas
>
>
>>
>> Change-Id: Ic7c4637e2e521af2d0444d3b5886f710131c80ca
>> Signed-off-by: Kent Russell <kent.russell at amd.com>
>> ---
>> drivers/gpu/drm/amd/display/dc/calcs/Makefile | 8 ++++----
>> drivers/gpu/drm/amd/display/dc/dcn20/Makefile | 8 ++++----
>> drivers/gpu/drm/amd/display/dc/dcn21/Makefile | 8 ++++----
>> drivers/gpu/drm/amd/display/dc/dcn30/Makefile | 8 ++++----
>> drivers/gpu/drm/amd/display/dc/dml/Makefile | 9 +++++----
>> drivers/gpu/drm/amd/display/dc/dsc/Makefile | 8 ++++----
>> 6 files changed, 25 insertions(+), 24 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/display/dc/calcs/Makefile b/drivers/gpu/drm/amd/display/dc/calcs/Makefile
>> index 4674aca8f206..5c519cec9039 100644
>> --- a/drivers/gpu/drm/amd/display/dc/calcs/Makefile
>> +++ b/drivers/gpu/drm/amd/display/dc/calcs/Makefile
>> @@ -26,7 +26,9 @@
>> #
>>
>> ifdef CONFIG_X86
>> -calcs_ccflags := -mhard-float -msse
>> +# Certain kernels don't compile with -mpreferred-stack-boundary=3, so explicitly set it
>> +# to 4, even if we enable SSE2
>> +calcs_ccflags := -mhard-float -msse -mpreferred-stack-boundary=4
>> endif
>>
>> ifdef CONFIG_PPC64
>> @@ -40,12 +42,10 @@ endif
>> endif
>>
>> ifdef CONFIG_X86
>> -ifdef IS_OLD_GCC
>> +ifndef IS_OLD_GCC
>> # Stack alignment mismatch, proceed with caution.
>> # GCC < 7.1 cannot compile code using `double` and -mpreferred-stack-boundary=3
>> # (8B stack alignment).
>> -calcs_ccflags += -mpreferred-stack-boundary=4
>> -else
>> calcs_ccflags += -msse2
>> endif
>> endif
>> diff --git a/drivers/gpu/drm/amd/display/dc/dcn20/Makefile b/drivers/gpu/drm/amd/display/dc/dcn20/Makefile
>> index 5fcaf78334ff..78d3e0563a4c 100644
>> --- a/drivers/gpu/drm/amd/display/dc/dcn20/Makefile
>> +++ b/drivers/gpu/drm/amd/display/dc/dcn20/Makefile
>> @@ -10,7 +10,9 @@ DCN20 = dcn20_resource.o dcn20_init.o dcn20_hwseq.o dcn20_dpp.o dcn20_dpp_cm.o d
>> DCN20 += dcn20_dsc.o
>>
>> ifdef CONFIG_X86
>> -CFLAGS_$(AMDDALPATH)/dc/dcn20/dcn20_resource.o := -mhard-float -msse
>> +# Certain kernels don't compile with -mpreferred-stack-boundary=3, so explicitly set it
>> +# to 4, even if we enable SSE2
>> +CFLAGS_$(AMDDALPATH)/dc/dcn20/dcn20_resource.o := -mhard-float -msse -mpreferred-stack-boundary=4
>> endif
>>
>> ifdef CONFIG_PPC64
>> @@ -24,12 +26,10 @@ endif
>> endif
>>
>> ifdef CONFIG_X86
>> -ifdef IS_OLD_GCC
>> +ifndef IS_OLD_GCC
>> # Stack alignment mismatch, proceed with caution.
>> # GCC < 7.1 cannot compile code using `double` and -mpreferred-stack-boundary=3
>> # (8B stack alignment).
>> -CFLAGS_$(AMDDALPATH)/dc/dcn20/dcn20_resource.o += -mpreferred-stack-boundary=4
>> -else
>> CFLAGS_$(AMDDALPATH)/dc/dcn20/dcn20_resource.o += -msse2
>> endif
>> endif
>> diff --git a/drivers/gpu/drm/amd/display/dc/dcn21/Makefile b/drivers/gpu/drm/amd/display/dc/dcn21/Makefile
>> index 07684d3e375a..6183e8f141bb 100644
>> --- a/drivers/gpu/drm/amd/display/dc/dcn21/Makefile
>> +++ b/drivers/gpu/drm/amd/display/dc/dcn21/Makefile
>> @@ -6,7 +6,9 @@ DCN21 = dcn21_init.o dcn21_hubp.o dcn21_hubbub.o dcn21_resource.o \
>> dcn21_hwseq.o dcn21_link_encoder.o
>>
>> ifdef CONFIG_X86
>> -CFLAGS_$(AMDDALPATH)/dc/dcn21/dcn21_resource.o := -mhard-float -msse
>> +# Certain kernels don't compile with -mpreferred-stack-boundary=3, so explicitly set it
>> +# to 4, even if we enable SSE2
>> +CFLAGS_$(AMDDALPATH)/dc/dcn21/dcn21_resource.o := -mhard-float -msse -mpreferred-stack-boundary=4
>> endif
>>
>> ifdef CONFIG_PPC64
>> @@ -20,12 +22,10 @@ endif
>> endif
>>
>> ifdef CONFIG_X86
>> -ifdef IS_OLD_GCC
>> +ifndef IS_OLD_GCC
>> # Stack alignment mismatch, proceed with caution.
>> # GCC < 7.1 cannot compile code using `double` and -mpreferred-stack-boundary=3
>> # (8B stack alignment).
>> -CFLAGS_$(AMDDALPATH)/dc/dcn21/dcn21_resource.o += -mpreferred-stack-boundary=4
>> -else
>> CFLAGS_$(AMDDALPATH)/dc/dcn21/dcn21_resource.o += -msse2
>> endif
>> endif
>> diff --git a/drivers/gpu/drm/amd/display/dc/dcn30/Makefile b/drivers/gpu/drm/amd/display/dc/dcn30/Makefile
>> index 025637a83c3b..0d803486e051 100644
>> --- a/drivers/gpu/drm/amd/display/dc/dcn30/Makefile
>> +++ b/drivers/gpu/drm/amd/display/dc/dcn30/Makefile
>> @@ -33,19 +33,19 @@ DCN30 = dcn30_init.o dcn30_hubbub.o dcn30_hubp.o dcn30_dpp.o dcn30_optc.o \
>>
>> CFLAGS_$(AMDDALPATH)/dc/dcn30/dcn30_optc.o := -mhard-float -msse -mpreferred-stack-boundary=4
>>
>> -CFLAGS_$(AMDDALPATH)/dc/dcn30/dcn30_resource.o := -mhard-float -msse
>> +# Certain kernels don't compile with -mpreferred-stack-boundary=3, so explicitly set it
>> +# to 4, even if we enable SSE2
>> +CFLAGS_$(AMDDALPATH)/dc/dcn30/dcn30_resource.o := -mhard-float -msse -mpreferred-stack-boundary=4
>> ifdef CONFIG_CC_IS_GCC
>> ifeq ($(call cc-ifversion, -lt, 0701, y), y)
>> IS_OLD_GCC = 1
>> endif
>> endif
>>
>> -ifdef IS_OLD_GCC
>> +ifndef IS_OLD_GCC
>> # Stack alignment mismatch, proceed with caution.
>> # GCC < 7.1 cannot compile code using `double` and -mpreferred-stack-boundary=3
>> # (8B stack alignment).
>> -CFLAGS_$(AMDDALPATH)/dc/dcn30/dcn30_resource.o += -mpreferred-stack-boundary=4
>> -else
>> CFLAGS_$(AMDDALPATH)/dc/dcn30/dcn30_resource.o += -msse2
>> endif
>>
>> diff --git a/drivers/gpu/drm/amd/display/dc/dml/Makefile b/drivers/gpu/drm/amd/display/dc/dml/Makefile
>> index 417331438c30..fc5e304c4dac 100644
>> --- a/drivers/gpu/drm/amd/display/dc/dml/Makefile
>> +++ b/drivers/gpu/drm/amd/display/dc/dml/Makefile
>> @@ -25,8 +25,11 @@
>> # It provides the general basic services required by other DAL
>> # subcomponents.
>>
>> +
>> ifdef CONFIG_X86
>> -dml_ccflags := -mhard-float -msse
>> +# Certain kernels don't compile with -mpreferred-stack-boundary=3, so explicitly set it
>> +# to 4, even if we enable SSE2
>> +dml_ccflags := -mhard-float -msse -mpreferred-stack-boundary=4
>> endif
>>
>> ifdef CONFIG_PPC64
>> @@ -40,12 +43,10 @@ endif
>> endif
>>
>> ifdef CONFIG_X86
>> -ifdef IS_OLD_GCC
>> +ifndef IS_OLD_GCC
>> # Stack alignment mismatch, proceed with caution.
>> # GCC < 7.1 cannot compile code using `double` and -mpreferred-stack-boundary=3
>> # (8B stack alignment).
>> -dml_ccflags += -mpreferred-stack-boundary=4
>> -else
>> dml_ccflags += -msse2
>> endif
>> endif
>> diff --git a/drivers/gpu/drm/amd/display/dc/dsc/Makefile b/drivers/gpu/drm/amd/display/dc/dsc/Makefile
>> index ea29cf95d470..98695c66eaf1 100644
>> --- a/drivers/gpu/drm/amd/display/dc/dsc/Makefile
>> +++ b/drivers/gpu/drm/amd/display/dc/dsc/Makefile
>> @@ -3,7 +3,9 @@
>> # Makefile for the 'dsc' sub-component of DAL.
>>
>> ifdef CONFIG_X86
>> -dsc_ccflags := -mhard-float -msse
>> +# Certain kernels don't compile with -mpreferred-stack-boundary=3, so explicitly set it
>> +# to 4, even if we enable SSE2
>> +dsc_ccflags := -mhard-float -msse -mpreferred-stack-boundary=4
>> endif
>>
>> ifdef CONFIG_PPC64
>> @@ -17,12 +19,10 @@ endif
>> endif
>>
>> ifdef CONFIG_X86
>> -ifdef IS_OLD_GCC
>> +ifndef IS_OLD_GCC
>> # Stack alignment mismatch, proceed with caution.
>> # GCC < 7.1 cannot compile code using `double` and -mpreferred-stack-boundary=3
>> # (8B stack alignment).
>> -dsc_ccflags += -mpreferred-stack-boundary=4
>> -else
>> dsc_ccflags += -msse2
>> endif
>> endif
> _______________________________________________
> amd-gfx mailing list
> amd-gfx at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
>
More information about the amd-gfx
mailing list