[08/12] De-PLTize __stack_chk_fail internal calls within libc.so.

Message ID 87y3zhjn1s.fsf@esperi.org.uk
State Superseded
Headers

Commit Message

Nix Dec. 15, 2016, 2:15 p.m. UTC
  On 15 Dec 2016, Florian Weimer said:

> On 11/28/2016 01:32 PM, Nix wrote:
>> From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
[...]
>> diff --git a/sysdeps/generic/symbol-hacks.h b/sysdeps/generic/symbol-hacks.h
>> index ce576c9..36908b5 100644
>> --- a/sysdeps/generic/symbol-hacks.h
>> +++ b/sysdeps/generic/symbol-hacks.h
>> @@ -4,4 +4,8 @@
>>  asm ("memmove = __GI_memmove");
>>  asm ("memset = __GI_memset");
>>  asm ("memcpy = __GI_memcpy");
>> +
>> +/* -fstack-protector generates calls to __stack_chk_fail, which need
>> +   similar adjustments to avoid going through the PLT.  */
>> +asm ("__stack_chk_fail = __stack_chk_fail_local");
>>  #endif
>
> We should do this only if we compile glibc with stack protector support enabled, and disable this for the files which we compile
> without stack protector.  I hope this will fix an assembler error while compiling __stack_chk_fail.c on ia64:

I don't think we need to disable it for *all* such files -- but at the
very least it must be disabled for debug/stack_chk_fail.c, and if we're
doing that it's probably easier to do as you suggest (though it's
invasive enough I'll have to kick another test cycle off, sigh).

Possible fix, untested:
  

Comments

Florian Weimer Dec. 15, 2016, 2:21 p.m. UTC | #1
On 12/15/2016 03:15 PM, Nix wrote:

> Possible fix, untested:
>
> diff --git a/sysdeps/generic/symbol-hacks.h b/sysdeps/generic/symbol-hacks.h
> index 36908b5..0679354 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 __SSP__ || defined __SSP_ALL__ || defined __SSP_STRONG__
>  asm ("__stack_chk_fail = __stack_chk_fail_local");
>  #endif
> +#endif

The condition looks rather brittle.  What if GCC grows an 
-fstack-protector-light switch and __SSP_LIGHT__ macro?

I wonder if it's better to add something to $(no-stack-protector) and 
use that in the conditional.

Thanks,
Florian
  

Patch

diff --git a/sysdeps/generic/symbol-hacks.h b/sysdeps/generic/symbol-hacks.h
index 36908b5..0679354 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 __SSP__ || defined __SSP_ALL__ || defined __SSP_STRONG__
 asm ("__stack_chk_fail = __stack_chk_fail_local");
 #endif
+#endif