Module Name: src
Committed By: riastradh
Date: Sun Jul 30 09:20:14 UTC 2023
Modified Files:
src/libexec/ld.elf_so: Makefile reloc.c rtld.c rtld.h symbol.c
Added Files:
src/libexec/ld.elf_so: hash.c hash.h
Log Message:
ld.elf_so: Split hash functions into a separate file.
This way we can test them in isolation.
No functional change intended.
To generate a diff of this commit:
cvs rdiff -u -r1.146 -r1.147 src/libexec/ld.elf_so/Makefile \
src/libexec/ld.elf_so/rtld.h
cvs rdiff -u -r0 -r1.1 src/libexec/ld.elf_so/hash.c \
src/libexec/ld.elf_so/hash.h
cvs rdiff -u -r1.117 -r1.118 src/libexec/ld.elf_so/reloc.c
cvs rdiff -u -r1.214 -r1.215 src/libexec/ld.elf_so/rtld.c
cvs rdiff -u -r1.75 -r1.76 src/libexec/ld.elf_so/symbol.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/libexec/ld.elf_so/Makefile
diff -u src/libexec/ld.elf_so/Makefile:1.146 src/libexec/ld.elf_so/Makefile:1.147
--- src/libexec/ld.elf_so/Makefile:1.146 Sun Jul 30 09:19:19 2023
+++ src/libexec/ld.elf_so/Makefile Sun Jul 30 09:20:14 2023
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.146 2023/07/30 09:19:19 riastradh Exp $
+# $NetBSD: Makefile,v 1.147 2023/07/30 09:20:14 riastradh Exp $
#
# NOTE: when changing ld.so, ensure that ldd still compiles.
#
@@ -76,6 +76,7 @@ SRCS+= compat.c
SRCS+= debug.c
SRCS+= diagassert.c
SRCS+= expand.c
+SRCS+= hash.c
SRCS+= headers.c
SRCS+= load.c
SRCS+= map_object.c
Index: src/libexec/ld.elf_so/rtld.h
diff -u src/libexec/ld.elf_so/rtld.h:1.146 src/libexec/ld.elf_so/rtld.h:1.147
--- src/libexec/ld.elf_so/rtld.h:1.146 Sun Jun 4 01:24:56 2023
+++ src/libexec/ld.elf_so/rtld.h Sun Jul 30 09:20:14 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: rtld.h,v 1.146 2023/06/04 01:24:56 joerg Exp $ */
+/* $NetBSD: rtld.h,v 1.147 2023/07/30 09:20:14 riastradh Exp $ */
/*
* Copyright 1996 John D. Polstra.
@@ -442,8 +442,6 @@ void _rtld_call_ifunc(Obj_Entry *, sigse
Obj_Entry *_rtld_load_library(const char *, const Obj_Entry *, int);
/* symbol.c */
-Elf32_Word _rtld_sysv_hash(const char *);
-Elf32_Word _rtld_gnu_hash(const char *);
const Elf_Sym *_rtld_symlook_obj(const char *, Elf_Hash *,
const Obj_Entry *, u_int, const Ver_Entry *);
const Elf_Sym *_rtld_find_symdef(unsigned long, const Obj_Entry *,
Index: src/libexec/ld.elf_so/reloc.c
diff -u src/libexec/ld.elf_so/reloc.c:1.117 src/libexec/ld.elf_so/reloc.c:1.118
--- src/libexec/ld.elf_so/reloc.c:1.117 Sat Dec 4 08:53:34 2021
+++ src/libexec/ld.elf_so/reloc.c Sun Jul 30 09:20:14 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: reloc.c,v 1.117 2021/12/04 08:53:34 skrll Exp $ */
+/* $NetBSD: reloc.c,v 1.118 2023/07/30 09:20:14 riastradh Exp $ */
/*
* Copyright 1996 John D. Polstra.
@@ -39,7 +39,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: reloc.c,v 1.117 2021/12/04 08:53:34 skrll Exp $");
+__RCSID("$NetBSD: reloc.c,v 1.118 2023/07/30 09:20:14 riastradh Exp $");
#endif /* not lint */
#include <err.h>
@@ -56,6 +56,7 @@ __RCSID("$NetBSD: reloc.c,v 1.117 2021/1
#include <dirent.h>
#include "debug.h"
+#include "hash.h"
#include "rtld.h"
#ifndef RTLD_INHIBIT_COPY_RELOCS
Index: src/libexec/ld.elf_so/rtld.c
diff -u src/libexec/ld.elf_so/rtld.c:1.214 src/libexec/ld.elf_so/rtld.c:1.215
--- src/libexec/ld.elf_so/rtld.c:1.214 Sun Jun 4 23:42:38 2023
+++ src/libexec/ld.elf_so/rtld.c Sun Jul 30 09:20:14 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: rtld.c,v 1.214 2023/06/04 23:42:38 riastradh Exp $ */
+/* $NetBSD: rtld.c,v 1.215 2023/07/30 09:20:14 riastradh Exp $ */
/*
* Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.214 2023/06/04 23:42:38 riastradh Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.215 2023/07/30 09:20:14 riastradh Exp $");
#endif /* not lint */
#include <sys/param.h>
@@ -60,7 +60,9 @@ __RCSID("$NetBSD: rtld.c,v 1.214 2023/06
#include <ctype.h>
#include <dlfcn.h>
+
#include "debug.h"
+#include "hash.h"
#include "rtld.h"
#if !defined(lint)
Index: src/libexec/ld.elf_so/symbol.c
diff -u src/libexec/ld.elf_so/symbol.c:1.75 src/libexec/ld.elf_so/symbol.c:1.76
--- src/libexec/ld.elf_so/symbol.c:1.75 Tue Apr 18 22:42:52 2023
+++ src/libexec/ld.elf_so/symbol.c Sun Jul 30 09:20:14 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: symbol.c,v 1.75 2023/04/18 22:42:52 christos Exp $ */
+/* $NetBSD: symbol.c,v 1.76 2023/07/30 09:20:14 riastradh Exp $ */
/*
* Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: symbol.c,v 1.75 2023/04/18 22:42:52 christos Exp $");
+__RCSID("$NetBSD: symbol.c,v 1.76 2023/07/30 09:20:14 riastradh Exp $");
#endif /* not lint */
#include <err.h>
@@ -57,6 +57,7 @@ __RCSID("$NetBSD: symbol.c,v 1.75 2023/0
#include <dirent.h>
#include "debug.h"
+#include "hash.h"
#include "rtld.h"
/*
@@ -80,39 +81,6 @@ _rtld_donelist_check(DoneList *dlp, cons
return false;
}
-/*
- * SysV hash function for symbol table lookup. It is a slightly optimized
- * version of the hash specified by the System V ABI.
- */
-Elf32_Word
-_rtld_sysv_hash(const char *name)
-{
- const unsigned char *p = (const unsigned char *) name;
- Elf32_Word h = 0;
-
- while (__predict_true(*p != '\0')) {
- h = (h << 4) + *p++;
- h ^= (h >> 24) & 0xf0;
- }
- return (h & 0x0fffffff);
-}
-
-/*
- * Hash function for symbol table lookup. Don't even think about changing
- * this. It is specified by the GNU toolchain ABI.
- */
-Elf32_Word
-_rtld_gnu_hash(const char *name)
-{
- const unsigned char *p = (const unsigned char *) name;
- uint_fast32_t h = 5381;
- unsigned char c;
-
- for (c = *p; c != '\0'; c = *++p)
- h = h * 33 + c;
- return (h & 0xffffffff);
-}
-
const Elf_Sym *
_rtld_symlook_list(const char *name, Elf_Hash *hash, const Objlist *objlist,
const Obj_Entry **defobj_out, u_int flags, const Ver_Entry *ventry,
Added files:
Index: src/libexec/ld.elf_so/hash.c
diff -u /dev/null src/libexec/ld.elf_so/hash.c:1.1
--- /dev/null Sun Jul 30 09:20:14 2023
+++ src/libexec/ld.elf_so/hash.c Sun Jul 30 09:20:14 2023
@@ -0,0 +1,81 @@
+/* $NetBSD: hash.c,v 1.1 2023/07/30 09:20:14 riastradh Exp $ */
+
+/*
+ * Copyright 1996 John D. Polstra.
+ * Copyright 1996 Matt Thomas <m...@3am-software.com>
+ * Copyright 2002 Charles M. Hannum <r...@ihack.net>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by John Polstra.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Dynamic linker for ELF.
+ *
+ * John Polstra <j...@polstra.com>.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: hash.c,v 1.1 2023/07/30 09:20:14 riastradh Exp $");
+#endif /* not lint */
+
+#include <stdint.h>
+
+#include "hash.h"
+
+/*
+ * SysV hash function for symbol table lookup. It is a slightly optimized
+ * version of the hash specified by the System V ABI.
+ */
+Elf32_Word
+_rtld_sysv_hash(const char *name)
+{
+ const unsigned char *p = (const unsigned char *) name;
+ Elf32_Word h = 0;
+
+ while (__predict_true(*p != '\0')) {
+ h = (h << 4) + *p++;
+ h ^= (h >> 24) & 0xf0;
+ }
+ return (h & 0x0fffffff);
+}
+
+/*
+ * Hash function for symbol table lookup. Don't even think about changing
+ * this. It is specified by the GNU toolchain ABI.
+ */
+Elf32_Word
+_rtld_gnu_hash(const char *name)
+{
+ const unsigned char *p = (const unsigned char *) name;
+ uint_fast32_t h = 5381;
+ unsigned char c;
+
+ for (c = *p; c != '\0'; c = *++p)
+ h = h * 33 + c;
+ return (h & 0xffffffff);
+}
Index: src/libexec/ld.elf_so/hash.h
diff -u /dev/null src/libexec/ld.elf_so/hash.h:1.1
--- /dev/null Sun Jul 30 09:20:14 2023
+++ src/libexec/ld.elf_so/hash.h Sun Jul 30 09:20:14 2023
@@ -0,0 +1,42 @@
+/* $NetBSD: hash.h,v 1.1 2023/07/30 09:20:14 riastradh Exp $ */
+
+/*
+ * Copyright 1996 John D. Polstra.
+ * Copyright 1996 Matt Thomas <m...@3am-software.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by John Polstra.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef RTLD_HASH_H
+#define RTLD_HASH_H
+
+#include <sys/exec_elf.h>
+
+Elf32_Word _rtld_sysv_hash(const char *);
+Elf32_Word _rtld_gnu_hash(const char *);
+
+#endif /* RTLD_HASH_H */