From bc8bb57301186279c74b55cd2daec9131d087ef8 Mon Sep 17 00:00:00 2001
From: guenther <>
Date: Wed, 29 Nov 2017 05:13:57 +0000
Subject: 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@
---
 src/lib/libc/include/namespace.h | 22 +++++++++++++++++-----
 src/lib/libc/string/memcpy.c     |  4 ++--
 src/lib/libc/string/memmove.c    |  4 ++--
 src/lib/libc/string/memset.c     |  4 ++--
 4 files changed, 23 insertions(+), 11 deletions(-)

(limited to 'src')

diff --git a/src/lib/libc/include/namespace.h b/src/lib/libc/include/namespace.h
index 980c1a8dd6..73b845e10f 100644
--- a/src/lib/libc/include/namespace.h
+++ b/src/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 <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_ */
 
diff --git a/src/lib/libc/string/memcpy.c b/src/lib/libc/string/memcpy.c
index a2516ed041..19fddc0ab5 100644
--- a/src/lib/libc/string/memcpy.c
+++ b/src/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/src/lib/libc/string/memmove.c b/src/lib/libc/string/memmove.c
index 2f1deb2c70..1cd1086ab9 100644
--- a/src/lib/libc/string/memmove.c
+++ b/src/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/src/lib/libc/string/memset.c b/src/lib/libc/string/memset.c
index 242529ee0f..0c261f0965 100644
--- a/src/lib/libc/string/memset.c
+++ b/src/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);
-- 
cgit v1.2.3-55-g6feb