Message ID | 20161128123228.30856-9-nix@esperi.org.uk |
---|---|
State | Superseded |
Headers |
Received: (qmail 55966 invoked by alias); 28 Nov 2016 13:25:27 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: <libc-alpha.sourceware.org> List-Unsubscribe: <mailto:libc-alpha-unsubscribe-##L=##H@sourceware.org> List-Subscribe: <mailto:libc-alpha-subscribe@sourceware.org> List-Archive: <http://sourceware.org/ml/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-help@sourceware.org>, <http://sourceware.org/ml/#faqs> Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 55909 invoked by uid 89); 28 Nov 2016 13:25:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.4 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=Hx-languages-length:1161 X-HELO: mail.esperi.org.uk From: Nix <nix@esperi.org.uk> To: libc-alpha@sourceware.org Cc: fweimer@redhat.com, Adhemerval Zanella <adhemerval.zanella@linaro.org> Subject: [PATCH 08/12] De-PLTize __stack_chk_fail internal calls within libc.so. Date: Mon, 28 Nov 2016 12:32:24 +0000 Message-Id: <20161128123228.30856-9-nix@esperi.org.uk> In-Reply-To: <20161128123228.30856-1-nix@esperi.org.uk> References: <20161128123228.30856-1-nix@esperi.org.uk> X-DCC--Metrics: spindle 1282; Body=3 Fuz1=3 Fuz2=3 |
Commit Message
Nix
Nov. 28, 2016, 12:32 p.m. UTC
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
We use the same assembler-macro trick we use to de-PLTize
compiler-generated libcalls to memcpy and memset to redirect
__stack_chk_fail to __stack_chk_fail_local.
v5: New.
v6: Only do it within the shared library: with __stack_chk_fail_local
in libc_pic.a now we don't need to worry about calls from inside
other routines in libc_nonshared.a any more.
v8: Merge #ifdef blocks.
* sysdeps/generic/symbol-hacks.h (__stack_chk_fail): Add internal
alias.
---
sysdeps/generic/symbol-hacks.h | 4 ++++
1 file changed, 4 insertions(+)
Comments
On 11/28/2016 01:32 PM, Nix wrote: > From: Adhemerval Zanella <adhemerval.zanella@linaro.org> > > We use the same assembler-macro trick we use to de-PLTize > compiler-generated libcalls to memcpy and memset to redirect > __stack_chk_fail to __stack_chk_fail_local. > > v5: New. > v6: Only do it within the shared library: with __stack_chk_fail_local > in libc_pic.a now we don't need to worry about calls from inside > other routines in libc_nonshared.a any more. > v8: Merge #ifdef blocks. > > * sysdeps/generic/symbol-hacks.h (__stack_chk_fail): Add internal > alias. > --- > sysdeps/generic/symbol-hacks.h | 4 ++++ > 1 file changed, 4 insertions(+) > > 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: /tmp/ccCNZVJs.s:51: Error: `__stack_chk_fail' was not defined within procedure /tmp/ccCNZVJs.s:51: Warning: `__stack_chk_fail#' was not specified with previous .proc /tmp/ccCNZVJs.s:51: Warning: `__stack_chk_fail' should be an operand to this .endp The .s file looks like this: 1 .file "stack_chk_fail.c" 2 .pred.safe_across_calls p1-p5,p16-p63 3 .text 4 .Ltext0: 5 #APP 6 memmove = __GI_memmove 7 memset = __GI_memset 8 memcpy = __GI_memcpy 9 __stack_chk_fail = __stack_chk_fail_local 10 .section .rodata.str1.8,"aMS",@progbits,1 11 .align 8 12 .LC0: 13 stringz "stack smashing detected" 14 #NO_APP 15 .text 16 .align 16 17 .align 64 18 .global __stack_chk_fail# 19 .type __stack_chk_fail#, @function 20 .proc __stack_chk_fail# 21 __stack_chk_fail: 22 [.LFB33:] 23 .file 1 "stack_chk_fail.c" 24 .loc 1 27 0 25 .prologue 12, 32 26 .mib 27 .save ar.pfs, r33 28 alloc r33 = ar.pfs, 0, 3, 1, 0 29 [.LCFI0:] 30 .save rp, r32 31 mov r32 = b0 32 [.LCFI1:] 33 .loc 1 28 0 34 nop 0 35 .mlx 36 nop 0 37 movl r35 = @gprel(.LC0) 38 .loc 1 27 0 39 .body 40 .loc 1 28 0 41 ;; 42 .mib 43 nop 0 44 add r35 = r1, r35 45 br.call.sptk.many b0 = __GI___fortify_fail 46 [.LVL0:] 47 ;; 48 break.f 0 49 ;; 50 .LFE33: 51 .endp __stack_chk_fail# Thanks, Florian
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