CVS commit: src/lib/libc/dlfcn

2018-07-13 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Fri Jul 13 19:49:47 UTC 2018

Modified Files:
src/lib/libc/dlfcn: dlfcn_elf.c

Log Message:
Compute relocbase correctly for static PIE. AT_BASE is not usable in
this case.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/lib/libc/dlfcn/dlfcn_elf.c

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

Modified files:

Index: src/lib/libc/dlfcn/dlfcn_elf.c
diff -u src/lib/libc/dlfcn/dlfcn_elf.c:1.15 src/lib/libc/dlfcn/dlfcn_elf.c:1.16
--- src/lib/libc/dlfcn/dlfcn_elf.c:1.15	Fri Jan  5 19:29:44 2018
+++ src/lib/libc/dlfcn/dlfcn_elf.c	Fri Jul 13 19:49:47 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: dlfcn_elf.c,v 1.15 2018/01/05 19:29:44 kamil Exp $	*/
+/*	$NetBSD: dlfcn_elf.c,v 1.16 2018/07/13 19:49:47 joerg Exp $	*/
 
 /*
  * Copyright (c) 2000 Takuya SHIOZAKI
@@ -27,7 +27,7 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: dlfcn_elf.c,v 1.15 2018/01/05 19:29:44 kamil Exp $");
+__RCSID("$NetBSD: dlfcn_elf.c,v 1.16 2018/07/13 19:49:47 joerg Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -176,6 +176,17 @@ dl_iterate_phdr_setup(void)
 			break;
 		}
 	}
+
+	if (!dlpi_phdr)
+		return;
+
+	const Elf_Phdr *phdr = (const Elf_Phdr *)dlpi_phdr;
+	const Elf_Phdr *phlimit = phdr + dlpi_phnum;
+
+	for (; phdr < phlimit; ++phdr) {
+		if (phdr->p_type == PT_PHDR)
+			dlpi_addr = (uintptr_t)phdr - phdr->p_vaddr;
+	}
 }
 
 /*ARGSUSED*/



CVS commit: src/lib/libc/dlfcn

2011-03-12 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sat Mar 12 21:55:10 UTC 2011

Modified Files:
src/lib/libc/dlfcn: dlfcn_elf.c

Log Message:
Avoid a dependency issue between pthread TLS by using simple atomic
initialisation, possibly running the initialisation loop more than once.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/lib/libc/dlfcn/dlfcn_elf.c

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

Modified files:

Index: src/lib/libc/dlfcn/dlfcn_elf.c
diff -u src/lib/libc/dlfcn/dlfcn_elf.c:1.8 src/lib/libc/dlfcn/dlfcn_elf.c:1.9
--- src/lib/libc/dlfcn/dlfcn_elf.c:1.8	Mon Mar  7 05:09:11 2011
+++ src/lib/libc/dlfcn/dlfcn_elf.c	Sat Mar 12 21:55:09 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: dlfcn_elf.c,v 1.8 2011/03/07 05:09:11 joerg Exp $	*/
+/*	$NetBSD: dlfcn_elf.c,v 1.9 2011/03/12 21:55:09 joerg Exp $	*/
 
 /*
  * Copyright (c) 2000 Takuya SHIOZAKI
@@ -27,14 +27,15 @@
 
 #include 
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: dlfcn_elf.c,v 1.8 2011/03/07 05:09:11 joerg Exp $");
+__RCSID("$NetBSD: dlfcn_elf.c,v 1.9 2011/03/12 21:55:09 joerg Exp $");
 #endif /* LIBC_SCCS and not lint */
 
-#include "reentrant.h"
 #include "namespace.h"
+#include 
 #include 
 #include 
 #include 
+#include 
 
 #undef dlopen
 #undef dlclose
@@ -132,7 +133,6 @@
 	return -1;
 }
 
-static once_t dl_iterate_phdr_once = ONCE_INITIALIZER;
 static const char *dlpi_name;
 static Elf_Addr dlpi_addr;
 static const Elf_Phdr *dlpi_phdr;
@@ -175,12 +175,22 @@
 dl_iterate_phdr(int (*callback)(struct dl_phdr_info *, size_t, void *),
 void *data)
 {
+	static bool setup_done;
 	struct dl_phdr_info phdr_info;
 
 	if (__auxinfo == NULL)
 		return EOPNOTSUPP;
 
-	thr_once(&dl_iterate_phdr_once, dl_iterate_phdr_setup);
+	if (!setup_done) {
+		/*
+		 * This can race on the first call to dl_iterate_phdr.
+		 * dl_iterate_phdr_setup only touches field of pointer size
+		 * and smaller and such stores are atomic.
+		 */
+		dl_iterate_phdr_setup();
+		membar_producer();
+		setup_done = true;
+	}
 
 	memset(&phdr_info, 0, sizeof(phdr_info));
 	phdr_info.dlpi_addr = dlpi_addr;