Re: How to define some additional KBUILD_CFLAGS after building include/generated/asm-offsets.h ?
From: Michael Ellerman <mpe@ellerman.id.au>
Date: 2018-09-27 06:31:56
Also in:
linux-kbuild, lkml
Masahiro Yamada [off-list ref] writes:
2018-09-25 10:16 GMT+09:00 Michael Ellerman [off-list ref]:quoted
Christophe LEROY [off-list ref] writes:quoted
Le 24/09/2018 =C3=A0 14:10, Michael Ellerman a =C3=A9crit :quoted
Christophe Leroy [off-list ref] writes:quoted
I'm trying to implement TLS based stack protector in the Linux Kernel. For that I need to give to GCC the offset at which it will find the canary (register r2 is pointing to the current task struct). I have been able to do it with the below patch, but it only works when include/generated/asm-offsets.h already exists from the start of the =
build.
quoted
quoted
quoted
quoted
Is there a way to evaluate CANARY_OFFSET and add the stack-protector flags to KBUILD_FLAGS only after include/generated/asm-offsets.h is b=
uilt ?
quoted
quoted
quoted
quoted
Or another way of add -mstack-protector-guard-offset=3Doffsetof(struct task_struct, stack_canary) ?This seems to work, at least I see the value in CFLAGS:diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile index 07d9dce..39ee113 100644 --- a/arch/powerpc/Makefile +++ b/arch/powerpc/Makefile@@ -404,6 +394,11 @@ archclean: archprepare: checkbin +prepare: stack_protector_prepare + +stack_protector_prepare: prepare0 + $(eval KBUILD_CFLAGS +=3D -mstack-protector-guard-offset=3D$(shel=
l awk '{if ($$2 =3D=3D "TSK_STACK_CANARY") print $$3;}' include/generated/a=
sm-offsets.h))quoted
quoted
quoted
+Great, it works ! Thanks, I have sent v3 of the patches.Cool. It would be good to here from someone who knows Kbuild better than me if this is acceptable or just a gross hack :)I am fine with this solution.
Thanks. cheers