-/* $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.
* 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
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
movq %r11,%rax
cld
ret
-// END(memcpy)
-END_STRONG(memmove)
+#ifdef memcpy_in_asm
+END_BUILTIN(memcpy)
+#endif
+END_BUILTIN(memmove)
END_WEAK(bcopy)
movq %r11,%rax
ret
-END_STRONG(memset)
+END_BUILTIN(memset)
-/* $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 <guenther@openbsd.org>
*
* 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
-/* $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 $ */
/*-
stmfd sp!, {r0, lr}
bl _memcpy
ldmfd sp!, {r0, pc}
-END_STRONG(memcpy)
+END_BUILTIN(memcpy)
-/* $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 $ */
/*-
stmfd sp!, {r0, lr}
bl _memcpy
ldmfd sp!, {r0, pc}
-END_STRONG(memmove)
+END_BUILTIN(memmove)
-/* $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 $ */
/*
ldmfd sp!, {r0}
mov pc, lr /* Exit */
-END_STRONG(memset)
+END_BUILTIN(memset)
-/* $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 <guenther@openbsd.org>
+ *
+ * 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 <machine/asm.h>
+
+/*
+ * 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
* 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 <machine/asm.h>
+#include "DEFS.h"
#include <sys/syscall.h>
#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:
*
-/* $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
* SUCH DAMAGE.
*/
-#include "SYS.h"
+#include "DEFS.h"
ENTRY(abs)
movl 4(%esp),%eax
* Public domain.
*/
-#include "SYS.h"
+#include "DEFS.h"
ENTRY(div)
movl 4(%esp),%eax
* SUCH DAMAGE.
*/
-#include "SYS.h"
+#include "DEFS.h"
ENTRY(labs)
movl 4(%esp),%eax
* Public domain.
*/
-#include "SYS.h"
+#include "DEFS.h"
ENTRY(ldiv)
movl 4(%esp),%eax
-/* $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 <jtc@netbsd.org>.
* Public domain.
*/
-#include "SYS.h"
+#include "DEFS.h"
ENTRY(bcmp)
pushl %edi
-/* $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 <jtc@netbsd.org>.
* Public domain.
*/
-#include "SYS.h"
+#include "DEFS.h"
ENTRY(bzero)
pushl %edi
-/* $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 <jtc@netbsd.org>.
* Public domain.
*/
-#include "SYS.h"
+#include "DEFS.h"
ENTRY(ffs)
bsfl 4(%esp),%eax
-/* $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 <jtc@netbsd.org>.
* Public domain.
*/
-#include "SYS.h"
+#include "DEFS.h"
ENTRY(memchr)
pushl %edi
-/* $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 <jtc@netbsd.org>.
* Public domain.
*/
-#include "SYS.h"
+#include "DEFS.h"
ENTRY(memcmp)
pushl %edi
-/* $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.
* SUCH DAMAGE.
*/
-#include "SYS.h"
+#include "DEFS.h"
/*
* Emulate bcopy() by swapping the first two arguments, and jumping
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
popl %esi
cld
ret
-END_STRONG(memmove)
+#ifdef memcpy_in_asm
+END_BUILTIN(memcpy)
+#endif
+END_BUILTIN(memmove)
END_WEAK(bcopy)
-/* $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 <jtc@netbsd.org>.
* Public domain.
*/
-#include "SYS.h"
+#include "DEFS.h"
ENTRY(memset)
pushl %edi
popl %ebx
popl %edi
ret
-END_STRONG(memset)
+END_BUILTIN(memset)
-/* $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 <jtc@netbsd.org>.
* Public domain.
*/
-#include "SYS.h"
+#include "DEFS.h"
WEAK_ALIAS(index, strchr)
-/* $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 <jtc@netbsd.org>.
* Public domain.
*/
-#include "SYS.h"
+#include "DEFS.h"
/*
* NOTE: I've unrolled the loop eight times: large enough to make a
-/* $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 <jtc@netbsd.org>.
* Public domain.
*/
-#include "SYS.h"
+#include "DEFS.h"
/*
* NOTE: I've unrolled the loop eight times: large enough to make a
-/* $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 <jtc@netbsd.org>.
* Public domain.
*/
-#include "SYS.h"
+#include "DEFS.h"
WEAK_ALIAS(rindex, strrchr)
-/* $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 <guenther@openbsd.org>
*
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);
-/* $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_
#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 <sys/_types.h>
-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_ */
-/* $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.
done:
return (dst0);
}
-DEF_STRONG(memcpy);
+DEF_BUILTIN(memcpy);
-/* $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.
done:
return (dst0);
}
-DEF_STRONG(memmove);
+DEF_BUILTIN(memmove);
-/* $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.
}
return (dst);
}
-DEF_STRONG(memset);
+DEF_BUILTIN(memset);
-/* $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.
_exit(127);
}
-DEF_STRONG(__stack_smash_handler);
+DEF_BUILTIN(__stack_smash_handler);