[PATCH 2/3] powerpc: Adjust adding stack protector flags to KBUILD_CLAGS for clang

Christophe Leroy christophe.leroy at csgroup.eu
Tue Oct 8 16:10:36 AEDT 2024



Le 08/10/2024 à 06:22, Nathan Chancellor a écrit :
> After fixing the HAVE_STACKPROTECTER checks for clang's in-progress
> per-task stack protector support [1], the build fails during prepare0
> because '-mstack-protector-guard-offset' has not been added to
> KBUILD_CFLAGS yet but the other '-mstack-protector-guard' flags have.
> 
>    clang: error: '-mstack-protector-guard=tls' is used without '-mstack-protector-guard-offset', and there is no default
>    clang: error: '-mstack-protector-guard=tls' is used without '-mstack-protector-guard-offset', and there is no default
>    make[4]: *** [scripts/Makefile.build:229: scripts/mod/empty.o] Error 1
>    make[4]: *** [scripts/Makefile.build:102: scripts/mod/devicetable-offsets.s] Error 1
> 
> Mirror other architectures and add all '-mstack-protector-guard' flags
> to KBUILD_CFLAGS atomically during stack_protector_prepare, which
> resolves the issue and allows clang's implementation to fully work with
> the kernel.
> 
> Link: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fllvm%2Fllvm-project%2Fpull%2F110928&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7Cc099707fa5464808c49108dce750d65e%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638639581583232977%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=b%2BcqodA6k739DD%2F74EJMXUtIHAZDt1DGcyd7mzzhbd8%3D&reserved=0 [1]
> Signed-off-by: Nathan Chancellor <nathan at kernel.org>

Is it worth a Fixes: tag so that it gets applied on stable, or wont 
CLANG 20 be used with kernels older than 6.13 ?

> ---
>   arch/powerpc/Makefile | 15 ++++++---------
>   1 file changed, 6 insertions(+), 9 deletions(-)
> 
> diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
> index bbfe4a1f06ef9db9b2f2e48e02096b1e0500a14b..8f9e387c4c7dd06d8756dca3eac808cc344a937d 100644
> --- a/arch/powerpc/Makefile
> +++ b/arch/powerpc/Makefile
> @@ -100,13 +100,6 @@ KBUILD_AFLAGS	+= -m$(BITS)
>   KBUILD_LDFLAGS	+= -m elf$(BITS)$(LDEMULATION)
>   endif
>   
> -cflags-$(CONFIG_STACKPROTECTOR)	+= -mstack-protector-guard=tls
> -ifdef CONFIG_PPC64
> -cflags-$(CONFIG_STACKPROTECTOR)	+= -mstack-protector-guard-reg=r13
> -else
> -cflags-$(CONFIG_STACKPROTECTOR)	+= -mstack-protector-guard-reg=r2
> -endif
> -
>   LDFLAGS_vmlinux-y := -Bstatic
>   LDFLAGS_vmlinux-$(CONFIG_RELOCATABLE) := -pie
>   LDFLAGS_vmlinux-$(CONFIG_RELOCATABLE) += -z notext
> @@ -402,9 +395,13 @@ prepare: stack_protector_prepare
>   PHONY += stack_protector_prepare
>   stack_protector_prepare: prepare0
>   ifdef CONFIG_PPC64
> -	$(eval KBUILD_CFLAGS += -mstack-protector-guard-offset=$(shell awk '{if ($$2 == "PACA_CANARY") print $$3;}' include/generated/asm-offsets.h))
> +	$(eval KBUILD_CFLAGS += -mstack-protector-guard=tls \
> +				-mstack-protector-guard-reg=r13 \

Can you put both above lines on a single line to avoid having too many 
lines at the end:

+	$(eval KBUILD_CFLAGS += -mstack-protector-guard=tls 
-mstack-protector-guard-reg=r13 \

> +				-mstack-protector-guard-offset=$(shell awk '{if ($$2 == "PACA_CANARY") print $$3;}' include/generated/asm-offsets.h))
>   else
> -	$(eval KBUILD_CFLAGS += -mstack-protector-guard-offset=$(shell awk '{if ($$2 == "TASK_CANARY") print $$3;}' include/generated/asm-offsets.h))
> +	$(eval KBUILD_CFLAGS += -mstack-protector-guard=tls \
> +				-mstack-protector-guard-reg=r2 \

Same

> +				-mstack-protector-guard-offset=$(shell awk '{if ($$2 == "TASK_CANARY") print $$3;}' include/generated/asm-offsets.h))
>   endif
>   endif
>   
> 


More information about the Linuxppc-dev mailing list