From ae3cb403620ab940fbaabb3055fac045a63d56b7 Mon Sep 17 00:00:00 2001 From: guenther Date: Thu, 18 Jan 2018 08:23:44 +0000 Subject: [PATCH] Instead of trying to handle ffs() with the normal rename-mark-hidden-and-alias dance, mark it protected. This works better for both gcc and clang: gcc blocks overriding of internal calls, while clang permits inlining again. ok otto@ --- lib/libc/arch/alpha/string/ffs.S | 5 +++-- lib/libc/arch/amd64/string/ffs.S | 5 +++-- lib/libc/arch/arm/string/ffs.S | 8 +++++--- lib/libc/arch/i386/string/ffs.S | 5 +++-- lib/libc/arch/mips64/string/ffs.S | 5 +++-- lib/libc/arch/sh/string/ffs.S | 5 +++-- lib/libc/arch/sparc64/string/ffs.S | 6 ++++-- lib/libc/hidden/string.h | 4 ++-- lib/libc/include/namespace.h | 7 +++++-- lib/libc/string/ffs.c | 3 +-- 10 files changed, 32 insertions(+), 21 deletions(-) diff --git a/lib/libc/arch/alpha/string/ffs.S b/lib/libc/arch/alpha/string/ffs.S index 6600b3aeeb2..9e0dba4654c 100644 --- a/lib/libc/arch/alpha/string/ffs.S +++ b/lib/libc/arch/alpha/string/ffs.S @@ -1,4 +1,4 @@ -/* $OpenBSD: ffs.S,v 1.3 2015/08/31 02:53:56 guenther Exp $ */ +/* $OpenBSD: ffs.S,v 1.4 2018/01/18 08:23:44 guenther Exp $ */ /* $NetBSD: ffs.S,v 1.3 1996/10/17 03:08:13 cgd Exp $ */ /* @@ -89,4 +89,5 @@ Ldone: Lallzero: bis zero, zero, v0 RET -END_WEAK(ffs) +END(ffs) +.protected ffs diff --git a/lib/libc/arch/amd64/string/ffs.S b/lib/libc/arch/amd64/string/ffs.S index c10fb6b85f5..329b1e0c2ac 100644 --- a/lib/libc/arch/amd64/string/ffs.S +++ b/lib/libc/arch/amd64/string/ffs.S @@ -1,4 +1,4 @@ -/* $OpenBSD: ffs.S,v 1.4 2015/11/14 21:53:03 guenther Exp $ */ +/* $OpenBSD: ffs.S,v 1.5 2018/01/18 08:23:44 guenther Exp $ */ /* * Written by J.T. Conklin . * Public domain. @@ -16,4 +16,5 @@ ENTRY(ffs) _ALIGN_TEXT L1: xorl %eax,%eax /* clear result */ ret -END_WEAK(ffs) +END(ffs) +.protected ffs diff --git a/lib/libc/arch/arm/string/ffs.S b/lib/libc/arch/arm/string/ffs.S index df3b5d621b1..09a65b40459 100644 --- a/lib/libc/arch/arm/string/ffs.S +++ b/lib/libc/arch/arm/string/ffs.S @@ -1,4 +1,4 @@ -/* $OpenBSD: ffs.S,v 1.6 2016/09/18 10:22:10 kettenis Exp $ */ +/* $OpenBSD: ffs.S,v 1.7 2018/01/18 08:23:44 guenther Exp $ */ /* $NetBSD: ffs.S,v 1.5 2003/04/05 23:08:52 bjh21 Exp $ */ /* * Copyright (c) 2001 Christopher Gilbert @@ -63,8 +63,10 @@ ENTRY(ffs) ldrbne r0, [ r2, r0, lsr #26 ] mov pc, lr -END_WEAK(ffs) -.text; +END(ffs) +.protected ffs + + .section .rodata .type .L_ffs_table, _ASM_TYPE_OBJECT; .L_ffs_table: /* 0 1 2 3 4 5 6 7 */ diff --git a/lib/libc/arch/i386/string/ffs.S b/lib/libc/arch/i386/string/ffs.S index b02405ee2ef..e9c8c742eec 100644 --- a/lib/libc/arch/i386/string/ffs.S +++ b/lib/libc/arch/i386/string/ffs.S @@ -1,4 +1,4 @@ -/* $OpenBSD: ffs.S,v 1.6 2017/11/29 05:13:57 guenther Exp $ */ +/* $OpenBSD: ffs.S,v 1.7 2018/01/18 08:23:44 guenther Exp $ */ /* * Written by J.T. Conklin . * Public domain. @@ -15,4 +15,5 @@ ENTRY(ffs) .align 2,0xcc L1: xorl %eax,%eax /* clear result */ ret -END_WEAK(ffs) +END(ffs) +.protected ffs diff --git a/lib/libc/arch/mips64/string/ffs.S b/lib/libc/arch/mips64/string/ffs.S index f09de46a930..f96d9eaadaa 100644 --- a/lib/libc/arch/mips64/string/ffs.S +++ b/lib/libc/arch/mips64/string/ffs.S @@ -1,4 +1,4 @@ -/* $OpenBSD: ffs.S,v 1.4 2015/08/31 02:53:56 guenther Exp $ */ +/* $OpenBSD: ffs.S,v 1.5 2018/01/18 08:23:44 guenther Exp $ */ /*- * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. @@ -46,4 +46,5 @@ LEAF(ffs, 0) beq v1, zero, 1b # no, continue done: j ra -END_WEAK(ffs) +END(ffs) +.protected ffs diff --git a/lib/libc/arch/sh/string/ffs.S b/lib/libc/arch/sh/string/ffs.S index 0a639c79211..c199bb440fd 100644 --- a/lib/libc/arch/sh/string/ffs.S +++ b/lib/libc/arch/sh/string/ffs.S @@ -1,4 +1,4 @@ -/* $OpenBSD: ffs.S,v 1.3 2015/08/31 02:53:57 guenther Exp $ */ +/* $OpenBSD: ffs.S,v 1.4 2018/01/18 08:23:44 guenther Exp $ */ /* $NetBSD: ffs.S,v 1.1 2005/12/20 19:28:50 christos Exp $ */ /*- @@ -91,4 +91,5 @@ L8bit: Lzero: rts nop -END_WEAK(ffs) +END(ffs) +.protected ffs diff --git a/lib/libc/arch/sparc64/string/ffs.S b/lib/libc/arch/sparc64/string/ffs.S index 7fd91f871b6..6d2e6499706 100644 --- a/lib/libc/arch/sparc64/string/ffs.S +++ b/lib/libc/arch/sparc64/string/ffs.S @@ -1,4 +1,4 @@ -/* $OpenBSD: ffs.S,v 1.5 2015/08/31 02:53:57 guenther Exp $ */ +/* $OpenBSD: ffs.S,v 1.6 2018/01/18 08:23:44 guenther Exp $ */ /* * Copyright (c) 1992, 1993 @@ -83,8 +83,10 @@ ENTRY(ffs) ldsb [%o2 + %o0], %o0 retl add %o0, 24, %o0 -END_WEAK(ffs) +END(ffs) +.protected ffs + .section .rodata _C_LABEL(__ffstab): .byte -24,1,2,1,3,1,2,1,4,1,2,1,3,1,2,1 /* 00-0f */ .byte 5,1,2,1,3,1,2,1,4,1,2,1,3,1,2,1 /* 10-1f */ diff --git a/lib/libc/hidden/string.h b/lib/libc/hidden/string.h index a81cb0bf327..2f9004011e6 100644 --- a/lib/libc/hidden/string.h +++ b/lib/libc/hidden/string.h @@ -1,4 +1,4 @@ -/* $OpenBSD: string.h,v 1.5 2017/11/29 05:13:57 guenther Exp $ */ +/* $OpenBSD: string.h,v 1.6 2018/01/18 08:23:44 guenther Exp $ */ /* * Copyright (c) 2015 Philip Guenther * @@ -28,7 +28,7 @@ PROTO_NORMAL(bcmp); PROTO_NORMAL(bcopy); PROTO_NORMAL(bzero); PROTO_NORMAL(explicit_bzero); -PROTO_NORMAL(ffs); +PROTO_PROTECTED(ffs); PROTO_DEPRECATED(index); PROTO_NORMAL(memccpy); PROTO_NORMAL(memchr); diff --git a/lib/libc/include/namespace.h b/lib/libc/include/namespace.h index 73b845e10f1..60766afc0b9 100644 --- a/lib/libc/include/namespace.h +++ b/lib/libc/include/namespace.h @@ -1,4 +1,4 @@ -/* $OpenBSD: namespace.h,v 1.11 2017/11/29 05:13:57 guenther Exp $ */ +/* $OpenBSD: namespace.h,v 1.12 2018/01/18 08:23:44 guenther Exp $ */ #ifndef _LIBC_NAMESPACE_H_ #define _LIBC_NAMESPACE_H_ @@ -135,6 +135,8 @@ #include /* for __dso_hidden and __{weak,strong}_alias */ +#define __dso_protected __attribute__((__visibility__("protected"))) + #define HIDDEN(x) _libc_##x #define CANCEL(x) _libc_##x##_cancel #define WRAP(x) _libc_##x##_wrap @@ -148,6 +150,7 @@ #define PROTO_CANCEL(x) __dso_hidden typeof(x) HIDDEN(x), \ x asm(CANCEL_STRING(x)) #define PROTO_WRAP(x) PROTO_NORMAL(x), WRAP(x) +#define PROTO_PROTECTED(x) __dso_protected typeof(x) x #define DEF_STRONG(x) __strong_alias(x, HIDDEN(x)) #define DEF_WEAK(x) __weak_alias(x, HIDDEN(x)) @@ -156,7 +159,7 @@ #define DEF_SYS(x) __strong_alias(_thread_sys_##x, HIDDEN(x)) #ifdef __clang__ #define DEF_BUILTIN(x) __asm("") -#define BUILTIN __attribute__((__visibility__("protected"))) +#define BUILTIN __dso_protected #else #define DEF_BUILTIN(x) DEF_STRONG(x) #define BUILTIN diff --git a/lib/libc/string/ffs.c b/lib/libc/string/ffs.c index a75fd9d79f8..09d6e35eca2 100644 --- a/lib/libc/string/ffs.c +++ b/lib/libc/string/ffs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ffs.c,v 1.9 2015/08/31 02:53:57 guenther Exp $ */ +/* $OpenBSD: ffs.c,v 1.10 2018/01/18 08:23:44 guenther Exp $ */ /* * Public domain. @@ -38,4 +38,3 @@ ffs(int mask) return (bit + t[ r & 0xf ]); } -DEF_WEAK(ffs); -- 2.20.1