This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 08/12] De-PLTize __stack_chk_fail internal calls within libc.so.
On 15 Dec 2016, Florian Weimer uttered the following:
> On 12/15/2016 03:29 PM, Nix wrote:
>> On 15 Dec 2016, Florian Weimer told this:
>>> I wonder if it's better to add something to $(no-stack-protector) and use that in the conditional.
>>
>> That was my other option, but the total absence of anything in
>> configure.ac passing -D made me think twice.
>>
>> Something like this? (even more untested than the last one, if
>> possible -- but adds a new possibility: we can now differentiate between
>> "glibc built without stack protector" and "glibc built with stack
>> protector but this file doesn't have it" without relying on GCC
>> predefined macros. The __WITH_ naming scheme is completely arbitrary
>> and I can change it to anything you prefer.)
>
> WITH_STACK_PROTECTOR (without the leading underscores) looks okay to
> me because it's only used at build time. Or you could call it
> STACK_PROTECTOR_LEVEL, to match the other variable.
That's definitely the best choice, because it means we don't need
to change configure.ac as much, and we don't have a confusing mix
of nonzero STACK_PROTECTOR_LEVEL and zero WITH_STACK_PROTECTOR (or
whatever) in some files. It needs a tiny adjustment of config.h.in
to stop it being overridden though.
Something like this:
diff --git a/config.h.in b/config.h.in
index 610fa49..82f95a6 100644
--- a/config.h.in
+++ b/config.h.in
@@ -52,8 +52,11 @@
__attribute__ ((__optimize__)). */
#undef HAVE_CC_NO_STACK_PROTECTOR
-/* The level of stack protection in use for glibc as a whole. */
+/* The level of stack protection in use for glibc as a whole.
+ May be overridden on a file-by-file basis. */
+#ifndef STACK_PROTECTOR_LEVEL
#undef STACK_PROTECTOR_LEVEL
+#endif
/* Define if the regparm attribute shall be used for local functions
(gcc on ix86 only). */
diff --git a/configure.ac b/configure.ac
index 2396c1f..a420428 100644
--- a/configure.ac
+++ b/configure.ac
@@ -638,7 +638,7 @@ LIBC_TRY_CC_OPTION([$CFLAGS $CPPFLAGS -Werror -fstack-protector-all],
stack_protector=
no_stack_protector=
if test "$libc_cv_ssp" = yes; then
- no_stack_protector="-fno-stack-protector"
+ no_stack_protector="-fno-stack-protector -DSTACK_PROTECTOR_LEVEL=0"
AC_DEFINE(HAVE_CC_NO_STACK_PROTECTOR)
fi
diff --git a/sysdeps/generic/symbol-hacks.h b/sysdeps/generic/symbol-hacks.h
index 36908b5..15ff56a 100644
--- a/sysdeps/generic/symbol-hacks.h
+++ b/sysdeps/generic/symbol-hacks.h
@@ -7,5 +7,7 @@ asm ("memcpy = __GI_memcpy");
/* -fstack-protector generates calls to __stack_chk_fail, which need
similar adjustments to avoid going through the PLT. */
+# if defined STACK_PROTECTOR_LEVEL && STACK_PROTECTOR_LEVEL > 0
asm ("__stack_chk_fail = __stack_chk_fail_local");
+# endif
#endif