From ea6088e7d368d53c49ebfdf4520275cec2f78f5b Mon Sep 17 00:00:00 2001 From: guenther Date: Wed, 29 Nov 2017 05:13:57 +0000 Subject: [PATCH] clang doesn't propagate attributes like "asm labels" and "visibility(hidden)" to builtins like mem{set,cpy,move} and __stack_smash_handler. So, when building with clang, instead mark those as protected visibility to get rid of the PLT relocations. We can't take the address of them then, but that's ok: it's a build-time error not a run-time error. ok kettenis@ --- lib/libc/arch/amd64/DEFS.h | 10 +++++- lib/libc/arch/amd64/string/memmove.S | 10 ++++-- lib/libc/arch/amd64/string/memset.S | 2 +- lib/libc/arch/arm/DEFS.h | 11 ++++++- lib/libc/arch/arm/string/memcpy.S | 4 +-- lib/libc/arch/arm/string/memmove.S | 4 +-- lib/libc/arch/arm/string/memset.S | 4 +-- lib/libc/arch/i386/DEFS.h | 48 +++++++++++++++++++++++++++- lib/libc/arch/i386/SYS.h | 27 ++-------------- lib/libc/arch/i386/gen/flt_rounds.S | 4 +-- lib/libc/arch/i386/stdlib/abs.S | 2 +- lib/libc/arch/i386/stdlib/div.S | 2 +- lib/libc/arch/i386/stdlib/labs.S | 2 +- lib/libc/arch/i386/stdlib/ldiv.S | 2 +- lib/libc/arch/i386/string/bcmp.S | 4 +-- lib/libc/arch/i386/string/bzero.S | 4 +-- lib/libc/arch/i386/string/ffs.S | 4 +-- lib/libc/arch/i386/string/memchr.S | 4 +-- lib/libc/arch/i386/string/memcmp.S | 4 +-- lib/libc/arch/i386/string/memmove.S | 14 +++++--- lib/libc/arch/i386/string/memset.S | 6 ++-- lib/libc/arch/i386/string/strchr.S | 4 +-- lib/libc/arch/i386/string/strcmp.S | 4 +-- lib/libc/arch/i386/string/strncmp.S | 4 +-- lib/libc/arch/i386/string/strrchr.S | 4 +-- lib/libc/hidden/string.h | 8 ++--- lib/libc/include/namespace.h | 22 ++++++++++--- lib/libc/string/memcpy.c | 4 +-- lib/libc/string/memmove.c | 4 +-- lib/libc/string/memset.c | 4 +-- lib/libc/sys/stack_protector.c | 4 +-- 31 files changed, 148 insertions(+), 86 deletions(-) diff --git a/lib/libc/arch/amd64/DEFS.h b/lib/libc/arch/amd64/DEFS.h index 9a2daa3d424..8e39fc58122 100644 --- a/lib/libc/arch/amd64/DEFS.h +++ b/lib/libc/arch/amd64/DEFS.h @@ -1,4 +1,4 @@ -/* $OpenBSD: DEFS.h,v 1.1 2015/11/14 21:53:03 guenther Exp $ */ +/* $OpenBSD: DEFS.h,v 1.2 2017/11/29 05:13:57 guenther Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -55,7 +55,15 @@ * For functions implemented in ASM that aren't syscalls. * END_STRONG(x) Like DEF_STRONG() in C; for standard/reserved C names * END_WEAK(x) Like DEF_WEAK() in C; for non-ISO C names + * END_BUILTIN(x) If compiling with clang, then just END() and + * mark it .protected, else be like END_STRONG(); + * for clang builtins like memcpy */ #define END_STRONG(x) END(x); _HIDDEN_FALIAS(x,x); END(_HIDDEN(x)) #define END_WEAK(x) END_STRONG(x); .weak x +#ifdef __clang__ +#define END_BUILTIN(x) END(x); .protected x +#else +#define END_BUILTIN(x) END_STRONG(x) +#endif diff --git a/lib/libc/arch/amd64/string/memmove.S b/lib/libc/arch/amd64/string/memmove.S index f0e01654c2f..da244c332a1 100644 --- a/lib/libc/arch/amd64/string/memmove.S +++ b/lib/libc/arch/amd64/string/memmove.S @@ -51,12 +51,14 @@ ENTRY(memmove) subq %rsi,%rax cmpq %rcx,%rax /* overlapping? */ jb 1f +#ifdef memcpy_in_asm jmp 2f /* nope */ -// ENTRY(memcpy) +ENTRY(memcpy) movq %rdi,%r11 /* save dest */ movq %rdx,%rcx 2: +#endif cld /* copy forwards. */ shrq $3,%rcx /* copy by words */ rep @@ -85,6 +87,8 @@ ENTRY(memmove) movq %r11,%rax cld ret -// END(memcpy) -END_STRONG(memmove) +#ifdef memcpy_in_asm +END_BUILTIN(memcpy) +#endif +END_BUILTIN(memmove) END_WEAK(bcopy) diff --git a/lib/libc/arch/amd64/string/memset.S b/lib/libc/arch/amd64/string/memset.S index b3f4ffa17bf..2a8645cb1c3 100644 --- a/lib/libc/arch/amd64/string/memset.S +++ b/lib/libc/arch/amd64/string/memset.S @@ -53,4 +53,4 @@ L1: rep movq %r11,%rax ret -END_STRONG(memset) +END_BUILTIN(memset) diff --git a/lib/libc/arch/arm/DEFS.h b/lib/libc/arch/arm/DEFS.h index 828c9cd68aa..4220bdf2d37 100644 --- a/lib/libc/arch/arm/DEFS.h +++ b/lib/libc/arch/arm/DEFS.h @@ -1,4 +1,4 @@ -/* $OpenBSD: DEFS.h,v 1.1 2016/08/06 19:16:09 guenther Exp $ */ +/* $OpenBSD: DEFS.h,v 1.2 2017/11/29 05:13:57 guenther Exp $ */ /* * Copyright (c) 2016 Philip Guenther * @@ -35,6 +35,15 @@ * For functions implemented in ASM that aren't syscalls. * END_STRONG(x) Like DEF_STRONG() in C; for standard/reserved C names * END_WEAK(x) Like DEF_WEAK() in C; for non-ISO C names + * END_BUILTIN(x) If compiling with clang, then just END() and + * mark it .protected, else be like END_STRONG(); + * for clang builtins like memcpy */ #define END_STRONG(x) END(x); _HIDDEN_FALIAS(x,x); END(_HIDDEN(x)) #define END_WEAK(x) END_STRONG(x); .weak x + +#ifdef __clang__ +#define END_BUILTIN(x) END(x); .protected x +#else +#define END_BUILTIN(x) END_STRONG(x) +#endif diff --git a/lib/libc/arch/arm/string/memcpy.S b/lib/libc/arch/arm/string/memcpy.S index d1f557980a7..aba898b40a7 100644 --- a/lib/libc/arch/arm/string/memcpy.S +++ b/lib/libc/arch/arm/string/memcpy.S @@ -1,4 +1,4 @@ -/* $OpenBSD: memcpy.S,v 1.7 2017/10/29 02:21:33 guenther Exp $ */ +/* $OpenBSD: memcpy.S,v 1.8 2017/11/29 05:13:57 guenther Exp $ */ /* $NetBSD: memcpy.S,v 1.3 2003/04/05 23:08:52 bjh21 Exp $ */ /*- @@ -42,4 +42,4 @@ ENTRY(memcpy) stmfd sp!, {r0, lr} bl _memcpy ldmfd sp!, {r0, pc} -END_STRONG(memcpy) +END_BUILTIN(memcpy) diff --git a/lib/libc/arch/arm/string/memmove.S b/lib/libc/arch/arm/string/memmove.S index 95eca35bbde..1dfd4108105 100644 --- a/lib/libc/arch/arm/string/memmove.S +++ b/lib/libc/arch/arm/string/memmove.S @@ -1,4 +1,4 @@ -/* $OpenBSD: memmove.S,v 1.6 2017/10/29 02:21:33 guenther Exp $ */ +/* $OpenBSD: memmove.S,v 1.7 2017/11/29 05:13:57 guenther Exp $ */ /* $NetBSD: memmove.S,v 1.3 2003/04/05 23:08:52 bjh21 Exp $ */ /*- @@ -36,4 +36,4 @@ ENTRY(memmove) stmfd sp!, {r0, lr} bl _memcpy ldmfd sp!, {r0, pc} -END_STRONG(memmove) +END_BUILTIN(memmove) diff --git a/lib/libc/arch/arm/string/memset.S b/lib/libc/arch/arm/string/memset.S index 573e924209d..91511f117f1 100644 --- a/lib/libc/arch/arm/string/memset.S +++ b/lib/libc/arch/arm/string/memset.S @@ -1,4 +1,4 @@ -/* $OpenBSD: memset.S,v 1.5 2016/08/06 19:16:09 guenther Exp $ */ +/* $OpenBSD: memset.S,v 1.6 2017/11/29 05:13:57 guenther Exp $ */ /* $NetBSD: memset.S,v 1.3 2003/04/05 23:08:52 bjh21 Exp $ */ /* @@ -127,4 +127,4 @@ ENTRY(memset) ldmfd sp!, {r0} mov pc, lr /* Exit */ -END_STRONG(memset) +END_BUILTIN(memset) diff --git a/lib/libc/arch/i386/DEFS.h b/lib/libc/arch/i386/DEFS.h index 051613308e3..db2d9696d1d 100644 --- a/lib/libc/arch/i386/DEFS.h +++ b/lib/libc/arch/i386/DEFS.h @@ -1,3 +1,49 @@ -/* $OpenBSD: DEFS.h,v 1.2 1996/08/19 08:12:09 tholo Exp $ */ +/* $OpenBSD: DEFS.h,v 1.3 2017/11/29 05:13:57 guenther Exp $ */ +/* + * Copyright (c) 2017 Philip Guenther + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ #include + +/* + * We define a hidden alias with the prefix "_libc_" for each global symbol + * that may be used internally. By referencing _libc_x instead of x, other + * parts of libc prevent overriding by the application and avoid unnecessary + * relocations. + */ +#define _HIDDEN(x) _libc_##x +#define _HIDDEN_ALIAS(x,y) \ + STRONG_ALIAS(_HIDDEN(x),y); \ + .hidden _HIDDEN(x) +#define _HIDDEN_FALIAS(x,y) \ + _HIDDEN_ALIAS(x,y); \ + .type _HIDDEN(x),@function + +/* + * For functions implemented in ASM that aren't syscalls. + * END_STRONG(x) Like DEF_STRONG() in C; for standard/reserved C names + * END_WEAK(x) Like DEF_WEAK() in C; for non-ISO C names + * END_BUILTIN(x) If compiling with clang, then just END() and + * mark it .protected, else be like END_STRONG(); + * for clang builtins like memcpy + */ +#define END_STRONG(x) END(x); _HIDDEN_FALIAS(x,x); END(_HIDDEN(x)) +#define END_WEAK(x) END_STRONG(x); .weak x + +#ifdef __clang__ +#define END_BUILTIN(x) END(x); .protected x +#else +#define END_BUILTIN(x) END_STRONG(x) +#endif diff --git a/lib/libc/arch/i386/SYS.h b/lib/libc/arch/i386/SYS.h index 3ecba9830e4..993ad31715d 100644 --- a/lib/libc/arch/i386/SYS.h +++ b/lib/libc/arch/i386/SYS.h @@ -29,37 +29,14 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $OpenBSD: SYS.h,v 1.26 2017/06/01 12:14:48 naddy Exp $ + * $OpenBSD: SYS.h,v 1.27 2017/11/29 05:13:57 guenther Exp $ */ -#include +#include "DEFS.h" #include #define TCB_OFFSET_ERRNO 16 -/* - * We define a hidden alias with the prefix "_libc_" for each global symbol - * that may be used internally. By referencing _libc_x instead of x, other - * parts of libc prevent overriding by the application and avoid unnecessary - * relocations. - */ -#define _HIDDEN(x) _libc_##x -#define _HIDDEN_ALIAS(x,y) \ - STRONG_ALIAS(_HIDDEN(x),y); \ - .hidden _HIDDEN(x) -#define _HIDDEN_FALIAS(x,y) \ - _HIDDEN_ALIAS(x,y); \ - .type _HIDDEN(x),@function - -/* - * For functions implemented in ASM that aren't syscalls. - * END_STRONG(x) Like DEF_STRONG() in C; for standard/reserved C names - * END_WEAK(x) Like DEF_WEAK() in C; for non-ISO C names - */ -#define END_STRONG(x) END(x); _HIDDEN_FALIAS(x,x); END(_HIDDEN(x)) -#define END_WEAK(x) END_STRONG(x); .weak x - - /* * Design note: * diff --git a/lib/libc/arch/i386/gen/flt_rounds.S b/lib/libc/arch/i386/gen/flt_rounds.S index a46fe912fd5..7cba4a3f379 100644 --- a/lib/libc/arch/i386/gen/flt_rounds.S +++ b/lib/libc/arch/i386/gen/flt_rounds.S @@ -1,10 +1,10 @@ -/* $OpenBSD: flt_rounds.S,v 1.6 2017/08/19 18:23:00 deraadt Exp $ */ +/* $OpenBSD: flt_rounds.S,v 1.7 2017/11/29 05:13:57 guenther Exp $ */ /* * Written by J.T. Conklin, Apr 4, 1995 * Public domain. */ -#include "SYS.h" +#include "DEFS.h" .section .rodata .align 2 diff --git a/lib/libc/arch/i386/stdlib/abs.S b/lib/libc/arch/i386/stdlib/abs.S index 5403c642d1d..235ce5d9879 100644 --- a/lib/libc/arch/i386/stdlib/abs.S +++ b/lib/libc/arch/i386/stdlib/abs.S @@ -30,7 +30,7 @@ * SUCH DAMAGE. */ -#include "SYS.h" +#include "DEFS.h" ENTRY(abs) movl 4(%esp),%eax diff --git a/lib/libc/arch/i386/stdlib/div.S b/lib/libc/arch/i386/stdlib/div.S index 6c05fc34462..5227bfe3b9c 100644 --- a/lib/libc/arch/i386/stdlib/div.S +++ b/lib/libc/arch/i386/stdlib/div.S @@ -3,7 +3,7 @@ * Public domain. */ -#include "SYS.h" +#include "DEFS.h" ENTRY(div) movl 4(%esp),%eax diff --git a/lib/libc/arch/i386/stdlib/labs.S b/lib/libc/arch/i386/stdlib/labs.S index 980ecf3426a..d7e592822b4 100644 --- a/lib/libc/arch/i386/stdlib/labs.S +++ b/lib/libc/arch/i386/stdlib/labs.S @@ -30,7 +30,7 @@ * SUCH DAMAGE. */ -#include "SYS.h" +#include "DEFS.h" ENTRY(labs) movl 4(%esp),%eax diff --git a/lib/libc/arch/i386/stdlib/ldiv.S b/lib/libc/arch/i386/stdlib/ldiv.S index 48db16098af..3c2e84767c2 100644 --- a/lib/libc/arch/i386/stdlib/ldiv.S +++ b/lib/libc/arch/i386/stdlib/ldiv.S @@ -3,7 +3,7 @@ * Public domain. */ -#include "SYS.h" +#include "DEFS.h" ENTRY(ldiv) movl 4(%esp),%eax diff --git a/lib/libc/arch/i386/string/bcmp.S b/lib/libc/arch/i386/string/bcmp.S index b55c93a6e14..6a9772e0a48 100644 --- a/lib/libc/arch/i386/string/bcmp.S +++ b/lib/libc/arch/i386/string/bcmp.S @@ -1,10 +1,10 @@ -/* $OpenBSD: bcmp.S,v 1.4 2015/08/31 02:53:56 guenther Exp $ */ +/* $OpenBSD: bcmp.S,v 1.5 2017/11/29 05:13:57 guenther Exp $ */ /* * Written by J.T. Conklin . * Public domain. */ -#include "SYS.h" +#include "DEFS.h" ENTRY(bcmp) pushl %edi diff --git a/lib/libc/arch/i386/string/bzero.S b/lib/libc/arch/i386/string/bzero.S index 43251b5cdff..75cbf72278b 100644 --- a/lib/libc/arch/i386/string/bzero.S +++ b/lib/libc/arch/i386/string/bzero.S @@ -1,10 +1,10 @@ -/* $OpenBSD: bzero.S,v 1.5 2015/08/31 02:53:56 guenther Exp $ */ +/* $OpenBSD: bzero.S,v 1.6 2017/11/29 05:13:57 guenther Exp $ */ /* * Written by J.T. Conklin . * Public domain. */ -#include "SYS.h" +#include "DEFS.h" ENTRY(bzero) pushl %edi diff --git a/lib/libc/arch/i386/string/ffs.S b/lib/libc/arch/i386/string/ffs.S index 7befc0bcbbe..b02405ee2ef 100644 --- a/lib/libc/arch/i386/string/ffs.S +++ b/lib/libc/arch/i386/string/ffs.S @@ -1,10 +1,10 @@ -/* $OpenBSD: ffs.S,v 1.5 2017/08/19 18:25:50 deraadt Exp $ */ +/* $OpenBSD: ffs.S,v 1.6 2017/11/29 05:13:57 guenther Exp $ */ /* * Written by J.T. Conklin . * Public domain. */ -#include "SYS.h" +#include "DEFS.h" ENTRY(ffs) bsfl 4(%esp),%eax diff --git a/lib/libc/arch/i386/string/memchr.S b/lib/libc/arch/i386/string/memchr.S index b3d773bea4c..660f0373153 100644 --- a/lib/libc/arch/i386/string/memchr.S +++ b/lib/libc/arch/i386/string/memchr.S @@ -1,10 +1,10 @@ -/* $OpenBSD: memchr.S,v 1.5 2017/08/19 18:25:50 deraadt Exp $ */ +/* $OpenBSD: memchr.S,v 1.6 2017/11/29 05:13:57 guenther Exp $ */ /* * Written by J.T. Conklin . * Public domain. */ -#include "SYS.h" +#include "DEFS.h" ENTRY(memchr) pushl %edi diff --git a/lib/libc/arch/i386/string/memcmp.S b/lib/libc/arch/i386/string/memcmp.S index 171af0734b1..a5f2c36bdd7 100644 --- a/lib/libc/arch/i386/string/memcmp.S +++ b/lib/libc/arch/i386/string/memcmp.S @@ -1,10 +1,10 @@ -/* $OpenBSD: memcmp.S,v 1.5 2015/08/31 02:53:56 guenther Exp $ */ +/* $OpenBSD: memcmp.S,v 1.6 2017/11/29 05:13:57 guenther Exp $ */ /* * Written by J.T. Conklin . * Public domain. */ -#include "SYS.h" +#include "DEFS.h" ENTRY(memcmp) pushl %edi diff --git a/lib/libc/arch/i386/string/memmove.S b/lib/libc/arch/i386/string/memmove.S index afa465aa4dd..8d124ad76a9 100644 --- a/lib/libc/arch/i386/string/memmove.S +++ b/lib/libc/arch/i386/string/memmove.S @@ -1,4 +1,4 @@ -/* $OpenBSD: memmove.S,v 1.6 2015/08/31 02:53:56 guenther Exp $ */ +/* $OpenBSD: memmove.S,v 1.7 2017/11/29 05:13:57 guenther Exp $ */ /*- * Copyright (c) 1993, 1994, 1995 Charles M. Hannum. All rights reserved. @@ -33,7 +33,7 @@ * SUCH DAMAGE. */ -#include "SYS.h" +#include "DEFS.h" /* * Emulate bcopy() by swapping the first two arguments, and jumping @@ -61,17 +61,20 @@ docopy: subl %esi,%eax cmpl %ecx,%eax # overlapping? jb 1f +#ifdef memcpy_in_asm jmp docopyf # nope + /* * memcpy() doesn't worry about overlap and always copies forward */ -// ENTRY(memcpy) +ENTRY(memcpy) pushl %esi pushl %edi movl 12(%esp),%edi movl 16(%esp),%esi movl 20(%esp),%ecx docopyf: +#endif movl %edi,%eax # setup return value for memcpy/memmove shrl $2,%ecx # copy by 32-bit words rep @@ -104,5 +107,8 @@ docopyf: popl %esi cld ret -END_STRONG(memmove) +#ifdef memcpy_in_asm +END_BUILTIN(memcpy) +#endif +END_BUILTIN(memmove) END_WEAK(bcopy) diff --git a/lib/libc/arch/i386/string/memset.S b/lib/libc/arch/i386/string/memset.S index 0eb4381558e..5103b616054 100644 --- a/lib/libc/arch/i386/string/memset.S +++ b/lib/libc/arch/i386/string/memset.S @@ -1,10 +1,10 @@ -/* $OpenBSD: memset.S,v 1.5 2015/08/31 02:53:56 guenther Exp $ */ +/* $OpenBSD: memset.S,v 1.6 2017/11/29 05:13:57 guenther Exp $ */ /* * Written by J.T. Conklin . * Public domain. */ -#include "SYS.h" +#include "DEFS.h" ENTRY(memset) pushl %edi @@ -53,4 +53,4 @@ L1: rep popl %ebx popl %edi ret -END_STRONG(memset) +END_BUILTIN(memset) diff --git a/lib/libc/arch/i386/string/strchr.S b/lib/libc/arch/i386/string/strchr.S index 3792d2292ab..a73f62311d9 100644 --- a/lib/libc/arch/i386/string/strchr.S +++ b/lib/libc/arch/i386/string/strchr.S @@ -1,10 +1,10 @@ -/* $OpenBSD: strchr.S,v 1.7 2015/08/31 02:53:56 guenther Exp $ */ +/* $OpenBSD: strchr.S,v 1.8 2017/11/29 05:13:57 guenther Exp $ */ /* * Written by J.T. Conklin . * Public domain. */ -#include "SYS.h" +#include "DEFS.h" WEAK_ALIAS(index, strchr) diff --git a/lib/libc/arch/i386/string/strcmp.S b/lib/libc/arch/i386/string/strcmp.S index 373232419e9..3bb042bd99f 100644 --- a/lib/libc/arch/i386/string/strcmp.S +++ b/lib/libc/arch/i386/string/strcmp.S @@ -1,10 +1,10 @@ -/* $OpenBSD: strcmp.S,v 1.4 2015/08/31 02:53:56 guenther Exp $ */ +/* $OpenBSD: strcmp.S,v 1.5 2017/11/29 05:13:57 guenther Exp $ */ /* * Written by J.T. Conklin . * Public domain. */ -#include "SYS.h" +#include "DEFS.h" /* * NOTE: I've unrolled the loop eight times: large enough to make a diff --git a/lib/libc/arch/i386/string/strncmp.S b/lib/libc/arch/i386/string/strncmp.S index bbe3f218a38..0d34a44d9fa 100644 --- a/lib/libc/arch/i386/string/strncmp.S +++ b/lib/libc/arch/i386/string/strncmp.S @@ -1,10 +1,10 @@ -/* $OpenBSD: strncmp.S,v 1.5 2017/08/19 18:25:50 deraadt Exp $ */ +/* $OpenBSD: strncmp.S,v 1.6 2017/11/29 05:13:57 guenther Exp $ */ /* * Written by J.T. Conklin . * Public domain. */ -#include "SYS.h" +#include "DEFS.h" /* * NOTE: I've unrolled the loop eight times: large enough to make a diff --git a/lib/libc/arch/i386/string/strrchr.S b/lib/libc/arch/i386/string/strrchr.S index e1f5cc2e32e..24ce661ef25 100644 --- a/lib/libc/arch/i386/string/strrchr.S +++ b/lib/libc/arch/i386/string/strrchr.S @@ -1,10 +1,10 @@ -/* $OpenBSD: strrchr.S,v 1.7 2015/08/31 02:53:56 guenther Exp $ */ +/* $OpenBSD: strrchr.S,v 1.8 2017/11/29 05:13:57 guenther Exp $ */ /* * Written by J.T. Conklin . * Public domain. */ -#include "SYS.h" +#include "DEFS.h" WEAK_ALIAS(rindex, strrchr) diff --git a/lib/libc/hidden/string.h b/lib/libc/hidden/string.h index 0b9554a9f4a..a81cb0bf327 100644 --- a/lib/libc/hidden/string.h +++ b/lib/libc/hidden/string.h @@ -1,4 +1,4 @@ -/* $OpenBSD: string.h,v 1.4 2017/09/05 03:16:13 schwarze Exp $ */ +/* $OpenBSD: string.h,v 1.5 2017/11/29 05:13:57 guenther Exp $ */ /* * Copyright (c) 2015 Philip Guenther * @@ -33,11 +33,11 @@ PROTO_DEPRECATED(index); PROTO_NORMAL(memccpy); PROTO_NORMAL(memchr); PROTO_NORMAL(memcmp); -PROTO_NORMAL(memcpy); +/*PROTO_NORMAL(memcpy); use declaration from namespace.h */ PROTO_NORMAL(memmem); -PROTO_NORMAL(memmove); +/*PROTO_NORMAL(memmove); use declaration from namespace.h */ PROTO_NORMAL(memrchr); -PROTO_NORMAL(memset); +/*PROTO_NORMAL(memset); use declaration from namespace.h */ PROTO_DEPRECATED(rindex); PROTO_DEPRECATED(stpcpy); PROTO_NORMAL(stpncpy); diff --git a/lib/libc/include/namespace.h b/lib/libc/include/namespace.h index 980c1a8dd61..73b845e10f1 100644 --- a/lib/libc/include/namespace.h +++ b/lib/libc/include/namespace.h @@ -1,4 +1,4 @@ -/* $OpenBSD: namespace.h,v 1.10 2016/05/07 19:05:22 guenther Exp $ */ +/* $OpenBSD: namespace.h,v 1.11 2017/11/29 05:13:57 guenther Exp $ */ #ifndef _LIBC_NAMESPACE_H_ #define _LIBC_NAMESPACE_H_ @@ -154,23 +154,35 @@ #define DEF_CANCEL(x) __weak_alias(x, CANCEL(x)) #define DEF_WRAP(x) __weak_alias(x, WRAP(x)) #define DEF_SYS(x) __strong_alias(_thread_sys_##x, HIDDEN(x)) +#ifdef __clang__ +#define DEF_BUILTIN(x) __asm("") +#define BUILTIN __attribute__((__visibility__("protected"))) +#else +#define DEF_BUILTIN(x) DEF_STRONG(x) +#define BUILTIN +#endif #define MAKE_CLONE(dst, src) __dso_hidden typeof(dst) HIDDEN(dst) \ __attribute__((alias (HIDDEN_STRING(src)))) /* - * gcc will generate calls to the functions below. + * gcc and clang will generate calls to the functions below. * Declare and redirect them here so we always go * directly to our hidden aliases. */ #include -void *memcpy(void *__restrict, const void *__restrict, __size_t); -void *memset(void *, int, __size_t); -void __stack_smash_handler(const char [], int __attribute__((__unused__))); +BUILTIN void *memmove(void *, const void *, __size_t); +BUILTIN void *memcpy(void *__restrict, const void *__restrict, __size_t); +BUILTIN void *memset(void *, int, __size_t); +BUILTIN void __stack_smash_handler(const char [], int __unused); +#ifndef __clang__ +PROTO_NORMAL(memmove); PROTO_NORMAL(memcpy); PROTO_NORMAL(memset); PROTO_NORMAL(__stack_smash_handler); +#endif +#undef BUILTIN #endif /* _LIBC_NAMESPACE_H_ */ diff --git a/lib/libc/string/memcpy.c b/lib/libc/string/memcpy.c index a2516ed041a..19fddc0ab5f 100644 --- a/lib/libc/string/memcpy.c +++ b/lib/libc/string/memcpy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: memcpy.c,v 1.3 2017/08/14 17:10:02 guenther Exp $ */ +/* $OpenBSD: memcpy.c,v 1.4 2017/11/29 05:13:57 guenther Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. @@ -106,4 +106,4 @@ memcpy(void *dst0, const void *src0, size_t length) done: return (dst0); } -DEF_STRONG(memcpy); +DEF_BUILTIN(memcpy); diff --git a/lib/libc/string/memmove.c b/lib/libc/string/memmove.c index 2f1deb2c70d..1cd1086ab97 100644 --- a/lib/libc/string/memmove.c +++ b/lib/libc/string/memmove.c @@ -1,4 +1,4 @@ -/* $OpenBSD: memmove.c,v 1.2 2015/08/31 02:53:57 guenther Exp $ */ +/* $OpenBSD: memmove.c,v 1.3 2017/11/29 05:13:57 guenther Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. @@ -110,4 +110,4 @@ memmove(void *dst0, const void *src0, size_t length) done: return (dst0); } -DEF_STRONG(memmove); +DEF_BUILTIN(memmove); diff --git a/lib/libc/string/memset.c b/lib/libc/string/memset.c index 242529ee0f2..0c261f0965a 100644 --- a/lib/libc/string/memset.c +++ b/lib/libc/string/memset.c @@ -1,4 +1,4 @@ -/* $OpenBSD: memset.c,v 1.7 2015/08/31 02:53:57 guenther Exp $ */ +/* $OpenBSD: memset.c,v 1.8 2017/11/29 05:13:57 guenther Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. @@ -45,4 +45,4 @@ memset(void *dst, int c, size_t n) } return (dst); } -DEF_STRONG(memset); +DEF_BUILTIN(memset); diff --git a/lib/libc/sys/stack_protector.c b/lib/libc/sys/stack_protector.c index 116aecd316a..d9ecb2cfbb4 100644 --- a/lib/libc/sys/stack_protector.c +++ b/lib/libc/sys/stack_protector.c @@ -1,4 +1,4 @@ -/* $OpenBSD: stack_protector.c,v 1.23 2016/03/21 22:41:28 bluhm Exp $ */ +/* $OpenBSD: stack_protector.c,v 1.24 2017/11/29 05:13:57 guenther Exp $ */ /* * Copyright (c) 2002 Hiroaki Etoh, Federico G. Schwindt, and Miodrag Vallat. @@ -80,4 +80,4 @@ __stack_smash_handler(const char func[], int damaged) _exit(127); } -DEF_STRONG(__stack_smash_handler); +DEF_BUILTIN(__stack_smash_handler); -- 2.20.1