summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorotto <otto@openbsd.org>2018-01-30 20:15:25 +0000
committerotto <otto@openbsd.org>2018-01-30 20:15:25 +0000
commit544a27041b454910782e3cf3b3673938dffaa3b6 (patch)
treed8c67d5e14bbce62e278ddb748dd34143a580d5e
parentkeep in sync with ld.so malloc.c (diff)
downloadwireguard-openbsd-544a27041b454910782e3cf3b3673938dffaa3b6.tar.xz
wireguard-openbsd-544a27041b454910782e3cf3b3673938dffaa3b6.zip
provide ffs, gcc generates calls to it, even when __builtin_ffs() is used.
ok deraadt@
-rw-r--r--libexec/ld.so/Makefile4
-rw-r--r--libexec/ld.so/ffs.c40
2 files changed, 42 insertions, 2 deletions
diff --git a/libexec/ld.so/Makefile b/libexec/ld.so/Makefile
index 6de38637dd5..50228d66ff3 100644
--- a/libexec/ld.so/Makefile
+++ b/libexec/ld.so/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.71 2017/12/08 05:30:16 deraadt Exp $
+# $OpenBSD: Makefile,v 1.72 2018/01/30 20:15:25 otto Exp $
SUBDIR=ldconfig ldd
MAN= ld.so.1
@@ -19,7 +19,7 @@ VPATH=${.CURDIR}/../../lib/libc/string
SRCS= ldasm.S boot.c loader.c resolve.c dlfcn.c dl_printf.c rtld_machine.c
SRCS+= path.c util.c sod.c strsep.c strtol.c dir.c library_subr.c
SRCS+= dl_realpath.c dl_uname.c dl_dirname.c strlcat.c strlen.c trace.c
-SRCS+= malloc.c reallocarray.c tib.c
+SRCS+= malloc.c reallocarray.c tib.c ffs.c
syscall=__syscall close exit fstat __getcwd getdents getentropy getthrid \
issetugid mprotect munmap open pledge read readlink sendsyslog \
diff --git a/libexec/ld.so/ffs.c b/libexec/ld.so/ffs.c
new file mode 100644
index 00000000000..8c5e6240f5d
--- /dev/null
+++ b/libexec/ld.so/ffs.c
@@ -0,0 +1,40 @@
+/* $OpenBSD: ffs.c,v 1.1 2018/01/30 20:15:25 otto Exp $ */
+
+/*
+ * Public domain.
+ * Written by Dale Rahn.
+ */
+
+#include <string.h>
+
+/*
+ * ffs -- vax ffs instruction
+ */
+int
+ffs(int mask)
+{
+ int bit;
+ unsigned int r = mask;
+ static const signed char t[16] = {
+ -28, 1, 2, 1,
+ 3, 1, 2, 1,
+ 4, 1, 2, 1,
+ 3, 1, 2, 1
+ };
+
+ bit = 0;
+ if (!(r & 0xffff)) {
+ bit += 16;
+ r >>= 16;
+ }
+ if (!(r & 0xff)) {
+ bit += 8;
+ r >>= 8;
+ }
+ if (!(r & 0xf)) {
+ bit += 4;
+ r >>= 4;
+ }
+
+ return (bit + t[ r & 0xf ]);
+}