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.
- From: Florian Weimer <fweimer at redhat dot com>
- To: Nix <nix at esperi dot org dot uk>, libc-alpha at sourceware dot org
- Cc: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>
- Date: Thu, 15 Dec 2016 14:56:21 +0100
- Subject: Re: [PATCH 08/12] De-PLTize __stack_chk_fail internal calls within libc.so.
- Authentication-results: sourceware.org; auth=none
- References: <20161128123228.30856-1-nix@esperi.org.uk> <20161128123228.30856-9-nix@esperi.org.uk>
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