CVS commit: src/libexec/ld.elf_so

2022-03-30 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Mar 30 08:26:45 UTC 2022

Modified Files:
src/libexec/ld.elf_so: map_object.c

Log Message:
_rtld_map_object(): no need to mmap an empty bss segment.


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/libexec/ld.elf_so/map_object.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/map_object.c
diff -u src/libexec/ld.elf_so/map_object.c:1.61 src/libexec/ld.elf_so/map_object.c:1.62
--- src/libexec/ld.elf_so/map_object.c:1.61	Wed Mar  4 01:21:17 2020
+++ src/libexec/ld.elf_so/map_object.c	Wed Mar 30 08:26:45 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: map_object.c,v 1.61 2020/03/04 01:21:17 thorpej Exp $	 */
+/*	$NetBSD: map_object.c,v 1.62 2022/03/30 08:26:45 hannken Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -34,7 +34,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: map_object.c,v 1.61 2020/03/04 01:21:17 thorpej Exp $");
+__RCSID("$NetBSD: map_object.c,v 1.62 2022/03/30 08:26:45 hannken Exp $");
 #endif /* not lint */
 
 #include 
@@ -371,11 +371,13 @@ _rtld_map_object(const char *path, int f
 	}
 
 	/* Overlay the bss segment onto the proper region. */
-	if (mmap(mapbase + data_vlimit - base_vaddr, base_vlimit - data_vlimit,
-	data_flags, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0) ==
-	MAP_FAILED) {
-		_rtld_error("mmap of bss failed: %s", xstrerror(errno));
-		goto bad;
+	if (base_vlimit > data_vlimit) {
+		if (mmap(mapbase + data_vlimit - base_vaddr,
+		base_vlimit - data_vlimit, data_flags,
+		MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0) == MAP_FAILED) {
+			_rtld_error("mmap of bss failed: %s", xstrerror(errno));
+			goto bad;
+		}
 	}
 
 	/* Unmap the gap between the text and data. */



CVS commit: src/libexec/ld.elf_so

2022-03-30 Thread Juergen Hannken-Illjes
Module Name:src
Committed By:   hannken
Date:   Wed Mar 30 08:26:45 UTC 2022

Modified Files:
src/libexec/ld.elf_so: map_object.c

Log Message:
_rtld_map_object(): no need to mmap an empty bss segment.


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/libexec/ld.elf_so/map_object.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2022-04-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Apr  9 23:39:07 UTC 2022

Modified Files:
src/libexec/ld.elf_so: rtld.c

Log Message:
rtld: Convert membar_exit/enter to membar_release/acquire.

These are basic CAS-based locking primitives needing release and
acquire semantics, nothing fancy here -- except the membar_sync parts
which are questionable but not relevant to the present audit.


To generate a diff of this commit:
cvs rdiff -u -r1.210 -r1.211 src/libexec/ld.elf_so/rtld.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2022-04-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Apr  9 23:39:07 UTC 2022

Modified Files:
src/libexec/ld.elf_so: rtld.c

Log Message:
rtld: Convert membar_exit/enter to membar_release/acquire.

These are basic CAS-based locking primitives needing release and
acquire semantics, nothing fancy here -- except the membar_sync parts
which are questionable but not relevant to the present audit.


To generate a diff of this commit:
cvs rdiff -u -r1.210 -r1.211 src/libexec/ld.elf_so/rtld.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/rtld.c
diff -u src/libexec/ld.elf_so/rtld.c:1.210 src/libexec/ld.elf_so/rtld.c:1.211
--- src/libexec/ld.elf_so/rtld.c:1.210	Sat Dec  4 14:39:08 2021
+++ src/libexec/ld.elf_so/rtld.c	Sat Apr  9 23:39:07 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.210 2021/12/04 14:39:08 skrll Exp $	 */
+/*	$NetBSD: rtld.c,v 1.211 2022/04/09 23:39:07 riastradh Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.210 2021/12/04 14:39:08 skrll Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.211 2022/04/09 23:39:07 riastradh Exp $");
 #endif /* not lint */
 
 #include 
@@ -1682,7 +1682,7 @@ _rtld_shared_enter(void)
 			/* Yes, so increment use counter */
 			if (atomic_cas_uint(&_rtld_mutex, cur, cur + 1) != cur)
 continue;
-			membar_enter();
+			membar_acquire();
 			return;
 		}
 		/*
@@ -1728,7 +1728,7 @@ _rtld_shared_exit(void)
 	 * Wakeup LWPs waiting for an exclusive lock if this is the last
 	 * LWP on the shared lock.
 	 */
-	membar_exit();
+	membar_release();
 	if (atomic_dec_uint_nv(&_rtld_mutex))
 		return;
 	membar_sync();
@@ -1750,7 +1750,7 @@ _rtld_exclusive_enter(sigset_t *mask)
 
 	for (;;) {
 		if (atomic_cas_uint(&_rtld_mutex, 0, locked_value) == 0) {
-			membar_enter();
+			membar_acquire();
 			break;
 		}
 		waiter = atomic_swap_uint(&_rtld_waiter_exclusive, self);
@@ -1774,7 +1774,7 @@ _rtld_exclusive_exit(sigset_t *mask)
 {
 	lwpid_t waiter;
 
-	membar_exit();
+	membar_release();
 	_rtld_mutex = 0;
 	membar_sync();
 	if ((waiter = _rtld_waiter_exclusive) != 0)



CVS commit: src/libexec/ld.elf_so

2024-01-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jan 19 19:21:34 UTC 2024

Modified Files:
src/libexec/ld.elf_so: Makefile rtld.c

Log Message:
use header decl of __fork()


To generate a diff of this commit:
cvs rdiff -u -r1.148 -r1.149 src/libexec/ld.elf_so/Makefile
cvs rdiff -u -r1.216 -r1.217 src/libexec/ld.elf_so/rtld.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2024-01-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jan 19 19:21:34 UTC 2024

Modified Files:
src/libexec/ld.elf_so: Makefile rtld.c

Log Message:
use header decl of __fork()


To generate a diff of this commit:
cvs rdiff -u -r1.148 -r1.149 src/libexec/ld.elf_so/Makefile
cvs rdiff -u -r1.216 -r1.217 src/libexec/ld.elf_so/rtld.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.148 src/libexec/ld.elf_so/Makefile:1.149
--- src/libexec/ld.elf_so/Makefile:1.148	Sat Oct  7 08:15:53 2023
+++ src/libexec/ld.elf_so/Makefile	Fri Jan 19 14:21:34 2024
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.148 2023/10/07 12:15:53 rin Exp $
+#	$NetBSD: Makefile,v 1.149 2024/01/19 19:21:34 christos Exp $
 #
 # NOTE: when changing ld.so, ensure that ldd still compiles.
 #
@@ -111,7 +111,7 @@ BINDIR=		${SHLINKINSTALLDIR}
 CPPFLAGS.tls.c+=	-std=gnu11
 CPPFLAGS+=	-DLIBDIR=\"${LIBDIR}\" -D_PATH_RTLD=\"${BINDIR}/${PROG}\"
 CPPFLAGS+=	-I${.CURDIR} -I. -D_KERNTYPES
-CPPFLAGS+=	-DRTLD_LOADER
+CPPFLAGS+=	-DRTLD_LOADER -D_LIBC_INTERNAL
 CPPFLAGS+=	-DGNU_RELRO
 CPPFLAGS+=	-D_RTLD_SOURCE
 CPPFLAGS+=	-DHAVE_INITFINI_ARRAY

Index: src/libexec/ld.elf_so/rtld.c
diff -u src/libexec/ld.elf_so/rtld.c:1.216 src/libexec/ld.elf_so/rtld.c:1.217
--- src/libexec/ld.elf_so/rtld.c:1.216	Tue Oct  3 05:48:18 2023
+++ src/libexec/ld.elf_so/rtld.c	Fri Jan 19 14:21:34 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.216 2023/10/03 09:48:18 martin Exp $	 */
+/*	$NetBSD: rtld.c,v 1.217 2024/01/19 19:21:34 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.216 2023/10/03 09:48:18 martin Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.217 2024/01/19 19:21:34 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -1550,8 +1550,6 @@ __dl_cxa_refcount(void *addr, ssize_t de
 	_rtld_exclusive_exit(&mask);
 }
 
-pid_t __fork(void);
-
 __dso_public pid_t
 __locked_fork(int *my_errno)
 {



CVS commit: src/libexec/ld.elf_so

2023-04-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Apr 18 16:48:45 UTC 2023

Modified Files:
src/libexec/ld.elf_so: rtld.h symbol.c

Log Message:
The SysV ABI specifies that the symbol hash function should return only 32
bits of hash. Unfortunately due to an implementation bu and the fact that
the return type is unsigned long which is 64 bits in LP64, this can fail
in some cases: "\xff\x0f\x0f\x0f\x0f\x0f\x12". See:
https://maskray.me/blog/2023-04-12-elf-hash-function
>From Ed Maste @ FreeBSD:
https://cgit.freebsd.org/src/commit/\
?id=29e3a06510823edbb91667d21f530d3ec778116d
Need to write Unit Tests for this.


To generate a diff of this commit:
cvs rdiff -u -r1.144 -r1.145 src/libexec/ld.elf_so/rtld.h
cvs rdiff -u -r1.73 -r1.74 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/rtld.h
diff -u src/libexec/ld.elf_so/rtld.h:1.144 src/libexec/ld.elf_so/rtld.h:1.145
--- src/libexec/ld.elf_so/rtld.h:1.144	Tue Jun 21 02:52:17 2022
+++ src/libexec/ld.elf_so/rtld.h	Tue Apr 18 12:48:45 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.h,v 1.144 2022/06/21 06:52:17 skrll Exp $	 */
+/*	$NetBSD: rtld.h,v 1.145 2023/04/18 16:48:45 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -440,8 +440,8 @@ void _rtld_call_ifunc(Obj_Entry *, sigse
 Obj_Entry *_rtld_load_library(const char *, const Obj_Entry *, int);
 
 /* symbol.c */
-unsigned long _rtld_sysv_hash(const char *);
-unsigned long _rtld_gnu_hash(const char *);
+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/symbol.c
diff -u src/libexec/ld.elf_so/symbol.c:1.73 src/libexec/ld.elf_so/symbol.c:1.74
--- src/libexec/ld.elf_so/symbol.c:1.73	Sat Feb 29 13:45:20 2020
+++ src/libexec/ld.elf_so/symbol.c	Tue Apr 18 12:48:45 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: symbol.c,v 1.73 2020/02/29 18:45:20 kamil Exp $	 */
+/*	$NetBSD: symbol.c,v 1.74 2023/04/18 16:48:45 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: symbol.c,v 1.73 2020/02/29 18:45:20 kamil Exp $");
+__RCSID("$NetBSD: symbol.c,v 1.74 2023/04/18 16:48:45 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -81,33 +81,27 @@ _rtld_donelist_check(DoneList *dlp, cons
 }
 
 /*
- * Hash function for symbol table lookup.  Don't even think about changing
- * this.  It is specified by the System V ABI.
+ * SysV hash function for symbol table lookup.  It is a slightly optimized
+ * version of the hash specified by the System V ABI.
  */
-unsigned long
+Elf32_Word
 _rtld_sysv_hash(const char *name)
 {
 	const unsigned char *p = (const unsigned char *) name;
-	unsigned long   h = 0;
-	unsigned long   g;
-	unsigned long   c;
-
-	for (; __predict_true((c = *p) != '\0'); p++) {
-		h <<= 4;
-		h += c;
-		if ((g = h & 0xf000) != 0) {
-			h ^= g;
-			h ^= g >> 24;
-		}
+	Elf32_Word h = 0;
+
+	while (__predict_true(*p != '\0')) {
+		h = (h << 4) + *p++;
+		h ^= (h >> 24) & 0xf0;
 	}
-	return (h);
+	return (h & 0x);
 }
 
 /*
  * Hash function for symbol table lookup.  Don't even think about changing
  * this.  It is specified by the GNU toolchain ABI.
  */
-unsigned long
+Elf32_Word
 _rtld_gnu_hash(const char *name)
 {
 	const unsigned char *p = (const unsigned char *) name;
@@ -116,7 +110,7 @@ _rtld_gnu_hash(const char *name)
 
 	for (c = *p; c != '\0'; c = *++p)
 		h = h * 33 + c;
-	return (unsigned long)h;
+	return (h & 0x);
 }
 
 const Elf_Sym *



CVS commit: src/libexec/ld.elf_so

2023-04-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Apr 18 16:48:45 UTC 2023

Modified Files:
src/libexec/ld.elf_so: rtld.h symbol.c

Log Message:
The SysV ABI specifies that the symbol hash function should return only 32
bits of hash. Unfortunately due to an implementation bu and the fact that
the return type is unsigned long which is 64 bits in LP64, this can fail
in some cases: "\xff\x0f\x0f\x0f\x0f\x0f\x12". See:
https://maskray.me/blog/2023-04-12-elf-hash-function
>From Ed Maste @ FreeBSD:
https://cgit.freebsd.org/src/commit/\
?id=29e3a06510823edbb91667d21f530d3ec778116d
Need to write Unit Tests for this.


To generate a diff of this commit:
cvs rdiff -u -r1.144 -r1.145 src/libexec/ld.elf_so/rtld.h
cvs rdiff -u -r1.73 -r1.74 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.



CVS commit: src/libexec/ld.elf_so

2023-04-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Apr 18 22:42:52 UTC 2023

Modified Files:
src/libexec/ld.elf_so: symbol.c

Log Message:
Oops wrong mask.


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 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/symbol.c
diff -u src/libexec/ld.elf_so/symbol.c:1.74 src/libexec/ld.elf_so/symbol.c:1.75
--- src/libexec/ld.elf_so/symbol.c:1.74	Tue Apr 18 12:48:45 2023
+++ src/libexec/ld.elf_so/symbol.c	Tue Apr 18 18:42:52 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: symbol.c,v 1.74 2023/04/18 16:48:45 christos Exp $	 */
+/*	$NetBSD: symbol.c,v 1.75 2023/04/18 22:42:52 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: symbol.c,v 1.74 2023/04/18 16:48:45 christos Exp $");
+__RCSID("$NetBSD: symbol.c,v 1.75 2023/04/18 22:42:52 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -94,7 +94,7 @@ _rtld_sysv_hash(const char *name)
 		h = (h << 4) + *p++;
 		h ^= (h >> 24) & 0xf0;
 	}
-	return (h & 0x);
+	return (h & 0x0fff);
 }
 
 /*



CVS commit: src/libexec/ld.elf_so

2023-04-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Apr 18 22:42:52 UTC 2023

Modified Files:
src/libexec/ld.elf_so: symbol.c

Log Message:
Oops wrong mask.


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 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.



CVS commit: src/libexec/ld.elf_so

2023-04-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Apr 23 11:53:00 UTC 2023

Modified Files:
src/libexec/ld.elf_so: rtld.c

Log Message:
dlopen(3): Read _rtld_objtail under the lock.

XXX pullup-8
XXX pullup-9
XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.212 -r1.213 src/libexec/ld.elf_so/rtld.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2023-04-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Apr 23 11:53:00 UTC 2023

Modified Files:
src/libexec/ld.elf_so: rtld.c

Log Message:
dlopen(3): Read _rtld_objtail under the lock.

XXX pullup-8
XXX pullup-9
XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.212 -r1.213 src/libexec/ld.elf_so/rtld.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/rtld.c
diff -u src/libexec/ld.elf_so/rtld.c:1.212 src/libexec/ld.elf_so/rtld.c:1.213
--- src/libexec/ld.elf_so/rtld.c:1.212	Tue Sep 13 10:18:58 2022
+++ src/libexec/ld.elf_so/rtld.c	Sun Apr 23 11:53:00 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.212 2022/09/13 10:18:58 riastradh Exp $	 */
+/*	$NetBSD: rtld.c,v 1.213 2023/04/23 11:53:00 riastradh Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.212 2022/09/13 10:18:58 riastradh Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.213 2023/04/23 11:53:00 riastradh Exp $");
 #endif /* not lint */
 
 #include 
@@ -1026,7 +1026,7 @@ __strong_alias(__dlopen,dlopen)
 void *
 dlopen(const char *name, int mode)
 {
-	Obj_Entry **old_obj_tail = _rtld_objtail;
+	Obj_Entry **old_obj_tail;
 	Obj_Entry *obj = NULL;
 	int flags = _RTLD_DLOPEN;
 	bool nodelete;
@@ -1038,6 +1038,8 @@ dlopen(const char *name, int mode)
 
 	_rtld_exclusive_enter(&mask);
 
+	old_obj_tail = _rtld_objtail;
+
 	flags |= (mode & RTLD_GLOBAL) ? _RTLD_GLOBAL : 0;
 	flags |= (mode & RTLD_NOLOAD) ? _RTLD_NOLOAD : 0;
 



CVS commit: src/libexec/ld.elf_so

2023-05-31 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed May 31 18:44:39 UTC 2023

Modified Files:
src/libexec/ld.elf_so: map_object.c tls.c

Log Message:
ld.elf_so: Sprinkle tls debug messages.

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/libexec/ld.elf_so/map_object.c
cvs rdiff -u -r1.15 -r1.16 src/libexec/ld.elf_so/tls.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/map_object.c
diff -u src/libexec/ld.elf_so/map_object.c:1.65 src/libexec/ld.elf_so/map_object.c:1.66
--- src/libexec/ld.elf_so/map_object.c:1.65	Thu Jan 12 19:17:11 2023
+++ src/libexec/ld.elf_so/map_object.c	Wed May 31 18:44:39 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: map_object.c,v 1.65 2023/01/12 19:17:11 christos Exp $	 */
+/*	$NetBSD: map_object.c,v 1.66 2023/05/31 18:44:39 riastradh Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -34,7 +34,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: map_object.c,v 1.65 2023/01/12 19:17:11 christos Exp $");
+__RCSID("$NetBSD: map_object.c,v 1.66 2023/05/31 18:44:39 riastradh Exp $");
 #endif /* not lint */
 
 #include 
@@ -310,6 +310,9 @@ _rtld_map_object(const char *path, int f
 		obj->tlsalign = phtls->p_align;
 		obj->tlsinitsize = phtls->p_filesz;
 		tls_vaddr = phtls->p_vaddr;
+		dbg(("%s: tls index %zu size %zu align %zu initsize %zu",
+		obj->path, obj->tlsindex, obj->tlssize, obj->tlsalign,
+		obj->tlsinitsize));
 	}
 #endif
 
@@ -437,8 +440,11 @@ _rtld_map_object(const char *path, int f
 	}
 
 #if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II)
-	if (phtls != NULL)
+	if (phtls != NULL) {
 		obj->tlsinit = mapbase + tls_vaddr;
+		dbg(("%s: tls init = %p + %"PRImemsz" = %p", obj->path,
+		mapbase, tls_vaddr, obj->tlsinit));
+	}
 #endif
 
 	obj->mapbase = mapbase;

Index: src/libexec/ld.elf_so/tls.c
diff -u src/libexec/ld.elf_so/tls.c:1.15 src/libexec/ld.elf_so/tls.c:1.16
--- src/libexec/ld.elf_so/tls.c:1.15	Fri Feb 10 08:12:48 2023
+++ src/libexec/ld.elf_so/tls.c	Wed May 31 18:44:39 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: tls.c,v 1.15 2023/02/10 08:12:48 skrll Exp $	*/
+/*	$NetBSD: tls.c,v 1.16 2023/05/31 18:44:39 riastradh Exp $	*/
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,7 +29,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: tls.c,v 1.15 2023/02/10 08:12:48 skrll Exp $");
+__RCSID("$NetBSD: tls.c,v 1.16 2023/05/31 18:44:39 riastradh Exp $");
 
 #include 
 #include 
@@ -261,6 +261,8 @@ _rtld_tls_offset_allocate(Obj_Entry *obj
 		}
 	}
 	obj->tlsoffset = offset;
+	dbg(("%s: static tls offset 0x%zx size %zu\n",
+	obj->path, obj->tlsoffset, obj->tlssize));
 	_rtld_tls_static_offset = next_offset;
 	obj->tls_done = 1;
 



CVS commit: src/libexec/ld.elf_so

2023-05-31 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed May 31 18:44:39 UTC 2023

Modified Files:
src/libexec/ld.elf_so: map_object.c tls.c

Log Message:
ld.elf_so: Sprinkle tls debug messages.

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/libexec/ld.elf_so/map_object.c
cvs rdiff -u -r1.15 -r1.16 src/libexec/ld.elf_so/tls.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2023-06-01 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Jun  1 08:20:10 UTC 2023

Modified Files:
src/libexec/ld.elf_so: tls.c

Log Message:
ld.elf_so: Make tls alloc debug messages more detailed and greppable.

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/libexec/ld.elf_so/tls.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2023-06-01 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Jun  1 08:20:10 UTC 2023

Modified Files:
src/libexec/ld.elf_so: tls.c

Log Message:
ld.elf_so: Make tls alloc debug messages more detailed and greppable.

XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/libexec/ld.elf_so/tls.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/tls.c
diff -u src/libexec/ld.elf_so/tls.c:1.16 src/libexec/ld.elf_so/tls.c:1.17
--- src/libexec/ld.elf_so/tls.c:1.16	Wed May 31 18:44:39 2023
+++ src/libexec/ld.elf_so/tls.c	Thu Jun  1 08:20:10 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: tls.c,v 1.16 2023/05/31 18:44:39 riastradh Exp $	*/
+/*	$NetBSD: tls.c,v 1.17 2023/06/01 08:20:10 riastradh Exp $	*/
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,7 +29,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: tls.c,v 1.16 2023/05/31 18:44:39 riastradh Exp $");
+__RCSID("$NetBSD: tls.c,v 1.17 2023/06/01 08:20:10 riastradh Exp $");
 
 #include 
 #include 
@@ -129,7 +129,7 @@ _rtld_tls_allocate_locked(void)
 	tcb = (struct tls_tcb *)p;
 	tcb->tcb_self = tcb;
 #endif
-	dbg(("tcb %p", tcb));
+	dbg(("lwp %d tls tcb %p", _lwp_self(), tcb));
 	tcb->tcb_dtv = xcalloc(sizeof(*tcb->tcb_dtv) * (2 + _rtld_tls_max_index));
 	++tcb->tcb_dtv;
 	SET_DTV_MAX_INDEX(tcb->tcb_dtv, _rtld_tls_max_index);
@@ -142,8 +142,9 @@ _rtld_tls_allocate_locked(void)
 #else
 			q = p - obj->tlsoffset;
 #endif
-			dbg(("obj %p dtv %p tlsoffset %zu",
-			obj, q, obj->tlsoffset));
+			dbg(("%s: [lwp %d] tls dtv %p index %zu offset %zu",
+			obj->path, _lwp_self(),
+			q, obj->tlsindex, obj->tlsoffset));
 			if (obj->tlsinitsize)
 memcpy(q, obj->tlsinit, obj->tlsinitsize);
 			tcb->tcb_dtv[obj->tlsindex] = q;



CVS commit: src/libexec/ld.elf_so

2023-06-04 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jun  4 23:42:38 UTC 2023

Modified Files:
src/libexec/ld.elf_so: rtld.c

Log Message:
ld.elf_so: Sprinkle more debug messages on dlopen and error.

PR pkg/57445


To generate a diff of this commit:
cvs rdiff -u -r1.213 -r1.214 src/libexec/ld.elf_so/rtld.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2023-06-04 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jun  4 23:42:38 UTC 2023

Modified Files:
src/libexec/ld.elf_so: rtld.c

Log Message:
ld.elf_so: Sprinkle more debug messages on dlopen and error.

PR pkg/57445


To generate a diff of this commit:
cvs rdiff -u -r1.213 -r1.214 src/libexec/ld.elf_so/rtld.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/rtld.c
diff -u src/libexec/ld.elf_so/rtld.c:1.213 src/libexec/ld.elf_so/rtld.c:1.214
--- src/libexec/ld.elf_so/rtld.c:1.213	Sun Apr 23 11:53:00 2023
+++ src/libexec/ld.elf_so/rtld.c	Sun Jun  4 23:42:38 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.213 2023/04/23 11:53:00 riastradh Exp $	 */
+/*	$NetBSD: rtld.c,v 1.214 2023/06/04 23:42:38 riastradh Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.213 2023/04/23 11:53:00 riastradh Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.214 2023/06/04 23:42:38 riastradh Exp $");
 #endif /* not lint */
 
 #include 
@@ -1034,7 +1034,7 @@ dlopen(const char *name, int mode)
 	sigset_t mask;
 	int result;
 
-	dbg(("dlopen of %s %d", name, mode));
+	dbg(("dlopen of %s 0x%x", name, mode));
 
 	_rtld_exclusive_enter(&mask);
 
@@ -1091,6 +1091,9 @@ dlopen(const char *name, int mode)
 	_rtld_debug.r_state = RT_CONSISTENT;
 	_rtld_debug_state();
 
+	dbg(("dlopen of %s 0x%x returned %p%s%s%s", name, mode, obj,
+	obj ? "" : " (", obj ? "" : error_message, obj ? "" : ")"));
+
 	_rtld_exclusive_exit(&mask);
 
 	return obj;
@@ -1565,6 +1568,7 @@ _rtld_error(const char *fmt,...)
 
 	va_start(ap, fmt);
 	xvsnprintf(buf, sizeof buf, fmt, ap);
+	dbg(("%s: %s", __func__, buf));
 	error_message = buf;
 	va_end(ap);
 }



CVS commit: src/libexec/ld.elf_so

2023-06-07 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Wed Jun  7 13:50:04 UTC 2023

Modified Files:
src/libexec/ld.elf_so: tls.c

Log Message:
TLS variant I archs need to fudge the offset by the size of the TCB.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/libexec/ld.elf_so/tls.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2023-06-07 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Wed Jun  7 13:50:04 UTC 2023

Modified Files:
src/libexec/ld.elf_so: tls.c

Log Message:
TLS variant I archs need to fudge the offset by the size of the TCB.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/libexec/ld.elf_so/tls.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/tls.c
diff -u src/libexec/ld.elf_so/tls.c:1.18 src/libexec/ld.elf_so/tls.c:1.19
--- src/libexec/ld.elf_so/tls.c:1.18	Sun Jun  4 01:24:56 2023
+++ src/libexec/ld.elf_so/tls.c	Wed Jun  7 13:50:04 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: tls.c,v 1.18 2023/06/04 01:24:56 joerg Exp $	*/
+/*	$NetBSD: tls.c,v 1.19 2023/06/07 13:50:04 joerg Exp $	*/
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,7 +29,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: tls.c,v 1.18 2023/06/04 01:24:56 joerg Exp $");
+__RCSID("$NetBSD: tls.c,v 1.19 2023/06/07 13:50:04 joerg Exp $");
 
 #include 
 #include 
@@ -212,7 +212,7 @@ _rtld_tls_module_allocate(struct tls_tcb
 	}
 	if (obj->tls_static) {
 #ifdef __HAVE_TLS_VARIANT_I
-		p = (uint8_t *)tcb + obj->tlsoffset;
+		p = (uint8_t *)tcb + obj->tlsoffset + sizeof(struct tls_tcb);
 #else
 		p = (uint8_t *)tcb - obj->tlsoffset;
 #endif



CVS commit: src/libexec/ld.elf_so

2023-07-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jul 30 09:19:10 UTC 2023

Modified Files:
src/libexec/ld.elf_so: Makefile

Log Message:
ld.elf_so: Split SRCS onto multiple lines.

Makes updates easier.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.144 -r1.145 src/libexec/ld.elf_so/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2023-07-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jul 30 09:19:10 UTC 2023

Modified Files:
src/libexec/ld.elf_so: Makefile

Log Message:
ld.elf_so: Split SRCS onto multiple lines.

Makes updates easier.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.144 -r1.145 src/libexec/ld.elf_so/Makefile

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.144 src/libexec/ld.elf_so/Makefile:1.145
--- src/libexec/ld.elf_so/Makefile:1.144	Sat Dec  4 08:45:56 2021
+++ src/libexec/ld.elf_so/Makefile	Sun Jul 30 09:19:10 2023
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.144 2021/12/04 08:45:56 skrll Exp $
+#	$NetBSD: Makefile,v 1.145 2023/07/30 09:19:10 riastradh Exp $
 #
 # NOTE: when changing ld.so, ensure that ldd still compiles.
 #
@@ -72,9 +72,22 @@ PROG=		ld.elf_so
 
 CLIBOBJ!=	cd ${NETBSDSRCDIR}/lib/libc && ${PRINTOBJDIR}
 
-SRCS+=		rtld.c reloc.c symbol.c xmalloc.c xprintf.c debug.c \
-		map_object.c load.c search.c headers.c paths.c expand.c \
-		tls.c symver.c diagassert.c compat.c
+SRCS+=		rtld.c
+SRCS+=		reloc.c
+SRCS+=		symbol.c
+SRCS+=		xmalloc.c
+SRCS+=		xprintf.c
+SRCS+=		debug.c
+SRCS+=		map_object.c
+SRCS+=		load.c
+SRCS+=		search.c
+SRCS+=		headers.c
+SRCS+=		paths.c
+SRCS+=		expand.c
+SRCS+=		tls.c
+SRCS+=		symver.c
+SRCS+=		diagassert.c
+SRCS+=		compat.c
 
 .if ${USE_FORT} == "yes"
 .PATH.c: ${NETBSDSRCDIR}/lib/libc/misc



CVS commit: src/libexec/ld.elf_so

2023-07-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jul 30 09:19:19 UTC 2023

Modified Files:
src/libexec/ld.elf_so: Makefile

Log Message:
ld.elf_so: Sort SRCS.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.145 -r1.146 src/libexec/ld.elf_so/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2023-07-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jul 30 09:19:19 UTC 2023

Modified Files:
src/libexec/ld.elf_so: Makefile

Log Message:
ld.elf_so: Sort SRCS.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.145 -r1.146 src/libexec/ld.elf_so/Makefile

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.145 src/libexec/ld.elf_so/Makefile:1.146
--- src/libexec/ld.elf_so/Makefile:1.145	Sun Jul 30 09:19:10 2023
+++ src/libexec/ld.elf_so/Makefile	Sun Jul 30 09:19:19 2023
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.145 2023/07/30 09:19:10 riastradh Exp $
+#	$NetBSD: Makefile,v 1.146 2023/07/30 09:19:19 riastradh Exp $
 #
 # NOTE: when changing ld.so, ensure that ldd still compiles.
 #
@@ -72,22 +72,22 @@ PROG=		ld.elf_so
 
 CLIBOBJ!=	cd ${NETBSDSRCDIR}/lib/libc && ${PRINTOBJDIR}
 
-SRCS+=		rtld.c
-SRCS+=		reloc.c
-SRCS+=		symbol.c
-SRCS+=		xmalloc.c
-SRCS+=		xprintf.c
+SRCS+=		compat.c
 SRCS+=		debug.c
-SRCS+=		map_object.c
-SRCS+=		load.c
-SRCS+=		search.c
+SRCS+=		diagassert.c
+SRCS+=		expand.c
 SRCS+=		headers.c
+SRCS+=		load.c
+SRCS+=		map_object.c
 SRCS+=		paths.c
-SRCS+=		expand.c
-SRCS+=		tls.c
+SRCS+=		reloc.c
+SRCS+=		rtld.c
+SRCS+=		search.c
+SRCS+=		symbol.c
 SRCS+=		symver.c
-SRCS+=		diagassert.c
-SRCS+=		compat.c
+SRCS+=		tls.c
+SRCS+=		xmalloc.c
+SRCS+=		xprintf.c
 
 .if ${USE_FORT} == "yes"
 .PATH.c: ${NETBSDSRCDIR}/lib/libc/misc



CVS commit: src/libexec/ld.elf_so

2023-07-30 Thread Taylor R Campbell
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.



CVS commit: src/libexec/ld.elf_so

2023-07-30 Thread Taylor R Campbell
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 
 #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 
@@ -56,6 +56,7 @@ __RCSID("$NetBSD: reloc.c,v 1.117 2021/1
 #include 
 
 #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 
 #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 
@@ -60,7 +60,9 @@ __RCSID("$NetBSD: rtld.c,v 1.214 2023/06
 #include 
 
 #include 
+
 #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 
 #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 
@@ -57,6 +57,7 @@ __RCSID("$NetBSD: symbol.c,v 1.75 2023/0
 #include 
 
 #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 ha

CVS commit: src/libexec/ld.elf_so

2023-01-03 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Jan  4 01:37:00 UTC 2023

Modified Files:
src/libexec/ld.elf_so: expand.c

Log Message:
make the what argument size_t since we are passing in size_t


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/libexec/ld.elf_so/expand.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2023-01-03 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Jan  4 01:37:00 UTC 2023

Modified Files:
src/libexec/ld.elf_so: expand.c

Log Message:
make the what argument size_t since we are passing in size_t


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/libexec/ld.elf_so/expand.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/expand.c
diff -u src/libexec/ld.elf_so/expand.c:1.6 src/libexec/ld.elf_so/expand.c:1.7
--- src/libexec/ld.elf_so/expand.c:1.6	Mon May  6 04:02:20 2013
+++ src/libexec/ld.elf_so/expand.c	Tue Jan  3 20:37:00 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: expand.c,v 1.6 2013/05/06 08:02:20 skrll Exp $	*/
+/*	$NetBSD: expand.c,v 1.7 2023/01/04 01:37:00 christos Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 #include 
 #ifndef lint
-__RCSID("$NetBSD: expand.c,v 1.6 2013/05/06 08:02:20 skrll Exp $");
+__RCSID("$NetBSD: expand.c,v 1.7 2023/01/04 01:37:00 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -69,7 +69,7 @@ static int mib[3][2] = {
 };
 
 static size_t
-expand(char *buf, const char *execname, int what, size_t bl)
+expand(char *buf, const char *execname, size_t what, size_t bl)
 {
 	const char *p, *ep;
 	char *bp = buf;



CVS commit: src/libexec/ld.elf_so

2023-01-03 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Jan  4 01:37:24 UTC 2023

Modified Files:
src/libexec/ld.elf_so: headers.c

Log Message:
comment out a function that is only used in rtld


To generate a diff of this commit:
cvs rdiff -u -r1.70 -r1.71 src/libexec/ld.elf_so/headers.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2023-01-03 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Jan  4 01:37:24 UTC 2023

Modified Files:
src/libexec/ld.elf_so: headers.c

Log Message:
comment out a function that is only used in rtld


To generate a diff of this commit:
cvs rdiff -u -r1.70 -r1.71 src/libexec/ld.elf_so/headers.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/headers.c
diff -u src/libexec/ld.elf_so/headers.c:1.70 src/libexec/ld.elf_so/headers.c:1.71
--- src/libexec/ld.elf_so/headers.c:1.70	Sat Dec  4 09:39:08 2021
+++ src/libexec/ld.elf_so/headers.c	Tue Jan  3 20:37:24 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: headers.c,v 1.70 2021/12/04 14:39:08 skrll Exp $	 */
+/*	$NetBSD: headers.c,v 1.71 2023/01/04 01:37:24 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: headers.c,v 1.70 2021/12/04 14:39:08 skrll Exp $");
+__RCSID("$NetBSD: headers.c,v 1.71 2023/01/04 01:37:24 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -459,6 +459,7 @@ _rtld_digest_dynamic(const char *execnam
 	}
 }
 
+#ifdef RTLD_LOADER
 /*
  * Process a shared object's program header.  This is used only for the
  * main program, when the kernel has already loaded the main program
@@ -562,3 +563,4 @@ _rtld_digest_phdr(const Elf_Phdr *phdr, 
 	obj->entry = entry;
 	return obj;
 }
+#endif



CVS commit: src/libexec/ld.elf_so

2023-01-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jan  6 15:33:48 UTC 2023

Modified Files:
src/libexec/ld.elf_so: map_object.c

Log Message:
Remove the limitation of only being able to load binaries with 2 PT_LOAD
sections, like the kernel can. From FreeBSD.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/libexec/ld.elf_so/map_object.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2023-01-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jan  6 15:33:48 UTC 2023

Modified Files:
src/libexec/ld.elf_so: map_object.c

Log Message:
Remove the limitation of only being able to load binaries with 2 PT_LOAD
sections, like the kernel can. From FreeBSD.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/libexec/ld.elf_so/map_object.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/map_object.c
diff -u src/libexec/ld.elf_so/map_object.c:1.62 src/libexec/ld.elf_so/map_object.c:1.63
--- src/libexec/ld.elf_so/map_object.c:1.62	Wed Mar 30 04:26:45 2022
+++ src/libexec/ld.elf_so/map_object.c	Fri Jan  6 10:33:47 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: map_object.c,v 1.62 2022/03/30 08:26:45 hannken Exp $	 */
+/*	$NetBSD: map_object.c,v 1.63 2023/01/06 15:33:47 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -34,7 +34,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: map_object.c,v 1.62 2022/03/30 08:26:45 hannken Exp $");
+__RCSID("$NetBSD: map_object.c,v 1.63 2023/01/06 15:33:47 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -49,7 +49,8 @@ __RCSID("$NetBSD: map_object.c,v 1.62 20
 #include "debug.h"
 #include "rtld.h"
 
-static int protflags(int);	/* Elf flags -> mmap protection */
+static int convert_prot(int);	/* Elf flags -> mmap protection */
+static int convert_flags(int);  /* Elf flags -> mmap flags */
 
 #define EA_UNDEF		(~(Elf_Addr)0)
 
@@ -69,35 +70,35 @@ _rtld_map_object(const char *path, int f
 #if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II)
 	Elf_Phdr	*phtls;
 #endif
-	size_t		 phsize;
 	Elf_Phdr	*phlimit;
-	Elf_Phdr	*segs[2];
+	Elf_Phdr   **segs = NULL;
 	int		 nsegs;
 	caddr_t		 mapbase = MAP_FAILED;
 	size_t		 mapsize = 0;
 	int		 mapflags;
-	Elf_Off		 base_offset;
 	Elf_Addr	 base_alignment;
 	Elf_Addr	 base_vaddr;
 	Elf_Addr	 base_vlimit;
 	Elf_Addr	 text_vlimit;
-	int		 text_flags;
+	Elf_Addr	 text_end;
 	void		*base_addr;
 	Elf_Off		 data_offset;
 	Elf_Addr	 data_vaddr;
 	Elf_Addr	 data_vlimit;
 	int		 data_flags;
+	int		 data_prot;
 	caddr_t		 data_addr;
+	Elf_Addr	 bss_vaddr;
+	Elf_Addr	 bss_vlimit;
+	caddr_t		 bss_addr;
 #if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II)
 	Elf_Addr	 tls_vaddr = 0; /* Noise GCC */
 #endif
 	Elf_Addr	 phdr_vaddr;
-	size_t		 phdr_memsz;
-	caddr_t		 gap_addr;
-	size_t		 gap_size;
 	int i;
 #ifdef RTLD_LOADER
 	Elf_Addr	 clear_vaddr;
+	caddr_t	 	 clear_page;
 	caddr_t		 clear_addr;
 	size_t		 nclear;
 #endif
@@ -105,6 +106,9 @@ _rtld_map_object(const char *path, int f
 	Elf_Addr 	 relro_page;
 	size_t		 relro_size;
 #endif
+#ifdef notyet
+	int		 stack_flags;
+#endif
 
 	if (sb != NULL && sb->st_size < (off_t)sizeof (Elf_Ehdr)) {
 		_rtld_error("%s: not ELF file (too short)", path);
@@ -124,34 +128,34 @@ _rtld_map_object(const char *path, int f
 	obj->ehdr = ehdr;
 	if (ehdr == MAP_FAILED) {
 		_rtld_error("%s: read error: %s", path, xstrerror(errno));
-		goto bad;
+		goto error;
 	}
 	/* Make sure the file is valid */
 	if (memcmp(ELFMAG, ehdr->e_ident, SELFMAG) != 0) {
 		_rtld_error("%s: not ELF file (magic number bad)", path);
-		goto bad;
+		goto error;
 	}
 	if (ehdr->e_ident[EI_CLASS] != ELFCLASS) {
 		_rtld_error("%s: invalid ELF class %x; expected %x", path,
 		ehdr->e_ident[EI_CLASS], ELFCLASS);
-		goto bad;
+		goto error;
 	}
 	/* Elf_e_ident includes class */
 	if (ehdr->e_ident[EI_VERSION] != EV_CURRENT ||
 	ehdr->e_version != EV_CURRENT ||
 	ehdr->e_ident[EI_DATA] != ELFDEFNNAME(MACHDEP_ENDIANNESS)) {
 		_rtld_error("%s: unsupported file version", path);
-		goto bad;
+		goto error;
 	}
 	if (ehdr->e_type != ET_EXEC && ehdr->e_type != ET_DYN) {
 		_rtld_error("%s: unsupported file type", path);
-		goto bad;
+		goto error;
 	}
 	switch (ehdr->e_machine) {
 		ELFDEFNNAME(MACHDEP_ID_CASES)
 	default:
 		_rtld_error("%s: unsupported machine", path);
-		goto bad;
+		goto error;
 	}
 
 	/*
@@ -173,16 +177,22 @@ _rtld_map_object(const char *path, int f
 #if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II)
 	phtls = NULL;
 #endif
-	phsize = ehdr->e_phnum * sizeof(phdr[0]);
 	obj->phdr = NULL;
 #ifdef GNU_RELRO
 	relro_page = 0;
 	relro_size = 0;
 #endif
 	phdr_vaddr = EA_UNDEF;
-	phdr_memsz = 0;
 	phlimit = phdr + ehdr->e_phnum;
-	nsegs = 0;
+	segs = xmalloc(sizeof(segs[0]) * ehdr->e_phnum);
+	if (segs == NULL) {
+		_rtld_error("No memory for segs");
+		goto error;
+	}
+#ifdef notyet
+	stack_flags = PF_R | PF_W;
+#endif
+	nsegs = -1;
 	while (phdr < phlimit) {
 		switch (phdr->p_type) {
 		case PT_INTERP:
@@ -191,21 +201,37 @@ _rtld_map_object(const char *path, int f
 			break;
 
 		case PT_LOAD:
-			if (nsegs < 2)
-segs[nsegs] = phdr;
-			++nsegs;
+			segs[++nsegs] = phdr;
+			if ((segs[nsegs]->p_align & (_rtld_pagesz - 1)) != 0) {
+_rtld_error(
+"%s: PT_LOAD segment %d not page-aligned",
+p

CVS commit: src/libexec/ld.elf_so

2023-01-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jan 12 18:52:47 UTC 2023

Modified Files:
src/libexec/ld.elf_so: map_object.c

Log Message:
Handle program headers properly; fixes c++ exceptions on arm32.


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/libexec/ld.elf_so/map_object.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/map_object.c
diff -u src/libexec/ld.elf_so/map_object.c:1.63 src/libexec/ld.elf_so/map_object.c:1.64
--- src/libexec/ld.elf_so/map_object.c:1.63	Fri Jan  6 10:33:47 2023
+++ src/libexec/ld.elf_so/map_object.c	Thu Jan 12 13:52:47 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: map_object.c,v 1.63 2023/01/06 15:33:47 christos Exp $	 */
+/*	$NetBSD: map_object.c,v 1.64 2023/01/12 18:52:47 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -34,7 +34,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: map_object.c,v 1.63 2023/01/06 15:33:47 christos Exp $");
+__RCSID("$NetBSD: map_object.c,v 1.64 2023/01/12 18:52:47 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -95,12 +95,13 @@ _rtld_map_object(const char *path, int f
 	Elf_Addr	 tls_vaddr = 0; /* Noise GCC */
 #endif
 	Elf_Addr	 phdr_vaddr;
+	size_t		 phdr_memsz;
 	int i;
 #ifdef RTLD_LOADER
 	Elf_Addr	 clear_vaddr;
 	caddr_t	 	 clear_page;
 	caddr_t		 clear_addr;
-	size_t		 nclear;
+	size_t		 nclear, phsize;
 #endif
 #ifdef GNU_RELRO
 	Elf_Addr 	 relro_page;
@@ -177,12 +178,14 @@ _rtld_map_object(const char *path, int f
 #if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II)
 	phtls = NULL;
 #endif
+	phsize = ehdr->e_phnum * sizeof(phdr[0]);
 	obj->phdr = NULL;
 #ifdef GNU_RELRO
 	relro_page = 0;
 	relro_size = 0;
 #endif
 	phdr_vaddr = EA_UNDEF;
+	phdr_memsz = 0;
 	phlimit = phdr + ehdr->e_phnum;
 	segs = xmalloc(sizeof(segs[0]) * ehdr->e_phnum);
 	if (segs == NULL) {
@@ -221,6 +224,7 @@ _rtld_map_object(const char *path, int f
 
 		case PT_PHDR:
 			phdr_vaddr = phdr->p_vaddr;
+			phdr_memsz = phdr->p_memsz;
 			dbg(("%s: %s %p phsize %" PRImemsz, obj->path,
 			"PT_PHDR",
 			(void *)(uintptr_t)phdr->p_vaddr, phdr->p_memsz));
@@ -341,6 +345,7 @@ _rtld_map_object(const char *path, int f
 	}
 #endif
 
+	obj->phdr_loaded = false;
 	for (i = 0; i <= nsegs; i++) {
 		/* Overlay the segment onto the proper region. */
 		data_offset = round_down(segs[i]->p_offset);
@@ -405,11 +410,30 @@ _rtld_map_object(const char *path, int f
 			}
 		}
 
-		if (phdr_vaddr == 0 && data_offset <= ehdr->e_phoff &&
-		(data_vlimit - data_vaddr + data_offset) >=
-		(ehdr->e_phoff + ehdr->e_phnum * sizeof (Elf_Phdr))) {
-			phdr_vaddr = data_vaddr + ehdr->e_phoff - data_offset;
+		if (phdr_vaddr != EA_UNDEF &&
+		segs[i]->p_vaddr <= phdr_vaddr &&
+		segs[i]->p_memsz >= phdr_memsz) {
+			obj->phdr_loaded = true;
 		}
+		if (segs[i]->p_offset <= ehdr->e_phoff &&
+		segs[i]->p_memsz >= phsize) {
+			phdr_vaddr = segs[i]->p_vaddr + ehdr->e_phoff;
+			phdr_memsz = phsize;
+			obj->phdr_loaded = true;
+		}
+	}
+	if (obj->phdr_loaded) {
+		obj->phdr = (void *)(uintptr_t)phdr_vaddr;
+		obj->phsize = phdr_memsz;
+	} else {
+		Elf_Phdr *buf = xmalloc(phsize);
+		if (buf == NULL) {
+			_rtld_error("%s: cannot allocate program header", path);
+			goto error;
+		}
+		memcpy(buf, phdr, phsize);
+		obj->phdr = buf;
+		obj->phsize = phsize;
 	}
 
 #if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II)



CVS commit: src/libexec/ld.elf_so

2023-01-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jan 12 18:52:47 UTC 2023

Modified Files:
src/libexec/ld.elf_so: map_object.c

Log Message:
Handle program headers properly; fixes c++ exceptions on arm32.


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/libexec/ld.elf_so/map_object.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2023-01-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jan 12 19:17:11 UTC 2023

Modified Files:
src/libexec/ld.elf_so: map_object.c

Log Message:
fix the ldd build


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/libexec/ld.elf_so/map_object.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/map_object.c
diff -u src/libexec/ld.elf_so/map_object.c:1.64 src/libexec/ld.elf_so/map_object.c:1.65
--- src/libexec/ld.elf_so/map_object.c:1.64	Thu Jan 12 13:52:47 2023
+++ src/libexec/ld.elf_so/map_object.c	Thu Jan 12 14:17:11 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: map_object.c,v 1.64 2023/01/12 18:52:47 christos Exp $	 */
+/*	$NetBSD: map_object.c,v 1.65 2023/01/12 19:17:11 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -34,7 +34,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: map_object.c,v 1.64 2023/01/12 18:52:47 christos Exp $");
+__RCSID("$NetBSD: map_object.c,v 1.65 2023/01/12 19:17:11 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -95,13 +95,13 @@ _rtld_map_object(const char *path, int f
 	Elf_Addr	 tls_vaddr = 0; /* Noise GCC */
 #endif
 	Elf_Addr	 phdr_vaddr;
-	size_t		 phdr_memsz;
+	size_t		 phdr_memsz, phsize;
 	int i;
 #ifdef RTLD_LOADER
 	Elf_Addr	 clear_vaddr;
 	caddr_t	 	 clear_page;
 	caddr_t		 clear_addr;
-	size_t		 nclear, phsize;
+	size_t		 nclear;
 #endif
 #ifdef GNU_RELRO
 	Elf_Addr 	 relro_page;



CVS commit: src/libexec/ld.elf_so

2023-01-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jan 12 19:17:11 UTC 2023

Modified Files:
src/libexec/ld.elf_so: map_object.c

Log Message:
fix the ldd build


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/libexec/ld.elf_so/map_object.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2023-02-10 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Feb 10 08:12:48 UTC 2023

Modified Files:
src/libexec/ld.elf_so: tls.c

Log Message:
Alignment. NFCI.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/libexec/ld.elf_so/tls.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2023-02-10 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Feb 10 08:12:48 UTC 2023

Modified Files:
src/libexec/ld.elf_so: tls.c

Log Message:
Alignment. NFCI.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/libexec/ld.elf_so/tls.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/tls.c
diff -u src/libexec/ld.elf_so/tls.c:1.14 src/libexec/ld.elf_so/tls.c:1.15
--- src/libexec/ld.elf_so/tls.c:1.14	Tue Nov  5 22:22:42 2019
+++ src/libexec/ld.elf_so/tls.c	Fri Feb 10 08:12:48 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: tls.c,v 1.14 2019/11/05 22:22:42 joerg Exp $	*/
+/*	$NetBSD: tls.c,v 1.15 2023/02/10 08:12:48 skrll Exp $	*/
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,7 +29,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: tls.c,v 1.14 2019/11/05 22:22:42 joerg Exp $");
+__RCSID("$NetBSD: tls.c,v 1.15 2023/02/10 08:12:48 skrll Exp $");
 
 #include 
 #include 
@@ -53,8 +53,8 @@ static size_t _rtld_tls_static_offset;	/
 size_t _rtld_tls_dtv_generation = 1;
 size_t _rtld_tls_max_index = 1;
 
-#define	DTV_GENERATION(dtv)	((size_t)((dtv)[0]))
-#define	DTV_MAX_INDEX(dtv)	((size_t)((dtv)[-1]))
+#define	DTV_GENERATION(dtv)		((size_t)((dtv)[0]))
+#define	DTV_MAX_INDEX(dtv)		((size_t)((dtv)[-1]))
 #define	SET_DTV_GENERATION(dtv, val)	(dtv)[0] = (void *)(size_t)(val)
 #define	SET_DTV_MAX_INDEX(dtv, val)	(dtv)[-1] = (void *)(size_t)(val)
 



CVS commit: src/libexec/ld.elf_so

2023-10-03 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Oct  3 09:48:19 UTC 2023

Modified Files:
src/libexec/ld.elf_so: rtld.c

Log Message:
PR 57628: at the end of _rtld_init() explicitly initialize the ld.elf_so
local copy of the atomic access support functions for machines that do not
implement all required ops in hardware (like 32bit sparc).

XXX would be better to figure out a way to share this copy with libc
(thereby using half as many RAS sections). But even if we would share it,
we have to init it early enough for ld.elf_so internal uses.


To generate a diff of this commit:
cvs rdiff -u -r1.215 -r1.216 src/libexec/ld.elf_so/rtld.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2023-10-03 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Oct  3 09:48:19 UTC 2023

Modified Files:
src/libexec/ld.elf_so: rtld.c

Log Message:
PR 57628: at the end of _rtld_init() explicitly initialize the ld.elf_so
local copy of the atomic access support functions for machines that do not
implement all required ops in hardware (like 32bit sparc).

XXX would be better to figure out a way to share this copy with libc
(thereby using half as many RAS sections). But even if we would share it,
we have to init it early enough for ld.elf_so internal uses.


To generate a diff of this commit:
cvs rdiff -u -r1.215 -r1.216 src/libexec/ld.elf_so/rtld.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/rtld.c
diff -u src/libexec/ld.elf_so/rtld.c:1.215 src/libexec/ld.elf_so/rtld.c:1.216
--- src/libexec/ld.elf_so/rtld.c:1.215	Sun Jul 30 09:20:14 2023
+++ src/libexec/ld.elf_so/rtld.c	Tue Oct  3 09:48:18 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.215 2023/07/30 09:20:14 riastradh Exp $	 */
+/*	$NetBSD: rtld.c,v 1.216 2023/10/03 09:48:18 martin Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.215 2023/07/30 09:20:14 riastradh Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.216 2023/10/03 09:48:18 martin Exp $");
 #endif /* not lint */
 
 #include 
@@ -70,6 +70,13 @@ __RCSID("$NetBSD: rtld.c,v 1.215 2023/07
 #endif
 
 /*
+ * Hidden function from common/lib/libc/atomic - nop on machines
+ * with enough atomic ops. Need to explicitly call it early.
+ * libc has the same symbol and will initialize itself, but not our copy.
+ */
+void __libc_atomic_init(void);
+
+/*
  * Function declarations.
  */
 static void _rtld_init(caddr_t, caddr_t, const char *);
@@ -404,6 +411,8 @@ _rtld_init(caddr_t mapbase, caddr_t relo
 	ehdr = (Elf_Ehdr *)mapbase;
 	_rtld_objself.phdr = (Elf_Phdr *)((char *)mapbase + ehdr->e_phoff);
 	_rtld_objself.phsize = ehdr->e_phnum * sizeof(_rtld_objself.phdr[0]);
+
+	__libc_atomic_init();
 }
 
 /*



CVS commit: src/libexec/ld.elf_so

2022-09-13 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep 13 10:18:58 UTC 2022

Modified Files:
src/libexec/ld.elf_so: rtld.c

Log Message:
ld.elf_so(8): Make fork take a shared, not exclusive, lock.

We only need to ensure that there are no concurrent modifications to
the rtld data structures in flight, since the threads that began
those modifications will not exist in the child and will therefore be
unable to complete them in the child.

A shared lock suffices to ensure there are no such concurrent
modifications in flight; an exclusive lock is not necessary, and can
cause deadlock if fork is executed from a signal handler, which is
explicitly allowed by POSIX (and our own sigaction(2) man page) which
marks fork as async-signal-safe.

PR lib/56979


To generate a diff of this commit:
cvs rdiff -u -r1.211 -r1.212 src/libexec/ld.elf_so/rtld.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2022-09-13 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Sep 13 10:18:58 UTC 2022

Modified Files:
src/libexec/ld.elf_so: rtld.c

Log Message:
ld.elf_so(8): Make fork take a shared, not exclusive, lock.

We only need to ensure that there are no concurrent modifications to
the rtld data structures in flight, since the threads that began
those modifications will not exist in the child and will therefore be
unable to complete them in the child.

A shared lock suffices to ensure there are no such concurrent
modifications in flight; an exclusive lock is not necessary, and can
cause deadlock if fork is executed from a signal handler, which is
explicitly allowed by POSIX (and our own sigaction(2) man page) which
marks fork as async-signal-safe.

PR lib/56979


To generate a diff of this commit:
cvs rdiff -u -r1.211 -r1.212 src/libexec/ld.elf_so/rtld.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/rtld.c
diff -u src/libexec/ld.elf_so/rtld.c:1.211 src/libexec/ld.elf_so/rtld.c:1.212
--- src/libexec/ld.elf_so/rtld.c:1.211	Sat Apr  9 23:39:07 2022
+++ src/libexec/ld.elf_so/rtld.c	Tue Sep 13 10:18:58 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.211 2022/04/09 23:39:07 riastradh Exp $	 */
+/*	$NetBSD: rtld.c,v 1.212 2022/09/13 10:18:58 riastradh Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.211 2022/04/09 23:39:07 riastradh Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.212 2022/09/13 10:18:58 riastradh Exp $");
 #endif /* not lint */
 
 #include 
@@ -1539,14 +1539,13 @@ pid_t __fork(void);
 __dso_public pid_t
 __locked_fork(int *my_errno)
 {
-	sigset_t mask;
 	pid_t result;
 
-	_rtld_exclusive_enter(&mask);
+	_rtld_shared_enter();
 	result = __fork();
 	if (result == -1)
 		*my_errno = errno;
-	_rtld_exclusive_exit(&mask);
+	_rtld_shared_exit();
 
 	return result;
 }



CVS commit: src/libexec/ld.elf_so

2019-09-15 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Sep 15 13:40:46 UTC 2019

Modified Files:
src/libexec/ld.elf_so: rtld.c

Log Message:
Return the ELF loader dl_phdr_info information for dl_iterate_phdr(3)

Sync the behavior of dl_iterate_phdr(3) with Linux/FreeBSD/OpenBSD.


To generate a diff of this commit:
cvs rdiff -u -r1.197 -r1.198 src/libexec/ld.elf_so/rtld.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/rtld.c
diff -u src/libexec/ld.elf_so/rtld.c:1.197 src/libexec/ld.elf_so/rtld.c:1.198
--- src/libexec/ld.elf_so/rtld.c:1.197	Sun Apr 14 19:21:37 2019
+++ src/libexec/ld.elf_so/rtld.c	Sun Sep 15 13:40:46 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.197 2019/04/14 19:21:37 christos Exp $	 */
+/*	$NetBSD: rtld.c,v 1.198 2019/09/15 13:40:46 kamil Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.197 2019/04/14 19:21:37 christos Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.198 2019/09/15 13:40:46 kamil Exp $");
 #endif /* not lint */
 
 #include 
@@ -134,6 +134,7 @@ static void _rtld_objlist_clear(Objlist 
 static void _rtld_unload_object(sigset_t *, Obj_Entry *, bool);
 static void _rtld_unref_dag(Obj_Entry *);
 static Obj_Entry *_rtld_obj_from_addr(const void *);
+static void _rtld_fill_dl_phdr_info(const Obj_Entry *, struct dl_phdr_info *);
 
 static inline void
 _rtld_call_initfini_function(const Obj_Entry *obj, Elf_Addr func, sigset_t *mask)
@@ -344,6 +345,7 @@ restart:
 static void
 _rtld_init(caddr_t mapbase, caddr_t relocbase, const char *execname)
 {
+	const Elf_Ehdr *ehdr;
 
 	/* Conjure up an Obj_Entry structure for the dynamic linker. */
 	_rtld_objself.path = __UNCONST(_rtld_path);
@@ -394,6 +396,10 @@ _rtld_init(caddr_t mapbase, caddr_t relo
 
 	_rtld_debug.r_brk = _rtld_debug_state;
 	_rtld_debug.r_state = RT_CONSISTENT;
+
+	ehdr = (Elf_Ehdr *)mapbase;
+	_rtld_objself.phdr = (Elf_Phdr *)((char *)mapbase + ehdr->e_phoff);
+	_rtld_objself.phsize = ehdr->e_phnum * sizeof(_rtld_objself.phdr[0]);
 }
 
 /*
@@ -1433,6 +1439,26 @@ dlinfo(void *handle, int req, void *v)
 	return 0;
 }
 
+static void
+_rtld_fill_dl_phdr_info(const Obj_Entry *obj, struct dl_phdr_info *phdr_info)
+{
+
+	phdr_info->dlpi_addr = (Elf_Addr)obj->relocbase;
+	/* XXX: wrong but not fixing it yet */
+	phdr_info->dlpi_name = obj->path;
+	phdr_info->dlpi_phdr = obj->phdr;
+	phdr_info->dlpi_phnum = obj->phsize / sizeof(obj->phdr[0]);
+#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II)
+	phdr_info->dlpi_tls_modid = obj->tlsindex;
+	phdr_info->dlpi_tls_data = obj->tlsinit;
+#else
+	phdr_info->dlpi_tls_modid = 0;
+	phdr_info->dlpi_tls_data = 0;
+#endif
+	phdr_info->dlpi_adds = _rtld_objloads;
+	phdr_info->dlpi_subs = _rtld_objloads - _rtld_objcount;
+}
+
 __strong_alias(__dl_iterate_phdr,dl_iterate_phdr);
 int
 dl_iterate_phdr(int (*callback)(struct dl_phdr_info *, size_t, void *), void *param)
@@ -1446,20 +1472,7 @@ dl_iterate_phdr(int (*callback)(struct d
 	_rtld_shared_enter();
 
 	for (obj = _rtld_objlist;  obj != NULL;  obj = obj->next) {
-		phdr_info.dlpi_addr = (Elf_Addr)obj->relocbase;
-		/* XXX: wrong but not fixing it yet */
-		phdr_info.dlpi_name = obj->path;
-		phdr_info.dlpi_phdr = obj->phdr;
-		phdr_info.dlpi_phnum = obj->phsize / sizeof(obj->phdr[0]);
-#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II)
-		phdr_info.dlpi_tls_modid = obj->tlsindex;
-		phdr_info.dlpi_tls_data = obj->tlsinit;
-#else
-		phdr_info.dlpi_tls_modid = 0;
-		phdr_info.dlpi_tls_data = 0;
-#endif
-		phdr_info.dlpi_adds = _rtld_objloads;
-		phdr_info.dlpi_subs = _rtld_objloads - _rtld_objcount;
+		_rtld_fill_dl_phdr_info(obj, &phdr_info);
 
 		/* XXXlocking: exit point */
 		error = callback(&phdr_info, sizeof(phdr_info), param);
@@ -1467,6 +1480,13 @@ dl_iterate_phdr(int (*callback)(struct d
 			break;
 	}
 
+	if (error == 0) {
+		_rtld_fill_dl_phdr_info(&_rtld_objself, &phdr_info);
+
+		/* XXXlocking: exit point */
+		error = callback(&phdr_info, sizeof(phdr_info), param);
+	}
+
 	_rtld_shared_exit();
 	return error;
 }



CVS commit: src/libexec/ld.elf_so

2019-09-15 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Sun Sep 15 13:40:46 UTC 2019

Modified Files:
src/libexec/ld.elf_so: rtld.c

Log Message:
Return the ELF loader dl_phdr_info information for dl_iterate_phdr(3)

Sync the behavior of dl_iterate_phdr(3) with Linux/FreeBSD/OpenBSD.


To generate a diff of this commit:
cvs rdiff -u -r1.197 -r1.198 src/libexec/ld.elf_so/rtld.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2019-10-03 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Thu Oct  3 10:34:30 UTC 2019

Modified Files:
src/libexec/ld.elf_so: rtld.c

Log Message:
improve error message


To generate a diff of this commit:
cvs rdiff -u -r1.198 -r1.199 src/libexec/ld.elf_so/rtld.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2019-10-03 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Thu Oct  3 10:34:30 UTC 2019

Modified Files:
src/libexec/ld.elf_so: rtld.c

Log Message:
improve error message


To generate a diff of this commit:
cvs rdiff -u -r1.198 -r1.199 src/libexec/ld.elf_so/rtld.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/rtld.c
diff -u src/libexec/ld.elf_so/rtld.c:1.198 src/libexec/ld.elf_so/rtld.c:1.199
--- src/libexec/ld.elf_so/rtld.c:1.198	Sun Sep 15 13:40:46 2019
+++ src/libexec/ld.elf_so/rtld.c	Thu Oct  3 10:34:30 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.198 2019/09/15 13:40:46 kamil Exp $	 */
+/*	$NetBSD: rtld.c,v 1.199 2019/10/03 10:34:30 tnn Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.198 2019/09/15 13:40:46 kamil Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.199 2019/10/03 10:34:30 tnn Exp $");
 #endif /* not lint */
 
 #include 
@@ -1674,7 +1674,7 @@ _rtld_shared_enter(void)
 		if (cur == (self | RTLD_EXCLUSIVE_MASK)) {
 			if (_rtld_mutex_may_recurse)
 return;
-			_rtld_error("dead lock detected");
+			_rtld_error("%s: dead lock detected", __FUNCTION__);
 			_rtld_die();
 		}
 		waiter = atomic_swap_uint(&_rtld_waiter_shared, self);
@@ -1738,7 +1738,7 @@ _rtld_exclusive_enter(sigset_t *mask)
 		membar_sync();
 		cur = _rtld_mutex;
 		if (cur == locked_value) {
-			_rtld_error("dead lock detected");
+			_rtld_error("%s: dead lock detected", __FUNCTION__);
 			_rtld_die();
 		}
 		if (cur)



CVS commit: src/libexec/ld.elf_so

2019-10-03 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Oct  4 01:57:53 UTC 2019

Modified Files:
src/libexec/ld.elf_so: rtld.c

Log Message:
use __func__ (c99, c++11) instead of __FUNCTION__


To generate a diff of this commit:
cvs rdiff -u -r1.199 -r1.200 src/libexec/ld.elf_so/rtld.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2019-10-03 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Oct  4 01:57:53 UTC 2019

Modified Files:
src/libexec/ld.elf_so: rtld.c

Log Message:
use __func__ (c99, c++11) instead of __FUNCTION__


To generate a diff of this commit:
cvs rdiff -u -r1.199 -r1.200 src/libexec/ld.elf_so/rtld.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/rtld.c
diff -u src/libexec/ld.elf_so/rtld.c:1.199 src/libexec/ld.elf_so/rtld.c:1.200
--- src/libexec/ld.elf_so/rtld.c:1.199	Thu Oct  3 06:34:30 2019
+++ src/libexec/ld.elf_so/rtld.c	Thu Oct  3 21:57:53 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.199 2019/10/03 10:34:30 tnn Exp $	 */
+/*	$NetBSD: rtld.c,v 1.200 2019/10/04 01:57:53 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.199 2019/10/03 10:34:30 tnn Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.200 2019/10/04 01:57:53 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -1674,7 +1674,7 @@ _rtld_shared_enter(void)
 		if (cur == (self | RTLD_EXCLUSIVE_MASK)) {
 			if (_rtld_mutex_may_recurse)
 return;
-			_rtld_error("%s: dead lock detected", __FUNCTION__);
+			_rtld_error("%s: dead lock detected", __func__);
 			_rtld_die();
 		}
 		waiter = atomic_swap_uint(&_rtld_waiter_shared, self);
@@ -1738,7 +1738,7 @@ _rtld_exclusive_enter(sigset_t *mask)
 		membar_sync();
 		cur = _rtld_mutex;
 		if (cur == locked_value) {
-			_rtld_error("%s: dead lock detected", __FUNCTION__);
+			_rtld_error("%s: dead lock detected", __func__);
 			_rtld_die();
 		}
 		if (cur)



CVS commit: src/libexec/ld.elf_so

2010-01-09 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Jan 10 06:37:33 UTC 2010

Modified Files:
src/libexec/ld.elf_so: rtld.c

Log Message:
Fixup comment.


To generate a diff of this commit:
cvs rdiff -u -r1.127 -r1.128 src/libexec/ld.elf_so/rtld.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2010-01-09 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Jan 10 07:29:47 UTC 2010

Modified Files:
src/libexec/ld.elf_so: map_object.c rtld.h symbol.c

Log Message:
Reset the COMBRELOC cache Obj_Entry if it was freed.

Fixes PR 41482. Done slightly differently to the patch in the PR.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/libexec/ld.elf_so/map_object.c
cvs rdiff -u -r1.82 -r1.83 src/libexec/ld.elf_so/rtld.h
cvs rdiff -u -r1.48 -r1.49 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.



CVS commit: src/libexec/ld.elf_so

2010-01-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Jan 13 20:17:23 UTC 2010

Modified Files:
src/libexec/ld.elf_so: reloc.c rtld.h symbol.c
src/libexec/ld.elf_so/arch/alpha: alpha_reloc.c
src/libexec/ld.elf_so/arch/arm: mdreloc.c
src/libexec/ld.elf_so/arch/hppa: hppa_reloc.c
src/libexec/ld.elf_so/arch/i386: mdreloc.c
src/libexec/ld.elf_so/arch/m68k: mdreloc.c
src/libexec/ld.elf_so/arch/mips: mips_reloc.c
src/libexec/ld.elf_so/arch/powerpc: ppc_reloc.c
src/libexec/ld.elf_so/arch/sh3: mdreloc.c
src/libexec/ld.elf_so/arch/sparc: mdreloc.c
src/libexec/ld.elf_so/arch/sparc64: mdreloc.c
src/libexec/ld.elf_so/arch/vax: mdreloc.c
src/libexec/ld.elf_so/arch/x86_64: mdreloc.c

Log Message:
PR/39240: Satoshi Suetake: Don't fail when attempting to resolve weak symbols
when we are doing immediate binding, leave them alone and they will be dealt
with later during lazy binding. From skrll@


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 src/libexec/ld.elf_so/reloc.c
cvs rdiff -u -r1.83 -r1.84 src/libexec/ld.elf_so/rtld.h
cvs rdiff -u -r1.49 -r1.50 src/libexec/ld.elf_so/symbol.c
cvs rdiff -u -r1.33 -r1.34 src/libexec/ld.elf_so/arch/alpha/alpha_reloc.c
cvs rdiff -u -r1.30 -r1.31 src/libexec/ld.elf_so/arch/arm/mdreloc.c
cvs rdiff -u -r1.30 -r1.31 src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c
cvs rdiff -u -r1.28 -r1.29 src/libexec/ld.elf_so/arch/i386/mdreloc.c
cvs rdiff -u -r1.24 -r1.25 src/libexec/ld.elf_so/arch/m68k/mdreloc.c
cvs rdiff -u -r1.56 -r1.57 src/libexec/ld.elf_so/arch/mips/mips_reloc.c
cvs rdiff -u -r1.43 -r1.44 src/libexec/ld.elf_so/arch/powerpc/ppc_reloc.c
cvs rdiff -u -r1.26 -r1.27 src/libexec/ld.elf_so/arch/sh3/mdreloc.c
cvs rdiff -u -r1.42 -r1.43 src/libexec/ld.elf_so/arch/sparc/mdreloc.c
cvs rdiff -u -r1.45 -r1.46 src/libexec/ld.elf_so/arch/sparc64/mdreloc.c
cvs rdiff -u -r1.25 -r1.26 src/libexec/ld.elf_so/arch/vax/mdreloc.c
cvs rdiff -u -r1.35 -r1.36 src/libexec/ld.elf_so/arch/x86_64/mdreloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2010-01-14 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Jan 14 21:52:07 UTC 2010

Modified Files:
src/libexec/ld.elf_so: reloc.c rtld.h

Log Message:
Remove the entry points for dlopen() and friends. They haven't been used
since Aug 2003.


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/libexec/ld.elf_so/reloc.c
cvs rdiff -u -r1.84 -r1.85 src/libexec/ld.elf_so/rtld.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2010-01-14 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Jan 15 07:07:12 UTC 2010

Modified Files:
src/libexec/ld.elf_so: reloc.c rtld.h

Log Message:
Put the dlopen,and friends entry points back.

They're needed by pre-2.0 binaries. Backward compatibiliity for these
was broken by another commit recently which I'll fix shortly.


To generate a diff of this commit:
cvs rdiff -u -r1.99 -r1.100 src/libexec/ld.elf_so/reloc.c
cvs rdiff -u -r1.85 -r1.86 src/libexec/ld.elf_so/rtld.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2010-01-16 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Jan 16 10:37:51 UTC 2010

Modified Files:
src/libexec/ld.elf_so: reloc.c rtld.h

Log Message:
Remove cargo cult dlinfo entry point.


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 src/libexec/ld.elf_so/reloc.c
cvs rdiff -u -r1.86 -r1.87 src/libexec/ld.elf_so/rtld.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2010-01-17 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Jan 17 08:04:20 UTC 2010

Modified Files:
src/libexec/ld.elf_so: rtld.h

Log Message:
Restore backwards compatibility for binaries referencing the main
Obj_Entry.


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/libexec/ld.elf_so/rtld.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2010-02-27 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Sat Feb 27 11:16:38 UTC 2010

Modified Files:
src/libexec/ld.elf_so: load.c rtld.c rtld.h symbol.c

Log Message:
Implement negative cache checks for symbol lookups.
Uses the Donelist idea from FreeBSD.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/libexec/ld.elf_so/load.c
cvs rdiff -u -r1.128 -r1.129 src/libexec/ld.elf_so/rtld.c
cvs rdiff -u -r1.88 -r1.89 src/libexec/ld.elf_so/rtld.h
cvs rdiff -u -r1.50 -r1.51 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.



CVS commit: src/libexec/ld.elf_so

2010-02-27 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Sat Feb 27 11:16:38 UTC 2010

Modified Files:
src/libexec/ld.elf_so: load.c rtld.c rtld.h symbol.c

Log Message:
Implement negative cache checks for symbol lookups.
Uses the Donelist idea from FreeBSD.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/libexec/ld.elf_so/load.c
cvs rdiff -u -r1.128 -r1.129 src/libexec/ld.elf_so/rtld.c
cvs rdiff -u -r1.88 -r1.89 src/libexec/ld.elf_so/rtld.h
cvs rdiff -u -r1.50 -r1.51 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/load.c
diff -u src/libexec/ld.elf_so/load.c:1.36 src/libexec/ld.elf_so/load.c:1.37
--- src/libexec/ld.elf_so/load.c:1.36	Tue May 19 20:44:52 2009
+++ src/libexec/ld.elf_so/load.c	Sat Feb 27 11:16:38 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: load.c,v 1.36 2009/05/19 20:44:52 christos Exp $	 */
+/*	$NetBSD: load.c,v 1.37 2010/02/27 11:16:38 roy Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: load.c,v 1.36 2009/05/19 20:44:52 christos Exp $");
+__RCSID("$NetBSD: load.c,v 1.37 2010/02/27 11:16:38 roy Exp $");
 #endif /* not lint */
 
 #include 
@@ -155,6 +155,7 @@
 
 		*_rtld_objtail = obj;
 		_rtld_objtail = &obj->next;
+		_rtld_objcount++;
 #ifdef RTLD_LOADER
 		_rtld_linkmap_add(obj);	/* for GDB */
 #endif

Index: src/libexec/ld.elf_so/rtld.c
diff -u src/libexec/ld.elf_so/rtld.c:1.128 src/libexec/ld.elf_so/rtld.c:1.129
--- src/libexec/ld.elf_so/rtld.c:1.128	Sun Jan 10 06:37:32 2010
+++ src/libexec/ld.elf_so/rtld.c	Sat Feb 27 11:16:38 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.128 2010/01/10 06:37:32 skrll Exp $	 */
+/*	$NetBSD: rtld.c,v 1.129 2010/02/27 11:16:38 roy Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.128 2010/01/10 06:37:32 skrll Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.129 2010/02/27 11:16:38 roy Exp $");
 #endif /* not lint */
 
 #include 
@@ -83,6 +83,7 @@
 bool_rtld_trust;	/* False for setuid and setgid programs */
 Obj_Entry  *_rtld_objlist;	/* Head of linked list of shared objects */
 Obj_Entry **_rtld_objtail;	/* Link field of last object in list */
+int		_rtld_objcount;	/* Number of shared objects */
 Obj_Entry  *_rtld_objmain;	/* The main program shared object */
 Obj_Entry   _rtld_objself;	/* The dynamic linker shared object */
 const char	_rtld_path[] = _PATH_RTLD;
@@ -271,6 +272,7 @@
 	/* Make the object list empty again. */
 	_rtld_objlist = NULL;
 	_rtld_objtail = &_rtld_objlist;
+	_rtld_objcount = 0;
 
 	_rtld_debug.r_brk = _rtld_debug_state;
 	_rtld_debug.r_state = RT_CONSISTENT;
@@ -705,6 +707,7 @@
 _rtld_objlist_remove(&_rtld_list_global, obj);
 _rtld_linkmap_delete(obj);
 *linkp = obj->next;
+_rtld_objcount--;
 _rtld_obj_free(obj);
 			} else
 linkp = &obj->next;
@@ -810,11 +813,16 @@
 	unsigned long hash;
 	const Elf_Sym *def;
 	const Obj_Entry *obj;
+	DoneList donelist;
 
 	hash = _rtld_elf_hash(name);
 	obj = _rtld_objmain;
+	_rtld_donelist_init(&donelist);
 
-	def = _rtld_symlook_list(name, hash, &_rtld_list_main, &obj, false);
+	def = _rtld_symlook_list(name, hash, &_rtld_list_main, &obj, false,
+	&donelist);
+
+	_rtld_donelist_clear(&donelist);
 
 	if (def != NULL)
 		return obj->relocbase + def->st_value;
@@ -838,6 +846,7 @@
 	const Elf_Sym *def;
 	const Obj_Entry *defobj;
 	void *retaddr;
+	DoneList donelist; 
 	
 	hash = _rtld_elf_hash(name);
 	def = NULL;
@@ -892,20 +901,28 @@
 		if ((obj = _rtld_dlcheck(handle)) == NULL)
 			return NULL;
 		
+		_rtld_donelist_init(&donelist);
+
 		if (obj->mainprog) {
 			/* Search main program and all libraries loaded by it */
 			def = _rtld_symlook_list(name, hash, &_rtld_list_main,
-			&defobj, false);
+			&defobj, false, &donelist);
 		} else {
 			Needed_Entry fake;
+			DoneList depth;
 
 			/* Search the object and all the libraries loaded by it. */
 			fake.next = NULL;
 			fake.obj = __UNCONST(obj);
 			fake.name = 0;
+
+			_rtld_donelist_init(&depth);
 			def = _rtld_symlook_needed(name, hash, &fake, &defobj,
-			false);
+			false, &donelist, &depth);
+			_rtld_donelist_clear(&depth);
 		}
+
+		_rtld_donelist_clear(&donelist);
 		break;
 	}
 	

Index: src/libexec/ld.elf_so/rtld.h
diff -u src/libexec/ld.elf_so/rtld.h:1.88 src/libexec/ld.elf_so/rtld.h:1.89
--- src/libexec/ld.elf_so/rtld.h:1.88	Sun Jan 17 08:04:20 2010
+++ src/libexec/ld.elf_so/rtld.h	Sat Feb 27 11:16:38 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.h,v 1.88 2010/01/17 08:04:20 skrll Exp $	 */
+/*	$NetBSD: rtld.h,v 1.89 2010/02/27 11:16:38 roy Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -59,6 +59,16 @@
 #define NEW(type)	((type *) xmalloc(sizeof(type)))
 #define CNEW(type)	((type *) xcalloc(sizeof(type)))
 
+/*
+ * Fill in a DoneList with an allocation large enough to ho

CVS commit: src/libexec/ld.elf_so

2021-12-04 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Dec  4 08:45:56 UTC 2021

Modified Files:
src/libexec/ld.elf_so: Makefile

Log Message:
Error if there are undefined symbols, e.g. _rtld_call_ifunc


To generate a diff of this commit:
cvs rdiff -u -r1.143 -r1.144 src/libexec/ld.elf_so/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2021-12-04 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Dec  4 08:45:56 UTC 2021

Modified Files:
src/libexec/ld.elf_so: Makefile

Log Message:
Error if there are undefined symbols, e.g. _rtld_call_ifunc


To generate a diff of this commit:
cvs rdiff -u -r1.143 -r1.144 src/libexec/ld.elf_so/Makefile

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.143 src/libexec/ld.elf_so/Makefile:1.144
--- src/libexec/ld.elf_so/Makefile:1.143	Sun Feb  9 09:11:59 2020
+++ src/libexec/ld.elf_so/Makefile	Sat Dec  4 08:45:56 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.143 2020/02/09 09:11:59 kamil Exp $
+#	$NetBSD: Makefile,v 1.144 2021/12/04 08:45:56 skrll Exp $
 #
 # NOTE: when changing ld.so, ensure that ldd still compiles.
 #
@@ -49,6 +49,7 @@ LDFLAGS+=	${${ACTIVE_CC} == "clang":? -W
 		-shared -nostartfiles -nodefaultlibs
 LDFLAGS+=	-Wl,-static
 LDFLAGS+=	-Wl,--warn-shared-textrel
+LDFLAGS+=	-Wl,--no-undefined
 LDFLAGS+=	-Wl,-Map=${.TARGET}.map
 
 COPTS+=		-fvisibility=hidden



CVS commit: src/libexec/ld.elf_so

2021-12-04 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Dec  4 08:53:34 UTC 2021

Modified Files:
src/libexec/ld.elf_so: reloc.c
src/libexec/ld.elf_so/arch/aarch64: Makefile.inc

Log Message:
Provide a stub _rtld_call_ifunc when a platform doesn't use one of the
common ones or doesn't provide its own.


To generate a diff of this commit:
cvs rdiff -u -r1.116 -r1.117 src/libexec/ld.elf_so/reloc.c
cvs rdiff -u -r1.2 -r1.3 src/libexec/ld.elf_so/arch/aarch64/Makefile.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2021-12-04 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Dec  4 08:53:34 UTC 2021

Modified Files:
src/libexec/ld.elf_so: reloc.c
src/libexec/ld.elf_so/arch/aarch64: Makefile.inc

Log Message:
Provide a stub _rtld_call_ifunc when a platform doesn't use one of the
common ones or doesn't provide its own.


To generate a diff of this commit:
cvs rdiff -u -r1.116 -r1.117 src/libexec/ld.elf_so/reloc.c
cvs rdiff -u -r1.2 -r1.3 src/libexec/ld.elf_so/arch/aarch64/Makefile.inc

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/reloc.c
diff -u src/libexec/ld.elf_so/reloc.c:1.116 src/libexec/ld.elf_so/reloc.c:1.117
--- src/libexec/ld.elf_so/reloc.c:1.116	Sat Feb 29 04:24:33 2020
+++ src/libexec/ld.elf_so/reloc.c	Sat Dec  4 08:53:34 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: reloc.c,v 1.116 2020/02/29 04:24:33 kamil Exp $	 */
+/*	$NetBSD: reloc.c,v 1.117 2021/12/04 08:53:34 skrll Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -39,7 +39,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: reloc.c,v 1.116 2020/02/29 04:24:33 kamil Exp $");
+__RCSID("$NetBSD: reloc.c,v 1.117 2021/12/04 08:53:34 skrll Exp $");
 #endif /* not lint */
 
 #include 
@@ -260,6 +260,16 @@ _rtld_resolve_ifunc2(const Obj_Entry *ob
 	return target;
 }
 
+#if \
+!defined(RTLD_COMMON_CALL_IFUNC_RELA) && \
+!defined(RTLD_COMMON_CALL_IFUNC_REL) && \
+!defined(RTLD_ARCH_CALL_IFUNC)
+void
+_rtld_call_ifunc(Obj_Entry *obj, sigset_t *mask, u_int cur_objgen)
+{
+}
+#endif
+
 #ifdef RTLD_COMMON_CALL_IFUNC_RELA
 #  ifdef __sparc__
 #  include 

Index: src/libexec/ld.elf_so/arch/aarch64/Makefile.inc
diff -u src/libexec/ld.elf_so/arch/aarch64/Makefile.inc:1.2 src/libexec/ld.elf_so/arch/aarch64/Makefile.inc:1.3
--- src/libexec/ld.elf_so/arch/aarch64/Makefile.inc:1.2	Thu Dec 27 18:58:14 2018
+++ src/libexec/ld.elf_so/arch/aarch64/Makefile.inc	Sat Dec  4 08:53:34 2021
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.inc,v 1.2 2018/12/27 18:58:14 christos Exp $
+# $NetBSD: Makefile.inc,v 1.3 2021/12/04 08:53:34 skrll Exp $
 
 SRCS+=		rtld_start.S mdreloc.c
 
@@ -7,5 +7,6 @@ CPPFLAGS+=	-fpic
 
 CPPFLAGS+=	-DELFSIZE=64
 CPPFLAGS+=	-DELF_NOTE_MARCH_DESC=\"${LDELFSO_MACHINE_ARCH}\"
+CPPFLAGS+=	-DRTLD_ARCH_CALL_IFUNC
 
 LDFLAGS+=	-Wl,-e,_rtld_start



CVS commit: src/libexec/ld.elf_so

2021-12-04 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Dec  4 14:39:08 UTC 2021

Modified Files:
src/libexec/ld.elf_so: headers.c rtld.c rtld.h
src/libexec/ld.elf_so/arch/hppa: hppa_reloc.c

Log Message:
Restore the fptr_t type of {init,fini}{,_array} that was removed when initial
support for indirect functions was added.  This fixes {init,fini}_array support
on hppa where each member of the array is (already) a plabel.

Discussed with joerg.

 4 files changed, 29 insertions(+), 39 deletions(-)
: --


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/libexec/ld.elf_so/headers.c
cvs rdiff -u -r1.209 -r1.210 src/libexec/ld.elf_so/rtld.c
cvs rdiff -u -r1.141 -r1.142 src/libexec/ld.elf_so/rtld.h
cvs rdiff -u -r1.47 -r1.48 src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2021-12-04 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Dec  4 14:39:08 UTC 2021

Modified Files:
src/libexec/ld.elf_so: headers.c rtld.c rtld.h
src/libexec/ld.elf_so/arch/hppa: hppa_reloc.c

Log Message:
Restore the fptr_t type of {init,fini}{,_array} that was removed when initial
support for indirect functions was added.  This fixes {init,fini}_array support
on hppa where each member of the array is (already) a plabel.

Discussed with joerg.

 4 files changed, 29 insertions(+), 39 deletions(-)
: --


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/libexec/ld.elf_so/headers.c
cvs rdiff -u -r1.209 -r1.210 src/libexec/ld.elf_so/rtld.c
cvs rdiff -u -r1.141 -r1.142 src/libexec/ld.elf_so/rtld.h
cvs rdiff -u -r1.47 -r1.48 src/libexec/ld.elf_so/arch/hppa/hppa_reloc.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/headers.c
diff -u src/libexec/ld.elf_so/headers.c:1.69 src/libexec/ld.elf_so/headers.c:1.70
--- src/libexec/ld.elf_so/headers.c:1.69	Sat May 16 16:43:15 2020
+++ src/libexec/ld.elf_so/headers.c	Sat Dec  4 14:39:08 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: headers.c,v 1.69 2020/05/16 16:43:15 skrll Exp $	 */
+/*	$NetBSD: headers.c,v 1.70 2021/12/04 14:39:08 skrll Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: headers.c,v 1.69 2020/05/16 16:43:15 skrll Exp $");
+__RCSID("$NetBSD: headers.c,v 1.70 2021/12/04 14:39:08 skrll Exp $");
 #endif /* not lint */
 
 #include 
@@ -299,7 +299,7 @@ _rtld_digest_dynamic(const char *execnam
 #ifdef HAVE_INITFINI_ARRAY
 		case DT_INIT_ARRAY:
 			obj->init_array =
-			(Elf_Addr *)(obj->relocbase + dynp->d_un.d_ptr);
+			(fptr_t *)(obj->relocbase + dynp->d_un.d_ptr);
 			dbg(("headers: DT_INIT_ARRAY at %p",
 			obj->init_array));
 			break;
@@ -320,7 +320,7 @@ _rtld_digest_dynamic(const char *execnam
 #ifdef HAVE_INITFINI_ARRAY
 		case DT_FINI_ARRAY:
 			obj->fini_array =
-			(Elf_Addr *)(obj->relocbase + dynp->d_un.d_ptr);
+			(fptr_t *)(obj->relocbase + dynp->d_un.d_ptr);
 			dbg(("headers: DT_FINI_ARRAY at %p",
 			obj->fini_array));
 			break;
@@ -434,10 +434,19 @@ _rtld_digest_dynamic(const char *execnam
 	}
 
 #ifdef RTLD_LOADER
+#if defined(__HAVE_FUNCTION_DESCRIPTORS)
+ 	if (init != 0)
+		obj->init = (void (*)(void))
+		_rtld_function_descriptor_alloc(obj, NULL, init);
+ 	if (fini != 0)
+		obj->fini = (void (*)(void))
+		_rtld_function_descriptor_alloc(obj, NULL, fini);
+#else
 	if (init != 0)
-		obj->init = (Elf_Addr) obj->relocbase + init;
+		obj->init = (void (*)(void)) (obj->relocbase + init);
 	if (fini != 0)
-		obj->fini = (Elf_Addr) obj->relocbase + fini;
+		obj->fini = (void (*)(void)) (obj->relocbase + fini);
+#endif
 #endif
 
 	if (dyn_rpath != NULL) {

Index: src/libexec/ld.elf_so/rtld.c
diff -u src/libexec/ld.elf_so/rtld.c:1.209 src/libexec/ld.elf_so/rtld.c:1.210
--- src/libexec/ld.elf_so/rtld.c:1.209	Wed Jun 16 21:53:51 2021
+++ src/libexec/ld.elf_so/rtld.c	Sat Dec  4 14:39:08 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.209 2021/06/16 21:53:51 riastradh Exp $	 */
+/*	$NetBSD: rtld.c,v 1.210 2021/12/04 14:39:08 skrll Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.209 2021/06/16 21:53:51 riastradh Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.210 2021/12/04 14:39:08 skrll Exp $");
 #endif /* not lint */
 
 #include 
@@ -137,25 +137,25 @@ static Obj_Entry *_rtld_obj_from_addr(co
 static void _rtld_fill_dl_phdr_info(const Obj_Entry *, struct dl_phdr_info *);
 
 static inline void
-_rtld_call_initfini_function(const Obj_Entry *obj, Elf_Addr func, sigset_t *mask)
+_rtld_call_initfini_function(fptr_t func, sigset_t *mask)
 {
 	_rtld_exclusive_exit(mask);
-	_rtld_call_function_void(obj, func);
+	(*func)();
 	_rtld_exclusive_enter(mask);
 }
 
 static void
 _rtld_call_fini_function(Obj_Entry *obj, sigset_t *mask, u_int cur_objgen)
 {
-	if (obj->fini_arraysz == 0 && (obj->fini == 0 || obj->fini_called))
+	if (obj->fini_arraysz == 0 && (obj->fini == NULL || obj->fini_called))
 		return;
 
-	if (obj->fini != 0 && !obj->fini_called) {
+	if (obj->fini != NULL && !obj->fini_called) {
 		dbg (("calling fini function %s at %p%s", obj->path,
 		(void *)obj->fini,
 		obj->z_initfirst ? " (DF_1_INITFIRST)" : ""));
 		obj->fini_called = 1;
-		_rtld_call_initfini_function(obj, obj->fini, mask);
+		_rtld_call_initfini_function(obj->fini, mask);
 	}
 #ifdef HAVE_INITFINI_ARRAY
 	/*
@@ -165,12 +165,12 @@ _rtld_call_fini_function(Obj_Entry *obj,
 	 * the loop.
 	 */
 	while (obj->fini_arraysz > 0 && _rtld_objgen == cur_objgen) {
-		Elf_Addr fini = *obj->fini_array++;
+		fptr_t fini = *obj->fini_array++;
 		obj->fini_arraysz--;
 		dbg (("calling fini array function %s at %p%s", obj->path,
 		

CVS commit: src/libexec/ld.elf_so

2019-10-13 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Oct 13 20:18:42 UTC 2019

Modified Files:
src/libexec/ld.elf_so: search.c

Log Message:
use strlcpy to ensure termination.

the buffer is statically sized so that it works without an
allocator, so truncation is the desired effect here.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/libexec/ld.elf_so/search.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/search.c
diff -u src/libexec/ld.elf_so/search.c:1.25 src/libexec/ld.elf_so/search.c:1.26
--- src/libexec/ld.elf_so/search.c:1.25	Sat Jan 12 18:58:10 2019
+++ src/libexec/ld.elf_so/search.c	Sun Oct 13 20:18:42 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: search.c,v 1.25 2019/01/12 18:58:10 christos Exp $	 */
+/*	$NetBSD: search.c,v 1.26 2019/10/13 20:18:42 mrg Exp $	 */
 
 /*
  * Copyright 1996 Matt Thomas 
@@ -38,7 +38,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: search.c,v 1.25 2019/01/12 18:58:10 christos Exp $");
+__RCSID("$NetBSD: search.c,v 1.26 2019/10/13 20:18:42 mrg Exp $");
 #endif /* not lint */
 
 #include 
@@ -138,7 +138,7 @@ _rtld_load_library(const char *name, con
 
 	tmperrorp = dlerror();
 	if (tmperrorp != NULL) {
-		strncpy(tmperror, tmperrorp, sizeof tmperror);
+		strlcpy(tmperror, tmperrorp, sizeof(tmperror));
 		tmperrorp = tmperror;
 	}
 



CVS commit: src/libexec/ld.elf_so

2019-10-13 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Oct 13 20:18:42 UTC 2019

Modified Files:
src/libexec/ld.elf_so: search.c

Log Message:
use strlcpy to ensure termination.

the buffer is statically sized so that it works without an
allocator, so truncation is the desired effect here.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/libexec/ld.elf_so/search.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2024-07-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Jul 22 23:14:25 UTC 2024

Modified Files:
src/libexec/ld.elf_so: README.TLS tls.c

Log Message:
ld.elf_so: Sprinkle comments and references for thread-local storage.

Maybe this will help the TLS business to be less mysterious to the
next traveller to pass by here.

Prompted by PR lib/58154.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/libexec/ld.elf_so/README.TLS
cvs rdiff -u -r1.19 -r1.20 src/libexec/ld.elf_so/tls.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2024-07-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Jul 22 23:14:25 UTC 2024

Modified Files:
src/libexec/ld.elf_so: README.TLS tls.c

Log Message:
ld.elf_so: Sprinkle comments and references for thread-local storage.

Maybe this will help the TLS business to be less mysterious to the
next traveller to pass by here.

Prompted by PR lib/58154.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/libexec/ld.elf_so/README.TLS
cvs rdiff -u -r1.19 -r1.20 src/libexec/ld.elf_so/tls.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/README.TLS
diff -u src/libexec/ld.elf_so/README.TLS:1.6 src/libexec/ld.elf_so/README.TLS:1.7
--- src/libexec/ld.elf_so/README.TLS:1.6	Sun Jun  4 01:24:56 2023
+++ src/libexec/ld.elf_so/README.TLS	Mon Jul 22 23:14:25 2024
@@ -1,11 +1,111 @@
+Thread-local storage.
+
+Each thread has a thread control block, or TCB.  The TCB is a
+variable-size structure headed by `struct tls_tcb' from ,
+with:
+
+(a) static thread-local storage for the TLS data of initial objects,
+i.e., those loaded at startup rather than those dynamically loaded
+by dlopen
+
+(b) a pointer to a dynamic thread vector (DTV) for the TLS data
+pointers of objects that use global-dynamic or local-dynamic models
+(typically shared libraries or dlopenable modules)
+
+(c) the pthread_t pointer
+
+The per-thread lwp private pointer, also sometimes called TP (thread
+pointer), managed by the _lwp_setprivate and _lwp_setprivate syscalls,
+either points at the TCB directly, or, on some architectures, points at
+
+	tp = tcb + sizeof(struct tls_tcb) + TLS_TP_OFFSET.
+
+This bias is chosen for architectures where signed displacements from
+TP enable twice the range of static TLS offsets when biased like this.
+Architectures with such a tp/tcb offset must provide
+
+void *__lwp_gettcb_fast(void);
+
+in machine/mcontext.h and must define __HAVE___LWP_GETTCB_FAST in
+machine/types.h to reflect this; otherwise they must provide
+__lwp_getprivate_fast to return the TCB pointer.
+
+Each architecture has one of two TLS variants, variant I or variant II.
+Variant I places the static thread-local storage _after_ the fixed
+content of the TCB, at increasing addresses (increasing addresses grow
+down in diagram):
+
+	+---+
+	| dtv pointer   |   tcb points here (struct tls_tcb)
+	+---+
+	| pthread_t |
+	+---+
+	| obj0 tls  |   obj0->tlsoffset = 0
+	|   |
+	|   |
+	+---+
+	| obj1 tls  |   obj1->tlsoffset = 3
+	+---+
+	| obj2 tls  |   obj2->tlsoffset = 4
+	|   |
+	.		.
+	.		.
+	.		.
+	|   |
+	+---+
+	| objN tls  |   objN->tlsoffset = k
+	+---+
+
+Variant II places the static thread-local storage _before_ the fixed
+content of the TCB, at decreasing addresses:
+
+	+---+
+	| objN tls  |   objN->tlsoffset = k
+	+---+
+	| obj(N-1) tls  |   obj(N-1)->tlsoffset = k - 1
+	.   .
+	.   .
+	.   .
+	|   |
+	+---+
+	| obj2 tls  |   obj2->tlsoffset = 4
+	+---+
+	| obj1 tls  |   obj1->tlsoffset = 3
+	+---+
+	| obj0 tls  |   obj0->tlsoffset = 0
+	|   |
+	|   |
+	+---+
+	| tcb pointer   |   tcb points here (struct tls_tcb)
+	+---+
+	| dtv pointer   |
+	+---+
+	| pthread_t |
+	+---+
+
+See [ELFTLS] Sec. 3 `Run-Time Handling of TLS', Figs 1 and 2, for
+bigger pictures including the DTV and dynamically allocated TLS blocks.
+
+Each architecture also has its own ELF ABI processor supplement with
+the architecture-specific relocations and TLS details.
+
+References:
+
+	[ELFTLS] Ulrich Drepper, `ELF Handling For Thread-Local
+	Storage', Version 0.21, 2023-08-22.
+	https://akkadia.org/drepper/tls.pdf
+	https://web.archive.org/web/20240718081934/https://akkadia.org/drepper/tls.pdf
+
 Steps for adding TLS support for a new platform:
 
 (1) Declare TLS variant in machine/types.h by defining either
 __HAVE_TLS_VARIANT_I or __HAVE_TLS_VARIANT_II.
 
-(2) _lwp_makecontext has to set the reserved register or kernel transfer
-variable in uc_mcontext to the provided value of 'private'. See
-src/lib/libc/arch/$PLATFORM/gen/_lwp.c.
+(2) _lwp_makecontext has to set the reserved register or kernel
+transfer variable in uc_mcontext according to the provided value of
+`private'.  Note that _lwp_makecontext takes tcb, not tp, as an
+argument, so make sure to adjust it if needed for the tp/tcb offset.
+See src/lib/libc/arch/$PLATFORM/gen/_lwp.c.
 
 This is not possible on the VAX as there is no free space in ucontext_t.
 This requires either a special version of _lwp_create or versioning
@@ -60,9 +160,22 @@ def->st_value - defobj->tlsoffset 

CVS commit: src/libexec/ld.elf_so

2024-07-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Jul 22 23:15:57 UTC 2024

Modified Files:
src/libexec/ld.elf_so: tls.c

Log Message:
ld.elf_so: Add comments explaining DTV allocation size.

Patch by pho@ for PR lib/58154.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/libexec/ld.elf_so/tls.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2024-07-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Jul 22 23:15:57 UTC 2024

Modified Files:
src/libexec/ld.elf_so: tls.c

Log Message:
ld.elf_so: Add comments explaining DTV allocation size.

Patch by pho@ for PR lib/58154.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/libexec/ld.elf_so/tls.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/tls.c
diff -u src/libexec/ld.elf_so/tls.c:1.20 src/libexec/ld.elf_so/tls.c:1.21
--- src/libexec/ld.elf_so/tls.c:1.20	Mon Jul 22 23:14:25 2024
+++ src/libexec/ld.elf_so/tls.c	Mon Jul 22 23:15:57 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: tls.c,v 1.20 2024/07/22 23:14:25 riastradh Exp $	*/
+/*	$NetBSD: tls.c,v 1.21 2024/07/22 23:15:57 riastradh Exp $	*/
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,7 +29,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: tls.c,v 1.20 2024/07/22 23:14:25 riastradh Exp $");
+__RCSID("$NetBSD: tls.c,v 1.21 2024/07/22 23:15:57 riastradh Exp $");
 
 /*
  * Thread-local storage
@@ -164,6 +164,10 @@ _rtld_tls_get_addr(void *tls, size_t idx
 	if (__predict_false(DTV_GENERATION(dtv) != _rtld_tls_dtv_generation)) {
 		size_t to_copy = DTV_MAX_INDEX(dtv);
 
+		/*
+		 * "2 +" because the first element is the generation and
+		 * the second one is the maximum index.
+		 */
 		new_dtv = xcalloc((2 + _rtld_tls_max_index) * sizeof(*dtv));
 		++new_dtv;		/* advance past DTV_MAX_INDEX */
 		if (to_copy > _rtld_tls_max_index)	/* XXX How? */
@@ -248,6 +252,10 @@ _rtld_tls_allocate_locked(void)
 	tcb->tcb_self = tcb;
 #endif
 	dbg(("lwp %d tls tcb %p", _lwp_self(), tcb));
+	/*
+	 * "2 +" because the first element is the generation and the second
+	 * one is the maximum index.
+	 */
 	tcb->tcb_dtv = xcalloc(sizeof(*tcb->tcb_dtv) * (2 + _rtld_tls_max_index));
 	++tcb->tcb_dtv;		/* advance past DTV_MAX_INDEX */
 	SET_DTV_MAX_INDEX(tcb->tcb_dtv, _rtld_tls_max_index);



CVS commit: src/libexec/ld.elf_so

2024-07-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 23 22:00:00 UTC 2024

Modified Files:
src/libexec/ld.elf_so: tls.c

Log Message:
ld.elf_so: Fix off-by-one error in common __tls_get_addr.

DTV_MAX_INDEX(dtv) is an _inclusive_ upper bound, i.e., the actual
maximum value of the allowed indices.  It is not an exclusive upper
bound -- it is not the number of allowed indices.

This off-by-one doesn't hurt correctness, but it may hurt performance
by using the slow path when the fast path would be safe.

Found by pho@ in PR lib/58154.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/libexec/ld.elf_so/tls.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2024-07-23 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 23 22:00:00 UTC 2024

Modified Files:
src/libexec/ld.elf_so: tls.c

Log Message:
ld.elf_so: Fix off-by-one error in common __tls_get_addr.

DTV_MAX_INDEX(dtv) is an _inclusive_ upper bound, i.e., the actual
maximum value of the allowed indices.  It is not an exclusive upper
bound -- it is not the number of allowed indices.

This off-by-one doesn't hurt correctness, but it may hurt performance
by using the slow path when the fast path would be safe.

Found by pho@ in PR lib/58154.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/libexec/ld.elf_so/tls.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/tls.c
diff -u src/libexec/ld.elf_so/tls.c:1.21 src/libexec/ld.elf_so/tls.c:1.22
--- src/libexec/ld.elf_so/tls.c:1.21	Mon Jul 22 23:15:57 2024
+++ src/libexec/ld.elf_so/tls.c	Tue Jul 23 22:00:00 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: tls.c,v 1.21 2024/07/22 23:15:57 riastradh Exp $	*/
+/*	$NetBSD: tls.c,v 1.22 2024/07/23 22:00:00 riastradh Exp $	*/
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,7 +29,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: tls.c,v 1.21 2024/07/22 23:15:57 riastradh Exp $");
+__RCSID("$NetBSD: tls.c,v 1.22 2024/07/23 22:00:00 riastradh Exp $");
 
 /*
  * Thread-local storage
@@ -523,7 +523,7 @@ __tls_get_addr(void *arg_)
 	 * application bug if code of the module is still running at
 	 * that point.
 	 */
-	if (__predict_true(idx < DTV_MAX_INDEX(dtv) && dtv[idx] != NULL))
+	if (__predict_true(idx <= DTV_MAX_INDEX(dtv) && dtv[idx] != NULL))
 		return (uint8_t *)dtv[idx] + offset;
 
 	return _rtld_tls_get_addr(tcb, idx, offset);



CVS commit: src/libexec/ld.elf_so

2024-08-02 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Aug  2 11:45:52 UTC 2024

Modified Files:
src/libexec/ld.elf_so: map_object.c

Log Message:
KNF


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/libexec/ld.elf_so/map_object.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2024-08-02 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Aug  2 11:45:52 UTC 2024

Modified Files:
src/libexec/ld.elf_so: map_object.c

Log Message:
KNF


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/libexec/ld.elf_so/map_object.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/map_object.c
diff -u src/libexec/ld.elf_so/map_object.c:1.67 src/libexec/ld.elf_so/map_object.c:1.68
--- src/libexec/ld.elf_so/map_object.c:1.67	Sun Jun  4 01:24:56 2023
+++ src/libexec/ld.elf_so/map_object.c	Fri Aug  2 11:45:52 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: map_object.c,v 1.67 2023/06/04 01:24:56 joerg Exp $	 */
+/*	$NetBSD: map_object.c,v 1.68 2024/08/02 11:45:52 skrll Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -34,7 +34,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: map_object.c,v 1.67 2023/06/04 01:24:56 joerg Exp $");
+__RCSID("$NetBSD: map_object.c,v 1.68 2024/08/02 11:45:52 skrll Exp $");
 #endif /* not lint */
 
 #include 
@@ -376,7 +376,9 @@ _rtld_map_object(const char *path, int f
 			- base_vaddr);
 
 			if ((nclear = data_vlimit - clear_vaddr) > 0) {
-/* Make sure the end of the segment is writable
+/*
+ * Make sure the end of the segment is
+ * writable.
  */
 if ((data_prot & PROT_WRITE) == 0 && -1 ==
  mprotect(clear_page, _rtld_pagesz,



CVS commit: src/libexec/ld.elf_so

2024-08-03 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Aug  3 21:59:59 UTC 2024

Modified Files:
src/libexec/ld.elf_so: debug.h headers.c map_object.c
src/libexec/ld.elf_so/arch/alpha: alpha_reloc.c
src/libexec/ld.elf_so/arch/arm: mdreloc.c
src/libexec/ld.elf_so/arch/i386: mdreloc.c
src/libexec/ld.elf_so/arch/mips: mips_reloc.c rtld_start.S
src/libexec/ld.elf_so/arch/or1k: mdreloc.c
src/libexec/ld.elf_so/arch/powerpc: ppc_reloc.c
src/libexec/ld.elf_so/arch/sparc: mdreloc.c
src/libexec/ld.elf_so/arch/sparc64: mdreloc.c rtld_start.S
src/libexec/ld.elf_so/arch/vax: rtld_start.S
src/libexec/ld.elf_so/arch/x86_64: mdreloc.c

Log Message:
ld.elf_so(1): Nix trailing whitespace.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/libexec/ld.elf_so/debug.h
cvs rdiff -u -r1.71 -r1.72 src/libexec/ld.elf_so/headers.c
cvs rdiff -u -r1.68 -r1.69 src/libexec/ld.elf_so/map_object.c
cvs rdiff -u -r1.44 -r1.45 src/libexec/ld.elf_so/arch/alpha/alpha_reloc.c
cvs rdiff -u -r1.47 -r1.48 src/libexec/ld.elf_so/arch/arm/mdreloc.c
cvs rdiff -u -r1.43 -r1.44 src/libexec/ld.elf_so/arch/i386/mdreloc.c
cvs rdiff -u -r1.75 -r1.76 src/libexec/ld.elf_so/arch/mips/mips_reloc.c
cvs rdiff -u -r1.10 -r1.11 src/libexec/ld.elf_so/arch/mips/rtld_start.S
cvs rdiff -u -r1.4 -r1.5 src/libexec/ld.elf_so/arch/or1k/mdreloc.c
cvs rdiff -u -r1.64 -r1.65 src/libexec/ld.elf_so/arch/powerpc/ppc_reloc.c
cvs rdiff -u -r1.59 -r1.60 src/libexec/ld.elf_so/arch/sparc/mdreloc.c
cvs rdiff -u -r1.71 -r1.72 src/libexec/ld.elf_so/arch/sparc64/mdreloc.c
cvs rdiff -u -r1.17 -r1.18 src/libexec/ld.elf_so/arch/sparc64/rtld_start.S
cvs rdiff -u -r1.24 -r1.25 src/libexec/ld.elf_so/arch/vax/rtld_start.S
cvs rdiff -u -r1.48 -r1.49 src/libexec/ld.elf_so/arch/x86_64/mdreloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so

2024-08-03 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Aug  3 21:59:59 UTC 2024

Modified Files:
src/libexec/ld.elf_so: debug.h headers.c map_object.c
src/libexec/ld.elf_so/arch/alpha: alpha_reloc.c
src/libexec/ld.elf_so/arch/arm: mdreloc.c
src/libexec/ld.elf_so/arch/i386: mdreloc.c
src/libexec/ld.elf_so/arch/mips: mips_reloc.c rtld_start.S
src/libexec/ld.elf_so/arch/or1k: mdreloc.c
src/libexec/ld.elf_so/arch/powerpc: ppc_reloc.c
src/libexec/ld.elf_so/arch/sparc: mdreloc.c
src/libexec/ld.elf_so/arch/sparc64: mdreloc.c rtld_start.S
src/libexec/ld.elf_so/arch/vax: rtld_start.S
src/libexec/ld.elf_so/arch/x86_64: mdreloc.c

Log Message:
ld.elf_so(1): Nix trailing whitespace.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/libexec/ld.elf_so/debug.h
cvs rdiff -u -r1.71 -r1.72 src/libexec/ld.elf_so/headers.c
cvs rdiff -u -r1.68 -r1.69 src/libexec/ld.elf_so/map_object.c
cvs rdiff -u -r1.44 -r1.45 src/libexec/ld.elf_so/arch/alpha/alpha_reloc.c
cvs rdiff -u -r1.47 -r1.48 src/libexec/ld.elf_so/arch/arm/mdreloc.c
cvs rdiff -u -r1.43 -r1.44 src/libexec/ld.elf_so/arch/i386/mdreloc.c
cvs rdiff -u -r1.75 -r1.76 src/libexec/ld.elf_so/arch/mips/mips_reloc.c
cvs rdiff -u -r1.10 -r1.11 src/libexec/ld.elf_so/arch/mips/rtld_start.S
cvs rdiff -u -r1.4 -r1.5 src/libexec/ld.elf_so/arch/or1k/mdreloc.c
cvs rdiff -u -r1.64 -r1.65 src/libexec/ld.elf_so/arch/powerpc/ppc_reloc.c
cvs rdiff -u -r1.59 -r1.60 src/libexec/ld.elf_so/arch/sparc/mdreloc.c
cvs rdiff -u -r1.71 -r1.72 src/libexec/ld.elf_so/arch/sparc64/mdreloc.c
cvs rdiff -u -r1.17 -r1.18 src/libexec/ld.elf_so/arch/sparc64/rtld_start.S
cvs rdiff -u -r1.24 -r1.25 src/libexec/ld.elf_so/arch/vax/rtld_start.S
cvs rdiff -u -r1.48 -r1.49 src/libexec/ld.elf_so/arch/x86_64/mdreloc.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/debug.h
diff -u src/libexec/ld.elf_so/debug.h:1.7 src/libexec/ld.elf_so/debug.h:1.8
--- src/libexec/ld.elf_so/debug.h:1.7	Sat Aug  3 13:17:05 2013
+++ src/libexec/ld.elf_so/debug.h	Sat Aug  3 21:59:57 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: debug.h,v 1.7 2013/08/03 13:17:05 skrll Exp $	*/
+/*	$NetBSD: debug.h,v 1.8 2024/08/03 21:59:57 riastradh Exp $	*/
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -55,7 +55,7 @@ extern int debug;
 # define rdbg(a)	((void) 0)
 #endif
 
-#if ELFSIZE == 64   
+#if ELFSIZE == 64
 #define	PRImemsz	PRIu64
 #else
 #define	PRImemsz	PRIu32

Index: src/libexec/ld.elf_so/headers.c
diff -u src/libexec/ld.elf_so/headers.c:1.71 src/libexec/ld.elf_so/headers.c:1.72
--- src/libexec/ld.elf_so/headers.c:1.71	Wed Jan  4 01:37:24 2023
+++ src/libexec/ld.elf_so/headers.c	Sat Aug  3 21:59:57 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: headers.c,v 1.71 2023/01/04 01:37:24 christos Exp $	 */
+/*	$NetBSD: headers.c,v 1.72 2024/08/03 21:59:57 riastradh Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: headers.c,v 1.71 2023/01/04 01:37:24 christos Exp $");
+__RCSID("$NetBSD: headers.c,v 1.72 2024/08/03 21:59:57 riastradh Exp $");
 #endif /* not lint */
 
 #include 
@@ -435,10 +435,10 @@ _rtld_digest_dynamic(const char *execnam
 
 #ifdef RTLD_LOADER
 #if defined(__HAVE_FUNCTION_DESCRIPTORS)
- 	if (init != 0)
+	if (init != 0)
 		obj->init = (void (*)(void))
 		_rtld_function_descriptor_alloc(obj, NULL, init);
- 	if (fini != 0)
+	if (fini != 0)
 		obj->fini = (void (*)(void))
 		_rtld_function_descriptor_alloc(obj, NULL, fini);
 #else

Index: src/libexec/ld.elf_so/map_object.c
diff -u src/libexec/ld.elf_so/map_object.c:1.68 src/libexec/ld.elf_so/map_object.c:1.69
--- src/libexec/ld.elf_so/map_object.c:1.68	Fri Aug  2 11:45:52 2024
+++ src/libexec/ld.elf_so/map_object.c	Sat Aug  3 21:59:57 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: map_object.c,v 1.68 2024/08/02 11:45:52 skrll Exp $	 */
+/*	$NetBSD: map_object.c,v 1.69 2024/08/03 21:59:57 riastradh Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -34,7 +34,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: map_object.c,v 1.68 2024/08/02 11:45:52 skrll Exp $");
+__RCSID("$NetBSD: map_object.c,v 1.69 2024/08/03 21:59:57 riastradh Exp $");
 #endif /* not lint */
 
 #include 
@@ -359,7 +359,7 @@ _rtld_map_object(const char *path, int f
 		data_prot = convert_prot(segs[i]->p_flags);
 		data_flags = convert_flags(segs[i]->p_flags) | MAP_FIXED;
 		if (data_vlimit != data_vaddr &&
-		mmap(data_addr, data_vlimit - data_vaddr, data_prot, 
+		mmap(data_addr, data_vlimit - data_vaddr, data_prot,
 		data_flags, fd, data_offset) == MAP_FAILED) {
 			_rtld_error("%s: mmap of data failed: %s", path,
 			xstrerror(errno));

Index: src/libexec/ld.elf_so/arch/alpha/alpha_reloc.c
diff -u src/libexec/ld.elf_so/arch/alpha/alpha_reloc.c:1.44 src/libexec/ld.elf_so/arch/alpha/alpha_reloc.c:1.45
---

CVS commit: src/libexec/ld.elf_so/arch

2010-01-14 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Jan 14 11:57:06 UTC 2010

Modified Files:
src/libexec/ld.elf_so/arch/alpha: alpha_reloc.c
src/libexec/ld.elf_so/arch/arm: mdreloc.c
src/libexec/ld.elf_so/arch/hppa: hppa_reloc.c
src/libexec/ld.elf_so/arch/mips: mips_reloc.c

Log Message:
Shut gcc up.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/libexec/ld.elf_so/arch/alpha/alpha_reloc.c
cvs rdiff -u -r1.31 -r1.32 src/libexec/ld.elf_so/arch/arm/mdreloc.c
cvs rdiff -u -r1.31 -r1.32 src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c
cvs rdiff -u -r1.57 -r1.58 src/libexec/ld.elf_so/arch/mips/mips_reloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so/arch

2010-01-14 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Jan 14 11:58:32 UTC 2010

Modified Files:
src/libexec/ld.elf_so/arch/alpha: alpha_reloc.c
src/libexec/ld.elf_so/arch/i386: mdreloc.c
src/libexec/ld.elf_so/arch/m68k: mdreloc.c

Log Message:
Wrap a few long lines.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/libexec/ld.elf_so/arch/alpha/alpha_reloc.c
cvs rdiff -u -r1.30 -r1.31 src/libexec/ld.elf_so/arch/i386/mdreloc.c
cvs rdiff -u -r1.25 -r1.26 src/libexec/ld.elf_so/arch/m68k/mdreloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: CVS commit: src/libexec/ld.elf_so

2010-03-19 Thread Matthias Scheler
On Thu, Mar 18, 2010 at 10:17:55PM +, Roy Marples wrote:
> Log Message:
> Use alloca(3) instead of local xmalloc for creating our DoneLists.
> This allows threaded programs to use us a little better, PR lib/43005.
> We need to disable SSP when using alloca.

No, you don't. You only need to disable the warnings which would tell
you that the *particular* function which uses alloca(3) cannot be
protected. Please look at the end of "src/sys/conf/Makefile.inc"
how to handle this and update your change accordingly.

Kind regards

-- 
Matthias Scheler  http://zhadum.org.uk/


Re: CVS commit: src/libexec/ld.elf_so

2012-12-16 Thread David Laight
On Sun, Dec 16, 2012 at 11:15:21AM +, David Laight wrote:
> Module Name:  src
> Committed By: dsl
> Date: Sun Dec 16 11:15:21 UTC 2012
> 
> Modified Files:
>   src/libexec/ld.elf_so: rtld.c
> 
> Log Message:
> You need to pass 0 (not -1) to lwp_park() if you don't also
>   want to do an unpark.
> Clearly this code path was never tested!
> Needs pullup to netbsd-6

Note that since this caused the code to spin forever, there must
be something else wrong otherwise I'd have thought it would
have made progress.

David

-- 
David Laight: da...@l8s.co.uk


Re: CVS commit: src/libexec/ld.elf_so

2018-12-28 Thread Rin Okuyama

Hi,

On 2018/12/28 3:58, Christos Zoulas wrote:

Module Name:src
Committed By:   christos
Date:   Thu Dec 27 18:58:14 UTC 2018

Modified Files:
src/libexec/ld.elf_so: Makefile
src/libexec/ld.elf_so/arch/aarch64: Makefile.inc
src/libexec/ld.elf_so/arch/arm: Makefile.inc
src/libexec/ld.elf_so/arch/riscv: Makefile.inc

Log Message:
initfini array support for everyone.


To generate a diff of this commit:
cvs rdiff -u -r1.139 -r1.140 src/libexec/ld.elf_so/Makefile
cvs rdiff -u -r1.1 -r1.2 src/libexec/ld.elf_so/arch/aarch64/Makefile.inc
cvs rdiff -u -r1.21 -r1.22 src/libexec/ld.elf_so/arch/arm/Makefile.inc
cvs rdiff -u -r1.1 -r1.2 src/libexec/ld.elf_so/arch/riscv/Makefile.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.


This breaks GCC on m68k; gcc and g++ receive SIGSEGV when compiling
hello.c. Please find a backtrace of cc1plus below (cc1 does not dump
a core). The problem does not occur if initfini array support is
disabled for libexec/ld.elf_so and lib/csu. Thoughts?

Thanks,
rin

# g++ hello.c
g++: internal compiler error: Segmentation fault (program cc1plus received 
signal 11)
Please submit a full bug report,
with preprocessed source if appropriate.
See  for instructions.
# ls *.core
cc1plus.core
# gdb /usr/libexec/cc1plus cc1plus.core
GNU gdb (GDB) 8.0.1
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "m68k--netbsdelf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
.
Find the GDB manual and other documentation resources online at:
.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /usr/libexec/cc1plus...Reading symbols from 
/usr/libdata/debug//usr/libexec/cc1plus.debug...done.
done.
[New process 1]

warning: Error reading shared library list entry at 0x4

warning: Error reading shared library list entry at 0x74843b1e
Core was generated by `cc1plus'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x008b4390 in va_heap::release<(anonymous namespace)::line_span> (
v=@0xbc2f88: 0x0)
at /var/build/src/external/gpl3/gcc.old/dist/gcc/vec.h:307
307::free (v);
(gdb) bt
#0  0x008b4390 in va_heap::release<(anonymous namespace)::line_span> (
v=@0xbc2f88: 0x0)
at /var/build/src/external/gpl3/gcc.old/dist/gcc/vec.h:307
#1  vec<(anonymous namespace)::line_span, va_heap, vl_ptr>::release (
this=0xbc2f88 )
at /var/build/src/external/gpl3/gcc.old/dist/gcc/vec.h:1460
#2  0x00111368 in init_operators ()
at /var/build/src/external/gpl3/gcc.old/dist/gcc/cp/operators.def:142
#3  cxx_init () at /var/build/src/external/gpl3/gcc.old/dist/gcc/cp/lex.c:248
#4  0x0017f518 in build_vec_init_elt (type=0xf100d80, init=0x2, complain=1)
at /var/build/src/external/gpl3/gcc.old/dist/gcc/cp/tree.c:561
#5  0x0018099c in gt_ggc_mx (h=0x1dffee84,
h=0x1dffee84)
at /var/build/src/external/gpl3/gcc.old/dist/gcc/hash-table.h:1020
#6  gt_ggc_mx_hash_table_cxx_int_tree_map_hasher_ (x_p=0xf100d80)
at 
/var/build/src/external/gpl3/gcc.old/usr.bin/backend/obj.amiga-m68k/gt-cp-tree.h:78
#7  0x0010f894 in language_to_string (c=)
at /var/build/src/external/gpl3/gcc.old/dist/gcc/cp/error.c:3013
#8  cp_printer (pp=0xbfb510, text=0x1dffef04, spec=0x0, precision=255926280,
wide=4, set_locus=10, verbose=196)
at /var/build/src/external/gpl3/gcc.old/dist/gcc/cp/error.c:3562
#9  0x008b8df6 in hash_pointer (p=0xbfb510)
at /var/build/src/external/gpl3/gcc.old/dist/libiberty/hashtab.c:996
#10 0x008b98e4 in htab_collisions (htab=0xa49adc)
at /var/build/src/external/gpl3/gcc.old/dist/libiberty/hashtab.c:804
#11 0x002f6b32 in go_define (lineno=, buffer=)
at /var/build/src/external/gpl3/gcc.old/dist/gcc/godump.c:283
#12 0x0ed57084 in ?? ()
#13 0x000b in ?? ()
#14 0x1dffef98 in ?? ()
#15 0x1dfff018 in ?? ()
#16 0x000b in ?? ()
#17 0x0001 in ?? ()
#18 0x in ?? ()
(gdb) q
#


Re: CVS commit: src/libexec/ld.elf_so

2018-12-28 Thread maya
Does anything simpler than GCC crash?

BTW while looking at it I noticed GCC has
gcc/arch/vax/auto-host.h
1389:#define HAVE_INITFINI_ARRAY_SUPPORT 0

So we might wanna re-run mknative at the end.


Re: CVS commit: src/libexec/ld.elf_so

2018-12-28 Thread Christos Zoulas
On Dec 28,  3:49pm, m...@netbsd.org (m...@netbsd.org) wrote:
-- Subject: Re: CVS commit: src/libexec/ld.elf_so

| Does anything simpler than GCC crash?
| 
| BTW while looking at it I noticed GCC has
| gcc/arch/vax/auto-host.h
| 1389:#define HAVE_INITFINI_ARRAY_SUPPORT 0
| 
| So we might wanna re-run mknative at the end.

Let's not go there now. We should not be modifying more stuff.
The thing to do is to revert to the old working state.
Then build and install the new csu code, build and install the
tests in lib/csu and then see if they work. If they don't we
should debug the simple tests first. If they work, then build
and install the new rtld and run the tests again.

If all of that works, then constructors work properly, and the
rest should also work (without modifying compilers and toolchain).

christos



Re: CVS commit: src/libexec/ld.elf_so

2018-12-31 Thread Joerg Sonnenberger
On Sat, Dec 29, 2018 at 08:48:37PM -0500, Christos Zoulas wrote:
> Module Name:  src
> Committed By: christos
> Date: Sun Dec 30 01:48:37 UTC 2018
> 
> Modified Files:
>   src/libexec/ld.elf_so: reloc.c rtld.c rtld.h
> 
> Log Message:
> binutils 2.31.1 can put copy relocations in the relro segment. Delay
> protecting the relro segment for the main object until copy relocations
> are done.

This sounds really really wrong...

Joerg


Re: CVS commit: src/libexec/ld.elf_so

2019-01-01 Thread Martin Husemann
On Tue, Jan 01, 2019 at 04:18:06AM +0100, Joerg Sonnenberger wrote:
> On Sat, Dec 29, 2018 at 08:48:37PM -0500, Christos Zoulas wrote:
> > Module Name:src
> > Committed By:   christos
> > Date:   Sun Dec 30 01:48:37 UTC 2018
> > 
> > Modified Files:
> > src/libexec/ld.elf_so: reloc.c rtld.c rtld.h
> > 
> > Log Message:
> > binutils 2.31.1 can put copy relocations in the relro segment. Delay
> > protecting the relro segment for the main object until copy relocations
> > are done.
> 
> This sounds really really wrong...

I agree - smells like a binutils bug to me.

Martin


Re: CVS commit: src/libexec/ld.elf_so

2019-04-15 Thread Christoph Badura
On Sun, Apr 14, 2019 at 08:27:02PM +, Maya Rashish wrote:
> Module Name:  src
> Committed By: maya
> Date: Sun Apr 14 20:27:02 UTC 2019
> Modified Files:
>   src/libexec/ld.elf_so: ld.elf_so.1
> Log Message:
> Note that we now search DT_RUNPATH paths as well.

This doesn't document what happens when bot DT_RPATH and DT_RUNPATH are
present.

Man pages are reference documentation.  The need to document actual
semantics.

--chris


Re: CVS commit: src/libexec/ld.elf_so

2019-04-15 Thread maya
On Mon, Apr 15, 2019 at 10:57:17AM +0200, Christoph Badura wrote:
> On Sun, Apr 14, 2019 at 08:27:02PM +, Maya Rashish wrote:
> > Module Name:src
> > Committed By:   maya
> > Date:   Sun Apr 14 20:27:02 UTC 2019
> > Modified Files:
> > src/libexec/ld.elf_so: ld.elf_so.1
> > Log Message:
> > Note that we now search DT_RUNPATH paths as well.
> 
> This doesn't document what happens when bot DT_RPATH and DT_RUNPATH are
> present.
> 
> Man pages are reference documentation.  The need to document actual
> semantics.
> 
> --chris

If I am reading things correctly, the later one that appears on the list
of headers is respected.

Our respecting of DT_RUNPATH is mostly a hack to deal with upstreams
that do things like read the ELF spec that calls RPATH deprecated.

I would really like not to re-ignite this discussion, it took a lot of
time until we got an OK to do it, and the time wasted by people not
understanding why random binaries failed to run was staggering.


Re: CVS commit: src/libexec/ld.elf_so

2019-04-15 Thread Martin Husemann
On Mon, Apr 15, 2019 at 09:16:22AM +, m...@netbsd.org wrote:
> If I am reading things correctly, the later one that appears on the list
> of headers is respected.

Indeed. AFAICT a binary must not have both.

Martin


CVS commit: src/libexec/ld.elf_so/arch

2024-07-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Jul 22 23:10:35 UTC 2024

Modified Files:
src/libexec/ld.elf_so/arch/aarch64: mdreloc.c
src/libexec/ld.elf_so/arch/arm: mdreloc.c

Log Message:
ld.elf_so: Cite reference for Arm ELF relocations.

PR lib/58455: Missing references for processor-specific ELF
relocation semantics


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/libexec/ld.elf_so/arch/aarch64/mdreloc.c
cvs rdiff -u -r1.46 -r1.47 src/libexec/ld.elf_so/arch/arm/mdreloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so/arch

2024-07-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Jul 22 23:10:35 UTC 2024

Modified Files:
src/libexec/ld.elf_so/arch/aarch64: mdreloc.c
src/libexec/ld.elf_so/arch/arm: mdreloc.c

Log Message:
ld.elf_so: Cite reference for Arm ELF relocations.

PR lib/58455: Missing references for processor-specific ELF
relocation semantics


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/libexec/ld.elf_so/arch/aarch64/mdreloc.c
cvs rdiff -u -r1.46 -r1.47 src/libexec/ld.elf_so/arch/arm/mdreloc.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/arch/aarch64/mdreloc.c
diff -u src/libexec/ld.elf_so/arch/aarch64/mdreloc.c:1.18 src/libexec/ld.elf_so/arch/aarch64/mdreloc.c:1.19
--- src/libexec/ld.elf_so/arch/aarch64/mdreloc.c:1.18	Sun Jun  4 01:24:56 2023
+++ src/libexec/ld.elf_so/arch/aarch64/mdreloc.c	Mon Jul 22 23:10:35 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: mdreloc.c,v 1.18 2023/06/04 01:24:56 joerg Exp $ */
+/* $NetBSD: mdreloc.c,v 1.19 2024/07/22 23:10:35 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -60,9 +60,24 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: mdreloc.c,v 1.18 2023/06/04 01:24:56 joerg Exp $");
+__RCSID("$NetBSD: mdreloc.c,v 1.19 2024/07/22 23:10:35 riastradh Exp $");
 #endif /* not lint */
 
+/*
+ * AArch64 ELF relocations.
+ *
+ * References:
+ *
+ *	[AAELF64] ELF for the Arm 64-bit Architecture (AArch64),
+ *	2022Q3.  Arm Ltd.
+ *	https://github.com/ARM-software/abi-aa/blob/2982a9f3b512a5bfdc9e3fea5d3b298f9165c36b/aaelf64/aaelf64.rst
+ *
+ *	[TLSDESC] Glauber de Oliveira Costa and Alexandre Oliva,
+ *	`Thread-Local Storage Access in Dynamic Libraries in the ARM
+ *	Platform', 2006.
+ *	https://www.fsfla.org/~lxoliva/writeups/TLS/paper-lk2006.pdf
+ */
+
 #include 
 #include 
 

Index: src/libexec/ld.elf_so/arch/arm/mdreloc.c
diff -u src/libexec/ld.elf_so/arch/arm/mdreloc.c:1.46 src/libexec/ld.elf_so/arch/arm/mdreloc.c:1.47
--- src/libexec/ld.elf_so/arch/arm/mdreloc.c:1.46	Sun Jun  4 01:24:57 2023
+++ src/libexec/ld.elf_so/arch/arm/mdreloc.c	Mon Jul 22 23:10:35 2024
@@ -1,10 +1,19 @@
-/*	$NetBSD: mdreloc.c,v 1.46 2023/06/04 01:24:57 joerg Exp $	*/
+/*	$NetBSD: mdreloc.c,v 1.47 2024/07/22 23:10:35 riastradh Exp $	*/
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: mdreloc.c,v 1.46 2023/06/04 01:24:57 joerg Exp $");
+__RCSID("$NetBSD: mdreloc.c,v 1.47 2024/07/22 23:10:35 riastradh Exp $");
 #endif /* not lint */
 
+/*
+ * Arm (32-bit) ELF relocations.
+ *
+ * Reference:
+ *
+ *	[AAELF32] ELF for the Arm Architecture, 2022Q3.  Arm Ltd.
+ *	https://github.com/ARM-software/abi-aa/blob/2982a9f3b512a5bfdc9e3fea5d3b298f9165c36b/aaelf32/aaelf32.rst
+ */
+
 #include 
 #include 
 



CVS commit: src/libexec/ld.elf_so/arch

2024-07-23 Thread Valery Ushakov
Module Name:src
Committed By:   uwe
Date:   Tue Jul 23 09:55:19 UTC 2024

Modified Files:
src/libexec/ld.elf_so/arch/sparc: mdreloc.c
src/libexec/ld.elf_so/arch/sparc64: mdreloc.c

Log Message:
ld.elf_so: Cite reference for SPARC ELF relocations

PR lib/58455: Missing references for processor-specific ELF
relocation semantics


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/libexec/ld.elf_so/arch/sparc/mdreloc.c
cvs rdiff -u -r1.70 -r1.71 src/libexec/ld.elf_so/arch/sparc64/mdreloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so/arch/powerpc

2023-04-09 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Sun Apr  9 17:24:48 UTC 2023

Modified Files:
src/libexec/ld.elf_so/arch/powerpc: Makefile.inc
Removed Files:
src/libexec/ld.elf_so/arch/powerpc: ld.so.script

Log Message:
ld.elf_so powerpc: remove bogus ldscript

This ldscript is not needed and actually makes things worse by putting
everything in one LOAD section, which then needs to have rwx permission.
Remove it so that we get two LOAD sections with better permissions.
Fixes PR 57323.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/libexec/ld.elf_so/arch/powerpc/Makefile.inc
cvs rdiff -u -r1.4 -r0 src/libexec/ld.elf_so/arch/powerpc/ld.so.script

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so/arch/powerpc

2023-04-09 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Sun Apr  9 17:24:48 UTC 2023

Modified Files:
src/libexec/ld.elf_so/arch/powerpc: Makefile.inc
Removed Files:
src/libexec/ld.elf_so/arch/powerpc: ld.so.script

Log Message:
ld.elf_so powerpc: remove bogus ldscript

This ldscript is not needed and actually makes things worse by putting
everything in one LOAD section, which then needs to have rwx permission.
Remove it so that we get two LOAD sections with better permissions.
Fixes PR 57323.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/libexec/ld.elf_so/arch/powerpc/Makefile.inc
cvs rdiff -u -r1.4 -r0 src/libexec/ld.elf_so/arch/powerpc/ld.so.script

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/arch/powerpc/Makefile.inc
diff -u src/libexec/ld.elf_so/arch/powerpc/Makefile.inc:1.16 src/libexec/ld.elf_so/arch/powerpc/Makefile.inc:1.17
--- src/libexec/ld.elf_so/arch/powerpc/Makefile.inc:1.16	Tue Apr  3 21:10:27 2018
+++ src/libexec/ld.elf_so/arch/powerpc/Makefile.inc	Sun Apr  9 17:24:48 2023
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.16 2018/04/03 21:10:27 joerg Exp $
+#	$NetBSD: Makefile.inc,v 1.17 2023/04/09 17:24:48 chs Exp $
 
 SRCS+=		ppc_reloc.c
 LDFLAGS+=	-Wl,-e,_rtld_start
@@ -12,5 +12,4 @@ CPPFLAGS+=	-DELFSIZE=64
 .else
 SRCS+=		rtld_start.S
 CPPFLAGS+=	-DELFSIZE=32
-LDFLAGS+=	-Wl,--script,${.CURDIR}/arch/powerpc/ld.so.script
 .endif



CVS commit: src/libexec/ld.elf_so/arch/i386

2023-06-04 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Jun  4 20:02:29 UTC 2023

Modified Files:
src/libexec/ld.elf_so/arch/i386: mdreloc.c

Log Message:
Avoid using uninitialized variable "symnum" when building with DEBUG
enabled by borrowing the rdbg_symname() macro from arch/x86_64.


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/libexec/ld.elf_so/arch/i386/mdreloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so/arch/i386

2023-06-04 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Jun  4 20:02:29 UTC 2023

Modified Files:
src/libexec/ld.elf_so/arch/i386: mdreloc.c

Log Message:
Avoid using uninitialized variable "symnum" when building with DEBUG
enabled by borrowing the rdbg_symname() macro from arch/x86_64.


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/libexec/ld.elf_so/arch/i386/mdreloc.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/arch/i386/mdreloc.c
diff -u src/libexec/ld.elf_so/arch/i386/mdreloc.c:1.42 src/libexec/ld.elf_so/arch/i386/mdreloc.c:1.43
--- src/libexec/ld.elf_so/arch/i386/mdreloc.c:1.42	Sun Jun  4 01:24:57 2023
+++ src/libexec/ld.elf_so/arch/i386/mdreloc.c	Sun Jun  4 20:02:29 2023
@@ -1,8 +1,8 @@
-/*	$NetBSD: mdreloc.c,v 1.42 2023/06/04 01:24:57 joerg Exp $	*/
+/*	$NetBSD: mdreloc.c,v 1.43 2023/06/04 20:02:29 martin Exp $	*/
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: mdreloc.c,v 1.42 2023/06/04 01:24:57 joerg Exp $");
+__RCSID("$NetBSD: mdreloc.c,v 1.43 2023/06/04 20:02:29 martin Exp $");
 #endif /* not lint */
 
 #include 
@@ -15,6 +15,9 @@ void _rtld_bind_start(void);
 void _rtld_relocate_nonplt_self(Elf_Dyn *, Elf_Addr);
 caddr_t _rtld_bind(const Obj_Entry *, Elf_Word);
 
+#define rdbg_symname(obj, rela) \
+	((obj)->strtab + (obj)->symtab[ELF_R_SYM((rela)->r_info)].st_name)
+
 void
 _rtld_setup_pltgot(const Obj_Entry *obj)
 {
@@ -97,7 +100,7 @@ _rtld_relocate_nonplt_objects(Obj_Entry 
 
 			*where += target - (Elf_Addr)where;
 			rdbg(("PC32 %s in %s --> %p in %s",
-			obj->strtab + obj->symtab[symnum].st_name,
+			rdbg_symname(obj, rel),
 			obj->path, (void *)*where, defobj->path));
 			break;
 
@@ -111,7 +114,7 @@ _rtld_relocate_nonplt_objects(Obj_Entry 
 			if (*where != tmp)
 *where = tmp;
 			rdbg(("32/GLOB_DAT %s in %s --> %p in %s",
-			obj->strtab + obj->symtab[symnum].st_name,
+			rdbg_symname(obj, rel),
 			obj->path, (void *)*where, defobj->path));
 			break;
 
@@ -154,7 +157,7 @@ _rtld_relocate_nonplt_objects(Obj_Entry 
 			*where += (Elf_Addr)(def->st_value - defobj->tlsoffset);
 
 			rdbg(("TLS_TPOFF %s in %s --> %p",
-			obj->strtab + obj->symtab[symnum].st_name,
+			rdbg_symname(obj, rel),
 			obj->path, (void *)*where));
 			break;
 
@@ -165,7 +168,7 @@ _rtld_relocate_nonplt_objects(Obj_Entry 
 
 			*where += (Elf_Addr)(defobj->tlsoffset - def->st_value);
 			rdbg(("TLS_TPOFF32 %s in %s --> %p",
-			obj->strtab + obj->symtab[symnum].st_name,
+			rdbg_symname(obj, rel),
 			obj->path, (void *)*where));
 			break;
 
@@ -173,7 +176,7 @@ _rtld_relocate_nonplt_objects(Obj_Entry 
 			*where = (Elf_Addr)(defobj->tlsindex);
 
 			rdbg(("TLS_DTPMOD32 %s in %s --> %p",
-			obj->strtab + obj->symtab[symnum].st_name,
+			rdbg_symname(obj, rel),
 			obj->path, (void *)*where));
 			break;
 
@@ -181,7 +184,7 @@ _rtld_relocate_nonplt_objects(Obj_Entry 
 			*where = (Elf_Addr)(def->st_value);
 
 			rdbg(("TLS_DTPOFF32 %s in %s --> %p",
-			obj->strtab + obj->symtab[symnum].st_name,
+			rdbg_symname(obj, rel),
 			obj->path, (void *)*where));
 
 			break;
@@ -192,7 +195,7 @@ _rtld_relocate_nonplt_objects(Obj_Entry 
 			(u_long)ELF_R_SYM(rel->r_info),
 			(u_long)ELF_R_TYPE(rel->r_info),
 			(void *)rel->r_offset, (void *)*where,
-			obj->strtab + obj->symtab[symnum].st_name));
+			rdbg_symname(obj, rel)));
 			_rtld_error("%s: Unsupported relocation type %ld "
 			"in non-PLT relocations",
 			obj->path, (u_long) ELF_R_TYPE(rel->r_info));



CVS commit: src/libexec/ld.elf_so/arch/aarch64

2022-12-03 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Dec  3 09:10:40 UTC 2022

Modified Files:
src/libexec/ld.elf_so/arch/aarch64: mdreloc.c

Log Message:
Whitespace. NFC.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/libexec/ld.elf_so/arch/aarch64/mdreloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so/arch/aarch64

2022-12-03 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Dec  3 09:10:40 UTC 2022

Modified Files:
src/libexec/ld.elf_so/arch/aarch64: mdreloc.c

Log Message:
Whitespace. NFC.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/libexec/ld.elf_so/arch/aarch64/mdreloc.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/arch/aarch64/mdreloc.c
diff -u src/libexec/ld.elf_so/arch/aarch64/mdreloc.c:1.16 src/libexec/ld.elf_so/arch/aarch64/mdreloc.c:1.17
--- src/libexec/ld.elf_so/arch/aarch64/mdreloc.c:1.16	Tue Jun 21 06:52:17 2022
+++ src/libexec/ld.elf_so/arch/aarch64/mdreloc.c	Sat Dec  3 09:10:40 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: mdreloc.c,v 1.16 2022/06/21 06:52:17 skrll Exp $ */
+/* $NetBSD: mdreloc.c,v 1.17 2022/12/03 09:10:40 skrll Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: mdreloc.c,v 1.16 2022/06/21 06:52:17 skrll Exp $");
+__RCSID("$NetBSD: mdreloc.c,v 1.17 2022/12/03 09:10:40 skrll Exp $");
 #endif /* not lint */
 
 #include 
@@ -288,15 +288,14 @@ _rtld_relocate_nonplt_objects(Obj_Entry 
 			rdbg(("TLS_DTPREL %s in %s --> %p",
 			obj->strtab + obj->symtab[symnum].st_name,
 			obj->path, (void *)*where));
-
 			break;
+
 		case R_TLS_TYPE(TLS_DTPMOD):
 			*where = (Elf_Addr)(defobj->tlsindex);
 
 			rdbg(("TLS_DTPMOD %s in %s --> %p",
 			obj->strtab + obj->symtab[symnum].st_name,
 			obj->path, (void *)*where));
-
 			break;
 
 		case R_TLS_TYPE(TLS_TPREL):



CVS commit: src/libexec/ld.elf_so/arch/riscv

2022-12-03 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Dec  3 09:39:44 UTC 2022

Modified Files:
src/libexec/ld.elf_so/arch/riscv: mdreloc.c rtld_start.S

Log Message:
Trailing whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/libexec/ld.elf_so/arch/riscv/mdreloc.c
cvs rdiff -u -r1.2 -r1.3 src/libexec/ld.elf_so/arch/riscv/rtld_start.S

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/arch/riscv/mdreloc.c
diff -u src/libexec/ld.elf_so/arch/riscv/mdreloc.c:1.5 src/libexec/ld.elf_so/arch/riscv/mdreloc.c:1.6
--- src/libexec/ld.elf_so/arch/riscv/mdreloc.c:1.5	Mon Apr 15 19:13:03 2019
+++ src/libexec/ld.elf_so/arch/riscv/mdreloc.c	Sat Dec  3 09:39:44 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: mdreloc.c,v 1.5 2019/04/15 19:13:03 maya Exp $	*/
+/*	$NetBSD: mdreloc.c,v 1.6 2022/12/03 09:39:44 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: mdreloc.c,v 1.5 2019/04/15 19:13:03 maya Exp $");
+__RCSID("$NetBSD: mdreloc.c,v 1.6 2022/12/03 09:39:44 skrll Exp $");
 #endif /* not lint */
 
 #include 
@@ -256,7 +256,7 @@ _rtld_bind(const Obj_Entry *obj, Elf_Wor
 int
 _rtld_relocate_plt_objects(const Obj_Entry *obj)
 {
-	
+
 	for (const Elf_Rel *rel = obj->pltrel; rel < obj->pltrellim; rel++) {
 		if (_rtld_relocate_plt_object(obj, rel, NULL) < 0)
 			return -1;

Index: src/libexec/ld.elf_so/arch/riscv/rtld_start.S
diff -u src/libexec/ld.elf_so/arch/riscv/rtld_start.S:1.2 src/libexec/ld.elf_so/arch/riscv/rtld_start.S:1.3
--- src/libexec/ld.elf_so/arch/riscv/rtld_start.S:1.2	Fri Mar 27 23:14:53 2015
+++ src/libexec/ld.elf_so/arch/riscv/rtld_start.S	Sat Dec  3 09:39:44 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld_start.S,v 1.2 2015/03/27 23:14:53 matt Exp $	*/
+/*	$NetBSD: rtld_start.S,v 1.3 2022/12/03 09:39:44 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -110,7 +110,7 @@ ENTRY_NP(_rtld_bind_start)
 	REG_L	a5, XCALLFRAME_A5(sp)
 	REG_L	a6, XCALLFRAME_A6(sp)
 	REG_L	a7, XCALLFRAME_A7(sp)
-	REG_L	ra, XCALLFRAME_RA(sp)		
+	REG_L	ra, XCALLFRAME_RA(sp)
 	addi	sp, sp, XCALLFRAME_SIZ
 	jr	t0
 END(_rtld_bind_start)



CVS commit: src/libexec/ld.elf_so/arch/riscv

2022-12-03 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Dec  3 09:39:44 UTC 2022

Modified Files:
src/libexec/ld.elf_so/arch/riscv: mdreloc.c rtld_start.S

Log Message:
Trailing whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/libexec/ld.elf_so/arch/riscv/mdreloc.c
cvs rdiff -u -r1.2 -r1.3 src/libexec/ld.elf_so/arch/riscv/rtld_start.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/libexec/ld.elf_so/arch/riscv

2022-12-04 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Mon Dec  5 07:26:25 UTC 2022

Modified Files:
src/libexec/ld.elf_so/arch/riscv: mdreloc.c

Log Message:
RISC-V is RELA


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/libexec/ld.elf_so/arch/riscv/mdreloc.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/arch/riscv/mdreloc.c
diff -u src/libexec/ld.elf_so/arch/riscv/mdreloc.c:1.6 src/libexec/ld.elf_so/arch/riscv/mdreloc.c:1.7
--- src/libexec/ld.elf_so/arch/riscv/mdreloc.c:1.6	Sat Dec  3 09:39:44 2022
+++ src/libexec/ld.elf_so/arch/riscv/mdreloc.c	Mon Dec  5 07:26:25 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: mdreloc.c,v 1.6 2022/12/03 09:39:44 skrll Exp $	*/
+/*	$NetBSD: mdreloc.c,v 1.7 2022/12/05 07:26:25 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: mdreloc.c,v 1.6 2022/12/03 09:39:44 skrll Exp $");
+__RCSID("$NetBSD: mdreloc.c,v 1.7 2022/12/05 07:26:25 skrll Exp $");
 #endif /* not lint */
 
 #include 
@@ -206,15 +206,15 @@ _rtld_relocate_plt_lazy(Obj_Entry *obj)
 }
 
 static int
-_rtld_relocate_plt_object(const Obj_Entry *obj, const Elf_Rel *rel,
+_rtld_relocate_plt_object(const Obj_Entry *obj, const Elf_Rela *rela,
 Elf_Addr *tp)
 {
 	const Obj_Entry *defobj;
 	Elf_Addr new_value;
 
-assert(ELF_R_TYPE(rel->r_info) == R_TYPE(JMP_SLOT));
+assert(ELF_R_TYPE(rela->r_info) == R_TYPE(JMP_SLOT));
 
-	const Elf_Sym *def = _rtld_find_plt_symdef(ELF_R_SYM(rel->r_info),
+	const Elf_Sym *def = _rtld_find_plt_symdef(ELF_R_SYM(rela->r_info),
 	obj, &defobj, tp != NULL);
 	if (__predict_false(def == NULL))
 		return -1;
@@ -230,7 +230,7 @@ _rtld_relocate_plt_object(const Obj_Entr
 	}
 	rdbg(("bind now/fixup in %s --> new=%p",
 	defobj->strtab + def->st_name, (void *)new_value));
-	*(Elf_Addr *)(obj->relocbase + rel->r_offset) = new_value;
+	*(Elf_Addr *)(obj->relocbase + rela->r_offset) = new_value;
 
 	if (tp)
 		*tp = new_value;
@@ -240,7 +240,7 @@ _rtld_relocate_plt_object(const Obj_Entr
 void *
 _rtld_bind(const Obj_Entry *obj, Elf_Word reloff)
 {
-	const Elf_Rel *pltrel = (const Elf_Rel *)(obj->pltrel + reloff);
+	const Elf_Rela *pltrel = (const Elf_Rela *)(obj->pltrel + reloff);
 	Elf_Addr new_value;
 	int err;
 
@@ -257,8 +257,8 @@ int
 _rtld_relocate_plt_objects(const Obj_Entry *obj)
 {
 
-	for (const Elf_Rel *rel = obj->pltrel; rel < obj->pltrellim; rel++) {
-		if (_rtld_relocate_plt_object(obj, rel, NULL) < 0)
+	for (const Elf_Rela *rela = obj->pltrela; rela < obj->pltrelalim; rela++) {
+		if (_rtld_relocate_plt_object(obj, rela, NULL) < 0)
 			return -1;
 	}
 



CVS commit: src/libexec/ld.elf_so/arch/riscv

2022-12-04 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Mon Dec  5 07:26:25 UTC 2022

Modified Files:
src/libexec/ld.elf_so/arch/riscv: mdreloc.c

Log Message:
RISC-V is RELA


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/libexec/ld.elf_so/arch/riscv/mdreloc.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



  1   2   >