CVS commit: src/libexec/ld.elf_so

2020-09-21 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Tue Sep 22 00:41:28 UTC 2020

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

Log Message:
Correct r_ldbase valuse

It shall be the relocbase value, not linkmap.


To generate a diff of this commit:
cvs rdiff -u -r1.206 -r1.207 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.206 src/libexec/ld.elf_so/rtld.c:1.207
--- src/libexec/ld.elf_so/rtld.c:1.206	Mon Sep 21 16:08:57 2020
+++ src/libexec/ld.elf_so/rtld.c	Tue Sep 22 00:41:27 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.206 2020/09/21 16:08:57 kamil Exp $	 */
+/*	$NetBSD: rtld.c,v 1.207 2020/09/22 00:41:27 kamil Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.206 2020/09/21 16:08:57 kamil Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.207 2020/09/22 00:41:27 kamil Exp $");
 #endif /* not lint */
 
 #include 
@@ -397,7 +397,7 @@ _rtld_init(caddr_t mapbase, caddr_t relo
 	_rtld_debug.r_version = R_DEBUG_VERSION;
 	_rtld_debug.r_brk = _rtld_debug_state;
 	_rtld_debug.r_state = RT_CONSISTENT;
-	_rtld_debug.r_ldbase = &_rtld_objself.linkmap;
+	_rtld_debug.r_ldbase = _rtld_objself.relocbase;
 
 	ehdr = (Elf_Ehdr *)mapbase;
 	_rtld_objself.phdr = (Elf_Phdr *)((char *)mapbase + ehdr->e_phoff);



CVS commit: src/libexec/ld.elf_so

2021-03-06 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Mar  6 20:09:40 UTC 2021

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

Log Message:
pretend we know about %# and %j...


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/libexec/ld.elf_so/xprintf.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/xprintf.c
diff -u src/libexec/ld.elf_so/xprintf.c:1.22 src/libexec/ld.elf_so/xprintf.c:1.23
--- src/libexec/ld.elf_so/xprintf.c:1.22	Sun Dec  8 17:41:42 2019
+++ src/libexec/ld.elf_so/xprintf.c	Sat Mar  6 15:09:39 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: xprintf.c,v 1.22 2019/12/08 22:41:42 uwe Exp $	 */
+/*	$NetBSD: xprintf.c,v 1.23 2021/03/06 20:09:39 christos Exp $	 */
 
 /*
  * Copyright 1996 Matt Thomas 
@@ -29,7 +29,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: xprintf.c,v 1.22 2019/12/08 22:41:42 uwe Exp $");
+__RCSID("$NetBSD: xprintf.c,v 1.23 2021/03/06 20:09:39 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -73,9 +73,11 @@ xvsnprintf(char *buf, size_t buflen, con
 prec = va_arg(ap, int);
 /* FALLTHROUGH */
 			case '.':
+			case '#':
 fmt++;
 goto rflag;
 			case 'l':
+			case 'j':
 size |= SZ_LONG;
 fmt++;
 goto rflag;



CVS commit: src/libexec/ld.elf_so

2021-05-29 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sun May 30 02:26:08 UTC 2021

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

Log Message:
Don't use the return address hack with clang.


To generate a diff of this commit:
cvs rdiff -u -r1.207 -r1.208 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.207 src/libexec/ld.elf_so/rtld.c:1.208
--- src/libexec/ld.elf_so/rtld.c:1.207	Tue Sep 22 00:41:27 2020
+++ src/libexec/ld.elf_so/rtld.c	Sun May 30 02:26:08 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.207 2020/09/22 00:41:27 kamil Exp $	 */
+/*	$NetBSD: rtld.c,v 1.208 2021/05/30 02:26:08 joerg Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.207 2020/09/22 00:41:27 kamil Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.208 2021/05/30 02:26:08 joerg Exp $");
 #endif /* not lint */
 
 #include 
@@ -1118,7 +1118,7 @@ _rtld_objmain_sym(const char *name)
 	return NULL;
 }
 
-#ifdef __powerpc__
+#if defined(__powerpc__) && !defined(__clang__)
 static __noinline void *
 hackish_return_address(void)
 {
@@ -1284,7 +1284,7 @@ dlsym(void *handle, const char *name)
 
 	dbg(("dlsym of %s in %p", name, handle));
 
-#ifdef __powerpc__
+#if defined(__powerpc__) && !defined(__clang__)
 	retaddr = hackish_return_address();
 #else
 	retaddr = __builtin_return_address(0);
@@ -1309,7 +1309,7 @@ dlvsym(void *handle, const char *name, c
 		ver_entry.flags = 0;
 		ventry = &ver_entry;
 	}
-#ifdef __powerpc__
+#if defined(__powerpc__) && !defined(__clang__)
 	retaddr = hackish_return_address();
 #else
 	retaddr = __builtin_return_address(0);
@@ -1407,7 +1407,7 @@ dlinfo(void *handle, int req, void *v)
 	_rtld_shared_enter();
 
 	if (handle == RTLD_SELF) {
-#ifdef __powerpc__
+#if defined(__powerpc__) && !defined(__clang__)
 		retaddr = hackish_return_address();
 #else
 		retaddr = __builtin_return_address(0);



CVS commit: src/libexec/ld.elf_so

2021-06-16 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Jun 16 21:53:51 UTC 2021

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

Log Message:
ld.elf_so(1): Omit needless membar_enter.

The use of membar_enter is to separate atomic r/m/w on a lock from
the body of the critical section so two different critical sections
happen in order:

body of previous critical section;

exit critical section:
membar_exit();
atomic_r/m/w(lock stuff);

enter critical section:
atomic_r/m/w(lock stuff);
membar_enter();

body of next critical section;

_rtld_shared_enter does this, but it _also_ issued an extraneous
membar_enter before the atomic_r/m/w part, which doesn't impose any
semantically important order but may cost some performance.


To generate a diff of this commit:
cvs rdiff -u -r1.208 -r1.209 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.208 src/libexec/ld.elf_so/rtld.c:1.209
--- src/libexec/ld.elf_so/rtld.c:1.208	Sun May 30 02:26:08 2021
+++ src/libexec/ld.elf_so/rtld.c	Wed Jun 16 21:53:51 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.208 2021/05/30 02:26:08 joerg Exp $	 */
+/*	$NetBSD: rtld.c,v 1.209 2021/06/16 21:53:51 riastradh Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.208 2021/05/30 02:26:08 joerg Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.209 2021/06/16 21:53:51 riastradh Exp $");
 #endif /* not lint */
 
 #include 
@@ -1673,8 +1673,6 @@ _rtld_shared_enter(void)
 	unsigned int cur;
 	lwpid_t waiter, self = 0;
 
-	membar_enter();
-
 	for (;;) {
 		cur = _rtld_mutex;
 		/*



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.

Modified files:

Index: src/libexec/ld.elf_so/rtld.c
diff -u src/libexec/ld.elf_so/rtld.c:1.127 src/libexec/ld.elf_so/rtld.c:1.128
--- src/libexec/ld.elf_so/rtld.c:1.127	Wed Dec  2 15:50:13 2009
+++ src/libexec/ld.elf_so/rtld.c	Sun Jan 10 06:37:32 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.127 2009/12/02 15:50:13 christos Exp $	 */
+/*	$NetBSD: rtld.c,v 1.128 2010/01/10 06:37:32 skrll Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.127 2009/12/02 15:50:13 christos Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.128 2010/01/10 06:37:32 skrll Exp $");
 #endif /* not lint */
 
 #include 
@@ -231,10 +231,12 @@
 	_rtld_objself.strtab = "_rtld_sym_zero";
 
 	/*
-	 * Set value to -relocabase so that
-	 * _rtld_objself.relocbase + _rtld_smy_zero.st_value == 0
+	 * Set value to -relocbase so that
+	 *
+	 * _rtld_objself.relocbase + _rtld_sym_zero.st_value == 0
+	 *
 	 * This allows unresolved references to weak symbols to be computed
-	 * to value a value of 0.
+	 * to a value of 0.
 	 */
 	_rtld_sym_zero.st_value = -(uintptr_t)relocbase;
 



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.

Modified files:

Index: src/libexec/ld.elf_so/map_object.c
diff -u src/libexec/ld.elf_so/map_object.c:1.38 src/libexec/ld.elf_so/map_object.c:1.39
--- src/libexec/ld.elf_so/map_object.c:1.38	Tue May 19 20:44:52 2009
+++ src/libexec/ld.elf_so/map_object.c	Sun Jan 10 07:29:47 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: map_object.c,v 1.38 2009/05/19 20:44:52 christos Exp $	 */
+/*	$NetBSD: map_object.c,v 1.39 2010/01/10 07:29:47 skrll Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -34,7 +34,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: map_object.c,v 1.38 2009/05/19 20:44:52 christos Exp $");
+__RCSID("$NetBSD: map_object.c,v 1.39 2010/01/10 07:29:47 skrll Exp $");
 #endif /* not lint */
 
 #include 
@@ -325,6 +325,9 @@
 		xfree(elm);
 	}
 	xfree(obj);
+#ifdef COMBRELOC
+	_rtld_combreloc_reset(obj);
+#endif
 }
 
 Obj_Entry *

Index: src/libexec/ld.elf_so/rtld.h
diff -u src/libexec/ld.elf_so/rtld.h:1.82 src/libexec/ld.elf_so/rtld.h:1.83
--- src/libexec/ld.elf_so/rtld.h:1.82	Tue Nov 17 18:44:33 2009
+++ src/libexec/ld.elf_so/rtld.h	Sun Jan 10 07:29:47 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.h,v 1.82 2009/11/17 18:44:33 skrll Exp $	 */
+/*	$NetBSD: rtld.h,v 1.83 2010/01/10 07:29:47 skrll Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -278,6 +278,9 @@
 const Obj_Entry *, const Obj_Entry **, bool);
 const Elf_Sym *_rtld_symlook_needed(const char *, unsigned long,
 const Needed_Entry *, const Obj_Entry **, bool);
+#ifdef COMBRELOC
+void _rtld_combreloc_reset(const Obj_Entry *);
+#endif
 
 /* map_object.c */
 Obj_Entry *_rtld_map_object(const char *, int, const struct stat *);

Index: src/libexec/ld.elf_so/symbol.c
diff -u src/libexec/ld.elf_so/symbol.c:1.48 src/libexec/ld.elf_so/symbol.c:1.49
--- src/libexec/ld.elf_so/symbol.c:1.48	Thu Sep 24 21:21:34 2009
+++ src/libexec/ld.elf_so/symbol.c	Sun Jan 10 07:29:47 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: symbol.c,v 1.48 2009/09/24 21:21:34 pooka Exp $	 */
+/*	$NetBSD: symbol.c,v 1.49 2010/01/10 07:29:47 skrll Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: symbol.c,v 1.48 2009/09/24 21:21:34 pooka Exp $");
+__RCSID("$NetBSD: symbol.c,v 1.49 2010/01/10 07:29:47 skrll Exp $");
 #endif /* not lint */
 
 #include 
@@ -236,6 +236,21 @@
 	return NULL;
 }
 
+#ifdef COMBRELOC
+static const Obj_Entry *_rtld_last_refobj;
+
+/*
+ * Called when an object is freed. Reset the cached symbol look up if
+ * our last referencing or definition object just got unloaded.
+ */
+void
+_rtld_combreloc_reset(const Obj_Entry *obj)
+{
+	if (_rtld_last_refobj == obj)
+		_rtld_last_refobj = NULL;
+}
+#endif
+
 /*
  * Given a symbol number in a referencing object, find the corresponding
  * definition of the symbol.  Returns a pointer to the symbol, or NULL if
@@ -261,11 +276,10 @@
 	 * return the cached results.
 	 */
 	static unsigned long last_symnum;
-	static const Elf_Sym *last_def;
-	static const Obj_Entry *last_refobj;
 	static const Obj_Entry *last_defobj;
+	static const Elf_Sym *last_def;
 
-	if (symnum == last_symnum && refobj == last_refobj
+	if (symnum == last_symnum && refobj == _rtld_last_refobj
 	&& in_plt == false) {
 		*defobj_out = last_defobj;
 		return last_def;
@@ -319,7 +333,7 @@
 			 * non-PLT lookup.
 			 */
 			last_symnum = symnum;
-			last_refobj = refobj;
+			_rtld_last_refobj = refobj;
 			last_def = def;
 			last_defobj = defobj;
 		}



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.

Modified files:

Index: src/libexec/ld.elf_so/reloc.c
diff -u src/libexec/ld.elf_so/reloc.c:1.97 src/libexec/ld.elf_so/reloc.c:1.98
--- src/libexec/ld.elf_so/reloc.c:1.97	Thu Sep 24 17:21:34 2009
+++ src/libexec/ld.elf_so/reloc.c	Wed Jan 13 15:17:21 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: reloc.c,v 1.97 2009/09/24 21:21:34 pooka Exp $	 */
+/*	$NetBSD: reloc.c,v 1.98 2010/01/13 20:17:21 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -39,7 +39,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: reloc.c,v 1.97 2009/09/24 21:21:34 pooka Exp $");
+__RCSID("$NetBSD: reloc.c,v 1.98 2010/01/13 20:17:21 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -84,7 +84,7 @@
 	srcaddr = (const void *)(srcobj->relocbase + srcsym->st_value);
 	(void)memcpy(dstaddr, srcaddr, size);
 	rdbg(("COPY %s %s %s --> src=%p dst=%p size %ld",
-	dstobj->path, srcobj->path, name, (void *)srcaddr,
+	dstobj->path, srcobj->path, name, srcaddr,
 	(void *)dstaddr, (long)size));
 	return (0);
 }
@@ -198,8 +198,6 @@
 		if (!ok)
 			return -1;
 
-		(void)dlerror(); /* clear any errors since all is good */
-
 		/* Set some sanity-checking numbers in the Obj_Entry. */
 		obj->magic = RTLD_MAGIC;
 		obj->version = RTLD_VERSION;

Index: src/libexec/ld.elf_so/rtld.h
diff -u src/libexec/ld.elf_so/rtld.h:1.83 src/libexec/ld.elf_so/rtld.h:1.84
--- src/libexec/ld.elf_so/rtld.h:1.83	Sun Jan 10 02:29:47 2010
+++ src/libexec/ld.elf_so/rtld.h	Wed Jan 13 15:17:21 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.h,v 1.83 2010/01/10 07:29:47 skrll Exp $	 */
+/*	$NetBSD: rtld.h,v 1.84 2010/01/13 20:17:21 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -272,6 +272,9 @@
 const Obj_Entry *, bool);
 const Elf_Sym *_rtld_find_symdef(unsigned long, const Obj_Entry *,
 const Obj_Entry **, bool);
+const Elf_Sym *_rtld_find_plt_symdef(unsigned long, const Obj_Entry *, 
+const Obj_Entry **, bool);
+
 const Elf_Sym *_rtld_symlook_list(const char *, unsigned long,
 const Objlist *, const Obj_Entry **, bool);
 const Elf_Sym *_rtld_symlook_default(const char *, unsigned long,

Index: src/libexec/ld.elf_so/symbol.c
diff -u src/libexec/ld.elf_so/symbol.c:1.49 src/libexec/ld.elf_so/symbol.c:1.50
--- src/libexec/ld.elf_so/symbol.c:1.49	Sun Jan 10 02:29:47 2010
+++ src/libexec/ld.elf_so/symbol.c	Wed Jan 13 15:17:21 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: symbol.c,v 1.49 2010/01/10 07:29:47 skrll Exp $	 */
+/*	$NetBSD: symbol.c,v 1.50 2010/01/13 20:17:21 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: symbol.c,v 1.49 2010/01/10 07:29:47 skrll Exp $");
+__RCSID("$NetBSD: symbol.c,v 1.50 2010/01/13 20:17:21 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -314,11 +314,6 @@
 	 * symbol as having the value zero.
 	 */
 	if (de

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.

Modified files:

Index: src/libexec/ld.elf_so/reloc.c
diff -u src/libexec/ld.elf_so/reloc.c:1.98 src/libexec/ld.elf_so/reloc.c:1.99
--- src/libexec/ld.elf_so/reloc.c:1.98	Wed Jan 13 20:17:21 2010
+++ src/libexec/ld.elf_so/reloc.c	Thu Jan 14 21:52:07 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: reloc.c,v 1.98 2010/01/13 20:17:21 christos Exp $	 */
+/*	$NetBSD: reloc.c,v 1.99 2010/01/14 21:52:07 skrll Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -39,7 +39,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: reloc.c,v 1.98 2010/01/13 20:17:21 christos Exp $");
+__RCSID("$NetBSD: reloc.c,v 1.99 2010/01/14 21:52:07 skrll Exp $");
 #endif /* not lint */
 
 #include 
@@ -202,14 +202,6 @@
 		obj->magic = RTLD_MAGIC;
 		obj->version = RTLD_VERSION;
 
-		/* Fill in the dynamic linker entry points. */
-		obj->dlopen = dlopen;
-		obj->dlsym = dlsym;
-		obj->dlerror = dlerror;
-		obj->dlclose = dlclose;
-		obj->dladdr = dladdr;
-		obj->dlinfo = dlinfo;
-
 		dbg(("fixing up PLTGOT"));
 		/* Set the special PLTGOT entries. */
 		if (obj->pltgot != NULL)

Index: src/libexec/ld.elf_so/rtld.h
diff -u src/libexec/ld.elf_so/rtld.h:1.84 src/libexec/ld.elf_so/rtld.h:1.85
--- src/libexec/ld.elf_so/rtld.h:1.84	Wed Jan 13 20:17:21 2010
+++ src/libexec/ld.elf_so/rtld.h	Thu Jan 14 21:52:07 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.h,v 1.84 2010/01/13 20:17:21 christos Exp $	 */
+/*	$NetBSD: rtld.h,v 1.85 2010/01/14 21:52:07 skrll Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -162,14 +162,6 @@
 	void(*init)(void); 	/* Initialization function to call */
 	void(*fini)(void);	/* Termination function to call */
 
-	/* Entry points for dlopen() and friends. */
-	void   *(*dlopen)(const char *, int);
-	void   *(*dlsym)(void *, const char *);
-	char   *(*dlerror)(void);
-	int (*dlclose)(void *);
-	int (*dladdr)(const void *, Dl_info *);
-	int		(*dlinfo)(void *, int, void *);
-
 	u_int32_t	mainprog:1,	/* True if this is the main program */
 		rtld:1,		/* True if this is the dynamic linker */
 			textrel:1,	/* True if there are relocations to



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.

Modified files:

Index: src/libexec/ld.elf_so/reloc.c
diff -u src/libexec/ld.elf_so/reloc.c:1.99 src/libexec/ld.elf_so/reloc.c:1.100
--- src/libexec/ld.elf_so/reloc.c:1.99	Thu Jan 14 21:52:07 2010
+++ src/libexec/ld.elf_so/reloc.c	Fri Jan 15 07:07:11 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: reloc.c,v 1.99 2010/01/14 21:52:07 skrll Exp $	 */
+/*	$NetBSD: reloc.c,v 1.100 2010/01/15 07:07:11 skrll Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -39,7 +39,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: reloc.c,v 1.99 2010/01/14 21:52:07 skrll Exp $");
+__RCSID("$NetBSD: reloc.c,v 1.100 2010/01/15 07:07:11 skrll Exp $");
 #endif /* not lint */
 
 #include 
@@ -202,6 +202,14 @@
 		obj->magic = RTLD_MAGIC;
 		obj->version = RTLD_VERSION;
 
+		/* Fill in the dynamic linker entry points. */
+		obj->dlopen = dlopen;
+		obj->dlsym = dlsym;
+		obj->dlerror = dlerror;
+		obj->dlclose = dlclose;
+		obj->dladdr = dladdr;
+		obj->dlinfo = dlinfo;
+
 		dbg(("fixing up PLTGOT"));
 		/* Set the special PLTGOT entries. */
 		if (obj->pltgot != NULL)

Index: src/libexec/ld.elf_so/rtld.h
diff -u src/libexec/ld.elf_so/rtld.h:1.85 src/libexec/ld.elf_so/rtld.h:1.86
--- src/libexec/ld.elf_so/rtld.h:1.85	Thu Jan 14 21:52:07 2010
+++ src/libexec/ld.elf_so/rtld.h	Fri Jan 15 07:07:12 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.h,v 1.85 2010/01/14 21:52:07 skrll Exp $	 */
+/*	$NetBSD: rtld.h,v 1.86 2010/01/15 07:07:12 skrll Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -162,6 +162,14 @@
 	void(*init)(void); 	/* Initialization function to call */
 	void(*fini)(void);	/* Termination function to call */
 
+	/* Entry points for dlopen() and friends. */
+	void   *(*dlopen)(const char *, int);
+	void   *(*dlsym)(void *, const char *);
+	char   *(*dlerror)(void);
+	int (*dlclose)(void *);
+	int (*dladdr)(const void *, Dl_info *);
+	int		(*dlinfo)(void *, int, void *);
+
 	u_int32_t	mainprog:1,	/* True if this is the main program */
 		rtld:1,		/* True if this is the dynamic linker */
 			textrel:1,	/* True if there are relocations to



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.

Modified files:

Index: src/libexec/ld.elf_so/reloc.c
diff -u src/libexec/ld.elf_so/reloc.c:1.100 src/libexec/ld.elf_so/reloc.c:1.101
--- src/libexec/ld.elf_so/reloc.c:1.100	Fri Jan 15 07:07:11 2010
+++ src/libexec/ld.elf_so/reloc.c	Sat Jan 16 10:37:51 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: reloc.c,v 1.100 2010/01/15 07:07:11 skrll Exp $	 */
+/*	$NetBSD: reloc.c,v 1.101 2010/01/16 10:37:51 skrll Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -39,7 +39,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: reloc.c,v 1.100 2010/01/15 07:07:11 skrll Exp $");
+__RCSID("$NetBSD: reloc.c,v 1.101 2010/01/16 10:37:51 skrll Exp $");
 #endif /* not lint */
 
 #include 
@@ -208,7 +208,6 @@
 		obj->dlerror = dlerror;
 		obj->dlclose = dlclose;
 		obj->dladdr = dladdr;
-		obj->dlinfo = dlinfo;
 
 		dbg(("fixing up PLTGOT"));
 		/* Set the special PLTGOT entries. */

Index: src/libexec/ld.elf_so/rtld.h
diff -u src/libexec/ld.elf_so/rtld.h:1.86 src/libexec/ld.elf_so/rtld.h:1.87
--- src/libexec/ld.elf_so/rtld.h:1.86	Fri Jan 15 07:07:12 2010
+++ src/libexec/ld.elf_so/rtld.h	Sat Jan 16 10:37:51 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.h,v 1.86 2010/01/15 07:07:12 skrll Exp $	 */
+/*	$NetBSD: rtld.h,v 1.87 2010/01/16 10:37:51 skrll Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -168,7 +168,6 @@
 	char   *(*dlerror)(void);
 	int (*dlclose)(void *);
 	int (*dladdr)(const void *, Dl_info *);
-	int		(*dlinfo)(void *, int, void *);
 
 	u_int32_t	mainprog:1,	/* True if this is the main program */
 		rtld:1,		/* True if this is the dynamic linker */



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.

Modified files:

Index: src/libexec/ld.elf_so/rtld.h
diff -u src/libexec/ld.elf_so/rtld.h:1.87 src/libexec/ld.elf_so/rtld.h:1.88
--- src/libexec/ld.elf_so/rtld.h:1.87	Sat Jan 16 10:37:51 2010
+++ src/libexec/ld.elf_so/rtld.h	Sun Jan 17 08:04:20 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.h,v 1.87 2010/01/16 10:37:51 skrll Exp $	 */
+/*	$NetBSD: rtld.h,v 1.88 2010/01/17 08:04:20 skrll Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -130,7 +130,6 @@
 	caddr_t entry;		/* Entry point */
 	const Elf_Phdr *__junk001;
 	size_t		pathlen;	/* Pathname length */
-	void		*ehdr;
 
 	/* Items from the dynamic section. */
 	Elf_Addr   *pltgot;		/* PLTGOT table */
@@ -195,6 +194,8 @@
 	Objlist dagmembers;	/* DAG has these members (%) */
 	dev_t   dev;		/* Object's filesystem's device */
 	ino_t   ino;		/* Object's inode number */
+
+	void		*ehdr;
 } Obj_Entry;
 
 #if defined(_RTLD_SOURCE)



CVS commit: src/libexec/ld.elf_so

2010-03-18 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Thu Mar 18 22:17:55 UTC 2010

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

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.


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 src/libexec/ld.elf_so/Makefile
cvs rdiff -u -r1.129 -r1.130 src/libexec/ld.elf_so/rtld.c
cvs rdiff -u -r1.89 -r1.90 src/libexec/ld.elf_so/rtld.h
cvs rdiff -u -r1.51 -r1.52 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.93 src/libexec/ld.elf_so/Makefile:1.94
--- src/libexec/ld.elf_so/Makefile:1.93	Sun Dec 13 09:31:47 2009
+++ src/libexec/ld.elf_so/Makefile	Thu Mar 18 22:17:55 2010
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.93 2009/12/13 09:31:47 mrg Exp $
+#	$NetBSD: Makefile,v 1.94 2010/03/18 22:17:55 roy Exp $
 #
 # NOTE: when changing ld.so, ensure that ldd still compiles.
 #
@@ -16,6 +16,10 @@
 .include 			# for OBJECT_FMT definition
 .include 			# for SHLINKINSTALLDIR definition
 
+# We use alloca
+USE_FORT=	no
+USE_SSP=	no
+
 .if defined(LDELFSO_MACHINE_CPU) && !empty(LDELFSO_MACHINE_CPU) && \
 exists(${.CURDIR}/arch/${LDELFSO_MACHINE_CPU})
 ARCHSUBDIR=	${LDELFSO_MACHINE_CPU}

Index: src/libexec/ld.elf_so/rtld.c
diff -u src/libexec/ld.elf_so/rtld.c:1.129 src/libexec/ld.elf_so/rtld.c:1.130
--- src/libexec/ld.elf_so/rtld.c:1.129	Sat Feb 27 11:16:38 2010
+++ src/libexec/ld.elf_so/rtld.c	Thu Mar 18 22:17:55 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.129 2010/02/27 11:16:38 roy Exp $	 */
+/*	$NetBSD: rtld.c,v 1.130 2010/03/18 22:17:55 roy Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.129 2010/02/27 11:16:38 roy Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.130 2010/03/18 22:17:55 roy Exp $");
 #endif /* not lint */
 
 #include 
@@ -822,8 +822,6 @@
 	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;
 	return(NULL);
@@ -919,10 +917,8 @@
 			_rtld_donelist_init(&depth);
 			def = _rtld_symlook_needed(name, hash, &fake, &defobj,
 			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.89 src/libexec/ld.elf_so/rtld.h:1.90
--- src/libexec/ld.elf_so/rtld.h:1.89	Sat Feb 27 11:16:38 2010
+++ src/libexec/ld.elf_so/rtld.h	Thu Mar 18 22:17:55 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.h,v 1.89 2010/02/27 11:16:38 roy Exp $	 */
+/*	$NetBSD: rtld.h,v 1.90 2010/03/18 22:17:55 roy Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -61,13 +61,14 @@
 
 /*
  * Fill in a DoneList with an allocation large enough to hold all of
- * the currently-loaded objects.
+ * the currently-loaded objects. Keep this in a macro since it calls
+ * alloca and we want that to occur within the scope of the caller.
  */
-#define _rtld_donelist_init(dlp)		\
-((dlp)->objs = xmalloc(_rtld_objcount * sizeof((dlp)->objs[0])),	\
-(dlp)->num_alloc = _rtld_objcount,	\
+#define _rtld_donelist_init(dlp)	\
+((dlp)->num_alloc = _rtld_objcount,	\
+(dlp)->objs = alloca((dlp)->num_alloc * sizeof((dlp)->objs[0])),	\
+assert((dlp)->objs != NULL),	\
 (dlp)->num_used = 0)
-#define _rtld_donelist_clear(dlp)		xfree((dlp)->objs)
 
 #endif /* _RTLD_SOURCE */
 

Index: src/libexec/ld.elf_so/symbol.c
diff -u src/libexec/ld.elf_so/symbol.c:1.51 src/libexec/ld.elf_so/symbol.c:1.52
--- src/libexec/ld.elf_so/symbol.c:1.51	Sat Feb 27 11:16:38 2010
+++ src/libexec/ld.elf_so/symbol.c	Thu Mar 18 22:17:55 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: symbol.c,v 1.51 2010/02/27 11:16:38 roy Exp $	 */
+/*	$NetBSD: symbol.c,v 1.52 2010/03/18 22:17:55 roy Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: symbol.c,v 1.51 2010/02/27 11:16:38 roy Exp $");
+__RCSID("$NetBSD: symbol.c,v 1.52 2010/03/18 22:17:55 roy Exp $");
 #endif /* not lint */
 
 #include 
@@ -479,8 +479,6 @@
 		}
 	}
 
-	_rtld_donelist_clear(&donelist);
-
 	if (def != NULL)
 		*defobj_out = defobj;
 	return def;



CVS commit: src/libexec/ld.elf_so

2010-03-19 Thread Roy Marples
Module Name:src
Committed By:   roy
Date:   Fri Mar 19 20:53:50 UTC 2010

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

Log Message:
Use the gcc directive to disable SSP warnings.


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 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.94 src/libexec/ld.elf_so/Makefile:1.95
--- src/libexec/ld.elf_so/Makefile:1.94	Thu Mar 18 22:17:55 2010
+++ src/libexec/ld.elf_so/Makefile	Fri Mar 19 20:53:50 2010
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.94 2010/03/18 22:17:55 roy Exp $
+#	$NetBSD: Makefile,v 1.95 2010/03/19 20:53:50 roy Exp $
 #
 # NOTE: when changing ld.so, ensure that ldd still compiles.
 #
@@ -16,10 +16,6 @@
 .include 			# for OBJECT_FMT definition
 .include 			# for SHLINKINSTALLDIR definition
 
-# We use alloca
-USE_FORT=	no
-USE_SSP=	no
-
 .if defined(LDELFSO_MACHINE_CPU) && !empty(LDELFSO_MACHINE_CPU) && \
 exists(${.CURDIR}/arch/${LDELFSO_MACHINE_CPU})
 ARCHSUBDIR=	${LDELFSO_MACHINE_CPU}
@@ -120,3 +116,7 @@
 
 .include 
 .endif
+
+# We use alloca, so disable SSP warnings.
+# This has to come last in the CFLAGS ordering
+CFLAGS+=	-Wno-stack-protector



CVS commit: src/libexec/ld.elf_so

2010-03-20 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Mar 20 16:36:35 UTC 2010

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

Log Message:
Only apply -Wno-stack-protector where alloca is used.


To generate a diff of this commit:
cvs rdiff -u -r1.95 -r1.96 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.95 src/libexec/ld.elf_so/Makefile:1.96
--- src/libexec/ld.elf_so/Makefile:1.95	Fri Mar 19 20:53:50 2010
+++ src/libexec/ld.elf_so/Makefile	Sat Mar 20 16:36:35 2010
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.95 2010/03/19 20:53:50 roy Exp $
+#	$NetBSD: Makefile,v 1.96 2010/03/20 16:36:35 skrll Exp $
 #
 # NOTE: when changing ld.so, ensure that ldd still compiles.
 #
@@ -85,6 +85,10 @@
 CPPFLAGS+=	-DRTLD_DEFAULT_LIBRARY_PATH=\"${SHLIBDIR}:${LIBDIR}\"
 .endif
 
+# rtld.c and symbol.c use alloca, so disable SSP warnings.
+COPTS.rtld.c+=	-Wno-stack-protector
+COPTS.symbol.c+=-Wno-stack-protector
+
 LDADD+=		-L${CLIBOBJ} -L${DESTDIR}${LIBDIR}
 .if ${MKPICLIB} != "no"
 LDADD+=		-lc_pic
@@ -116,7 +120,3 @@
 
 .include 
 .endif
-
-# We use alloca, so disable SSP warnings.
-# This has to come last in the CFLAGS ordering
-CFLAGS+=	-Wno-stack-protector



CVS commit: src/libexec/ld.elf_so

2010-08-06 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Fri Aug  6 16:33:19 UTC 2010

Modified Files:
src/libexec/ld.elf_so: rtld.h
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:
Reduce header pollution for mdreloc.c. Make Obj_Entry argument of
_rtld_relocate_nonplt_objects non-const in preparation for TLS support.


To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 src/libexec/ld.elf_so/rtld.h
cvs rdiff -u -r1.36 -r1.37 src/libexec/ld.elf_so/arch/alpha/alpha_reloc.c
cvs rdiff -u -r1.33 -r1.34 src/libexec/ld.elf_so/arch/arm/mdreloc.c
cvs rdiff -u -r1.32 -r1.33 src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c
cvs rdiff -u -r1.31 -r1.32 src/libexec/ld.elf_so/arch/i386/mdreloc.c
cvs rdiff -u -r1.26 -r1.27 src/libexec/ld.elf_so/arch/m68k/mdreloc.c
cvs rdiff -u -r1.58 -r1.59 src/libexec/ld.elf_so/arch/mips/mips_reloc.c
cvs rdiff -u -r1.44 -r1.45 src/libexec/ld.elf_so/arch/powerpc/ppc_reloc.c
cvs rdiff -u -r1.27 -r1.28 src/libexec/ld.elf_so/arch/sh3/mdreloc.c
cvs rdiff -u -r1.43 -r1.44 src/libexec/ld.elf_so/arch/sparc/mdreloc.c
cvs rdiff -u -r1.46 -r1.47 src/libexec/ld.elf_so/arch/sparc64/mdreloc.c
cvs rdiff -u -r1.26 -r1.27 src/libexec/ld.elf_so/arch/vax/mdreloc.c
cvs rdiff -u -r1.37 -r1.38 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/rtld.h
diff -u src/libexec/ld.elf_so/rtld.h:1.91 src/libexec/ld.elf_so/rtld.h:1.92
--- src/libexec/ld.elf_so/rtld.h:1.91	Mon Apr  5 14:01:26 2010
+++ src/libexec/ld.elf_so/rtld.h	Fri Aug  6 16:33:17 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.h,v 1.91 2010/04/05 14:01:26 joerg Exp $	 */
+/*	$NetBSD: rtld.h,v 1.92 2010/08/06 16:33:17 joerg Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -280,7 +280,7 @@
 /* reloc.c */
 int _rtld_do_copy_relocations(const Obj_Entry *);
 int _rtld_relocate_objects(Obj_Entry *, bool);
-int _rtld_relocate_nonplt_objects(const Obj_Entry *);
+int _rtld_relocate_nonplt_objects(Obj_Entry *);
 int _rtld_relocate_plt_lazy(const Obj_Entry *);
 int _rtld_relocate_plt_objects(const Obj_Entry *);
 void _rtld_setup_pltgot(const Obj_Entry *);
@@ -309,6 +309,7 @@
 #endif
 
 /* map_object.c */
+struct stat;
 Obj_Entry *_rtld_map_object(const char *, int, const struct stat *);
 void _rtld_obj_free(Obj_Entry *);
 Obj_Entry *_rtld_obj_new(void);

Index: src/libexec/ld.elf_so/arch/alpha/alpha_reloc.c
diff -u src/libexec/ld.elf_so/arch/alpha/alpha_reloc.c:1.36 src/libexec/ld.elf_so/arch/alpha/alpha_reloc.c:1.37
--- src/libexec/ld.elf_so/arch/alpha/alpha_reloc.c:1.36	Thu Jan 14 11:58:31 2010
+++ src/libexec/ld.elf_so/arch/alpha/alpha_reloc.c	Fri Aug  6 16:33:17 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: alpha_reloc.c,v 1.36 2010/01/14 11:58:31 skrll Exp $	*/
+/*	$NetBSD: alpha_reloc.c,v 1.37 2010/08/06 16:33:17 joerg Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -62,11 +62,10 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: alpha_reloc.c,v 1.36 2010/01/14 11:58:31 skrll Exp $");
+__RCSID("$NetBSD: alpha_reloc.c,v 1.37 2010/08/06 16:33:17 joerg Exp $");
 #endif /* not lint */
 
 #include 
-#include 
 #include 
 
 #include "rtld.h"
@@ -196,7 +195,7 @@
 }
 
 int
-_rtld_relocate_nonplt_objects(const Obj_Entry *obj)
+_rtld_relocate_nonplt_objects(Obj_Entry *obj)
 {
 	const Elf_Rela *rela;
 	Elf_Addr target = -1;

Index: src/libexec/ld.elf_so/arch/arm/mdreloc.c
diff -u src/libexec/ld.elf_so/arch/arm/mdreloc.c:1.33 src/libexec/ld.elf_so/arch/arm/mdreloc.c:1.34
--- src/libexec/ld.elf_so/arch/arm/mdreloc.c:1.33	Thu Jan 14 12:12:07 2010
+++ src/libexec/ld.elf_so/arch/arm/mdreloc.c	Fri Aug  6 16:33:17 2010
@@ -1,13 +1,11 @@
-/*	$NetBSD: mdreloc.c,v 1.33 2010/01/14 12:12:07 skrll Exp $	*/
+/*	$NetBSD: mdreloc.c,v 1.34 2010/08/06 16:33:17 joerg Exp $	*/
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: mdreloc.c,v 1.33 2010/01/14 12:12:07 skrll Exp $");
+__RCSID("$NetBSD: mdreloc.c,v 1.34 2010/08/06 16:33:17 joerg Exp $");
 #endif /* not lint */
 
 #include 
-#include 
-
 #include 
 
 #include "debug.h"
@@ -73,7 +71,7 @@
 }
 
 int
-_rtld_relocate_nonplt_objects(const Obj_Entry *obj)
+_rtld_relocate_nonplt_objects(Obj_Entry *obj)
 {
 	const Elf_Rel *rel;
 

Index: src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c
diff -u src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c:1.32 src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c:1.33
--- src

CVS commit: src/libexec/ld.elf_so

2010-08-07 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sat Aug  7 19:47:35 UTC 2010

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

Log Message:
Stricter matching for _rtld_invalid_paths by ensuring separator.
Use mem* functions instead of str* for strings of known size.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 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.21 src/libexec/ld.elf_so/search.c:1.22
--- src/libexec/ld.elf_so/search.c:1.21	Tue Mar 21 17:48:10 2006
+++ src/libexec/ld.elf_so/search.c	Sat Aug  7 19:47:34 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: search.c,v 1.21 2006/03/21 17:48:10 christos Exp $	 */
+/*	$NetBSD: search.c,v 1.22 2010/08/07 19:47:34 joerg Exp $	 */
 
 /*
  * Copyright 1996 Matt Thomas 
@@ -38,7 +38,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: search.c,v 1.21 2006/03/21 17:48:10 christos Exp $");
+__RCSID("$NetBSD: search.c,v 1.22 2010/08/07 19:47:34 joerg Exp $");
 #endif /* not lint */
 
 #include 
@@ -80,15 +80,17 @@
 
 	for (sp = _rtld_invalid_paths; sp != NULL; sp = sp->sp_next) {
 		if (sp->sp_pathlen == pathnamelen &&
+		sp->sp_path[dirlen] == '/' &&
 		!memcmp(name, sp->sp_path + dirlen + 1, namelen) &&
 		!memcmp(dir, sp->sp_path, dirlen)) {
 			return NULL;
 		}
 	}
 
-	(void)strncpy(pathname, dir, dirlen);
+	memcpy(pathname, dir, dirlen);
 	pathname[dirlen] = '/';
-	strcpy(pathname + dirlen + 1, name);
+	memcpy(pathname + dirlen + 1, name, namelen);
+	pathname[pathnamelen] = '\0';
 
 	dbg(("  Trying \"%s\"", pathname));
 	obj = _rtld_load_object(pathname, mode);



CVS commit: src/libexec/ld.elf_so

2009-04-12 Thread Luke Mewburn
Module Name:src
Committed By:   lukem
Date:   Sun Apr 12 13:29:29 UTC 2009

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

Log Message:
Fix const issues (cast const pointers to "const uint8_t *" instead of "caddr_t")


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 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.27 src/libexec/ld.elf_so/headers.c:1.28
--- src/libexec/ld.elf_so/headers.c:1.27	Tue Jan  6 04:01:46 2009
+++ src/libexec/ld.elf_so/headers.c	Sun Apr 12 13:29:29 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: headers.c,v 1.27 2009/01/06 04:01:46 mrg Exp $	 */
+/*	$NetBSD: headers.c,v 1.28 2009/04/12 13:29:29 lukem Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: headers.c,v 1.27 2009/01/06 04:01:46 mrg Exp $");
+__RCSID("$NetBSD: headers.c,v 1.28 2009/04/12 13:29:29 lukem Exp $");
 #endif /* not lint */
 
 #include 
@@ -232,8 +232,8 @@
 		}
 	}
 
-	obj->rellim = (const Elf_Rel *)((caddr_t)obj->rel + relsz);
-	obj->relalim = (const Elf_Rela *)((caddr_t)obj->rela + relasz);
+	obj->rellim = (const Elf_Rel *)((const uint8_t *)obj->rel + relsz);
+	obj->relalim = (const Elf_Rela *)((const uint8_t *)obj->rela + relasz);
 	if (plttype == DT_REL) {
 		obj->pltrel = (const Elf_Rel *)(obj->relocbase + pltrel);
 		obj->pltrellim = (const Elf_Rel *)(obj->relocbase + pltrel + pltrelsz);



CVS commit: src/libexec/ld.elf_so

2009-05-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue May 19 20:44:52 UTC 2009

Modified Files:
src/libexec/ld.elf_so: Makefile load.c map_object.c paths.c rtld.c
rtld.h xmalloc.c xprintf.c

Log Message:
warns=4


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 src/libexec/ld.elf_so/Makefile
cvs rdiff -u -r1.35 -r1.36 src/libexec/ld.elf_so/load.c
cvs rdiff -u -r1.37 -r1.38 src/libexec/ld.elf_so/map_object.c
cvs rdiff -u -r1.39 -r1.40 src/libexec/ld.elf_so/paths.c
cvs rdiff -u -r1.123 -r1.124 src/libexec/ld.elf_so/rtld.c
cvs rdiff -u -r1.79 -r1.80 src/libexec/ld.elf_so/rtld.h
cvs rdiff -u -r1.8 -r1.9 src/libexec/ld.elf_so/xmalloc.c
cvs rdiff -u -r1.19 -r1.20 src/libexec/ld.elf_so/xprintf.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.88 src/libexec/ld.elf_so/Makefile:1.89
--- src/libexec/ld.elf_so/Makefile:1.88	Sun Mar 15 22:24:56 2009
+++ src/libexec/ld.elf_so/Makefile	Tue May 19 16:44:52 2009
@@ -1,6 +1,6 @@
-#	$NetBSD: Makefile,v 1.88 2009/03/16 02:24:56 lukem Exp $
+#	$NetBSD: Makefile,v 1.89 2009/05/19 20:44:52 christos Exp $
 
-WARNS?=2	# XXX: too many sign-compare issues in xmalloc.c
+WARNS?=4
 
 # We are not building this with PIE
 PIE_CFLAGS=

Index: src/libexec/ld.elf_so/load.c
diff -u src/libexec/ld.elf_so/load.c:1.35 src/libexec/ld.elf_so/load.c:1.36
--- src/libexec/ld.elf_so/load.c:1.35	Fri Dec  7 15:34:04 2007
+++ src/libexec/ld.elf_so/load.c	Tue May 19 16:44:52 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: load.c,v 1.35 2007/12/07 20:34:04 ad Exp $	 */
+/*	$NetBSD: load.c,v 1.36 2009/05/19 20:44:52 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: load.c,v 1.35 2007/12/07 20:34:04 ad Exp $");
+__RCSID("$NetBSD: load.c,v 1.36 2009/05/19 20:44:52 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -185,7 +185,8 @@
 {
 	Library_Xform *x = _rtld_xforms;
 	Obj_Entry *o = NULL;
-	size_t i, j;
+	size_t j;
+	ssize_t i;
 	bool got = false;
 	union {
 		int i;

Index: src/libexec/ld.elf_so/map_object.c
diff -u src/libexec/ld.elf_so/map_object.c:1.37 src/libexec/ld.elf_so/map_object.c:1.38
--- src/libexec/ld.elf_so/map_object.c:1.37	Mon Jan  5 23:01:46 2009
+++ src/libexec/ld.elf_so/map_object.c	Tue May 19 16:44:52 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: map_object.c,v 1.37 2009/01/06 04:01:46 mrg Exp $	 */
+/*	$NetBSD: map_object.c,v 1.38 2009/05/19 20:44:52 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -34,7 +34,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: map_object.c,v 1.37 2009/01/06 04:01:46 mrg Exp $");
+__RCSID("$NetBSD: map_object.c,v 1.38 2009/05/19 20:44:52 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -91,7 +91,7 @@
 	size_t		 nclear;
 #endif
 
-	if (sb != NULL && sb->st_size < sizeof (Elf_Ehdr)) {
+	if (sb != NULL && sb->st_size < (off_t)sizeof (Elf_Ehdr)) {
 		_rtld_error("%s: unrecognized file format1", path);
 		return NULL;
 	}

Index: src/libexec/ld.elf_so/paths.c
diff -u src/libexec/ld.elf_so/paths.c:1.39 src/libexec/ld.elf_so/paths.c:1.40
--- src/libexec/ld.elf_so/paths.c:1.39	Wed Jun  4 20:03:20 2008
+++ src/libexec/ld.elf_so/paths.c	Tue May 19 16:44:52 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: paths.c,v 1.39 2008/06/05 00:03:20 ad Exp $	 */
+/*	$NetBSD: paths.c,v 1.40 2009/05/19 20:44:52 christos Exp $	 */
 
 /*
  * Copyright 1996 Matt Thomas 
@@ -30,7 +30,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: paths.c,v 1.39 2008/06/05 00:03:20 ad Exp $");
+__RCSID("$NetBSD: paths.c,v 1.40 2009/05/19 20:44:52 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -357,7 +357,7 @@
 		(void)close(fd);
 		return;
 	}
-	if (sz >= sizeof(small)) {
+	if (sz >= (ssize_t)sizeof(small)) {
 		if (fstat(fd, &st) == -1) {
 			/* Complain */
 			xwarn("fstat: %s", fname);
@@ -414,8 +414,8 @@
 {
 	const char *node, *ep;
 	struct sysctlnode query, *result, *newresult;
-	int mib[CTL_MAXNAME], i, r;
-	size_t res_size, n;
+	int mib[CTL_MAXNAME], r;
+	size_t res_size, n, i;
 	u_int miblen = 0;
 
 	/* Start with 16 entries, will grow it up as needed. */
@@ -426,7 +426,7 @@
 
 	ep = name + strlen(name);
 	do {
-		i = -1;
+		i = ~0ul;
 		while (*name == '/' || *name == '.')
 			name++;
 		if (name >= ep)
@@ -463,7 +463,7 @@
 			}
 	} while (name < ep && miblen <= CTL_MAXNAME);
 
-	if (name < ep || i == -1)
+	if (name < ep || i == ~0ul)
 		goto bad;
 	r = SYSCTL_TYPE(result[i].sysctl_flags);
 

Index: src/libexec/ld.elf_so/rtld.c
diff -u src/libexec/ld.elf_so/rtld.c:1.123 src/libexec/ld.elf_so/rtld.c:1.124
--- src/libexec/ld.elf_so/rtld.c:1.123	Sun Oct 26 03:11:54 2008
+++ src/libexec/ld.elf_so/rtld.c	Tue May 19 16:44:52 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.123 2008/10/26 07:11:54 mrg Exp $	 */
+/*	$NetBSD: rtld.c,v 1.124 2009/05/19 20:44:52 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -

CVS commit: src/libexec/ld.elf_so

2009-05-20 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Wed May 20 19:38:38 UTC 2009

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

Log Message:
Add a reminder about ldd depending on ld.so.


To generate a diff of this commit:
cvs rdiff -u -r1.89 -r1.90 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.89 src/libexec/ld.elf_so/Makefile:1.90
--- src/libexec/ld.elf_so/Makefile:1.89	Tue May 19 20:44:52 2009
+++ src/libexec/ld.elf_so/Makefile	Wed May 20 19:38:38 2009
@@ -1,4 +1,7 @@
-#	$NetBSD: Makefile,v 1.89 2009/05/19 20:44:52 christos Exp $
+#	$NetBSD: Makefile,v 1.90 2009/05/20 19:38:38 ad Exp $
+#
+# NOTE: when changing ld.so, ensure that ldd still compiles.
+#
 
 WARNS?=4
 



CVS commit: src/libexec/ld.elf_so

2010-04-05 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Mon Apr  5 14:01:26 UTC 2010

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

Log Message:
Use fast_remainder32 for the ELF hash. For the hot cache case, this
speeds up Firefox startup by over 2% on AMD64.
Limit hash table buckets to 32bit.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/libexec/ld.elf_so/headers.c
cvs rdiff -u -r1.101 -r1.102 src/libexec/ld.elf_so/reloc.c
cvs rdiff -u -r1.90 -r1.91 src/libexec/ld.elf_so/rtld.h
cvs rdiff -u -r1.52 -r1.53 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/headers.c
diff -u src/libexec/ld.elf_so/headers.c:1.28 src/libexec/ld.elf_so/headers.c:1.29
--- src/libexec/ld.elf_so/headers.c:1.28	Sun Apr 12 13:29:29 2009
+++ src/libexec/ld.elf_so/headers.c	Mon Apr  5 14:01:26 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: headers.c,v 1.28 2009/04/12 13:29:29 lukem Exp $	 */
+/*	$NetBSD: headers.c,v 1.29 2010/04/05 14:01:26 joerg Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: headers.c,v 1.28 2009/04/12 13:29:29 lukem Exp $");
+__RCSID("$NetBSD: headers.c,v 1.29 2010/04/05 14:01:26 joerg Exp $");
 #endif /* not lint */
 
 #include 
@@ -53,6 +53,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include "debug.h"
@@ -138,10 +139,23 @@
 const Elf_Word *hashtab = (const Elf_Word *)
 (obj->relocbase + dynp->d_un.d_ptr);
 
-obj->nbuckets = hashtab[0];
+if (hashtab[0] > UINT32_MAX)
+	obj->nbuckets = UINT32_MAX;
+else
+	obj->nbuckets = hashtab[0];
 obj->nchains = hashtab[1];
 obj->buckets = hashtab + 2;
 obj->chains = obj->buckets + obj->nbuckets;
+/*
+ * Should really be in _rtld_relocate_objects,
+ * but _rtld_symlook_obj might be used before.
+ */
+if (obj->nbuckets) {
+	fast_divide32_prepare(obj->nbuckets,
+	&obj->nbuckets_m,
+	&obj->nbuckets_s1,
+	&obj->nbuckets_s2);
+}
 			}
 			break;
 

Index: src/libexec/ld.elf_so/reloc.c
diff -u src/libexec/ld.elf_so/reloc.c:1.101 src/libexec/ld.elf_so/reloc.c:1.102
--- src/libexec/ld.elf_so/reloc.c:1.101	Sat Jan 16 10:37:51 2010
+++ src/libexec/ld.elf_so/reloc.c	Mon Apr  5 14:01:26 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: reloc.c,v 1.101 2010/01/16 10:37:51 skrll Exp $	 */
+/*	$NetBSD: reloc.c,v 1.102 2010/04/05 14:01:26 joerg Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -39,7 +39,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: reloc.c,v 1.101 2010/01/16 10:37:51 skrll Exp $");
+__RCSID("$NetBSD: reloc.c,v 1.102 2010/04/05 14:01:26 joerg Exp $");
 #endif /* not lint */
 
 #include 
@@ -52,6 +52,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include "debug.h"
@@ -154,6 +155,10 @@
 			" symbol table", obj->path);
 			return -1;
 		}
+		if (obj->nbuckets == UINT32_MAX) {
+			_rtld_error("%s: Symbol table too large", obj->path);
+			return -1;
+		}
 		rdbg((" relocating %s (%ld/%ld rel/rela, %ld/%ld plt rel/rela)",
 		obj->path,
 		(long)(obj->rellim - obj->rel),

Index: src/libexec/ld.elf_so/rtld.h
diff -u src/libexec/ld.elf_so/rtld.h:1.90 src/libexec/ld.elf_so/rtld.h:1.91
--- src/libexec/ld.elf_so/rtld.h:1.90	Thu Mar 18 22:17:55 2010
+++ src/libexec/ld.elf_so/rtld.h	Mon Apr  5 14:01:26 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.h,v 1.90 2010/03/18 22:17:55 roy Exp $	 */
+/*	$NetBSD: rtld.h,v 1.91 2010/04/05 14:01:26 joerg Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -162,7 +162,10 @@
 #endif
 
 	const Elf_Word *buckets;	/* Hash table buckets array */
-	unsigned long   nbuckets;	/* Number of buckets */
+	uint32_tnbuckets;	/* Number of buckets */
+	uint32_tnbuckets_m;	/* Precomputed for fast remainder */
+	uint8_t nbuckets_s1;
+	uint8_t nbuckets_s2;
 	const Elf_Word *chains;		/* Hash table chain array */
 	unsigned long   nchains;	/* Number of chains */
 

Index: src/libexec/ld.elf_so/symbol.c
diff -u src/libexec/ld.elf_so/symbol.c:1.52 src/libexec/ld.elf_so/symbol.c:1.53
--- src/libexec/ld.elf_so/symbol.c:1.52	Thu Mar 18 22:17:55 2010
+++ src/libexec/ld.elf_so/symbol.c	Mon Apr  5 14:01:26 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: symbol.c,v 1.52 2010/03/18 22:17:55 roy Exp $	 */
+/*	$NetBSD: symbol.c,v 1.53 2010/04/05 14:01:26 joerg Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: symbol.c,v 1.52 2010/03/18 22:17:55 roy Exp $");
+__RCSID("$NetBSD: symbol.c,v 1.53 2010/04/05 14:01:26 joerg Exp $");
 #endif /* not lint */
 
 #include 
@@ -53,6 +53,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include "debug.h"
@@ -229,7 +230,8 @@
 {
 	unsigned long symnum;
 
-	for (symnum = obj->buckets[hash % obj->nbuckets];
+	for (symnum = obj->buckets[fast_remainder32(hash, obj->nbuckets,
+	 obj

CVS commit: src/libexec/ld.elf_so

2010-09-11 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Sep 11 11:11:53 UTC 2010

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

Log Message:
Wrap long line.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 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.39 src/libexec/ld.elf_so/map_object.c:1.40
--- src/libexec/ld.elf_so/map_object.c:1.39	Sun Jan 10 07:29:47 2010
+++ src/libexec/ld.elf_so/map_object.c	Sat Sep 11 11:11:52 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: map_object.c,v 1.39 2010/01/10 07:29:47 skrll Exp $	 */
+/*	$NetBSD: map_object.c,v 1.40 2010/09/11 11:11:52 skrll Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -34,7 +34,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: map_object.c,v 1.39 2010/01/10 07:29:47 skrll Exp $");
+__RCSID("$NetBSD: map_object.c,v 1.40 2010/09/11 11:11:52 skrll Exp $");
 #endif /* not lint */
 
 #include 
@@ -114,7 +114,8 @@
 	/* Make sure the file is valid */
 	if (memcmp(ELFMAG, ehdr->e_ident, SELFMAG) != 0 ||
 	ehdr->e_ident[EI_CLASS] != ELFCLASS) {
-		_rtld_error("%s: unrecognized file format2 [%x != %x]", path, ehdr->e_ident[EI_CLASS], ELFCLASS);
+		_rtld_error("%s: unrecognized file format2 [%x != %x]", path,
+		ehdr->e_ident[EI_CLASS], ELFCLASS);
 		goto bad;
 	}
 	/* Elf_e_ident includes class */



CVS commit: src/libexec/ld.elf_so

2010-09-23 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Thu Sep 23 13:03:35 UTC 2010

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

Log Message:
Avoid casting from d_val to plttype of different signedness.
Just two booleans for the same purpose.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 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.29 src/libexec/ld.elf_so/headers.c:1.30
--- src/libexec/ld.elf_so/headers.c:1.29	Mon Apr  5 14:01:26 2010
+++ src/libexec/ld.elf_so/headers.c	Thu Sep 23 13:03:35 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: headers.c,v 1.29 2010/04/05 14:01:26 joerg Exp $	 */
+/*	$NetBSD: headers.c,v 1.30 2010/09/23 13:03:35 joerg Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: headers.c,v 1.29 2010/04/05 14:01:26 joerg Exp $");
+__RCSID("$NetBSD: headers.c,v 1.30 2010/09/23 13:03:35 joerg Exp $");
 #endif /* not lint */
 
 #include 
@@ -69,7 +69,8 @@
 	Elf_Dyn*dynp;
 	Needed_Entry  **needed_tail = &obj->needed;
 	const Elf_Dyn  *dyn_rpath = NULL;
-	Elf_Sword	plttype = DT_NULL;
+	bool		use_pltrel = false;
+	bool		use_pltrela = false;
 	Elf_Addrrelsz = 0, relasz = 0;
 	Elf_Addr	pltrel = 0, pltrelsz = 0;
 	Elf_Addr	init = 0, fini = 0;
@@ -112,8 +113,9 @@
 			break;
 
 		case DT_PLTREL:
-			plttype = dynp->d_un.d_val;
-			assert(plttype == DT_REL || plttype == DT_RELA);
+			use_pltrel = dynp->d_un.d_val == DT_REL;
+			use_pltrela = dynp->d_un.d_val == DT_RELA;
+			assert(use_pltrel || use_pltrela);
 			break;
 
 		case DT_SYMTAB:
@@ -248,7 +250,7 @@
 
 	obj->rellim = (const Elf_Rel *)((const uint8_t *)obj->rel + relsz);
 	obj->relalim = (const Elf_Rela *)((const uint8_t *)obj->rela + relasz);
-	if (plttype == DT_REL) {
+	if (use_pltrel) {
 		obj->pltrel = (const Elf_Rel *)(obj->relocbase + pltrel);
 		obj->pltrellim = (const Elf_Rel *)(obj->relocbase + pltrel + pltrelsz);
 		obj->pltrelalim = 0;
@@ -258,7 +260,7 @@
 		obj->rellim > obj->pltrel &&
 		obj->rellim <= obj->pltrellim)
 			obj->rellim = obj->pltrel;
-	} else if (plttype == DT_RELA) {
+	} else if (use_pltrela) {
 		obj->pltrela = (const Elf_Rela *)(obj->relocbase + pltrel);
 		obj->pltrellim = 0;
 		obj->pltrelalim = (const Elf_Rela *)(obj->relocbase + pltrel + pltrelsz);



CVS commit: src/libexec/ld.elf_so

2010-09-30 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Sep 30 19:43:11 UTC 2010

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

Log Message:
Improve debug output.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 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.31 src/libexec/ld.elf_so/headers.c:1.32
--- src/libexec/ld.elf_so/headers.c:1.31	Thu Sep 30 09:11:18 2010
+++ src/libexec/ld.elf_so/headers.c	Thu Sep 30 19:43:11 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: headers.c,v 1.31 2010/09/30 09:11:18 skrll Exp $	 */
+/*	$NetBSD: headers.c,v 1.32 2010/09/30 19:43:11 skrll Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: headers.c,v 1.31 2010/09/30 09:11:18 skrll Exp $");
+__RCSID("$NetBSD: headers.c,v 1.32 2010/09/30 19:43:11 skrll Exp $");
 #endif /* not lint */
 
 #include 
@@ -313,11 +313,12 @@
 	obj = _rtld_obj_new();
 	for (ph = phdr; ph < phlimit; ++ph) {
 		vaddr = ph->p_vaddr + relocoffs;
-		dbg(("headers: relocoffs = %lx\n", (long)relocoffs));
 		switch (ph->p_type) {
 
 		case PT_PHDR:
 			relocoffs = (uintptr_t)phdr - (uintptr_t)ph->p_vaddr;
+			dbg(("headers: phdr %p phsize %zu relocoffs %lx", obj->phdr,  
+			obj->phsize, (long)relocoffs)); 
 			break;
 
 		case PT_INTERP:



CVS commit: src/libexec/ld.elf_so

2010-09-30 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Sep 30 19:45:25 UTC 2010

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

Log Message:
Oops. Remove trailing whitespace in previous.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 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.32 src/libexec/ld.elf_so/headers.c:1.33
--- src/libexec/ld.elf_so/headers.c:1.32	Thu Sep 30 19:43:11 2010
+++ src/libexec/ld.elf_so/headers.c	Thu Sep 30 19:45:24 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: headers.c,v 1.32 2010/09/30 19:43:11 skrll Exp $	 */
+/*	$NetBSD: headers.c,v 1.33 2010/09/30 19:45:24 skrll Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: headers.c,v 1.32 2010/09/30 19:43:11 skrll Exp $");
+__RCSID("$NetBSD: headers.c,v 1.33 2010/09/30 19:45:24 skrll Exp $");
 #endif /* not lint */
 
 #include 
@@ -317,8 +317,8 @@
 
 		case PT_PHDR:
 			relocoffs = (uintptr_t)phdr - (uintptr_t)ph->p_vaddr;
-			dbg(("headers: phdr %p phsize %zu relocoffs %lx", obj->phdr,  
-			obj->phsize, (long)relocoffs)); 
+			dbg(("headers: phdr %p phsize %zu relocoffs %lx", obj->phdr,
+			obj->phsize, (long)relocoffs));
 			break;
 
 		case PT_INTERP:



CVS commit: src/libexec/ld.elf_so

2010-10-10 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Oct 10 21:27:16 UTC 2010

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

Log Message:
restore binary compatibility for pre-2.0 binaries, requested by skrll and core.


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

Modified files:

Index: src/libexec/ld.elf_so/rtld.h
diff -u src/libexec/ld.elf_so/rtld.h:1.93 src/libexec/ld.elf_so/rtld.h:1.94
--- src/libexec/ld.elf_so/rtld.h:1.93	Thu Sep 30 05:11:18 2010
+++ src/libexec/ld.elf_so/rtld.h	Sun Oct 10 17:27:16 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.h,v 1.93 2010/09/30 09:11:18 skrll Exp $	 */
+/*	$NetBSD: rtld.h,v 1.94 2010/10/10 21:27:16 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -116,6 +116,9 @@
  *
  * Items marked with "(%)" are dynamically allocated, and must be freed
  * when the structure is destroyed.
+ *
+ * The layout of this structure needs to be preserved because pre-2.0 binaries
+ * hard-coded the location of dlopen() and friends.
  */
 
 #define RTLD_MAGIC	0xd550b87a
@@ -162,10 +165,7 @@
 #endif
 
 	const Elf_Symindx *buckets;	/* Hash table buckets array */
-	uint32_tnbuckets;	/* Number of buckets */
-	uint32_tnbuckets_m;	/* Precomputed for fast remainder */
-	uint8_t nbuckets_s1;
-	uint8_t nbuckets_s2;
+	unsigned long	unused1;	/* Used to be nbuckets */
 	const Elf_Symindx *chains;	/* Hash table chain array */
 	unsigned long   nchains;	/* Number of chains */
 
@@ -210,6 +210,11 @@
 	ino_t   ino;		/* Object's inode number */
 
 	void		*ehdr;
+
+	uint32_tnbuckets;	/* Number of buckets */
+	uint32_tnbuckets_m;	/* Precomputed for fast remainder */
+	uint8_t nbuckets_s1;
+	uint8_t nbuckets_s2;
 } Obj_Entry;
 
 typedef struct Struct_DoneList {



CVS commit: src/libexec/ld.elf_so

2010-10-15 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Oct 15 07:22:44 UTC 2010

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

Log Message:
Be more tolerant to the location of PT_PHDR in the segment list.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 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.33 src/libexec/ld.elf_so/headers.c:1.34
--- src/libexec/ld.elf_so/headers.c:1.33	Thu Sep 30 19:45:24 2010
+++ src/libexec/ld.elf_so/headers.c	Fri Oct 15 07:22:44 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: headers.c,v 1.33 2010/09/30 19:45:24 skrll Exp $	 */
+/*	$NetBSD: headers.c,v 1.34 2010/10/15 07:22:44 skrll Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: headers.c,v 1.33 2010/09/30 19:45:24 skrll Exp $");
+__RCSID("$NetBSD: headers.c,v 1.34 2010/10/15 07:22:44 skrll Exp $");
 #endif /* not lint */
 
 #include 
@@ -307,20 +307,27 @@
 	const Elf_Phdr *phlimit = phdr + phnum;
 	const Elf_Phdr *ph;
 	int nsegs = 0;
-	ptrdiff_t	relocoffs = 0;
 	Elf_Addr	vaddr;
 
 	obj = _rtld_obj_new();
+
+	for (ph = phdr; ph < phlimit; ++ph) {
+		if (ph->p_type != PT_PHDR)
+			continue;
+		
+		obj->phdr = (void *)(uintptr_t)phdr->p_vaddr;
+		obj->phsize = phdr->p_memsz;
+		obj->relocbase = (caddr_t)((uintptr_t)phdr - (uintptr_t)ph->p_vaddr);
+		dbg(("headers: phdr %p phsize %zu relocbase %lx", obj->phdr,
+		obj->phsize, (long)obj->relocbase));
+		break;
+	}
+	assert(obj->phdr == phdr);
+	
 	for (ph = phdr; ph < phlimit; ++ph) {
-		vaddr = ph->p_vaddr + relocoffs;
+		vaddr = (Elf_Addr)obj->relocbase + ph->p_vaddr;
 		switch (ph->p_type) {
 
-		case PT_PHDR:
-			relocoffs = (uintptr_t)phdr - (uintptr_t)ph->p_vaddr;
-			dbg(("headers: phdr %p phsize %zu relocoffs %lx", obj->phdr,
-			obj->phsize, (long)relocoffs));
-			break;
-
 		case PT_INTERP:
 			obj->interp = (const char *)(uintptr_t)vaddr;
 			break;
@@ -330,7 +337,6 @@
 			if (nsegs == 0) {	/* First load segment */
 obj->vaddrbase = round_down(vaddr);
 obj->mapbase = (caddr_t)(uintptr_t)obj->vaddrbase;
-obj->relocbase = (void *)relocoffs;
 obj->textsize = round_up(vaddr + ph->p_memsz) -
 obj->vaddrbase;
 			} else {		/* Last load segment */



CVS commit: src/libexec/ld.elf_so

2010-10-15 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Oct 15 15:08:06 UTC 2010

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

Log Message:
Revert previous for now. It's part of a larger commit which will arrive
soon.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 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.34 src/libexec/ld.elf_so/headers.c:1.35
--- src/libexec/ld.elf_so/headers.c:1.34	Fri Oct 15 07:22:44 2010
+++ src/libexec/ld.elf_so/headers.c	Fri Oct 15 15:08:05 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: headers.c,v 1.34 2010/10/15 07:22:44 skrll Exp $	 */
+/*	$NetBSD: headers.c,v 1.35 2010/10/15 15:08:05 skrll Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: headers.c,v 1.34 2010/10/15 07:22:44 skrll Exp $");
+__RCSID("$NetBSD: headers.c,v 1.35 2010/10/15 15:08:05 skrll Exp $");
 #endif /* not lint */
 
 #include 
@@ -307,27 +307,20 @@
 	const Elf_Phdr *phlimit = phdr + phnum;
 	const Elf_Phdr *ph;
 	int nsegs = 0;
+	ptrdiff_t	relocoffs = 0;
 	Elf_Addr	vaddr;
 
 	obj = _rtld_obj_new();
-
-	for (ph = phdr; ph < phlimit; ++ph) {
-		if (ph->p_type != PT_PHDR)
-			continue;
-		
-		obj->phdr = (void *)(uintptr_t)phdr->p_vaddr;
-		obj->phsize = phdr->p_memsz;
-		obj->relocbase = (caddr_t)((uintptr_t)phdr - (uintptr_t)ph->p_vaddr);
-		dbg(("headers: phdr %p phsize %zu relocbase %lx", obj->phdr,
-		obj->phsize, (long)obj->relocbase));
-		break;
-	}
-	assert(obj->phdr == phdr);
-	
 	for (ph = phdr; ph < phlimit; ++ph) {
-		vaddr = (Elf_Addr)obj->relocbase + ph->p_vaddr;
+		vaddr = ph->p_vaddr + relocoffs;
 		switch (ph->p_type) {
 
+		case PT_PHDR:
+			relocoffs = (uintptr_t)phdr - (uintptr_t)ph->p_vaddr;
+			dbg(("headers: phdr %p phsize %zu relocoffs %lx", obj->phdr,
+			obj->phsize, (long)relocoffs));
+			break;
+
 		case PT_INTERP:
 			obj->interp = (const char *)(uintptr_t)vaddr;
 			break;
@@ -337,6 +330,7 @@
 			if (nsegs == 0) {	/* First load segment */
 obj->vaddrbase = round_down(vaddr);
 obj->mapbase = (caddr_t)(uintptr_t)obj->vaddrbase;
+obj->relocbase = (void *)relocoffs;
 obj->textsize = round_up(vaddr + ph->p_memsz) -
 obj->vaddrbase;
 			} else {		/* Last load segment */



CVS commit: src/libexec/ld.elf_so

2010-10-16 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Oct 16 17:48:13 UTC 2010

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

Log Message:
Add cast so that usr.bin/ldd/elf32 builds.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 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.36 src/libexec/ld.elf_so/headers.c:1.37
--- src/libexec/ld.elf_so/headers.c:1.36	Sat Oct 16 10:27:07 2010
+++ src/libexec/ld.elf_so/headers.c	Sat Oct 16 17:48:12 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: headers.c,v 1.36 2010/10/16 10:27:07 skrll Exp $	 */
+/*	$NetBSD: headers.c,v 1.37 2010/10/16 17:48:12 skrll Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: headers.c,v 1.36 2010/10/16 10:27:07 skrll Exp $");
+__RCSID("$NetBSD: headers.c,v 1.37 2010/10/16 17:48:12 skrll Exp $");
 #endif /* not lint */
 
 #include 
@@ -325,7 +325,7 @@
 	assert(obj->phdr == phdr);
 	
 	for (ph = phdr; ph < phlimit; ++ph) {
-		vaddr = (Elf_Addr)obj->relocbase + ph->p_vaddr;
+		vaddr = (Elf_Addr)(uintptr_t)(obj->relocbase + ph->p_vaddr);
 		switch (ph->p_type) {
 
 		case PT_INTERP:



CVS commit: src/libexec/ld.elf_so

2010-10-29 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Oct 29 15:08:18 UTC 2010

Modified Files:
src/libexec/ld.elf_so: Makefile rtld.c rtldenv.h
Added Files:
src/libexec/ld.elf_so: xenv.c

Log Message:
PR/44010: YAMAMOTO Takashi: sbrk: grow 0xb3ba2000 failed, error = 12"
(due to setenv changes?)
Provide a mini unsetenv that does not allocate/free memory and does not
bother about locking.


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 src/libexec/ld.elf_so/Makefile
cvs rdiff -u -r1.131 -r1.132 src/libexec/ld.elf_so/rtld.c
cvs rdiff -u -r1.9 -r1.10 src/libexec/ld.elf_so/rtldenv.h
cvs rdiff -u -r0 -r1.1 src/libexec/ld.elf_so/xenv.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.97 src/libexec/ld.elf_so/Makefile:1.98
--- src/libexec/ld.elf_so/Makefile:1.97	Tue Jul  6 01:59:56 2010
+++ src/libexec/ld.elf_so/Makefile	Fri Oct 29 11:08:17 2010
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.97 2010/07/06 05:59:56 mrg Exp $
+#	$NetBSD: Makefile,v 1.98 2010/10/29 15:08:17 christos Exp $
 #
 # NOTE: when changing ld.so, ensure that ldd still compiles.
 #
@@ -57,7 +57,7 @@
 
 CLIBOBJ!=	cd ${NETBSDSRCDIR}/lib/libc && ${PRINTOBJDIR}
 
-SRCS+=		rtld.c reloc.c symbol.c xmalloc.c xprintf.c debug.c \
+SRCS+=		rtld.c reloc.c symbol.c xenv.c xmalloc.c xprintf.c debug.c \
 		map_object.c load.c search.c headers.c paths.c expand.c
 
 .if ${USE_FORT} == "yes"

Index: src/libexec/ld.elf_so/rtld.c
diff -u src/libexec/ld.elf_so/rtld.c:1.131 src/libexec/ld.elf_so/rtld.c:1.132
--- src/libexec/ld.elf_so/rtld.c:1.131	Sat Oct 16 06:27:07 2010
+++ src/libexec/ld.elf_so/rtld.c	Fri Oct 29 11:08:17 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.131 2010/10/16 10:27:07 skrll Exp $	 */
+/*	$NetBSD: rtld.c,v 1.132 2010/10/29 15:08:17 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.131 2010/10/16 10:27:07 skrll Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.132 2010/10/29 15:08:17 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -444,7 +444,7 @@
 		getenv("LD_LIBRARY_PATH"));
 	} else {
 		execname = NULL;
-		if (unsetenv("LD_DEBUG") || unsetenv("LD_LIBRARY_PATH"))
+		if (xunsetenv("LD_DEBUG") || xunsetenv("LD_LIBRARY_PATH"))
 			_rtld_die();
 	}
 	_rtld_process_hints(execname, &_rtld_paths, &_rtld_xforms,
@@ -521,7 +521,7 @@
 		if (_rtld_preload(getenv("LD_PRELOAD")) == -1)
 			_rtld_die();
 	} else
-		if (unsetenv("LD_PRELOAD"))
+		if (xunsetenv("LD_PRELOAD"))
 			_rtld_die();
 
 	dbg(("loading needed objects"));

Index: src/libexec/ld.elf_so/rtldenv.h
diff -u src/libexec/ld.elf_so/rtldenv.h:1.9 src/libexec/ld.elf_so/rtldenv.h:1.10
--- src/libexec/ld.elf_so/rtldenv.h:1.9	Fri Oct  5 18:21:07 2007
+++ src/libexec/ld.elf_so/rtldenv.h	Fri Oct 29 11:08:17 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtldenv.h,v 1.9 2007/10/05 22:21:07 ad Exp $	 */
+/*	$NetBSD: rtldenv.h,v 1.10 2010/10/29 15:08:17 christos Exp $	 */
 
 /*
  * Copyright 1996 Matt Thomas 
@@ -59,6 +59,7 @@
 
 void xassert(const char *, int, const char *);
 const char *xstrerror(int);
+int	xunsetenv(const char *);
 
 # ifdef DEBUG
 #  define assert(cond)	((cond) ? (void) 0 : xassert(__FILE__, __LINE__, #cond))

Added files:

Index: src/libexec/ld.elf_so/xenv.c
diff -u /dev/null src/libexec/ld.elf_so/xenv.c:1.1
--- /dev/null	Fri Oct 29 11:08:18 2010
+++ src/libexec/ld.elf_so/xenv.c	Fri Oct 29 11:08:17 2010
@@ -0,0 +1,70 @@
+/*	$NetBSD: xenv.c,v 1.1 2010/10/29 15:08:17 christos Exp $	*/
+
+/*
+ * Copyright (c) 1987, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *may be used to endorse or promote products derived from this software
+ *without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BU

CVS commit: src/libexec/ld.elf_so

2010-11-14 Thread Matthias Scheler
Module Name:src
Committed By:   tron
Date:   Sun Nov 14 22:09:16 UTC 2010

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

Log Message:
Don't use internal libc function __findenv().


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/libexec/ld.elf_so/xenv.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/xenv.c
diff -u src/libexec/ld.elf_so/xenv.c:1.1 src/libexec/ld.elf_so/xenv.c:1.2
--- src/libexec/ld.elf_so/xenv.c:1.1	Fri Oct 29 15:08:17 2010
+++ src/libexec/ld.elf_so/xenv.c	Sun Nov 14 22:09:16 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: xenv.c,v 1.1 2010/10/29 15:08:17 christos Exp $	*/
+/*	$NetBSD: xenv.c,v 1.2 2010/11/14 22:09:16 tron Exp $	*/
 
 /*
  * Copyright (c) 1987, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)setenv.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: xenv.c,v 1.1 2010/10/29 15:08:17 christos Exp $");
+__RCSID("$NetBSD: xenv.c,v 1.2 2010/11/14 22:09:16 tron Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -42,9 +42,10 @@
 #include 
 #include "rtldenv.h"
 
-extern char * __findenv(const char *, int *);
 extern char **environ;
 
+#include 
+
 /*
  * xunsetenv(name) --
  *	Delete environmental variable "name".
@@ -52,19 +53,29 @@
 int
 xunsetenv(const char *name)
 {
-	int offset;
+	size_t l_name, r_offset, w_offset;
+
+	if (name == NULL) {
+		errno = EINVAL;
+		return -1;
+	}
 
-	if (name == NULL || *name == '\0' || strchr(name, '=') != NULL) {
+	l_name = strcspn(name, "=");
+	if (l_name == 0 || name[l_name] == '=') {
 		errno = EINVAL;
 		return -1;
 	}
 
-	while (__findenv(name, &offset) != NULL) {
-		while (environ[offset] != NULL) {
-			environ[offset] = environ[offset + 1];
-			offset++;
+	for (r_offset = 0, w_offset = 0; environ[r_offset] != NULL;
+	r_offset++) {
+		if (strncmp(name, environ[r_offset], l_name) != 0 ||
+		environ[r_offset][l_name] != '=') {
+			environ[w_offset++] = environ[r_offset];
 		}
 	}
 
+	while (w_offset < r_offset)
+		environ[w_offset++] = NULL;
+
 	return 0;
 }



CVS commit: src/libexec/ld.elf_so

2010-12-03 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Fri Dec  3 23:07:49 UTC 2010

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

Log Message:
ANSIfy


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/libexec/ld.elf_so/xmalloc.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/xmalloc.c
diff -u src/libexec/ld.elf_so/xmalloc.c:1.9 src/libexec/ld.elf_so/xmalloc.c:1.10
--- src/libexec/ld.elf_so/xmalloc.c:1.9	Tue May 19 20:44:52 2009
+++ src/libexec/ld.elf_so/xmalloc.c	Fri Dec  3 23:07:49 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: xmalloc.c,v 1.9 2009/05/19 20:44:52 christos Exp $	*/
+/*	$NetBSD: xmalloc.c,v 1.10 2010/12/03 23:07:49 joerg Exp $	*/
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -77,7 +77,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: xmalloc.c,v 1.9 2009/05/19 20:44:52 christos Exp $");
+__RCSID("$NetBSD: xmalloc.c,v 1.10 2010/12/03 23:07:49 joerg Exp $");
 #endif /* not lint */
 
 #include 
@@ -160,8 +160,7 @@
 #if defined(MALLOC_DEBUG) || defined(RCHECK)
 #define	ASSERT(p)   if (!(p)) botch("p")
 static void
-botch(
-const char *s)
+botch(const char *s)
 {
 xwarnx("\r\nassertion botched: %s\r\n", s);
 abort();
@@ -301,8 +300,7 @@
 }
 
 void
-xfree(cp)
-	void *cp;
+xfree(void *cp)
 {
   	int size;
 	union overhead *op;
@@ -386,6 +384,7 @@
  * for each size category, the second showing the number of mallocs -
  * frees for each size category.
  */
+void
 mstats(char *s)
 {
   	int i, j;



CVS commit: src/libexec/ld.elf_so

2010-12-04 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sun Dec  5 00:56:07 UTC 2010

Modified Files:
src/libexec/ld.elf_so: Makefile rtld.h
src/libexec/ld.elf_so/arch/i386: rtld_start.S
src/libexec/ld.elf_so/arch/x86_64: rtld_start.S

Log Message:
Build ld.elf_so with -fvisibility=hidden. Exploit this for i386/x86_64
to simplify the assembler code.


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/libexec/ld.elf_so/Makefile
cvs rdiff -u -r1.95 -r1.96 src/libexec/ld.elf_so/rtld.h
cvs rdiff -u -r1.10 -r1.11 src/libexec/ld.elf_so/arch/i386/rtld_start.S
cvs rdiff -u -r1.7 -r1.8 src/libexec/ld.elf_so/arch/x86_64/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/Makefile
diff -u src/libexec/ld.elf_so/Makefile:1.98 src/libexec/ld.elf_so/Makefile:1.99
--- src/libexec/ld.elf_so/Makefile:1.98	Fri Oct 29 15:08:17 2010
+++ src/libexec/ld.elf_so/Makefile	Sun Dec  5 00:56:06 2010
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.98 2010/10/29 15:08:17 christos Exp $
+#	$NetBSD: Makefile,v 1.99 2010/12/05 00:56:06 joerg Exp $
 #
 # NOTE: when changing ld.so, ensure that ldd still compiles.
 #
@@ -40,6 +40,7 @@
 
 LDFLAGS+=	-shared -symbolic -nostartfiles
 LDFLAGS+=	-Wl,-static
+CFLAGS+=	-fvisibility=hidden
 
 # Adds SRCS, CPPFLAGS, LDFLAGS, etc.  Must go first so MD startup source
 # is first.

Index: src/libexec/ld.elf_so/rtld.h
diff -u src/libexec/ld.elf_so/rtld.h:1.95 src/libexec/ld.elf_so/rtld.h:1.96
--- src/libexec/ld.elf_so/rtld.h:1.95	Sat Oct 16 10:27:07 2010
+++ src/libexec/ld.elf_so/rtld.h	Sun Dec  5 00:56:06 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.h,v 1.95 2010/10/16 10:27:07 skrll Exp $	 */
+/*	$NetBSD: rtld.h,v 1.96 2010/12/05 00:56:06 joerg Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -254,13 +254,13 @@
 /* rtld.c */
 
 /* We export these symbols using _rtld_symbol_lookup and is_exported. */
-char *dlerror(void);
-void *dlopen(const char *, int);
-void *dlsym(void *, const char *);
-int dlclose(void *);
-int dladdr(const void *, Dl_info *);
-int dlinfo(void *, int, void *);
-int dl_iterate_phdr(int (*)(struct dl_phdr_info *, size_t, void *),
+__dso_public char *dlerror(void);
+__dso_public void *dlopen(const char *, int);
+__dso_public void *dlsym(void *, const char *);
+__dso_public int dlclose(void *);
+__dso_public int dladdr(const void *, Dl_info *);
+__dso_public int dlinfo(void *, int, void *);
+__dso_public int dl_iterate_phdr(int (*)(struct dl_phdr_info *, size_t, void *),
 void *);
 
 /* These aren't exported */

Index: src/libexec/ld.elf_so/arch/i386/rtld_start.S
diff -u src/libexec/ld.elf_so/arch/i386/rtld_start.S:1.10 src/libexec/ld.elf_so/arch/i386/rtld_start.S:1.11
--- src/libexec/ld.elf_so/arch/i386/rtld_start.S:1.10	Mon Apr 28 20:23:03 2008
+++ src/libexec/ld.elf_so/arch/i386/rtld_start.S	Sun Dec  5 00:56:07 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld_start.S,v 1.10 2008/04/28 20:23:03 martin Exp $	*/
+/*	$NetBSD: rtld_start.S,v 1.11 2010/12/05 00:56:07 joerg Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2002 The NetBSD Foundation, Inc.
@@ -34,6 +34,7 @@
 	.text
 	.align	4
 	.globl	.rtld_start
+	.hidden	.rtld_start
 	.type	.rtld_start,@function
 .rtld_start:
 	subl	$8,%esp			# make room of obj_main and exit proc
@@ -48,12 +49,12 @@
 
 	pushl	%ebx			# relocbase
 	pushl	%ecx			# &_DYNAMIC
-	call	_rtld_relocate_nonplt_s...@plt
+	call	_rtld_relocate_nonplt_self
 
 	leal	12(%esp),%eax		# &cleanup
 	pushl	%ebx			# relocbase
 	pushl	%eax			# sp
-	call	_r...@plt		# _rtld(sp, relocbase)
+	call	_rtld			# _rtld(sp, relocbase)
 
 	addl	$16,%esp		# pop args
 
@@ -64,6 +65,7 @@
 
 	.align	4
 	.globl	_rtld_bind_start
+	.hidden	_rtld_bind_start
 	.type	_rtld_bind_start,@function
 _rtld_bind_start:	# (obj, reloff)
 	pushf# save registers
@@ -73,7 +75,7 @@
 
 	pushl	20(%esp)		# Copy of reloff
 	pushl	20(%esp)		# Copy of obj
-	call	_rtld_b...@plt		# Call the binder
+	call	_rtld_bind		# Call the binder
 	addl	$8,%esp			# pop binder args
 	movl	%eax,20(%esp)		# Store function to be called in obj
 

Index: src/libexec/ld.elf_so/arch/x86_64/rtld_start.S
diff -u src/libexec/ld.elf_so/arch/x86_64/rtld_start.S:1.7 src/libexec/ld.elf_so/arch/x86_64/rtld_start.S:1.8
--- src/libexec/ld.elf_so/arch/x86_64/rtld_start.S:1.7	Fri Dec  3 22:48:25 2010
+++ src/libexec/ld.elf_so/arch/x86_64/rtld_start.S	Sun Dec  5 00:56:07 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld_start.S,v 1.7 2010/12/03 22:48:25 joerg Exp $	*/
+/*	$NetBSD: rtld_start.S,v 1.8 2010/12/05 00:56:07 joerg Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -40,6 +40,7 @@
 	.text
 	.align	16
 	.globl	.rtld_start
+	.hidden	.rtld_start
 	.type	.rtld_start,@function
 .rtld_start:
 	subq	$16,%rsp		# make room of obj_main and exit proc
@@ -52,11 +53,11 @@
 	subq	(%rax),%rbx		# relocbase
 
 	movq	%rbx,%rsi
-	call	_rtld_relocate_nonplt_s...@plt
+	call	_rtld_relocate_nonplt_self
 
 	movq	%r12,%rdi
 	movq	%

CVS commit: src/libexec/ld.elf_so

2009-12-02 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Dec  2 15:50:13 UTC 2009

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

Log Message:
If the environment is corrupt, die. From FreeBSD.


To generate a diff of this commit:
cvs rdiff -u -r1.126 -r1.127 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.126 src/libexec/ld.elf_so/rtld.c:1.127
--- src/libexec/ld.elf_so/rtld.c:1.126	Tue Nov 17 13:44:33 2009
+++ src/libexec/ld.elf_so/rtld.c	Wed Dec  2 10:50:13 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.126 2009/11/17 18:44:33 skrll Exp $	 */
+/*	$NetBSD: rtld.c,v 1.127 2009/12/02 15:50:13 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.126 2009/11/17 18:44:33 skrll Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.127 2009/12/02 15:50:13 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -439,8 +439,8 @@
 		getenv("LD_LIBRARY_PATH"));
 	} else {
 		execname = NULL;
-		unsetenv("LD_DEBUG");
-		unsetenv("LD_LIBRARY_PATH");
+		if (unsetenv("LD_DEBUG") || unsetenv("LD_LIBRARY_PATH"))
+			_rtld_die();
 	}
 	_rtld_process_hints(execname, &_rtld_paths, &_rtld_xforms,
 	_PATH_LD_HINTS);
@@ -514,7 +514,8 @@
 		if (_rtld_preload(getenv("LD_PRELOAD")) == -1)
 			_rtld_die();
 	} else
-		unsetenv("LD_PRELOAD");
+		if (unsetenv("LD_PRELOAD"))
+			_rtld_die();
 
 	dbg(("loading needed objects"));
 	if (_rtld_load_needed_objects(_rtld_objmain, RTLD_MAIN) == -1)



CVS commit: src/libexec/ld.elf_so

2009-12-13 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Dec 13 09:31:47 UTC 2009

Modified Files:
src/libexec/ld.elf_so: Makefile
src/libexec/ld.elf_so/arch/i386: Makefile.inc
src/libexec/ld.elf_so/arch/sparc: Makefile.inc
Removed Files:
src/libexec/ld.elf_so/arch/i386: Makefile.ld32
src/libexec/ld.elf_so/arch/sparc: Makefile.ld32

Log Message:
simplify the logic for compat ld.elf_so and move it here.  we now can
find the libc objdir for multiple compat ld.elf_so's, too.


To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 src/libexec/ld.elf_so/Makefile
cvs rdiff -u -r1.13 -r1.14 src/libexec/ld.elf_so/arch/i386/Makefile.inc
cvs rdiff -u -r1.1 -r0 src/libexec/ld.elf_so/arch/i386/Makefile.ld32
cvs rdiff -u -r1.13 -r1.14 src/libexec/ld.elf_so/arch/sparc/Makefile.inc
cvs rdiff -u -r1.1 -r0 src/libexec/ld.elf_so/arch/sparc/Makefile.ld32

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.92 src/libexec/ld.elf_so/Makefile:1.93
--- src/libexec/ld.elf_so/Makefile:1.92	Sun Dec 13 09:01:45 2009
+++ src/libexec/ld.elf_so/Makefile	Sun Dec 13 09:31:47 2009
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.92 2009/12/13 09:01:45 mrg Exp $
+#	$NetBSD: Makefile,v 1.93 2009/12/13 09:31:47 mrg Exp $
 #
 # NOTE: when changing ld.so, ensure that ldd still compiles.
 #
@@ -38,8 +38,6 @@
  (${MACHINE_ARCH} == "vax")) &&	\
 ${OBJECT_FMT} == "ELF" && ${MKPIC} != "no"
 
-PROG?=		ld.elf_so
-
 LDFLAGS+=	-shared -symbolic -nostartfiles
 LDFLAGS+=	-Wl,-static
 
@@ -49,13 +47,16 @@
 .include "$M/Makefile.inc"
 .endif
 
-# Support src/compat/libexec/ld.elf_so.
+# Support compat ld.elf_so.
 .if defined(MLIBDIR)
-CLIBOBJ!=	cd ${NETBSDSRCDIR}/compat/lib/libc && ${PRINTOBJDIR}
+PROG=		ld.elf_so-${MLIBDIR}
+CPPFLAGS+=	-DRTLD_ARCH_SUBDIR=\"${MLIBDIR}\"
 .else
-CLIBOBJ!=	cd ${NETBSDSRCDIR}/lib/libc && ${PRINTOBJDIR}
+PROG=		ld.elf_so
 .endif
 
+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
 

Index: src/libexec/ld.elf_so/arch/i386/Makefile.inc
diff -u src/libexec/ld.elf_so/arch/i386/Makefile.inc:1.13 src/libexec/ld.elf_so/arch/i386/Makefile.inc:1.14
--- src/libexec/ld.elf_so/arch/i386/Makefile.inc:1.13	Sun Dec 13 08:25:20 2009
+++ src/libexec/ld.elf_so/arch/i386/Makefile.inc	Sun Dec 13 09:31:47 2009
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.13 2009/12/13 08:25:20 mrg Exp $
+#	$NetBSD: Makefile.inc,v 1.14 2009/12/13 09:31:47 mrg Exp $
 
 SRCS+=		rtld_start.S mdreloc.c
 
@@ -8,7 +8,3 @@
 CPPFLAGS+=	-DELFSIZE=32
 
 LDFLAGS+=	-Wl,-e,.rtld_start
-
-.if defined(MLIBDIR)
-.include "Makefile.ld32"
-.endif

Index: src/libexec/ld.elf_so/arch/sparc/Makefile.inc
diff -u src/libexec/ld.elf_so/arch/sparc/Makefile.inc:1.13 src/libexec/ld.elf_so/arch/sparc/Makefile.inc:1.14
--- src/libexec/ld.elf_so/arch/sparc/Makefile.inc:1.13	Sun Dec 13 08:25:20 2009
+++ src/libexec/ld.elf_so/arch/sparc/Makefile.inc	Sun Dec 13 09:31:47 2009
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.13 2009/12/13 08:25:20 mrg Exp $
+#	$NetBSD: Makefile.inc,v 1.14 2009/12/13 09:31:47 mrg Exp $
 
 SRCS+=		rtld_start.S mdreloc.c
 
@@ -8,7 +8,3 @@
 CPPFLAGS+=	-DELFSIZE=32
 
 LDFLAGS+=	-Wl,-e,_rtld_start
-
-.if defined(MLIBDIR)
-.include "Makefile.ld32"
-.endif



CVS commit: src/libexec/ld.elf_so

2010-12-16 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Thu Dec 16 19:25:41 UTC 2010

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

Log Message:
Note that $ORIGIN kernel support (in kern/kern_exec.c) is currently disabled.
Info from sk...@.
Bump date.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/libexec/ld.elf_so/ld.elf_so.1

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/ld.elf_so.1
diff -u src/libexec/ld.elf_so/ld.elf_so.1:1.12 src/libexec/ld.elf_so/ld.elf_so.1:1.13
--- src/libexec/ld.elf_so/ld.elf_so.1:1.12	Sun May 25 19:48:35 2008
+++ src/libexec/ld.elf_so/ld.elf_so.1	Thu Dec 16 19:25:41 2010
@@ -1,4 +1,4 @@
-.\"	$NetBSD: ld.elf_so.1,v 1.12 2008/05/25 19:48:35 wiz Exp $
+.\"	$NetBSD: ld.elf_so.1,v 1.13 2010/12/16 19:25:41 wiz Exp $
 .\"
 .\" Copyright (c) 2001 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd May 18, 2007
+.Dd December 16, 2010
 .Dt LD.ELF_SO 1
 .Os
 .Sh NAME
@@ -108,6 +108,9 @@
 Currently unimplemented.
 .It $ORIGIN
 The directory of the main object.
+Implemented in
+.Nm
+but the kernel support is currently disabled.
 .It $OSNAME
 The value of the
 .Dv kern.ostype



CVS commit: src/libexec/ld.elf_so

2010-12-16 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Dec 16 19:35:38 UTC 2010

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

Log Message:
Remove incorrect comment.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/libexec/ld.elf_so/load.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.38 src/libexec/ld.elf_so/load.c:1.39
--- src/libexec/ld.elf_so/load.c:1.38	Sat Oct 16 10:27:07 2010
+++ src/libexec/ld.elf_so/load.c	Thu Dec 16 19:35:38 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: load.c,v 1.38 2010/10/16 10:27:07 skrll Exp $	 */
+/*	$NetBSD: load.c,v 1.39 2010/12/16 19:35:38 skrll Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: load.c,v 1.38 2010/10/16 10:27:07 skrll Exp $");
+__RCSID("$NetBSD: load.c,v 1.39 2010/12/16 19:35:38 skrll Exp $");
 #endif /* not lint */
 
 #include 
@@ -236,8 +236,7 @@
 			val.s, name);
 			break;
 		}
-		/* XXX: This can mess up debuggers, cause we lie about
-		 * what we loaded in the needed objects */
+
 		for (j = 0; j < RTLD_MAX_LIBRARY &&
 		x->entry[i].library[j] != NULL; j++) {
 			o = _rtld_load_library(x->entry[i].library[j], obj,



CVS commit: src/libexec/ld.elf_so

2010-12-16 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Dec 16 19:59:40 UTC 2010

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

Log Message:
s/rdbg/dbg/ in a few places.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/libexec/ld.elf_so/load.c
cvs rdiff -u -r1.132 -r1.133 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/load.c
diff -u src/libexec/ld.elf_so/load.c:1.39 src/libexec/ld.elf_so/load.c:1.40
--- src/libexec/ld.elf_so/load.c:1.39	Thu Dec 16 19:35:38 2010
+++ src/libexec/ld.elf_so/load.c	Thu Dec 16 19:59:39 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: load.c,v 1.39 2010/12/16 19:35:38 skrll Exp $	 */
+/*	$NetBSD: load.c,v 1.40 2010/12/16 19:59:39 skrll Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: load.c,v 1.39 2010/12/16 19:35:38 skrll Exp $");
+__RCSID("$NetBSD: load.c,v 1.40 2010/12/16 19:59:39 skrll Exp $");
 #endif /* not lint */
 
 #include 
@@ -170,12 +170,12 @@
 #ifdef RTLD_LOADER
 	if (mode & RTLD_MAIN && !obj->mainref) {
 		obj->mainref = 1;
-		rdbg(("adding %p (%s) to _rtld_list_main", obj, obj->path));
+		dbg(("adding %p (%s) to _rtld_list_main", obj, obj->path));
 		_rtld_objlist_push_tail(&_rtld_list_main, obj);
 	}
 	if (mode & RTLD_GLOBAL && !obj->globalref) {
 		obj->globalref = 1;
-		rdbg(("adding %p (%s) to _rtld_list_global", obj, obj->path));
+		dbg(("adding %p (%s) to _rtld_list_global", obj, obj->path));
 		_rtld_objlist_push_tail(&_rtld_list_global, obj);
 	}
 #endif

Index: src/libexec/ld.elf_so/rtld.c
diff -u src/libexec/ld.elf_so/rtld.c:1.132 src/libexec/ld.elf_so/rtld.c:1.133
--- src/libexec/ld.elf_so/rtld.c:1.132	Fri Oct 29 15:08:17 2010
+++ src/libexec/ld.elf_so/rtld.c	Thu Dec 16 19:59:39 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.132 2010/10/29 15:08:17 christos Exp $	 */
+/*	$NetBSD: rtld.c,v 1.133 2010/12/16 19:59:39 skrll Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.132 2010/10/29 15:08:17 christos Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.133 2010/12/16 19:59:39 skrll Exp $");
 #endif /* not lint */
 
 #include 
@@ -660,7 +660,7 @@
 	if (!obj->mainref) {
 		if (_rtld_objlist_find(&obj->dldags, root))
 			return;
-		rdbg(("add %p (%s) to %p (%s) DAG", obj, obj->path, root,
+		dbg(("add %p (%s) to %p (%s) DAG", obj, obj->path, root,
 		root->path));
 		_rtld_objlist_push_tail(&obj->dldags, root);
 		_rtld_objlist_push_tail(&root->dagmembers, obj);



CVS commit: src/libexec/ld.elf_so

2010-12-16 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Thu Dec 16 22:47:28 UTC 2010

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

Log Message:
Don't use normal environment handling functions from libc, but iterate
once over the array and clean out entries as needed.


To generate a diff of this commit:
cvs rdiff -u -r1.99 -r1.100 src/libexec/ld.elf_so/Makefile
cvs rdiff -u -r1.133 -r1.134 src/libexec/ld.elf_so/rtld.c
cvs rdiff -u -r1.2 -r0 src/libexec/ld.elf_so/xenv.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.99 src/libexec/ld.elf_so/Makefile:1.100
--- src/libexec/ld.elf_so/Makefile:1.99	Sun Dec  5 00:56:06 2010
+++ src/libexec/ld.elf_so/Makefile	Thu Dec 16 22:47:27 2010
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.99 2010/12/05 00:56:06 joerg Exp $
+#	$NetBSD: Makefile,v 1.100 2010/12/16 22:47:27 joerg Exp $
 #
 # NOTE: when changing ld.so, ensure that ldd still compiles.
 #
@@ -58,7 +58,7 @@
 
 CLIBOBJ!=	cd ${NETBSDSRCDIR}/lib/libc && ${PRINTOBJDIR}
 
-SRCS+=		rtld.c reloc.c symbol.c xenv.c xmalloc.c xprintf.c debug.c \
+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
 
 .if ${USE_FORT} == "yes"

Index: src/libexec/ld.elf_so/rtld.c
diff -u src/libexec/ld.elf_so/rtld.c:1.133 src/libexec/ld.elf_so/rtld.c:1.134
--- src/libexec/ld.elf_so/rtld.c:1.133	Thu Dec 16 19:59:39 2010
+++ src/libexec/ld.elf_so/rtld.c	Thu Dec 16 22:47:27 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.133 2010/12/16 19:59:39 skrll Exp $	 */
+/*	$NetBSD: rtld.c,v 1.134 2010/12/16 22:47:27 joerg Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.133 2010/12/16 19:59:39 skrll Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.134 2010/12/16 22:47:27 joerg Exp $");
 #endif /* not lint */
 
 #include 
@@ -312,20 +312,21 @@
 	   *pAUX_phent, *pAUX_phnum, *pAUX_euid, *pAUX_egid,
 		   *pAUX_ruid, *pAUX_rgid;
 	const AuxInfo  *pAUX_pagesz;
-	char  **env;
+	char  **env, **oenvp;
 	const AuxInfo  *aux;
 	const AuxInfo  *auxp;
 	Elf_Addr   *const osp = sp;
 	boolbind_now = 0;
-	const char *ld_bind_now;
+	const char *ld_bind_now, *ld_preload, *ld_library_path;
 	const char**argv;
 	const char *execname;
 	long		argc;
 	const char **real___progname;
 	const Obj_Entry **real___mainprog_obj;
 	char ***real_environ;
-#if defined(RTLD_DEBUG)
+#ifdef DEBUG
 	int i = 0;
+	const char *ld_debug;
 #endif
 
 	/*
@@ -428,24 +429,68 @@
 	((pAUX_egid ? (gid_t)pAUX_egid->a_v : getegid()) ==
 	(pAUX_rgid ? (gid_t)pAUX_rgid->a_v : getgid()));
 
-	ld_bind_now = getenv("LD_BIND_NOW");
+#ifdef DEBUG
+	ld_debug = NULL;
+#endif
+	ld_bind_now = NULL;
+	ld_library_path = NULL;
+	ld_preload = NULL;
+	/*
+	 * Inline avoid using normal getenv/unsetenv here as the libc
+	 * code is quite a bit more complicated.
+	 */
+	for (oenvp = env; *env != NULL; ++env) {
+		static const char bind_var[] = "LD_BIND_NOW=";
+		static const char debug_var[] =  "LD_DEBUG=";
+		static const char path_var[] = "LD_LIBRARY_PATH=";
+		static const char preload_var[] = "LD_PRELOAD=";
+#define LEN(x)	(sizeof(x) - 1)
+
+		if ((*env)[0] != 'L' || (*env)[1] != 'D') {
+			/*
+			 * Special case to skip most entries without
+			 * the more expensive calls to strncmp.
+			 */
+			*oenvp++ = *env;
+		} else if (strncmp(*env, debug_var, LEN(debug_var)) == 0) {
+			if (_rtld_trust) {
+#ifdef DEBUG
+ld_debug = *env + LEN(debug_var);
+#endif
+*oenvp++ = *env;
+			}
+		} else if (strncmp(*env, bind_var, LEN(bind_var)) == 0) {
+			ld_bind_now = *env + LEN(bind_var);
+		} else if (strncmp(*env, path_var, LEN(path_var)) == 0) {
+			if (_rtld_trust) {
+ld_library_path = *env + LEN(path_var);
+*oenvp++ = *env;
+			}
+		} else if (strncmp(*env, preload_var, LEN(preload_var)) == 0) {
+			if (_rtld_trust) {
+ld_preload = *env + LEN(preload_var);
+*oenvp++ = *env;
+			}
+		} else {
+			*oenvp++ = *env;
+		}
+#undef LEN
+	}
+	*oenvp++ = NULL;
+
 	if (ld_bind_now != NULL && *ld_bind_now != '\0')
 		bind_now = true;
 	if (_rtld_trust) {
 #ifdef DEBUG
-		const char *ld_debug = getenv("LD_DEBUG");
 #ifdef RTLD_DEBUG
 		debug = 0;
 #endif
 		if (ld_debug != NULL && *ld_debug != '\0')
 			debug = 1;
 #endif
-		_rtld_add_paths(execname, &_rtld_paths,
-		getenv("LD_LIBRARY_PATH"));
+		_rtld_add_paths(execname, &_rtld_paths, ld_library_path);
 	} else {
 		execname = NULL;
-		if (xunsetenv("LD_DEBUG") || xunsetenv("LD_LIBRARY_PATH"))
-			_rtld_die();
 	}
 	_rtld_process_hints(execname, &_rtld_paths, &_rtld_xforms,
 	_PATH_LD_HINTS);
@@ -512,17 +557,15 @@
 	_rtld_objmain->mainref = 1;
 	_rtld_objlist_push_tail(&_rtld_list_main, _rtld_objmain);
 
-	if (_rtl

CVS commit: src/libexec/ld.elf_so

2010-12-16 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Dec 17 07:04:52 UTC 2010

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

Log Message:
Remove implementation detail.

Bump date.


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

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/ld.elf_so.1
diff -u src/libexec/ld.elf_so/ld.elf_so.1:1.13 src/libexec/ld.elf_so/ld.elf_so.1:1.14
--- src/libexec/ld.elf_so/ld.elf_so.1:1.13	Thu Dec 16 19:25:41 2010
+++ src/libexec/ld.elf_so/ld.elf_so.1	Fri Dec 17 07:04:52 2010
@@ -1,4 +1,4 @@
-.\"	$NetBSD: ld.elf_so.1,v 1.13 2010/12/16 19:25:41 wiz Exp $
+.\"	$NetBSD: ld.elf_so.1,v 1.14 2010/12/17 07:04:52 skrll Exp $
 .\"
 .\" Copyright (c) 2001 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd December 16, 2010
+.Dd December 17, 2010
 .Dt LD.ELF_SO 1
 .Os
 .Sh NAME
@@ -63,13 +63,6 @@
 .Nm
 is loaded is also supplied.
 .Pp
-Careful use of code allows
-.Nm
-to relocate itself before proceeding.
-Specifically the use of global variables and
-large switch statements is not allowed.
-The later can cause the output of a jump table that
-can use the equivalent of a global variable.
 .Ss Finding objects
 Each
 .Xr elf 5



CVS commit: src/libexec/ld.elf_so

2010-12-17 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Fri Dec 17 08:50:26 UTC 2010

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

Log Message:
Remove superfluous Pp.


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

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/ld.elf_so.1
diff -u src/libexec/ld.elf_so/ld.elf_so.1:1.14 src/libexec/ld.elf_so/ld.elf_so.1:1.15
--- src/libexec/ld.elf_so/ld.elf_so.1:1.14	Fri Dec 17 07:04:52 2010
+++ src/libexec/ld.elf_so/ld.elf_so.1	Fri Dec 17 08:50:26 2010
@@ -1,4 +1,4 @@
-.\"	$NetBSD: ld.elf_so.1,v 1.14 2010/12/17 07:04:52 skrll Exp $
+.\"	$NetBSD: ld.elf_so.1,v 1.15 2010/12/17 08:50:26 wiz Exp $
 .\"
 .\" Copyright (c) 2001 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -62,7 +62,6 @@
 The entry point of the program and the base address of where
 .Nm
 is loaded is also supplied.
-.Pp
 .Ss Finding objects
 Each
 .Xr elf 5



CVS commit: src/libexec/ld.elf_so

2010-12-19 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Dec 19 17:17:50 UTC 2010

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

Log Message:
Remove unnecessary #ifdef RTLD_DEBUG


To generate a diff of this commit:
cvs rdiff -u -r1.134 -r1.135 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.134 src/libexec/ld.elf_so/rtld.c:1.135
--- src/libexec/ld.elf_so/rtld.c:1.134	Thu Dec 16 22:47:27 2010
+++ src/libexec/ld.elf_so/rtld.c	Sun Dec 19 17:17:50 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.134 2010/12/16 22:47:27 joerg Exp $	 */
+/*	$NetBSD: rtld.c,v 1.135 2010/12/19 17:17:50 skrll Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.134 2010/12/16 22:47:27 joerg Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.135 2010/12/19 17:17:50 skrll Exp $");
 #endif /* not lint */
 
 #include 
@@ -744,9 +744,7 @@
 		linkp = &_rtld_objlist->next;
 		while ((obj = *linkp) != NULL) {
 			if (obj->refcount == 0) {
-#ifdef RTLD_DEBUG
 dbg(("unloading \"%s\"", obj->path));
-#endif
 if (obj->ehdr != MAP_FAILED)
 	munmap(obj->ehdr, _rtld_pagesz);
 munmap(obj->mapbase, obj->mapsize);



CVS commit: src/libexec/ld.elf_so

2010-12-19 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sun Dec 19 17:26:51 UTC 2010

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

Log Message:
Sprinkle some KNF.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/libexec/ld.elf_so/load.c
cvs rdiff -u -r1.135 -r1.136 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/load.c
diff -u src/libexec/ld.elf_so/load.c:1.40 src/libexec/ld.elf_so/load.c:1.41
--- src/libexec/ld.elf_so/load.c:1.40	Thu Dec 16 19:59:39 2010
+++ src/libexec/ld.elf_so/load.c	Sun Dec 19 17:26:51 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: load.c,v 1.40 2010/12/16 19:59:39 skrll Exp $	 */
+/*	$NetBSD: load.c,v 1.41 2010/12/19 17:26:51 skrll Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: load.c,v 1.40 2010/12/16 19:59:39 skrll Exp $");
+__RCSID("$NetBSD: load.c,v 1.41 2010/12/19 17:26:51 skrll Exp $");
 #endif /* not lint */
 
 #include 
@@ -318,6 +318,6 @@
 		xfree(buf);
 	}
 
-	return (status);
+	return status;
 }
 #endif

Index: src/libexec/ld.elf_so/rtld.c
diff -u src/libexec/ld.elf_so/rtld.c:1.135 src/libexec/ld.elf_so/rtld.c:1.136
--- src/libexec/ld.elf_so/rtld.c:1.135	Sun Dec 19 17:17:50 2010
+++ src/libexec/ld.elf_so/rtld.c	Sun Dec 19 17:26:51 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.135 2010/12/19 17:17:50 skrll Exp $	 */
+/*	$NetBSD: rtld.c,v 1.136 2010/12/19 17:26:51 skrll Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.135 2010/12/19 17:17:50 skrll Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.136 2010/12/19 17:26:51 skrll Exp $");
 #endif /* not lint */
 
 #include 
@@ -868,7 +868,7 @@
 
 	if (def != NULL)
 		return obj->relocbase + def->st_value;
-	return(NULL);
+	return NULL;
 }
 
 #ifdef __powerpc__



CVS commit: src/libexec/ld.elf_so

2011-01-15 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Sun Jan 16 01:22:29 UTC 2011

Modified Files:
src/libexec/ld.elf_so: headers.c rtld.h
src/libexec/ld.elf_so/arch/powerpc: ppc_reloc.c rtld_start.S

Log Message:
Add secure-plt support for powerpc to ld.elf_so.  As part of this, we have to
stop calling into the GOT/_DYNAMIC since they are no longer executable.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/libexec/ld.elf_so/headers.c
cvs rdiff -u -r1.97 -r1.98 src/libexec/ld.elf_so/rtld.h
cvs rdiff -u -r1.45 -r1.46 src/libexec/ld.elf_so/arch/powerpc/ppc_reloc.c
cvs rdiff -u -r1.13 -r1.14 src/libexec/ld.elf_so/arch/powerpc/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/headers.c
diff -u src/libexec/ld.elf_so/headers.c:1.38 src/libexec/ld.elf_so/headers.c:1.39
--- src/libexec/ld.elf_so/headers.c:1.38	Fri Dec 24 12:41:43 2010
+++ src/libexec/ld.elf_so/headers.c	Sun Jan 16 01:22:29 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: headers.c,v 1.38 2010/12/24 12:41:43 skrll Exp $	 */
+/*	$NetBSD: headers.c,v 1.39 2011/01/16 01:22:29 matt Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: headers.c,v 1.38 2010/12/24 12:41:43 skrll Exp $");
+__RCSID("$NetBSD: headers.c,v 1.39 2011/01/16 01:22:29 matt Exp $");
 #endif /* not lint */
 
 #include 
@@ -241,6 +241,11 @@
 #endif
 			break;
 #endif
+#ifdef __powerpc__
+		case DT_PPC_GOT:
+			obj->gotptr = (Elf_Addr *)(obj->relocbase + dynp->d_un.d_ptr);
+			break;
+#endif
 		case DT_FLAGS_1:
 			obj->z_now =
 			((dynp->d_un.d_val & DF_1_BIND_NOW) != 0);

Index: src/libexec/ld.elf_so/rtld.h
diff -u src/libexec/ld.elf_so/rtld.h:1.97 src/libexec/ld.elf_so/rtld.h:1.98
--- src/libexec/ld.elf_so/rtld.h:1.97	Fri Dec 24 12:41:43 2010
+++ src/libexec/ld.elf_so/rtld.h	Sun Jan 16 01:22:29 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.h,v 1.97 2010/12/24 12:41:43 skrll Exp $	 */
+/*	$NetBSD: rtld.h,v 1.98 2011/01/16 01:22:29 matt Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -167,6 +167,9 @@
 	Elf_Wordsymtabno;	/* Number of dynamic symbols */
 	Elf_Wordgotsym;		/* First dynamic symbol in GOT */
 #endif
+#ifdef __powerpc__
+	Elf_Addr   *gotptr;		/* GOT table (secure-plt only) */
+#endif
 
 	const Elf_Symindx *buckets;	/* Hash table buckets array */
 	unsigned long	unused1;	/* Used to be nbuckets */

Index: src/libexec/ld.elf_so/arch/powerpc/ppc_reloc.c
diff -u src/libexec/ld.elf_so/arch/powerpc/ppc_reloc.c:1.45 src/libexec/ld.elf_so/arch/powerpc/ppc_reloc.c:1.46
--- src/libexec/ld.elf_so/arch/powerpc/ppc_reloc.c:1.45	Fri Aug  6 16:33:18 2010
+++ src/libexec/ld.elf_so/arch/powerpc/ppc_reloc.c	Sun Jan 16 01:22:29 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ppc_reloc.c,v 1.45 2010/08/06 16:33:18 joerg Exp $	*/
+/*	$NetBSD: ppc_reloc.c,v 1.46 2011/01/16 01:22:29 matt Exp $	*/
 
 /*-
  * Copyright (C) 1998	Tsubai Masanari
@@ -30,7 +30,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: ppc_reloc.c,v 1.45 2010/08/06 16:33:18 joerg Exp $");
+__RCSID("$NetBSD: ppc_reloc.c,v 1.46 2011/01/16 01:22:29 matt Exp $");
 #endif /* not lint */
 
 #include 
@@ -50,10 +50,11 @@
 			((u_int32_t)(x) + 0x1) : (u_int32_t)(x)) >> 16)
 #define l(x) ((u_int32_t)(x) & 0x)
 
-void _rtld_bind_start(void);
+void _rtld_bind_bssplt_start(void);
+void _rtld_bind_secureplt_start(void);
 void _rtld_relocate_nonplt_self(Elf_Dyn *, Elf_Addr);
 caddr_t _rtld_bind(const Obj_Entry *, Elf_Word);
-static inline int _rtld_relocate_plt_object(const Obj_Entry *,
+static int _rtld_relocate_plt_object(const Obj_Entry *,
 const Elf_Rela *, int, Elf_Addr *);
 
 /*
@@ -67,7 +68,7 @@
  */
 
 /*
- * Setup the plt glue routines.
+ * Setup the plt glue routines (for bss-plt).
  */
 #define PLTCALL_SIZE	20
 #define PLTRESOLVE_SIZE	24
@@ -75,34 +76,42 @@
 void
 _rtld_setup_pltgot(const Obj_Entry *obj)
 {
-	Elf_Word *pltcall, *pltresolve;
-	Elf_Word *jmptab;
-	int N = obj->pltrelalim - obj->pltrela;
-
-	/* Entries beyond 8192 take twice as much space. */
-	if (N > 8192)
-		N += N-8192;
-
-	pltcall = obj->pltgot;
-	jmptab = pltcall + 18 + N * 2;
-
-	memcpy(pltcall, _rtld_powerpc_pltcall, PLTCALL_SIZE);
-	pltcall[1] |= ha(jmptab);
-	pltcall[2] |= l(jmptab);
-
-	pltresolve = obj->pltgot + 8;
-
-	memcpy(pltresolve, _rtld_powerpc_pltresolve, PLTRESOLVE_SIZE);
-	pltresolve[0] |= ha(_rtld_bind_start);
-	pltresolve[1] |= l(_rtld_bind_start);
-	pltresolve[3] |= ha(obj);
-	pltresolve[4] |= l(obj);
-
 	/*
-	 * Invalidate the icache for only the code part of the PLT
-	 * (and not the jump table at the end).
+	 * Secure-PLT is much more sane.
 	 */
-	__syncicache(pltcall, (char *)jmptab - (char *)pltcall);
+	if (obj->gotptr != NULL) {
+		obj->gotptr[1] = (Elf_Addr) _rtld_bind_secureplt_start;
+		obj->gotptr[2] = (Elf_Addr) obj;
+	} else {
+		Elf_Word *pltcall, *pltresolve;
+		Elf_Word *jmptab;
+		int N = obj->pl

CVS commit: src/libexec/ld.elf_so

2011-01-15 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Sun Jan 16 02:36:05 UTC 2011

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

Log Message:
Warn about DT_TEXTRELs


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 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.101 src/libexec/ld.elf_so/Makefile:1.102
--- src/libexec/ld.elf_so/Makefile:1.101	Thu Dec 16 22:52:32 2010
+++ src/libexec/ld.elf_so/Makefile	Sun Jan 16 02:36:05 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.101 2010/12/16 22:52:32 joerg Exp $
+#	$NetBSD: Makefile,v 1.102 2011/01/16 02:36:05 matt Exp $
 #
 # NOTE: when changing ld.so, ensure that ldd still compiles.
 #
@@ -40,6 +40,8 @@
 
 LDFLAGS+=	-shared -symbolic -nostartfiles
 LDFLAGS+=	-Wl,-static
+LDFLAGS+=	-Wl,--warn-shared-textrel
+
 CFLAGS+=	-fvisibility=hidden
 
 # Adds SRCS, CPPFLAGS, LDFLAGS, etc.  Must go first so MD startup source



CVS commit: src/libexec/ld.elf_so

2011-01-16 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Sun Jan 16 15:56:37 UTC 2011

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

Log Message:
Move powerpc gotptr to the end to preserve binary compatibility.


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

Modified files:

Index: src/libexec/ld.elf_so/rtld.h
diff -u src/libexec/ld.elf_so/rtld.h:1.98 src/libexec/ld.elf_so/rtld.h:1.99
--- src/libexec/ld.elf_so/rtld.h:1.98	Sun Jan 16 01:22:29 2011
+++ src/libexec/ld.elf_so/rtld.h	Sun Jan 16 15:56:37 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.h,v 1.98 2011/01/16 01:22:29 matt Exp $	 */
+/*	$NetBSD: rtld.h,v 1.99 2011/01/16 15:56:37 matt Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -167,9 +167,6 @@
 	Elf_Wordsymtabno;	/* Number of dynamic symbols */
 	Elf_Wordgotsym;		/* First dynamic symbol in GOT */
 #endif
-#ifdef __powerpc__
-	Elf_Addr   *gotptr;		/* GOT table (secure-plt only) */
-#endif
 
 	const Elf_Symindx *buckets;	/* Hash table buckets array */
 	unsigned long	unused1;	/* Used to be nbuckets */
@@ -234,6 +231,9 @@
 	size_t		pathlen;	/* Pathname length */
 	STAILQ_HEAD(, Struct_Name_Entry) names;	/* List of names for this object we
 		   know about. */
+#ifdef __powerpc__
+	Elf_Addr   *gotptr;		/* GOT table (secure-plt only) */
+#endif
 } Obj_Entry;
 
 typedef struct Struct_DoneList {



CVS commit: src/libexec/ld.elf_so

2011-01-25 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Tue Jan 25 12:25:44 UTC 2011

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

Log Message:
Unbreak gdb by ensuring _rtld_debug_state is in the dynamic symbol table.

mmm 1 line diffs

mmm not breaking backwards compatibility for anything known/unknown or
public/private.


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

Modified files:

Index: src/libexec/ld.elf_so/rtld.h
diff -u src/libexec/ld.elf_so/rtld.h:1.99 src/libexec/ld.elf_so/rtld.h:1.100
--- src/libexec/ld.elf_so/rtld.h:1.99	Sun Jan 16 15:56:37 2011
+++ src/libexec/ld.elf_so/rtld.h	Tue Jan 25 12:25:43 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.h,v 1.99 2011/01/16 15:56:37 matt Exp $	 */
+/*	$NetBSD: rtld.h,v 1.100 2011/01/25 12:25:43 skrll Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -285,7 +285,7 @@
  __attribute__((__format__(__printf__,1,2)));
 void _rtld_die(void) __attribute__((__noreturn__));
 void *_rtld_objmain_sym(const char *);
-void _rtld_debug_state(void);
+__dso_public void _rtld_debug_state(void);
 void _rtld_linkmap_add(Obj_Entry *);
 void _rtld_linkmap_delete(Obj_Entry *);
 void _rtld_objlist_push_head(Objlist *, Obj_Entry *);



CVS commit: src/libexec/ld.elf_so

2012-12-16 Thread David Laight
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


To generate a diff of this commit:
cvs rdiff -u -r1.159 -r1.160 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.159 src/libexec/ld.elf_so/rtld.c:1.160
--- src/libexec/ld.elf_so/rtld.c:1.159	Mon Oct  1 03:03:46 2012
+++ src/libexec/ld.elf_so/rtld.c	Sun Dec 16 11:15:21 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.159 2012/10/01 03:03:46 riastradh Exp $	 */
+/*	$NetBSD: rtld.c,v 1.160 2012/12/16 11:15:21 dsl Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.159 2012/10/01 03:03:46 riastradh Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.160 2012/12/16 11:15:21 dsl Exp $");
 #endif /* not lint */
 
 #include 
@@ -1546,7 +1546,7 @@ _rtld_shared_enter(void)
 		 */
 		if ((_rtld_mutex & RTLD_EXCLUSIVE_MASK) ||
 		_rtld_waiter_exclusive)
-			_lwp_park(NULL, -1, __UNVOLATILE(&_rtld_mutex), NULL);
+			_lwp_park(NULL, 0, __UNVOLATILE(&_rtld_mutex), NULL);
 		/* Try to remove us from the waiter list. */
 		atomic_cas_uint(&_rtld_waiter_shared, self, 0);
 		if (waiter)



CVS commit: src/libexec/ld.elf_so

2012-12-16 Thread David Laight
Module Name:src
Committed By:   dsl
Date:   Sun Dec 16 23:00:47 UTC 2012

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

Log Message:
Fix the other lwp_park() to pass 0 for the 'unpark' lwp.


To generate a diff of this commit:
cvs rdiff -u -r1.160 -r1.161 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.160 src/libexec/ld.elf_so/rtld.c:1.161
--- src/libexec/ld.elf_so/rtld.c:1.160	Sun Dec 16 11:15:21 2012
+++ src/libexec/ld.elf_so/rtld.c	Sun Dec 16 23:00:46 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.160 2012/12/16 11:15:21 dsl Exp $	 */
+/*	$NetBSD: rtld.c,v 1.161 2012/12/16 23:00:46 dsl Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.160 2012/12/16 11:15:21 dsl Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.161 2012/12/16 23:00:46 dsl Exp $");
 #endif /* not lint */
 
 #include 
@@ -1602,7 +1602,7 @@ _rtld_exclusive_enter(sigset_t *mask)
 			_rtld_die();
 		}
 		if (cur)
-			_lwp_park(NULL, -1, __UNVOLATILE(&_rtld_mutex), NULL);
+			_lwp_park(NULL, 0, __UNVOLATILE(&_rtld_mutex), NULL);
 		atomic_cas_uint(&_rtld_waiter_exclusive, self, 0);
 		if (waiter)
 			_lwp_unpark(waiter, __UNVOLATILE(&_rtld_mutex));



CVS commit: src/libexec/ld.elf_so

2013-01-24 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jan 24 17:57:29 UTC 2013

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

Log Message:
don't free cp before we copy it!


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/libexec/ld.elf_so/xmalloc.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/xmalloc.c
diff -u src/libexec/ld.elf_so/xmalloc.c:1.11 src/libexec/ld.elf_so/xmalloc.c:1.12
--- src/libexec/ld.elf_so/xmalloc.c:1.11	Wed May 25 10:41:46 2011
+++ src/libexec/ld.elf_so/xmalloc.c	Thu Jan 24 12:57:29 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: xmalloc.c,v 1.11 2011/05/25 14:41:46 christos Exp $	*/
+/*	$NetBSD: xmalloc.c,v 1.12 2013/01/24 17:57:29 christos Exp $	*/
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -77,7 +77,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: xmalloc.c,v 1.11 2011/05/25 14:41:46 christos Exp $");
+__RCSID("$NetBSD: xmalloc.c,v 1.12 2013/01/24 17:57:29 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -369,12 +369,13 @@ irealloc(void *cp, size_t nbytes)
 		*(u_short *)((caddr_t)(op + 1) + op->ov_size) = RMAGIC;
 #endif
 		return(cp);
-	} else
-		xfree(cp);
+	}
   	if ((res = imalloc(nbytes)) == NULL)
   		return (NULL);
-  	if (cp != res)		/* common optimization if "compacting" */
+  	if (cp != res) {	/* common optimization if "compacting" */
 		memcpy(res, cp, (nbytes < onb) ? nbytes : onb);
+		xfree(cp);
+	}
   	return (res);
 }
 



CVS commit: src/libexec/ld.elf_so

2011-10-23 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Oct 23 21:06:08 UTC 2011

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

Log Message:
Don't block SIGTRAP so that on architectures where the debugger needs to
be able to receive sigtrap for breakpoints to work, it can. For example
we are setting breakpoints inside dlopen(), after we've blocked the signal,
so the process keep trapping and looping over the trap instruction without
being able to send the signal. Another way would be to move the
_rtld_debug_state() calls outside the critical section...


To generate a diff of this commit:
cvs rdiff -u -r1.152 -r1.153 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.152 src/libexec/ld.elf_so/rtld.c:1.153
--- src/libexec/ld.elf_so/rtld.c:1.152	Sat Aug 13 18:24:24 2011
+++ src/libexec/ld.elf_so/rtld.c	Sun Oct 23 17:06:07 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.152 2011/08/13 22:24:24 christos Exp $	 */
+/*	$NetBSD: rtld.c,v 1.153 2011/10/23 21:06:07 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.152 2011/08/13 22:24:24 christos Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.153 2011/10/23 21:06:07 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -1532,6 +1532,7 @@ _rtld_exclusive_enter(sigset_t *mask)
 	sigset_t blockmask;
 
 	sigfillset(&blockmask);
+	sigdelset(&blockmask, SIGTRAP);	/* Allow the debugger */
 	sigprocmask(SIG_BLOCK, &blockmask, mask);
 
 	membar_enter();



CVS commit: src/libexec/ld.elf_so

2011-08-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Aug 13 22:24:24 UTC 2011

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

Log Message:
disable debugging that makes us core dump


To generate a diff of this commit:
cvs rdiff -u -r1.151 -r1.152 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.151 src/libexec/ld.elf_so/rtld.c:1.152
--- src/libexec/ld.elf_so/rtld.c:1.151	Sat Jun 25 01:45:12 2011
+++ src/libexec/ld.elf_so/rtld.c	Sat Aug 13 18:24:24 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.151 2011/06/25 05:45:12 nonaka Exp $	 */
+/*	$NetBSD: rtld.c,v 1.152 2011/08/13 22:24:24 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.151 2011/06/25 05:45:12 nonaka Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.152 2011/08/13 22:24:24 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -403,8 +403,10 @@
 	debug = 1;
 	dbg(("sp = %p, argc = %ld, argv = %p <%s> relocbase %p", sp,
 	(long)sp[2], &sp[3], (char *) sp[3], (void *)relocbase));
+#if 0
 	dbg(("got is at %p, dynamic is at %p", _GLOBAL_OFFSET_TABLE_,
 	&_DYNAMIC));
+#endif
 	dbg(("_ctype_ is %p", _ctype_));
 #endif
 



CVS commit: src/libexec/ld.elf_so

2011-08-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Aug 13 22:24:57 UTC 2011

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

Log Message:
printing the pathname of the shared object is much more useful than the
object's address.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 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.57 src/libexec/ld.elf_so/symbol.c:1.58
--- src/libexec/ld.elf_so/symbol.c:1.57	Sat Jun 25 01:45:12 2011
+++ src/libexec/ld.elf_so/symbol.c	Sat Aug 13 18:24:57 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: symbol.c,v 1.57 2011/06/25 05:45:12 nonaka Exp $	 */
+/*	$NetBSD: symbol.c,v 1.58 2011/08/13 22:24:57 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: symbol.c,v 1.57 2011/06/25 05:45:12 nonaka Exp $");
+__RCSID("$NetBSD: symbol.c,v 1.58 2011/08/13 22:24:57 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -255,7 +255,7 @@
 		assert(symnum < obj->nchains);
 		symp = obj->symtab + symnum;
 		strp = obj->strtab + symp->st_name;
-		rdbg(("check \"%s\" vs \"%s\" in %p", name, strp, obj));
+		rdbg(("check \"%s\" vs \"%s\" in %s", name, strp, obj->path));
 		if (name[1] != strp[1] || strcmp(name, strp))
 			continue;
 		if (symp->st_shndx != SHN_UNDEF)



CVS commit: src/libexec/ld.elf_so

2011-08-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Aug 13 22:25:20 UTC 2011

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

Log Message:
consistent debugging info for program headers


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 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.42 src/libexec/ld.elf_so/map_object.c:1.43
--- src/libexec/ld.elf_so/map_object.c:1.42	Wed Mar  9 18:10:07 2011
+++ src/libexec/ld.elf_so/map_object.c	Sat Aug 13 18:25:20 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: map_object.c,v 1.42 2011/03/09 23:10:07 joerg Exp $	 */
+/*	$NetBSD: map_object.c,v 1.43 2011/08/13 22:25:20 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -34,7 +34,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: map_object.c,v 1.42 2011/03/09 23:10:07 joerg Exp $");
+__RCSID("$NetBSD: map_object.c,v 1.43 2011/08/13 22:25:20 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -185,24 +185,28 @@
 			if (nsegs < 2)
 segs[nsegs] = phdr;
 			++nsegs;
-			dbg(("%s: PT_LOAD %p", obj->path, phdr));
+			dbg(("%s: %s %p phsize %zu", obj->path, "PT_LOAD",
+			(void *)(uintptr_t)phdr->p_vaddr, phdr->p_memsz));
 			break;
 
 		case PT_PHDR:
 			phdr_vaddr = phdr->p_vaddr;
 			phdr_memsz = phdr->p_memsz;
-			dbg(("%s: PT_PHDR %p phsize %zu", obj->path,
-			(void *)(uintptr_t)phdr_vaddr, phdr_memsz));
+			dbg(("%s: %s %p phsize %zu", obj->path, "PT_PHDR",
+			(void *)(uintptr_t)phdr->p_vaddr, phdr->p_memsz));
 			break;
 		
 		case PT_DYNAMIC:
 			obj->dynamic = (void *)(uintptr_t)phdr->p_vaddr;
- 			dbg(("%s: PT_DYNAMIC %p", obj->path, obj->dynamic));
+			dbg(("%s: %s %p phsize %zu", obj->path, "PT_DYNAMIC",
+			(void *)(uintptr_t)phdr->p_vaddr, phdr->p_memsz));
 			break;
 
 #if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II)
 		case PT_TLS:
 			phtls = phdr;
+			dbg(("%s: %s %p phsize %zu", obj->path, "PT_TLS",
+			(void *)(uintptr_t)phdr->p_vaddr, phdr->p_memsz));
 			break;
 #endif
 		}



CVS commit: src/libexec/ld.elf_so

2012-03-13 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Tue Mar 13 21:00:32 UTC 2012

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

Log Message:
Mark _rtld_debug_state as not to be inlined. Add an explicit instruction
barrier to prevent removal of calls to it.


To generate a diff of this commit:
cvs rdiff -u -r1.156 -r1.157 src/libexec/ld.elf_so/rtld.c
cvs rdiff -u -r1.108 -r1.109 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.

Modified files:

Index: src/libexec/ld.elf_so/rtld.c
diff -u src/libexec/ld.elf_so/rtld.c:1.156 src/libexec/ld.elf_so/rtld.c:1.157
--- src/libexec/ld.elf_so/rtld.c:1.156	Thu Feb 16 23:00:39 2012
+++ src/libexec/ld.elf_so/rtld.c	Tue Mar 13 21:00:31 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.156 2012/02/16 23:00:39 joerg Exp $	 */
+/*	$NetBSD: rtld.c,v 1.157 2012/03/13 21:00:31 joerg Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.156 2012/02/16 23:00:39 joerg Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.157 2012/03/13 21:00:31 joerg Exp $");
 #endif /* not lint */
 
 #include 
@@ -1385,7 +1385,8 @@ void
 _rtld_debug_state(void)
 {
 
-	/* do nothing */
+	/* Prevent optimizer from removing calls to this function */
+	__insn_barrier();
 }
 
 void

Index: src/libexec/ld.elf_so/rtld.h
diff -u src/libexec/ld.elf_so/rtld.h:1.108 src/libexec/ld.elf_so/rtld.h:1.109
--- src/libexec/ld.elf_so/rtld.h:1.108	Thu Feb 16 23:00:39 2012
+++ src/libexec/ld.elf_so/rtld.h	Tue Mar 13 21:00:32 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.h,v 1.108 2012/02/16 23:00:39 joerg Exp $	 */
+/*	$NetBSD: rtld.h,v 1.109 2012/03/13 21:00:32 joerg Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -338,7 +338,7 @@ void _rtld_error(const char *, ...)
  __attribute__((__format__(__printf__,1,2)));
 void _rtld_die(void) __attribute__((__noreturn__));
 void *_rtld_objmain_sym(const char *);
-__dso_public void _rtld_debug_state(void);
+__dso_public void _rtld_debug_state(void) __noinline;
 void _rtld_linkmap_add(Obj_Entry *);
 void _rtld_linkmap_delete(Obj_Entry *);
 void _rtld_objlist_push_head(Objlist *, Obj_Entry *);



CVS commit: src/libexec/ld.elf_so

2012-03-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Mar 15 00:16:07 UTC 2012

Modified Files:
src/libexec/ld.elf_so: Makefile
Added Files:
src/libexec/ld.elf_so: diagassert.c

Log Message:
Add __diagassert13() so that if libc is compiled with _DIAGNOSTIC, it does
not end up bringing in all of stdio.
XXX: This is temporary.


To generate a diff of this commit:
cvs rdiff -u -r1.110 -r1.111 src/libexec/ld.elf_so/Makefile
cvs rdiff -u -r0 -r1.1 src/libexec/ld.elf_so/diagassert.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.110 src/libexec/ld.elf_so/Makefile:1.111
--- src/libexec/ld.elf_so/Makefile:1.110	Fri Oct  7 05:15:21 2011
+++ src/libexec/ld.elf_so/Makefile	Wed Mar 14 20:16:07 2012
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.110 2011/10/07 09:15:21 mrg Exp $
+#	$NetBSD: Makefile,v 1.111 2012/03/15 00:16:07 christos Exp $
 #
 # NOTE: when changing ld.so, ensure that ldd still compiles.
 #
@@ -63,7 +63,7 @@ CLIBOBJ!=	cd ${NETBSDSRCDIR}/lib/libc &&
 
 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
+		tls.c symver.c diagassert.c
 
 .if ${USE_FORT} == "yes"
 .PATH.c: ${NETBSDSRCDIR}/lib/libc/misc

Added files:

Index: src/libexec/ld.elf_so/diagassert.c
diff -u /dev/null src/libexec/ld.elf_so/diagassert.c:1.1
--- /dev/null	Wed Mar 14 20:16:07 2012
+++ src/libexec/ld.elf_so/diagassert.c	Wed Mar 14 20:16:07 2012
@@ -0,0 +1,9 @@
+#include 
+#include 
+
+void
+/*ARGSUSED*/
+__diagassert13(const char *fn, int fl, const char *fu, const char *m)
+{
+	abort();
+}



CVS commit: src/libexec/ld.elf_so

2012-03-16 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Fri Mar 16 11:44:54 UTC 2012

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

Log Message:
This version of __diagssert13 is dead.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/libexec/ld.elf_so/diagassert.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/diagassert.c
diff -u src/libexec/ld.elf_so/diagassert.c:1.1 src/libexec/ld.elf_so/diagassert.c:1.2
--- src/libexec/ld.elf_so/diagassert.c:1.1	Thu Mar 15 00:16:07 2012
+++ src/libexec/ld.elf_so/diagassert.c	Fri Mar 16 11:44:54 2012
@@ -1,7 +1,7 @@
 #include 
 #include 
 
-void
+__dead void
 /*ARGSUSED*/
 __diagassert13(const char *fn, int fl, const char *fu, const char *m)
 {



CVS commit: src/libexec/ld.elf_so

2012-07-22 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Jul 22 09:16:36 UTC 2012

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

Log Message:
Remove a debug assert that does not hold for PIE (e.g. phdr = 0x40, but
obj has not been mapped at 0, so obj->phdr is 0x100040).
OK: skrll


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 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.41 src/libexec/ld.elf_so/headers.c:1.42
--- src/libexec/ld.elf_so/headers.c:1.41	Sat Jun 25 05:45:12 2011
+++ src/libexec/ld.elf_so/headers.c	Sun Jul 22 09:16:35 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: headers.c,v 1.41 2011/06/25 05:45:12 nonaka Exp $	 */
+/*	$NetBSD: headers.c,v 1.42 2012/07/22 09:16:35 martin Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: headers.c,v 1.41 2011/06/25 05:45:12 nonaka Exp $");
+__RCSID("$NetBSD: headers.c,v 1.42 2012/07/22 09:16:35 martin Exp $");
 #endif /* not lint */
 
 #include 
@@ -356,7 +356,6 @@ _rtld_digest_phdr(const Elf_Phdr *phdr, 
 		obj->phsize, (long)obj->relocbase));
 		break;
 	}
-	assert(obj->phdr == phdr);
 	
 	for (ph = phdr; ph < phlimit; ++ph) {
 		vaddr = (Elf_Addr)(uintptr_t)(obj->relocbase + ph->p_vaddr);



CVS commit: src/libexec/ld.elf_so

2012-07-25 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Jul 25 22:51:05 UTC 2012

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

Log Message:
Try to make dbg() printfs realy ELFSIZE independent


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 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.43 src/libexec/ld.elf_so/map_object.c:1.44
--- src/libexec/ld.elf_so/map_object.c:1.43	Sat Aug 13 22:25:20 2011
+++ src/libexec/ld.elf_so/map_object.c	Wed Jul 25 22:51:04 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: map_object.c,v 1.43 2011/08/13 22:25:20 christos Exp $	 */
+/*	$NetBSD: map_object.c,v 1.44 2012/07/25 22:51:04 martin Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -34,7 +34,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: map_object.c,v 1.43 2011/08/13 22:25:20 christos Exp $");
+__RCSID("$NetBSD: map_object.c,v 1.44 2012/07/25 22:51:04 martin Exp $");
 #endif /* not lint */
 
 #include 
@@ -185,27 +185,33 @@ _rtld_map_object(const char *path, int f
 			if (nsegs < 2)
 segs[nsegs] = phdr;
 			++nsegs;
-			dbg(("%s: %s %p phsize %zu", obj->path, "PT_LOAD",
+
+#if ELFSIZE == 64
+#define	PRImemsz	PRIu64
+#else
+#define PRImemsz	PRIu32
+#endif
+			dbg(("%s: %s %p phsize %" PRImemsz, obj->path, "PT_LOAD",
 			(void *)(uintptr_t)phdr->p_vaddr, phdr->p_memsz));
 			break;
 
 		case PT_PHDR:
 			phdr_vaddr = phdr->p_vaddr;
 			phdr_memsz = phdr->p_memsz;
-			dbg(("%s: %s %p phsize %zu", obj->path, "PT_PHDR",
+			dbg(("%s: %s %p phsize %" PRImemsz, obj->path, "PT_PHDR",
 			(void *)(uintptr_t)phdr->p_vaddr, phdr->p_memsz));
 			break;
 		
 		case PT_DYNAMIC:
 			obj->dynamic = (void *)(uintptr_t)phdr->p_vaddr;
-			dbg(("%s: %s %p phsize %zu", obj->path, "PT_DYNAMIC",
+			dbg(("%s: %s %p phsize %" PRImemsz, obj->path, "PT_DYNAMIC",
 			(void *)(uintptr_t)phdr->p_vaddr, phdr->p_memsz));
 			break;
 
 #if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II)
 		case PT_TLS:
 			phtls = phdr;
-			dbg(("%s: %s %p phsize %zu", obj->path, "PT_TLS",
+			dbg(("%s: %s %p phsize %" PRImemsz, obj->path, "PT_TLS",
 			(void *)(uintptr_t)phdr->p_vaddr, phdr->p_memsz));
 			break;
 #endif



CVS commit: src/libexec/ld.elf_so

2011-02-24 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Thu Feb 24 10:58:54 UTC 2011

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

Log Message:
make DEBUG compile without RTLD_DEBUG


To generate a diff of this commit:
cvs rdiff -u -r1.137 -r1.138 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.137 src/libexec/ld.elf_so/rtld.c:1.138
--- src/libexec/ld.elf_so/rtld.c:1.137	Fri Dec 24 12:41:43 2010
+++ src/libexec/ld.elf_so/rtld.c	Thu Feb 24 10:58:54 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.137 2010/12/24 12:41:43 skrll Exp $	 */
+/*	$NetBSD: rtld.c,v 1.138 2011/02/24 10:58:54 pooka Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.137 2010/12/24 12:41:43 skrll Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.138 2011/02/24 10:58:54 pooka Exp $");
 #endif /* not lint */
 
 #include 
@@ -325,9 +325,11 @@
 	const Obj_Entry **real___mainprog_obj;
 	char ***real_environ;
 #ifdef DEBUG
-	int i = 0;
 	const char *ld_debug;
 #endif
+#ifdef RTLD_DEBUG
+	int i = 0;
+#endif
 
 	/*
  * On entry, the dynamic linker itself has not been relocated yet.



CVS commit: src/libexec/ld.elf_so

2011-03-10 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Thu Mar 10 14:27:32 UTC 2011

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

Log Message:
Fix prototype for __tls_get_addr. Add a generic implementation of it
using __tls_get_addr. Update TLS notes.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/libexec/ld.elf_so/README.TLS \
src/libexec/ld.elf_so/tls.c
cvs rdiff -u -r1.101 -r1.102 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.

Modified files:

Index: src/libexec/ld.elf_so/README.TLS
diff -u src/libexec/ld.elf_so/README.TLS:1.1 src/libexec/ld.elf_so/README.TLS:1.2
--- src/libexec/ld.elf_so/README.TLS:1.1	Wed Mar  9 23:10:07 2011
+++ src/libexec/ld.elf_so/README.TLS	Thu Mar 10 14:27:31 2011
@@ -3,11 +3,7 @@
 (1) Declare TLS variant in machine/types.h by defining either
 __HAVE_TLS_VARIANT_I or __HAVE_TLS_VARIANT_II.
 
-(2) crt0.o has to call _rtld_tls_static_setup() if _DYNAMIC == NULL.
-This part is already done if the new src/lib/csu/arch layout is used
-by the architecture.
-
-(3) _lwp_makecontext has to set the reserved register or kernel transfer
+(2) _lwp_makecontext has to set the reserved register or kernel transfer
 variable in uc_mcontext to the provided value of 'private'.
 
 This is not possible on the VAX as there is no free space in ucontext_t.
@@ -15,38 +11,21 @@
 everything using ucontext_t. Debug support depends on getting the data from
 ucontext_t, so the second option is possibly required.
 
-(4) _lwp_setprivate(2) has to update the same register as
+(3) _lwp_setprivate(2) has to update the same register as
 _lwp_makecontext. cpu_lwp_setprivate has to call _lwp_setprivate(2) to
 reflect the kernel view. cpu_switch has to update the mapping.
 
 _lwp_setprivate is used for the initial thread, all other threads
 created by libpthread use _lwp_makecontext for this purpose.
 
-(5) Provide __tls_get_addr and possible other MD functions for dynamic
+(4) Provide __tls_get_addr and possible other MD functions for dynamic
 TLS offset computation. If such alternative entry points exist (currently
 only i386), also add a weak reference to 0 in src/lib/libc/tls/tls.c.
 
-The generic implementation is:
-
-#include 
-#include 
-#include 
-
-/* Weak entry is overriden by ld.elf_so for dynamic linkage */
-weak_alias(__tls_get_addr, __libc__tls_get_addr)
-
-void *
-__libc__tls_get_addr(size_t idx[2])
-{
-	struct tls_tcb *tcb;
-
-	tcb = _lwp_getprivate();
-	return _rtld_tls_get_addr(tcb, idx[0], idx[1]);
-}
-
-XXX Document optimisations based idx[0]
+The generic implementation can be found in tls.c and is used with
+__HAVE_COMMON___TLS_GET_ADDR. It depends on ___lwp_getprivate_fast.
 
-(6) Implement the necessary relocation records in mdreloc.c.  There are
+(5) Implement the necessary relocation records in mdreloc.c.  There are
 typically three relocation types found in dynamic binaries:
 
 (a) R_TYPE(TLS_DTPOFF): Offset inside the module.  The common TLS code
@@ -73,7 +52,7 @@
 
 e.g. starting offset is counting down from the TCB.
 
-(7) Implement _lwp_getprivate_fast() in machine/mcontext.h and set
+(6) Implement _lwp_getprivate_fast() in machine/mcontext.h and set
 __HAVE___LWP_GETPRIVATE_FAST.
 
 (8) Test using src/tests/lib/libc/tls.  Make sure with "objdump -R" that
Index: src/libexec/ld.elf_so/tls.c
diff -u src/libexec/ld.elf_so/tls.c:1.1 src/libexec/ld.elf_so/tls.c:1.2
--- src/libexec/ld.elf_so/tls.c:1.1	Wed Mar  9 23:10:07 2011
+++ src/libexec/ld.elf_so/tls.c	Thu Mar 10 14:27:31 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: tls.c,v 1.1 2011/03/09 23:10:07 joerg Exp $	*/
+/*	$NetBSD: tls.c,v 1.2 2011/03/10 14:27:31 joerg Exp $	*/
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,9 +29,10 @@
  */
 
 #include 
-__RCSID("$NetBSD: tls.c,v 1.1 2011/03/09 23:10:07 joerg Exp $");
+__RCSID("$NetBSD: tls.c,v 1.2 2011/03/10 14:27:31 joerg Exp $");
 
 #include 
+#include 
 #include 
 #include 
 #include "rtld.h"
@@ -232,4 +233,28 @@
 	return;
 }
 
+#ifdef __HAVE_COMMON___TLS_GET_ADDR
+/*
+ * The fast path is access to an already allocated DTV entry.
+ * This checks the current limit and the entry without needing any
+ * locking. Entries are only freed on dlclose() and it is an application
+ * bug if code of the module is still running at that point.
+ */
+void *
+__tls_get_addr(void *arg_)
+{
+	size_t *arg = (size_t *)arg_;
+	void **dtv;
+	struct tls_tcb *tcb = __lwp_getprivate_fast();
+	size_t idx = arg[0], offset = arg[1];
+
+	dtv = tcb->tcb_dtv;
+
+	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);
+}
+#endif
+
 #endif /* __HAVE_TLS_VARIANT_I || __HAVE_TLS_VARIANT_II */

Index: src/libexec/ld.elf_so/rtld.h
diff -u src/libexec/ld.elf_so/rtld.h:1.101 src/libexec/ld.elf_so/rtld.h:1.102
--- src/libexec/ld.elf_so/rtld.h:1.101	Wed Mar  9

CVS commit: src/libexec/ld.elf_so

2011-03-10 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Thu Mar 10 17:22:17 UTC 2011

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

Log Message:
Add source reference for _lwp_makecontext and
__HAVE___LWP_GETPRIVATE_FAST. Fix enumeration.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/libexec/ld.elf_so/README.TLS

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.2 src/libexec/ld.elf_so/README.TLS:1.3
--- src/libexec/ld.elf_so/README.TLS:1.2	Thu Mar 10 14:27:31 2011
+++ src/libexec/ld.elf_so/README.TLS	Thu Mar 10 17:22:17 2011
@@ -4,7 +4,8 @@
 __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'.
+variable in uc_mcontext to the provided value of 'private'. 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
@@ -53,8 +54,8 @@
 e.g. starting offset is counting down from the TCB.
 
 (6) Implement _lwp_getprivate_fast() in machine/mcontext.h and set
-__HAVE___LWP_GETPRIVATE_FAST.
+__HAVE___LWP_GETPRIVATE_FAST in machine/types.h.
 
-(8) Test using src/tests/lib/libc/tls.  Make sure with "objdump -R" that
+(7) Test using src/tests/lib/libc/tls.  Make sure with "objdump -R" that
 t_tls_dynamic has two TPOFF relocations and h_tls_dlopen.so.1 and
 libh_tls_dynamic.so.1 have both two DTPMOD and DTPOFF relocations.



CVS commit: src/libexec/ld.elf_so

2011-03-10 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Thu Mar 10 17:38:30 UTC 2011

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

Log Message:
Add some clarifications


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/libexec/ld.elf_so/README.TLS

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.3 src/libexec/ld.elf_so/README.TLS:1.4
--- src/libexec/ld.elf_so/README.TLS:1.3	Thu Mar 10 17:22:17 2011
+++ src/libexec/ld.elf_so/README.TLS	Thu Mar 10 17:38:30 2011
@@ -13,8 +13,13 @@
 ucontext_t, so the second option is possibly required.
 
 (3) _lwp_setprivate(2) has to update the same register as
-_lwp_makecontext. cpu_lwp_setprivate has to call _lwp_setprivate(2) to
-reflect the kernel view. cpu_switch has to update the mapping.
+_lwp_makecontext uses for the private area pointer. Normally
+cpu_lwp_setprivate is provided by MD to reflect the kernel view and
+enabled by defining __HAVE_CPU_LWP_SETPRIVATE in machine/types.h.
+cpu_setmcontext is responsible for keeping the MI l_private field
+synchronised by calling lwp_setprivate as needed.
+
+cpu_switchto has to update the mapping.
 
 _lwp_setprivate is used for the initial thread, all other threads
 created by libpthread use _lwp_makecontext for this purpose.
@@ -24,7 +29,8 @@
 only i386), also add a weak reference to 0 in src/lib/libc/tls/tls.c.
 
 The generic implementation can be found in tls.c and is used with
-__HAVE_COMMON___TLS_GET_ADDR. It depends on ___lwp_getprivate_fast.
+__HAVE_COMMON___TLS_GET_ADDR. It depends on ___lwp_getprivate_fast
+(see below).
 
 (5) Implement the necessary relocation records in mdreloc.c.  There are
 typically three relocation types found in dynamic binaries:



CVS commit: src/libexec/ld.elf_so

2011-03-11 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Sat Mar 12 07:43:53 UTC 2011

Modified Files:
src/libexec/ld.elf_so: tls.c
src/libexec/ld.elf_so/arch/powerpc: ppc_reloc.c

Log Message:
Add TLS support for PowerPC.
If the port has __lwp_gettcb_fast or __lwp_settcb use them instead of
__lwp_getprivate_fast or lwp_setprivate.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/libexec/ld.elf_so/tls.c
cvs rdiff -u -r1.47 -r1.48 src/libexec/ld.elf_so/arch/powerpc/ppc_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/tls.c
diff -u src/libexec/ld.elf_so/tls.c:1.2 src/libexec/ld.elf_so/tls.c:1.3
--- src/libexec/ld.elf_so/tls.c:1.2	Thu Mar 10 14:27:31 2011
+++ src/libexec/ld.elf_so/tls.c	Sat Mar 12 07:43:53 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: tls.c,v 1.2 2011/03/10 14:27:31 joerg Exp $	*/
+/*	$NetBSD: tls.c,v 1.3 2011/03/12 07:43:53 matt Exp $	*/
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,7 +29,7 @@
  */
 
 #include 
-__RCSID("$NetBSD: tls.c,v 1.2 2011/03/10 14:27:31 joerg Exp $");
+__RCSID("$NetBSD: tls.c,v 1.3 2011/03/12 07:43:53 matt Exp $");
 
 #include 
 #include 
@@ -39,6 +39,10 @@
 
 #if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II)
 
+#ifndef TLS_DTV_OFFSET
+#define	TLS_DTV_OFFSET	0
+#endif
+
 static size_t _rtld_tls_static_space;	/* Static TLS space allocated */
 static size_t _rtld_tls_static_offset;	/* Next offset for static TLS to use */
 size_t _rtld_tls_dtv_generation = 1;
@@ -91,7 +95,11 @@
 #endif
 
 	tcb = _rtld_tls_allocate();
+#ifdef __HAVE___LWP_SETTCB
+	__lwp_settcb(tcb);
+#else
 	_lwp_setprivate(tcb);
+#endif
 }
 
 struct tls_tcb *
@@ -245,8 +253,12 @@
 {
 	size_t *arg = (size_t *)arg_;
 	void **dtv;
-	struct tls_tcb *tcb = __lwp_getprivate_fast();
-	size_t idx = arg[0], offset = arg[1];
+#ifdef __HAVE___LWP_GETTCB_FAST
+	struct tls_tcb * const tcb = __lwp_gettcb_fast();
+#else
+	struct tls_tcb * const tcb = __lwp_getprivate_fast();
+#endif
+	size_t idx = arg[0], offset = arg[1] + TLS_DTV_OFFSET;
 
 	dtv = tcb->tcb_dtv;
 

Index: src/libexec/ld.elf_so/arch/powerpc/ppc_reloc.c
diff -u src/libexec/ld.elf_so/arch/powerpc/ppc_reloc.c:1.47 src/libexec/ld.elf_so/arch/powerpc/ppc_reloc.c:1.48
--- src/libexec/ld.elf_so/arch/powerpc/ppc_reloc.c:1.47	Thu Feb 10 02:28:20 2011
+++ src/libexec/ld.elf_so/arch/powerpc/ppc_reloc.c	Sat Mar 12 07:43:53 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ppc_reloc.c,v 1.47 2011/02/10 02:28:20 matt Exp $	*/
+/*	$NetBSD: ppc_reloc.c,v 1.48 2011/03/12 07:43:53 matt Exp $	*/
 
 /*-
  * Copyright (C) 1998	Tsubai Masanari
@@ -30,7 +30,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: ppc_reloc.c,v 1.47 2011/02/10 02:28:20 matt Exp $");
+__RCSID("$NetBSD: ppc_reloc.c,v 1.48 2011/03/12 07:43:53 matt Exp $");
 #endif /* not lint */
 
 #include 
@@ -204,6 +204,47 @@
 			rdbg(("COPY (avoid in main)"));
 			break;
 
+		case R_TYPE(DTPMOD32):
+			def = _rtld_find_symdef(symnum, obj, &defobj, false);
+			if (def == NULL)
+return -1;
+
+			*where = (Elf_Addr)defobj->tlsindex;
+			rdbg(("DTPMOD32 %s in %s --> %p in %s",
+			obj->strtab + obj->symtab[symnum].st_name,
+			obj->path, (void *)*where, defobj->path));
+			break;
+
+		case R_TYPE(DTPREL32):
+			def = _rtld_find_symdef(symnum, obj, &defobj, false);
+			if (def == NULL)
+return -1;
+
+			if (!defobj->tls_done && _rtld_tls_offset_allocate(obj))
+return -1;
+
+			*where = (Elf_Addr)(def->st_value + rela->r_addend
+			- TLS_DTV_OFFSET);
+			rdbg(("DTPREL32 %s in %s --> %p in %s",
+			obj->strtab + obj->symtab[symnum].st_name,
+			obj->path, (void *)*where, defobj->path));
+			break;
+
+		case R_TYPE(TPREL32):
+			def = _rtld_find_symdef(symnum, obj, &defobj, false);
+			if (def == NULL)
+return -1;
+
+			if (!defobj->tls_done && _rtld_tls_offset_allocate(obj))
+return -1;
+
+			*where = (Elf_Addr)(def->st_value + rela->r_addend
+			+ defobj->tlsoffset - TLS_TP_OFFSET);
+			rdbg(("TPREL32 %s in %s --> %p in %s",
+			obj->strtab + obj->symtab[symnum].st_name,
+			obj->path, (void *)*where, defobj->path));
+			break;
+
 		default:
 			rdbg(("sym = %lu, type = %lu, offset = %p, "
 			"addend = %p, contents = %p, symbol = %s",



CVS commit: src/libexec/ld.elf_so

2011-03-13 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sun Mar 13 21:08:45 UTC 2011

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

Log Message:
Fill in TLS related fields in dl_iterate_phdr if TLS is supported


To generate a diff of this commit:
cvs rdiff -u -r1.139 -r1.140 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.139 src/libexec/ld.elf_so/rtld.c:1.140
--- src/libexec/ld.elf_so/rtld.c:1.139	Wed Mar  9 23:10:07 2011
+++ src/libexec/ld.elf_so/rtld.c	Sun Mar 13 21:08:45 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.139 2011/03/09 23:10:07 joerg Exp $	 */
+/*	$NetBSD: rtld.c,v 1.140 2011/03/13 21:08:45 joerg Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.139 2011/03/09 23:10:07 joerg Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.140 2011/03/13 21:08:45 joerg Exp $");
 #endif /* not lint */
 
 #include 
@@ -1154,12 +1154,12 @@
 		STAILQ_FIRST(&obj->names)->name : obj->path;
 		phdr_info.dlpi_phdr = obj->phdr;
 		phdr_info.dlpi_phnum = obj->phsize / sizeof(obj->phdr[0]);
-#if 1
-		phdr_info.dlpi_tls_modid = 0;
-		phdr_info.dlpi_tls_data = 0;
-#else
+#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;



CVS commit: src/libexec/ld.elf_so

2011-03-26 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sat Mar 26 21:40:37 UTC 2011

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

Log Message:
Fix merge error that broke HPPA


To generate a diff of this commit:
cvs rdiff -u -r1.141 -r1.142 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.141 src/libexec/ld.elf_so/rtld.c:1.142
--- src/libexec/ld.elf_so/rtld.c:1.141	Fri Mar 25 18:07:04 2011
+++ src/libexec/ld.elf_so/rtld.c	Sat Mar 26 21:40:37 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.141 2011/03/25 18:07:04 joerg Exp $	 */
+/*	$NetBSD: rtld.c,v 1.142 2011/03/26 21:40:37 joerg Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.141 2011/03/25 18:07:04 joerg Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.142 2011/03/26 21:40:37 joerg Exp $");
 #endif /* not lint */
 
 #include 
@@ -1061,6 +1061,8 @@
 		void *p;
 #ifdef __HAVE_FUNCTION_DESCRIPTORS
 		if (ELF_ST_TYPE(def->st_info) == STT_FUNC) {
+			p = (void *)_rtld_function_descriptor_alloc(defobj,
+			def, 0);
 			lookup_mutex_exit();
 			return p;
 		}



CVS commit: src/libexec/ld.elf_so

2011-03-27 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sun Mar 27 13:14:42 UTC 2011

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

Log Message:
Locking around dlclose()


To generate a diff of this commit:
cvs rdiff -u -r1.142 -r1.143 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.142 src/libexec/ld.elf_so/rtld.c:1.143
--- src/libexec/ld.elf_so/rtld.c:1.142	Sat Mar 26 21:40:37 2011
+++ src/libexec/ld.elf_so/rtld.c	Sun Mar 27 13:14:42 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.142 2011/03/26 21:40:37 joerg Exp $	 */
+/*	$NetBSD: rtld.c,v 1.143 2011/03/27 13:14:42 joerg Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.142 2011/03/26 21:40:37 joerg Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.143 2011/03/27 13:14:42 joerg Exp $");
 #endif /* not lint */
 
 #include 
@@ -839,10 +839,17 @@
 int
 dlclose(void *handle)
 {
-	Obj_Entry *root = _rtld_dlcheck(handle);
+	Obj_Entry *root;
 
-	if (root == NULL)
+
+	_rtld_exclusive_enter();
+
+	root = _rtld_dlcheck(handle);
+
+	if (root == NULL) {
+		_rtld_exclusive_exit();
 		return -1;
+	}
 
 	_rtld_debug.r_state = RT_DELETE;
 	_rtld_debug_state();
@@ -853,6 +860,8 @@
 	_rtld_debug.r_state = RT_CONSISTENT;
 	_rtld_debug_state();
 
+	_rtld_exclusive_enter();
+
 	return 0;
 }
 



CVS commit: src/libexec/ld.elf_so

2011-03-27 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sun Mar 27 13:15:34 UTC 2011

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

Log Message:
Add some debug messages for explicit rtld entry points


To generate a diff of this commit:
cvs rdiff -u -r1.143 -r1.144 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.143 src/libexec/ld.elf_so/rtld.c:1.144
--- src/libexec/ld.elf_so/rtld.c:1.143	Sun Mar 27 13:14:42 2011
+++ src/libexec/ld.elf_so/rtld.c	Sun Mar 27 13:15:34 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.143 2011/03/27 13:14:42 joerg Exp $	 */
+/*	$NetBSD: rtld.c,v 1.144 2011/03/27 13:15:34 joerg Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.143 2011/03/27 13:14:42 joerg Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.144 2011/03/27 13:15:34 joerg Exp $");
 #endif /* not lint */
 
 #include 
@@ -841,6 +841,7 @@
 {
 	Obj_Entry *root;
 
+	dbg(("dlclose of %p", handle));
 
 	_rtld_exclusive_enter();
 
@@ -885,6 +886,8 @@
 	bool nodelete;
 	bool now;
 
+	dbg(("dlopen of %s %d", name, mode));
+
 	_rtld_exclusive_enter();
 
 	flags |= (mode & RTLD_GLOBAL) ? _RTLD_GLOBAL : 0;
@@ -985,6 +988,8 @@
 	void *retaddr;
 	DoneList donelist; 
 
+	dbg(("dlsym of %s in %p", name, handle));
+
 	lookup_mutex_enter();
 
 	hash = _rtld_elf_hash(name);
@@ -1095,6 +1100,8 @@
 	void *symbol_addr;
 	unsigned long symoffset;
 
+	dbg(("dladdr of %p", addr));
+
 	lookup_mutex_enter();
 
 #ifdef __HAVE_FUNCTION_DESCRIPTORS
@@ -1163,6 +1170,8 @@
 	const Obj_Entry *obj;
 	void *retaddr;
 
+	dbg(("dlinfo for %p %d", handle, req));
+
 	_rtld_shared_enter();
 
 	if (handle == RTLD_SELF) {
@@ -1211,6 +1220,8 @@
 	const Obj_Entry *obj;
 	int error = 0;
 
+	dbg(("dl_iterate_phdr"));
+
 	_rtld_shared_enter();
 
 	for (obj = _rtld_objlist;  obj != NULL;  obj = obj->next) {



CVS commit: src/libexec/ld.elf_so

2011-03-27 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sun Mar 27 21:58:51 UTC 2011

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

Log Message:
Handle _rtld_exit as full entry point since other threads may still be
running at the time.


To generate a diff of this commit:
cvs rdiff -u -r1.144 -r1.145 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.144 src/libexec/ld.elf_so/rtld.c:1.145
--- src/libexec/ld.elf_so/rtld.c:1.144	Sun Mar 27 13:15:34 2011
+++ src/libexec/ld.elf_so/rtld.c	Sun Mar 27 21:58:50 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.144 2011/03/27 13:15:34 joerg Exp $	 */
+/*	$NetBSD: rtld.c,v 1.145 2011/03/27 21:58:50 joerg Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.144 2011/03/27 13:15:34 joerg Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.145 2011/03/27 21:58:50 joerg Exp $");
 #endif /* not lint */
 
 #include 
@@ -304,7 +304,11 @@
 {
 	dbg(("rtld_exit()"));
 
+	_rtld_exclusive_enter();
+
 	_rtld_call_fini_functions(1);
+
+	_rtld_exclusive_exit();
 }
 
 /*



CVS commit: src/libexec/ld.elf_so

2011-03-27 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sun Mar 27 22:20:51 UTC 2011

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

Log Message:
exit, not enter


To generate a diff of this commit:
cvs rdiff -u -r1.145 -r1.146 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.145 src/libexec/ld.elf_so/rtld.c:1.146
--- src/libexec/ld.elf_so/rtld.c:1.145	Sun Mar 27 21:58:50 2011
+++ src/libexec/ld.elf_so/rtld.c	Sun Mar 27 22:20:51 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.145 2011/03/27 21:58:50 joerg Exp $	 */
+/*	$NetBSD: rtld.c,v 1.146 2011/03/27 22:20:51 joerg Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.145 2011/03/27 21:58:50 joerg Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.146 2011/03/27 22:20:51 joerg Exp $");
 #endif /* not lint */
 
 #include 
@@ -865,7 +865,7 @@
 	_rtld_debug.r_state = RT_CONSISTENT;
 	_rtld_debug_state();
 
-	_rtld_exclusive_enter();
+	_rtld_exclusive_exit();
 
 	return 0;
 }



CVS commit: src/libexec/ld.elf_so

2011-03-27 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Mon Mar 28 00:37:41 UTC 2011

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

Log Message:
Refine locking scheme around init/fini to not hold the exclusive lock.
Use a simple generation count instead and restart looking for work if it
changed (e.g. due to an dlopen call from an init function).
Leave the possible dlclose() race for now.


To generate a diff of this commit:
cvs rdiff -u -r1.146 -r1.147 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.146 src/libexec/ld.elf_so/rtld.c:1.147
--- src/libexec/ld.elf_so/rtld.c:1.146	Sun Mar 27 22:20:51 2011
+++ src/libexec/ld.elf_so/rtld.c	Mon Mar 28 00:37:40 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.146 2011/03/27 22:20:51 joerg Exp $	 */
+/*	$NetBSD: rtld.c,v 1.147 2011/03/28 00:37:40 joerg Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.146 2011/03/27 22:20:51 joerg Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.147 2011/03/28 00:37:40 joerg Exp $");
 #endif /* not lint */
 
 #include 
@@ -89,6 +89,7 @@
 Obj_Entry   _rtld_objself;	/* The dynamic linker shared object */
 u_int		_rtld_objcount;	/* Number of objects in _rtld_objlist */
 u_int		_rtld_objloads;	/* Number of objects loaded in _rtld_objlist */
+u_int		_rtld_objgen;	/* Generation count for _rtld_objlist */
 const char	_rtld_path[] = _PATH_RTLD;
 
 /* Initialize a fake symbol for resolving undefined weak references. */
@@ -139,9 +140,13 @@
 	Objlist_Entry *elm;
 	Objlist finilist;
 	Obj_Entry *obj;
+	void (*fini)(void);
+	u_int cur_objgen;
 
 	dbg(("_rtld_call_fini_functions(%d)", force));
 
+restart:
+	cur_objgen = ++_rtld_objgen;
 	SIMPLEQ_INIT(&finilist);
 	_rtld_initlist_tsort(&finilist, 1);
 
@@ -157,10 +162,20 @@
 		dbg (("calling fini function %s at %p",  obj->path,
 		(void *)obj->fini));
 		obj->fini_called = 1;
-		/* XXXlocking: exit point */
-		_rtld_mutex_may_recurse = true;
-		(*obj->fini)();
-		_rtld_mutex_may_recurse = false;
+		/*
+		 * XXX This can race against a concurrent dlclose().
+		 * XXX In that case, the object could be unmapped before
+		 * XXX the fini() call is done.
+		 */
+		fini = obj->fini;
+		_rtld_exclusive_exit();
+		(*fini)();
+		_rtld_exclusive_enter();
+		if (_rtld_objgen != cur_objgen) {
+			dbg(("restarting fini iteration"));
+			_rtld_objlist_clear(&finilist);
+			goto restart;
+		}
 	}
 
 	/* Second pass: objects marked with DF_1_INITFIRST. */
@@ -175,10 +190,16 @@
 		dbg (("calling fini function %s at %p (DF_1_INITFIRST)",
 		obj->path, (void *)obj->fini));
 		obj->fini_called = 1;
-		/* XXXlocking: exit point */
-		_rtld_mutex_may_recurse = true;
-		(*obj->fini)();
-		_rtld_mutex_may_recurse = false;
+		/* XXX See above for the race condition here */
+		fini = obj->fini;
+		_rtld_exclusive_exit();
+		(*fini)();
+		_rtld_exclusive_enter();
+		if (_rtld_objgen != cur_objgen) {
+			dbg(("restarting fini iteration"));
+			_rtld_objlist_clear(&finilist);
+			goto restart;
+		}
 	}
 
 _rtld_objlist_clear(&finilist);
@@ -190,8 +211,13 @@
 	Objlist_Entry *elm;
 	Objlist initlist;
 	Obj_Entry *obj;
+	void (*init)(void);
+	u_int cur_objgen;
 
 	dbg(("_rtld_call_init_functions()"));
+
+restart:
+	cur_objgen = ++_rtld_objgen;
 	SIMPLEQ_INIT(&initlist);
 	_rtld_initlist_tsort(&initlist, 0);
 
@@ -204,10 +230,15 @@
 		dbg (("calling init function %s at %p (DF_1_INITFIRST)",
 		obj->path, (void *)obj->init));
 		obj->init_called = 1;
-		/* XXXlocking: exit point */
-		_rtld_mutex_may_recurse = true;
-		(*obj->init)();
-		_rtld_mutex_may_recurse = false;
+		init = obj->init;
+		_rtld_exclusive_exit();
+		(*init)();
+		_rtld_exclusive_enter();
+		if (_rtld_objgen != cur_objgen) {
+			dbg(("restarting init iteration"));
+			_rtld_objlist_clear(&initlist);
+			goto restart;
+		}
 	}
 
 	/* Second pass: all other objects. */
@@ -219,10 +250,15 @@
 		dbg (("calling init function %s at %p",  obj->path,
 		(void *)obj->init));
 		obj->init_called = 1;
-		/* XXXlocking: exit point */
-		_rtld_mutex_may_recurse = true;
-		(*obj->init)();
-		_rtld_mutex_may_recurse = false;
+		init = obj->init;
+		_rtld_exclusive_exit();
+		(*init)();
+		_rtld_exclusive_enter();
+		if (_rtld_objgen != cur_objgen) {
+			dbg(("restarting init iteration"));
+			_rtld_objlist_clear(&initlist);
+			goto restart;
+		}
 	}
 
 _rtld_objlist_clear(&initlist);



CVS commit: src/libexec/ld.elf_so

2011-04-02 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sat Apr  2 12:30:41 UTC 2011

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

Log Message:
Unbreak HPPA


To generate a diff of this commit:
cvs rdiff -u -r1.148 -r1.149 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.148 src/libexec/ld.elf_so/rtld.c:1.149
--- src/libexec/ld.elf_so/rtld.c:1.148	Tue Mar 29 20:56:35 2011
+++ src/libexec/ld.elf_so/rtld.c	Sat Apr  2 12:30:41 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.148 2011/03/29 20:56:35 joerg Exp $	 */
+/*	$NetBSD: rtld.c,v 1.149 2011/04/02 12:30:41 joerg Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.148 2011/03/29 20:56:35 joerg Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.149 2011/04/02 12:30:41 joerg Exp $");
 #endif /* not lint */
 
 #include 
@@ -1147,6 +1147,9 @@
 	const Elf_Sym *def, *best_def;
 	void *symbol_addr;
 	unsigned long symoffset;
+#ifdef __HAVE_FUNCTION_DESCRIPTORS
+	sigset_t mask;
+#endif
 
 	dbg(("dladdr of %p", addr));
 
@@ -1405,6 +1408,24 @@
 	}
 }
 
+void
+_rtld_lock(int arg, sigset_t *mask)
+{
+	switch (arg) {
+	default:
+		dbg(("%s: invalid argument: %d", __func__, arg));
+		break;
+	case RTLD_LOCK_PRE_FORK:
+		_rtld_exclusive_enter(mask);
+		_rtld_mutex_may_recurse = true;
+		break;
+	case RTLD_LOCK_POST_FORK:
+		_rtld_mutex_may_recurse = false;
+		_rtld_exclusive_exit(mask);
+		break;
+	}
+}
+
 #define	RTLD_EXCLUSIVE_MASK	0x8000U
 static volatile unsigned int _rtld_mutex;
 static volatile unsigned int _rtld_waiter_exclusive;



CVS commit: src/libexec/ld.elf_so

2011-04-02 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sat Apr  2 16:49:49 UTC 2011

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

Log Message:
Revert pthread_atfork related change not intended for commit yet.


To generate a diff of this commit:
cvs rdiff -u -r1.149 -r1.150 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.149 src/libexec/ld.elf_so/rtld.c:1.150
--- src/libexec/ld.elf_so/rtld.c:1.149	Sat Apr  2 12:30:41 2011
+++ src/libexec/ld.elf_so/rtld.c	Sat Apr  2 16:49:49 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.149 2011/04/02 12:30:41 joerg Exp $	 */
+/*	$NetBSD: rtld.c,v 1.150 2011/04/02 16:49:49 joerg Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.149 2011/04/02 12:30:41 joerg Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.150 2011/04/02 16:49:49 joerg Exp $");
 #endif /* not lint */
 
 #include 
@@ -1408,24 +1408,6 @@
 	}
 }
 
-void
-_rtld_lock(int arg, sigset_t *mask)
-{
-	switch (arg) {
-	default:
-		dbg(("%s: invalid argument: %d", __func__, arg));
-		break;
-	case RTLD_LOCK_PRE_FORK:
-		_rtld_exclusive_enter(mask);
-		_rtld_mutex_may_recurse = true;
-		break;
-	case RTLD_LOCK_POST_FORK:
-		_rtld_mutex_may_recurse = false;
-		_rtld_exclusive_exit(mask);
-		break;
-	}
-}
-
 #define	RTLD_EXCLUSIVE_MASK	0x8000U
 static volatile unsigned int _rtld_mutex;
 static volatile unsigned int _rtld_waiter_exclusive;



CVS commit: src/libexec/ld.elf_so

2011-05-20 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Fri May 20 22:21:32 UTC 2011

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

Log Message:
Explicitly disable linking against libgcc and friends.


To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 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.103 src/libexec/ld.elf_so/Makefile:1.104
--- src/libexec/ld.elf_so/Makefile:1.103	Wed Mar  9 23:10:07 2011
+++ src/libexec/ld.elf_so/Makefile	Fri May 20 22:21:32 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.103 2011/03/09 23:10:07 joerg Exp $
+#	$NetBSD: Makefile,v 1.104 2011/05/20 22:21:32 joerg Exp $
 #
 # NOTE: when changing ld.so, ensure that ldd still compiles.
 #
@@ -38,7 +38,7 @@
  (${MACHINE_ARCH} == "vax")) &&	\
 ${MKPIC} != "no"
 
-LDFLAGS+=	-shared -symbolic -nostartfiles
+LDFLAGS+=	-shared -symbolic -nostartfiles -nodefaultlibs
 LDFLAGS+=	-Wl,-static
 LDFLAGS+=	-Wl,--warn-shared-textrel
 



CVS commit: src/libexec/ld.elf_so

2011-05-20 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Fri May 20 22:22:45 UTC 2011

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

Log Message:
Disable use of various X86 extensions since _rtld_bind_start doesn't
save the necessary registers.


To generate a diff of this commit:
cvs rdiff -u -r1.104 -r1.105 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.104 src/libexec/ld.elf_so/Makefile:1.105
--- src/libexec/ld.elf_so/Makefile:1.104	Fri May 20 22:21:32 2011
+++ src/libexec/ld.elf_so/Makefile	Fri May 20 22:22:44 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.104 2011/05/20 22:21:32 joerg Exp $
+#	$NetBSD: Makefile,v 1.105 2011/05/20 22:22:44 joerg Exp $
 #
 # NOTE: when changing ld.so, ensure that ldd still compiles.
 #
@@ -93,6 +93,10 @@
 #DBG=		-g
 DBG=		-O3 -fomit-frame-pointer
 
+.if ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "x86_64"
+DBG+=		-mno-3dnow -mno-mmx -mno-sse -mno-sse2 -mno-sse3
+.endif
+
 .if ${SHLIBDIR} != ${LIBDIR}
 CPPFLAGS+=	-DRTLD_DEFAULT_LIBRARY_PATH=\"${SHLIBDIR}:${LIBDIR}\"
 .endif



CVS commit: src/libexec/ld.elf_so

2011-05-25 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed May 25 14:41:46 UTC 2011

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

Log Message:
Don't use division since we are only dealing with powers of 2.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/libexec/ld.elf_so/xmalloc.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/xmalloc.c
diff -u src/libexec/ld.elf_so/xmalloc.c:1.10 src/libexec/ld.elf_so/xmalloc.c:1.11
--- src/libexec/ld.elf_so/xmalloc.c:1.10	Fri Dec  3 18:07:49 2010
+++ src/libexec/ld.elf_so/xmalloc.c	Wed May 25 10:41:46 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: xmalloc.c,v 1.10 2010/12/03 23:07:49 joerg Exp $	*/
+/*	$NetBSD: xmalloc.c,v 1.11 2011/05/25 14:41:46 christos Exp $	*/
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -77,7 +77,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: xmalloc.c,v 1.10 2010/12/03 23:07:49 joerg Exp $");
+__RCSID("$NetBSD: xmalloc.c,v 1.11 2011/05/25 14:41:46 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -148,6 +148,7 @@
 
 static	size_t pagesz;			/* page size */
 static	size_t pagebucket;		/* page size bucket */
+static	size_t pageshift;		/* page size shift */
 
 #ifdef MSTATS
 /*
@@ -203,6 +204,7 @@
 			bucket++;
 		}
 		pagebucket = bucket;
+		pageshift = ffs(pagesz) - 1;
 	}
 	/*
 	 * Convert amount of memory requested into closest block size
@@ -277,13 +279,13 @@
 #endif
 	if (sz < pagesz) {
 		amt = pagesz;
-  		nblks = amt / sz;
+		nblks = amt >> (bucket + 3);
 	} else {
 		amt = sz + pagesz;
 		nblks = 1;
 	}
 	if (amt > PAGEPOOL_SIZE)
-		if (morepages(amt/pagesz + NPOOLPAGES) == 0)
+		if (morepages((amt >> pageshift) + NPOOLPAGES) == 0)
 			return;
 	op = (union overhead *)pagepool_start;
 	pagepool_start += amt;



CVS commit: src/libexec/ld.elf_so

2011-05-30 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Mon May 30 16:30:01 UTC 2011

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

Log Message:
Use -Wl,-Bsymbolic directly for clang


To generate a diff of this commit:
cvs rdiff -u -r1.105 -r1.106 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.105 src/libexec/ld.elf_so/Makefile:1.106
--- src/libexec/ld.elf_so/Makefile:1.105	Fri May 20 22:22:44 2011
+++ src/libexec/ld.elf_so/Makefile	Mon May 30 16:30:01 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.105 2011/05/20 22:22:44 joerg Exp $
+#	$NetBSD: Makefile,v 1.106 2011/05/30 16:30:01 joerg Exp $
 #
 # NOTE: when changing ld.so, ensure that ldd still compiles.
 #
@@ -38,7 +38,8 @@
  (${MACHINE_ARCH} == "vax")) &&	\
 ${MKPIC} != "no"
 
-LDFLAGS+=	-shared -symbolic -nostartfiles -nodefaultlibs
+LDFLAGS+=	${${ACTIVE_CC} == "clang":? -Wl,-Bsymbolic : -symbolic} \
+		-shared -nostartfiles -nodefaultlibs
 LDFLAGS+=	-Wl,-static
 LDFLAGS+=	-Wl,--warn-shared-textrel
 



CVS commit: src/libexec/ld.elf_so

2011-06-05 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Jun  5 23:08:17 UTC 2011

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

Log Message:
Add libgcc_pic for millicode.


To generate a diff of this commit:
cvs rdiff -u -r1.106 -r1.107 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.106 src/libexec/ld.elf_so/Makefile:1.107
--- src/libexec/ld.elf_so/Makefile:1.106	Mon May 30 12:30:01 2011
+++ src/libexec/ld.elf_so/Makefile	Sun Jun  5 19:08:17 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.106 2011/05/30 16:30:01 joerg Exp $
+#	$NetBSD: Makefile,v 1.107 2011/06/05 23:08:17 christos Exp $
 #
 # NOTE: when changing ld.so, ensure that ldd still compiles.
 #
@@ -98,6 +98,7 @@
 DBG+=		-mno-3dnow -mno-mmx -mno-sse -mno-sse2 -mno-sse3
 .endif
 
+
 .if ${SHLIBDIR} != ${LIBDIR}
 CPPFLAGS+=	-DRTLD_DEFAULT_LIBRARY_PATH=\"${SHLIBDIR}:${LIBDIR}\"
 .endif
@@ -118,6 +119,12 @@
 DPADD+=		${CLIBOBJ}/libc.a
 .endif
 
+.if ${MACHINE_CPU} == "hppa"
+# for $$divU, $$remU etc. (millicode)
+LDADD+=		-lgcc_pic
+DPADD+=		${LIBGCC_PIC}
+.endif
+
 STRIPFLAG=
 
 .PATH: $M



CVS commit: src/libexec/ld.elf_so

2011-06-27 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Mon Jun 27 14:27:56 UTC 2011

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

Log Message:
sh3 also needs libgcc_pic for millicode (cf. revision 1.107)


To generate a diff of this commit:
cvs rdiff -u -r1.108 -r1.109 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.108 src/libexec/ld.elf_so/Makefile:1.109
--- src/libexec/ld.elf_so/Makefile:1.108	Sat Jun 25 05:45:12 2011
+++ src/libexec/ld.elf_so/Makefile	Mon Jun 27 14:27:56 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.108 2011/06/25 05:45:12 nonaka Exp $
+#	$NetBSD: Makefile,v 1.109 2011/06/27 14:27:56 uwe Exp $
 #
 # NOTE: when changing ld.so, ensure that ldd still compiles.
 #
@@ -119,7 +119,7 @@
 DPADD+=		${CLIBOBJ}/libc.a
 .endif
 
-.if ${MACHINE_CPU} == "hppa"
+.if ${MACHINE_CPU} == "hppa" || ${MACHINE_CPU} == "sh3"
 # for $$divU, $$remU etc. (millicode)
 LDADD+=		-lgcc_pic
 DPADD+=		${LIBGCC_PIC}



CVS commit: src/libexec/ld.elf_so

2011-11-25 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Fri Nov 25 14:39:02 UTC 2011

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

Log Message:
Replace if() NADA else if() NADA else continue logic with one explicit
block. Split out the MIPS handling to make it explicit and readable.


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 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.58 src/libexec/ld.elf_so/symbol.c:1.59
--- src/libexec/ld.elf_so/symbol.c:1.58	Sat Aug 13 22:24:57 2011
+++ src/libexec/ld.elf_so/symbol.c	Fri Nov 25 14:39:02 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: symbol.c,v 1.58 2011/08/13 22:24:57 christos Exp $	 */
+/*	$NetBSD: symbol.c,v 1.59 2011/11/25 14:39:02 joerg Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: symbol.c,v 1.58 2011/08/13 22:24:57 christos Exp $");
+__RCSID("$NetBSD: symbol.c,v 1.59 2011/11/25 14:39:02 joerg Exp $");
 #endif /* not lint */
 
 #include 
@@ -258,9 +258,10 @@ _rtld_symlook_obj(const char *name, unsi
 		rdbg(("check \"%s\" vs \"%s\" in %s", name, strp, obj->path));
 		if (name[1] != strp[1] || strcmp(name, strp))
 			continue;
-		if (symp->st_shndx != SHN_UNDEF)
-			/* Nothing to do */;
-#ifndef __mips__
+#ifdef __mips__
+		if (symp->st_shndx == SHN_UNDEF)
+			continue;
+#else
 		/*
 		 * XXX DANGER WILL ROBINSON!
 		 * If we have a function pointer in the executable's
@@ -271,13 +272,12 @@ _rtld_symlook_obj(const char *name, unsi
 		 * in the libraries to point to PLT slots in the
 		 * executable, if they exist.
 		 */
-		else if (!(flags & SYMLOOK_IN_PLT) &&
-		symp->st_value != 0 &&
-		ELF_ST_TYPE(symp->st_info) == STT_FUNC)
-			/* Nothing to do */;
-#endif
-		else
+		if (symp->st_shndx == SHN_UNDEF &&
+		((flags & SYMLOOK_IN_PLT) ||
+		symp->st_value == 0 ||
+		ELF_ST_TYPE(symp->st_info) != STT_FUNC))
 			continue;
+#endif
 
 		if (ventry == NULL) {
 			if (obj->versyms != NULL) {



CVS commit: src/libexec/ld.elf_so

2011-11-25 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Fri Nov 25 21:27:15 UTC 2011

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

Log Message:
Unbreak RTLD_NEXT and co on platforms that don't inline or tail call
do_dlsym.


To generate a diff of this commit:
cvs rdiff -u -r1.154 -r1.155 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.154 src/libexec/ld.elf_so/rtld.c:1.155
--- src/libexec/ld.elf_so/rtld.c:1.154	Thu Nov 17 16:20:11 2011
+++ src/libexec/ld.elf_so/rtld.c	Fri Nov 25 21:27:15 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.154 2011/11/17 16:20:11 joerg Exp $	 */
+/*	$NetBSD: rtld.c,v 1.155 2011/11/25 21:27:15 joerg Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.154 2011/11/17 16:20:11 joerg Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.155 2011/11/25 21:27:15 joerg Exp $");
 #endif /* not lint */
 
 #include 
@@ -1047,13 +1047,12 @@ hackish_return_address(void)
 #endif
 
 static void *
-do_dlsym(void *handle, const char *name, const Ver_Entry *ventry)
+do_dlsym(void *handle, const char *name, const Ver_Entry *ventry, void *retaddr)
 {
 	const Obj_Entry *obj;
 	unsigned long hash;
 	const Elf_Sym *def;
 	const Obj_Entry *defobj;
-	void *retaddr;
 	DoneList donelist;
 	const u_int flags = SYMLOOK_DLSYM | SYMLOOK_IN_PLT;
 #ifdef __HAVE_FUNCTION_DESCRIPTORS
@@ -1071,11 +1070,6 @@ do_dlsym(void *handle, const char *name,
 	case (intptr_t)RTLD_NEXT:
 	case (intptr_t)RTLD_DEFAULT:
 	case (intptr_t)RTLD_SELF:
-#ifdef __powerpc__
-		retaddr = hackish_return_address();
-#else
-		retaddr = __builtin_return_address(0);
-#endif
 		if ((obj = _rtld_obj_from_addr(retaddr)) == NULL) {
 			_rtld_error("Cannot determine caller's shared object");
 			lookup_mutex_exit();
@@ -1165,10 +1159,16 @@ __strong_alias(__dlsym,dlsym)
 void *
 dlsym(void *handle, const char *name)
 {
+	void *retaddr;
 
 	dbg(("dlsym of %s in %p", name, handle));
 
-	return do_dlsym(handle, name, NULL);
+#ifdef __powerpc__
+	retaddr = hackish_return_address();
+#else
+	retaddr = __builtin_return_address(0);
+#endif
+	return do_dlsym(handle, name, NULL, retaddr);
 }
 
 __strong_alias(__dlvsym,dlvsym)
@@ -1177,6 +1177,7 @@ dlvsym(void *handle, const char *name, c
 {
 	Ver_Entry *ventry = NULL;
 	Ver_Entry ver_entry;
+	void *retaddr;
 
 	dbg(("dlvsym of %s@%s in %p", name, version ? version : NULL, handle));
 
@@ -1187,7 +1188,12 @@ dlvsym(void *handle, const char *name, c
 		ver_entry.flags = 0;
 		ventry = &ver_entry;
 	}
-	return do_dlsym(handle, name, ventry);
+#ifdef __powerpc__
+	retaddr = hackish_return_address();
+#else
+	retaddr = __builtin_return_address(0);
+#endif
+	return do_dlsym(handle, name, ventry, retaddr);
 }
 
 __strong_alias(__dladdr,dladdr)



CVS commit: src/libexec/ld.elf_so

2011-12-02 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Dec  2 09:06:49 UTC 2011

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

Log Message:
Restore backwards compatibility by removing unnecessary addition of
dlvsym to Obj_Entry.

Add some comments.


To generate a diff of this commit:
cvs rdiff -u -r1.104 -r1.105 src/libexec/ld.elf_so/reloc.c
cvs rdiff -u -r1.106 -r1.107 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.

Modified files:

Index: src/libexec/ld.elf_so/reloc.c
diff -u src/libexec/ld.elf_so/reloc.c:1.104 src/libexec/ld.elf_so/reloc.c:1.105
--- src/libexec/ld.elf_so/reloc.c:1.104	Sat Jun 25 05:45:12 2011
+++ src/libexec/ld.elf_so/reloc.c	Fri Dec  2 09:06:49 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: reloc.c,v 1.104 2011/06/25 05:45:12 nonaka Exp $	 */
+/*	$NetBSD: reloc.c,v 1.105 2011/12/02 09:06:49 skrll Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -39,7 +39,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: reloc.c,v 1.104 2011/06/25 05:45:12 nonaka Exp $");
+__RCSID("$NetBSD: reloc.c,v 1.105 2011/12/02 09:06:49 skrll Exp $");
 #endif /* not lint */
 
 #include 
@@ -210,10 +210,13 @@ _rtld_relocate_objects(Obj_Entry *first,
 		obj->magic = RTLD_MAGIC;
 		obj->version = RTLD_VERSION;
 
-		/* Fill in the dynamic linker entry points. */
+		/*
+		 * Fill in the backwards compatibility dynamic linker entry points.
+		 *
+		 * DO NOT ADD TO THIS LIST
+		 */
 		obj->dlopen = dlopen;
 		obj->dlsym = dlsym;
-		obj->dlvsym = dlvsym;
 		obj->dlerror = dlerror;
 		obj->dlclose = dlclose;
 		obj->dladdr = dladdr;

Index: src/libexec/ld.elf_so/rtld.h
diff -u src/libexec/ld.elf_so/rtld.h:1.106 src/libexec/ld.elf_so/rtld.h:1.107
--- src/libexec/ld.elf_so/rtld.h:1.106	Sat Jun 25 05:45:12 2011
+++ src/libexec/ld.elf_so/rtld.h	Fri Dec  2 09:06:49 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.h,v 1.106 2011/06/25 05:45:12 nonaka Exp $	 */
+/*	$NetBSD: rtld.h,v 1.107 2011/12/02 09:06:49 skrll Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -191,10 +191,14 @@ typedef struct Struct_Obj_Entry {
 	void(*init)(void); 	/* Initialization function to call */
 	void(*fini)(void);	/* Termination function to call */
 
-	/* Entry points for dlopen() and friends. */
+	/*
+	 * BACKWARDS COMPAT Entry points for dlopen() and friends.
+	 *
+	 * DO NOT MOVE OR ADD TO THE LIST
+	 *
+	 */
 	void   *(*dlopen)(const char *, int);
 	void   *(*dlsym)(void *, const char *);
-	void   *(*dlvsym)(void *, const char *, const char *);
 	char   *(*dlerror)(void);
 	int (*dlclose)(void *);
 	int (*dladdr)(const void *, Dl_info *);



CVS commit: src/libexec/ld.elf_so

2011-12-11 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sun Dec 11 11:05:11 UTC 2011

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

Log Message:
Mark xassert as __dead


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/libexec/ld.elf_so/rtldenv.h

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/rtldenv.h
diff -u src/libexec/ld.elf_so/rtldenv.h:1.10 src/libexec/ld.elf_so/rtldenv.h:1.11
--- src/libexec/ld.elf_so/rtldenv.h:1.10	Fri Oct 29 15:08:17 2010
+++ src/libexec/ld.elf_so/rtldenv.h	Sun Dec 11 11:05:11 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtldenv.h,v 1.10 2010/10/29 15:08:17 christos Exp $	 */
+/*	$NetBSD: rtldenv.h,v 1.11 2011/12/11 11:05:11 joerg Exp $	 */
 
 /*
  * Copyright 1996 Matt Thomas 
@@ -57,7 +57,7 @@ void xerr(int, const char *, ...)
 void xerrx(int, const char *, ...)
 __attribute__((__noreturn__, __format__(__printf__, 2, 3)));
 
-void xassert(const char *, int, const char *);
+void xassert(const char *, int, const char *) __dead;
 const char *xstrerror(int);
 int	xunsetenv(const char *);
 



CVS commit: src/libexec/ld.elf_so

2012-01-06 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Jan  6 10:38:57 UTC 2012

Modified Files:
src/libexec/ld.elf_so: reloc.c
src/libexec/ld.elf_so/arch/hppa: hppa_reloc.c rtld_start.S

Log Message:
Implement lazy binding on hppa. rump_server needs it!?!?!

Mostly from OpenBSD.


To generate a diff of this commit:
cvs rdiff -u -r1.105 -r1.106 src/libexec/ld.elf_so/reloc.c
cvs rdiff -u -r1.41 -r1.42 src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c
cvs rdiff -u -r1.11 -r1.12 src/libexec/ld.elf_so/arch/hppa/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/reloc.c
diff -u src/libexec/ld.elf_so/reloc.c:1.105 src/libexec/ld.elf_so/reloc.c:1.106
--- src/libexec/ld.elf_so/reloc.c:1.105	Fri Dec  2 09:06:49 2011
+++ src/libexec/ld.elf_so/reloc.c	Fri Jan  6 10:38:56 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: reloc.c,v 1.105 2011/12/02 09:06:49 skrll Exp $	 */
+/*	$NetBSD: reloc.c,v 1.106 2012/01/06 10:38:56 skrll Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -39,7 +39,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: reloc.c,v 1.105 2011/12/02 09:06:49 skrll Exp $");
+__RCSID("$NetBSD: reloc.c,v 1.106 2012/01/06 10:38:56 skrll Exp $");
 #endif /* not lint */
 
 #include 
@@ -195,9 +195,6 @@ _rtld_relocate_objects(Obj_Entry *first,
 		dbg(("doing lazy PLT binding"));
 		if (_rtld_relocate_plt_lazy(obj) < 0)
 			ok = 0;
-#if defined(__hppa__)
-		bind_now = 1;
-#endif
 		if (obj->z_now || bind_now) {
 			dbg(("doing immediate PLT binding"));
 			if (_rtld_relocate_plt_objects(obj) < 0)

Index: src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c
diff -u src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c:1.41 src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c:1.42
--- src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c:1.41	Sun Dec  4 16:53:08 2011
+++ src/libexec/ld.elf_so/arch/hppa/hppa_reloc.c	Fri Jan  6 10:38:57 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: hppa_reloc.c,v 1.41 2011/12/04 16:53:08 skrll Exp $	*/
+/*	$NetBSD: hppa_reloc.c,v 1.42 2012/01/06 10:38:57 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2004 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: hppa_reloc.c,v 1.41 2011/12/04 16:53:08 skrll Exp $");
+__RCSID("$NetBSD: hppa_reloc.c,v 1.42 2012/01/06 10:38:57 skrll Exp $");
 #endif /* not lint */
 
 #include 
@@ -82,6 +82,30 @@ store_ptr(void *where, Elf_Addr val)
 		(void)memcpy(where, &val, sizeof(val));
 }
 
+static __inline void
+fdc(void *addr)
+{
+	__asm volatile("fdc %%r0(%%sr0, %0)" : : "r" (addr));
+}
+
+static __inline void
+fic(void *addr) 
+{   
+	__asm volatile("fic %%r0(%%sr0,%0)" : : "r" (addr));
+} 
+
+static __inline void
+sync(void)
+{
+	__asm volatile("sync" : : : "memory");
+}
+
+#define PLT_STUB_MAGIC1	0x00c0ffee
+#define PLT_STUB_MAGIC2	0xdeadbeef
+
+#define PLT_STUB_INSN1	0x0e801081	/* ldw	0(%r20), %r1 */
+#define PLT_STUB_INSN2	0xe820c000	/* bv	%r0(%r1) */
+
 /*
  * In the runtime architecture (ABI), PLABEL function pointers are
  * distinguished from normal function pointers by having the next-least-
@@ -355,7 +379,34 @@ _rtld_function_descriptor_function(const
 void
 _rtld_setup_pltgot(const Obj_Entry *obj)
 {
-	__rtld_setup_hppa_pltgot(obj, obj->pltgot);
+	Elf_Word *got = obj->pltgot;
+
+	assert(got[-2] == PLT_STUB_MAGIC1);
+	assert(got[-1] == PLT_STUB_MAGIC2);
+	
+	__rtld_setup_hppa_pltgot(obj, got);
+
+	fdc(&got[-2]);
+	fdc(&got[-1]);
+	fdc(&got[1]);
+	sync();
+	fic(&got[-2]);
+	fic(&got[-1]);
+	fic(&got[1]);
+	sync();
+
+	/*
+	 * libc makes use of %t1 (%r22) to pass errno values to __cerror. Fixup
+	 * the PLT stub to not use %r22.
+	 */
+	got[-7] = PLT_STUB_INSN1;
+	got[-6] = PLT_STUB_INSN2;
+	fdc(&got[-7]);
+	fdc(&got[-6]);
+	sync();
+	fic(&got[-7]);
+	fic(&got[-6]);
+	sync();
 }
 
 int

Index: src/libexec/ld.elf_so/arch/hppa/rtld_start.S
diff -u src/libexec/ld.elf_so/arch/hppa/rtld_start.S:1.11 src/libexec/ld.elf_so/arch/hppa/rtld_start.S:1.12
--- src/libexec/ld.elf_so/arch/hppa/rtld_start.S:1.11	Fri Sep 30 03:05:43 2011
+++ src/libexec/ld.elf_so/arch/hppa/rtld_start.S	Fri Jan  6 10:38:57 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld_start.S,v 1.11 2011/09/30 03:05:43 mrg Exp $	*/
+/*	$NetBSD: rtld_start.S,v 1.12 2012/01/06 10:38:57 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -181,6 +181,7 @@ ENTRY(_rtld_bind_start,HPPA_FRAME_SIZE)
 	/* 0(%r3) is filled with the saved %r3 above */
 	stw	%ret0, 4(%r3)
 	stw	%ret1, 8(%r3)
+	stw	%t1, 12(%r3)		/* %r22 */
 
 	/*
 	 * The linker PLT stub loads %r20 with (GOT - 8) for the object that
@@ -220,6 +221,7 @@ ENTRY(_rtld_bind_start,HPPA_FRAME_SIZE)
 	ldw	HPPA_FRAME_ARG(3)(%r3), %arg3
 	ldw	4(%r3), %ret0
 	ldw	8(%r3), %ret1
+	ldw	12(%r3), %t1		/* %r22 */
 
 	/* End stack calling convention. */
 	ldo	HPPA_FRAME_SIZE(%r3), %sp



CVS commit: src/libexec/ld.elf_so

2012-08-04 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Sat Aug  4 15:17:16 UTC 2012

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

Log Message:
Don't abuse DBG, use COPTS instead.


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 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.111 src/libexec/ld.elf_so/Makefile:1.112
--- src/libexec/ld.elf_so/Makefile:1.111	Thu Mar 15 00:16:07 2012
+++ src/libexec/ld.elf_so/Makefile	Sat Aug  4 15:17:16 2012
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.111 2012/03/15 00:16:07 christos Exp $
+#	$NetBSD: Makefile,v 1.112 2012/08/04 15:17:16 matt Exp $
 #
 # NOTE: when changing ld.so, ensure that ldd still compiles.
 #
@@ -43,7 +43,7 @@ LDFLAGS+=	${${ACTIVE_CC} == "clang":? -W
 LDFLAGS+=	-Wl,-static
 LDFLAGS+=	-Wl,--warn-shared-textrel
 
-CFLAGS+=	-fvisibility=hidden
+COPTS+=		-fvisibility=hidden
 
 # Adds SRCS, CPPFLAGS, LDFLAGS, etc.  Must go first so MD startup source
 # is first.
@@ -92,10 +92,10 @@ CPPFLAGS+=	-DCOMBRELOC
 #CPPFLAGS+=	-DRTLD_DEBUG
 #CPPFLAGS+=	-DRTLD_DEBUG_RELOC
 #DBG=		-g
-DBG=		-O3 -fomit-frame-pointer
+COPTS=		-O3 -fomit-frame-pointer
 
 .if ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "x86_64"
-DBG+=		-mno-3dnow -mno-mmx -mno-sse -mno-sse2 -mno-sse3
+COPTS+=		-mno-3dnow -mno-mmx -mno-sse -mno-sse2 -mno-sse3
 .endif
 
 



CVS commit: src/libexec/ld.elf_so

2012-08-14 Thread Matt Thomas
Module Name:src
Committed By:   matt
Date:   Wed Aug 15 03:46:07 UTC 2012

Modified Files:
src/libexec/ld.elf_so: headers.c rtld.c rtld.h symbol.c
src/libexec/ld.elf_so/arch/arm: Makefile.inc

Log Message:
Add .init_array/.fini_array support (conditionalized on HAVE_INITFINI_ARRAY).


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/libexec/ld.elf_so/headers.c
cvs rdiff -u -r1.157 -r1.158 src/libexec/ld.elf_so/rtld.c
cvs rdiff -u -r1.109 -r1.110 src/libexec/ld.elf_so/rtld.h
cvs rdiff -u -r1.60 -r1.61 src/libexec/ld.elf_so/symbol.c
cvs rdiff -u -r1.11 -r1.12 src/libexec/ld.elf_so/arch/arm/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/headers.c
diff -u src/libexec/ld.elf_so/headers.c:1.42 src/libexec/ld.elf_so/headers.c:1.43
--- src/libexec/ld.elf_so/headers.c:1.42	Sun Jul 22 09:16:35 2012
+++ src/libexec/ld.elf_so/headers.c	Wed Aug 15 03:46:06 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: headers.c,v 1.42 2012/07/22 09:16:35 martin Exp $	 */
+/*	$NetBSD: headers.c,v 1.43 2012/08/15 03:46:06 matt Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: headers.c,v 1.42 2012/07/22 09:16:35 martin Exp $");
+__RCSID("$NetBSD: headers.c,v 1.43 2012/08/15 03:46:06 matt Exp $");
 #endif /* not lint */
 
 #include 
@@ -227,10 +227,32 @@ _rtld_digest_dynamic(const char *execnam
 			init = dynp->d_un.d_ptr;
 			break;
 
+#ifdef HAVE_INITFINI_ARRAY
+		case DT_INIT_ARRAY:
+			obj->init_array =
+			(fptr_t *)(obj->relocbase + dynp->d_un.d_ptr);
+			break;
+
+		case DT_INIT_ARRAYSZ:
+			obj->init_arraysz = dynp->d_un.d_val / sizeof(fptr_t);
+			break;
+#endif
+
 		case DT_FINI:
 			fini = dynp->d_un.d_ptr;
 			break;
 
+#ifdef HAVE_INITFINI_ARRAY
+		case DT_FINI_ARRAY:
+			obj->fini_array =
+			(fptr_t *)(obj->relocbase + dynp->d_un.d_ptr);
+			break;
+
+		case DT_FINI_ARRAYSZ:
+			obj->fini_arraysz = dynp->d_un.d_val / sizeof(fptr_t); 
+			break;
+#endif
+
 		/*
 		 * Don't process DT_DEBUG on MIPS as the dynamic section
 		 * is mapped read-only. DT_MIPS_RLD_MAP is used instead.

Index: src/libexec/ld.elf_so/rtld.c
diff -u src/libexec/ld.elf_so/rtld.c:1.157 src/libexec/ld.elf_so/rtld.c:1.158
--- src/libexec/ld.elf_so/rtld.c:1.157	Tue Mar 13 21:00:31 2012
+++ src/libexec/ld.elf_so/rtld.c	Wed Aug 15 03:46:06 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.157 2012/03/13 21:00:31 joerg Exp $	 */
+/*	$NetBSD: rtld.c,v 1.158 2012/08/15 03:46:06 matt Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.157 2012/03/13 21:00:31 joerg Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.158 2012/08/15 03:46:06 matt Exp $");
 #endif /* not lint */
 
 #include 
@@ -135,13 +135,50 @@ static void _rtld_unload_object(sigset_t
 static void _rtld_unref_dag(Obj_Entry *);
 static Obj_Entry *_rtld_obj_from_addr(const void *);
 
+static inline void
+_rtld_call_initfini_function(fptr_t func, sigset_t *mask)
+{
+	_rtld_exclusive_exit(mask);
+	(*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 == NULL || obj->fini_called)) {
+			return;
+	}
+	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->fini, mask);
+	}
+#ifdef HAVE_INITFINI_ARRAY
+	/*
+	 * Now process the fini_array if it exists.  Simply go from
+	 * start to end.  We need to make restartable so just advance
+	 * the array pointer and decrement the size each time through
+	 * the loop.
+	 */
+	while (obj->fini_arraysz > 0 && _rtld_objgen == cur_objgen) {
+		fptr_t fini = *obj->fini_array++;
+		obj->fini_arraysz--;
+		dbg (("calling fini array function %s at %p%s", obj->path,
+		(void *)fini,
+		obj->z_initfirst ? " (DF_1_INITFIRST)" : ""));
+		_rtld_call_initfini_function(fini, mask);
+	}
+#endif /* HAVE_INITFINI_ARRAY */
+}
+
 static void
 _rtld_call_fini_functions(sigset_t *mask, int force)
 {
 	Objlist_Entry *elm;
 	Objlist finilist;
-	Obj_Entry *obj;
-	void (*fini)(void);
 	u_int cur_objgen;
 
 	dbg(("_rtld_call_fini_functions(%d)", force));
@@ -153,49 +190,33 @@ restart:
 
 	/* First pass: objects _not_ marked with DF_1_INITFIRST. */
 	SIMPLEQ_FOREACH(elm, &finilist, link) {
-		obj = elm->obj;
-		if (obj->refcount > 0 && !force) {
-			continue;
-		}
-		if (obj->fini == NULL || obj->fini_called || obj->z_initfirst) {
-			continue;
+		Obj_Entry * const obj = elm->obj;
+		if (!obj->z_initfirst) {
+			if (obj->refcount > 0 && !force) {
+continue;
+			}
+			/*
+			 * XXX This can race against a concurrent dlclose().
+			 * XXX In that case, the object could be unmapped

CVS commit: src/libexec/ld.elf_so

2012-09-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Oct  1 03:03:46 UTC 2012

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

Log Message:
On failure in _rtld_dlcheck, call _rtld_error, not xwarnx.

Callers need not call _rtld_error themselves now.

Fixes PR lib/41760.  Should add the test case from the PR too.


To generate a diff of this commit:
cvs rdiff -u -r1.158 -r1.159 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.158 src/libexec/ld.elf_so/rtld.c:1.159
--- src/libexec/ld.elf_so/rtld.c:1.158	Wed Aug 15 03:46:06 2012
+++ src/libexec/ld.elf_so/rtld.c	Mon Oct  1 03:03:46 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.158 2012/08/15 03:46:06 matt Exp $	 */
+/*	$NetBSD: rtld.c,v 1.159 2012/10/01 03:03:46 riastradh Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.158 2012/08/15 03:46:06 matt Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.159 2012/10/01 03:03:46 riastradh Exp $");
 #endif /* not lint */
 
 #include 
@@ -775,7 +775,7 @@ _rtld_dlcheck(void *handle)
 			break;
 
 	if (obj == NULL || obj->dl_refcount == 0) {
-		xwarnx("Invalid shared object handle %p", handle);
+		_rtld_error("Invalid shared object handle %p", handle);
 		return NULL;
 	}
 	return obj;
@@ -1335,7 +1335,6 @@ dlinfo(void *handle, int req, void *v)
 		}
 	} else {
 		if ((obj = _rtld_dlcheck(handle)) == NULL) {
-			_rtld_error("Invalid handle");
 			_rtld_shared_exit();
 			return -1;
 		}



CVS commit: src/libexec/ld.elf_so

2012-10-13 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sat Oct 13 21:13:07 UTC 2012

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

Log Message:
Improve the diagnostic messages for invalid/non-ELF files. Proposed a
while back; I forget the context. Has been sitting in one of my trees
awaiting a test run since, apparently, August 2011.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 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.44 src/libexec/ld.elf_so/map_object.c:1.45
--- src/libexec/ld.elf_so/map_object.c:1.44	Wed Jul 25 22:51:04 2012
+++ src/libexec/ld.elf_so/map_object.c	Sat Oct 13 21:13:07 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: map_object.c,v 1.44 2012/07/25 22:51:04 martin Exp $	 */
+/*	$NetBSD: map_object.c,v 1.45 2012/10/13 21:13:07 dholland Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -34,7 +34,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: map_object.c,v 1.44 2012/07/25 22:51:04 martin Exp $");
+__RCSID("$NetBSD: map_object.c,v 1.45 2012/10/13 21:13:07 dholland Exp $");
 #endif /* not lint */
 
 #include 
@@ -105,7 +105,7 @@ _rtld_map_object(const char *path, int f
 #endif
 
 	if (sb != NULL && sb->st_size < (off_t)sizeof (Elf_Ehdr)) {
-		_rtld_error("%s: unrecognized file format1", path);
+		_rtld_error("%s: not ELF file (too short)", path);
 		return NULL;
 	}
 
@@ -125,9 +125,12 @@ _rtld_map_object(const char *path, int f
 		goto bad;
 	}
 	/* Make sure the file is valid */
-	if (memcmp(ELFMAG, ehdr->e_ident, SELFMAG) != 0 ||
-	ehdr->e_ident[EI_CLASS] != ELFCLASS) {
-		_rtld_error("%s: unrecognized file format2 [%x != %x]", path,
+	if (memcmp(ELFMAG, ehdr->e_ident, SELFMAG) != 0) {
+		_rtld_error("%s: not ELF file (magic number bad)", path);
+		goto bad;
+	}
+	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;
 	}



CVS commit: src/libexec/ld.elf_so

2016-04-12 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Apr 12 19:10:48 UTC 2016

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

Log Message:
- Print a warning for text relocations
- Don't remap the text segment executable while relocating


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 src/libexec/ld.elf_so/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/reloc.c
diff -u src/libexec/ld.elf_so/reloc.c:1.107 src/libexec/ld.elf_so/reloc.c:1.108
--- src/libexec/ld.elf_so/reloc.c:1.107	Mon Aug 25 16:40:52 2014
+++ src/libexec/ld.elf_so/reloc.c	Tue Apr 12 15:10:48 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: reloc.c,v 1.107 2014/08/25 20:40:52 joerg Exp $	 */
+/*	$NetBSD: reloc.c,v 1.108 2016/04/12 19:10:48 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -39,7 +39,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: reloc.c,v 1.107 2014/08/25 20:40:52 joerg Exp $");
+__RCSID("$NetBSD: reloc.c,v 1.108 2016/04/12 19:10:48 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -170,12 +170,13 @@ _rtld_relocate_objects(Obj_Entry *first,
 		(long)(obj->pltrelalim - obj->pltrela)));
 
 		if (obj->textrel) {
+			xwarnx("%s: text relocations", obj->path);
 			/*
 			 * There are relocations to the write-protected text
 			 * segment.
 			 */
 			if (mprotect(obj->mapbase, obj->textsize,
-PROT_READ | PROT_WRITE | PROT_EXEC) == -1) {
+PROT_READ | PROT_WRITE) == -1) {
 _rtld_error("%s: Cannot write-enable text "
 "segment: %s", obj->path, xstrerror(errno));
 return -1;



CVS commit: src/libexec/ld.elf_so

2016-11-30 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Nov 30 19:43:32 UTC 2016

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

Log Message:
Emulate the standard symbol search order in dlsym() i.e. resolve weak or
not found symbols that are in the dynamic linker list of exported symbols
from the dynamic linker itself.


To generate a diff of this commit:
cvs rdiff -u -r1.178 -r1.179 src/libexec/ld.elf_so/rtld.c
cvs rdiff -u -r1.125 -r1.126 src/libexec/ld.elf_so/rtld.h
cvs rdiff -u -r1.65 -r1.66 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.c
diff -u src/libexec/ld.elf_so/rtld.c:1.178 src/libexec/ld.elf_so/rtld.c:1.179
--- src/libexec/ld.elf_so/rtld.c:1.178	Tue May 24 16:32:33 2016
+++ src/libexec/ld.elf_so/rtld.c	Wed Nov 30 14:43:32 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.178 2016/05/24 20:32:33 christos Exp $	 */
+/*	$NetBSD: rtld.c,v 1.179 2016/11/30 19:43:32 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.178 2016/05/24 20:32:33 christos Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.179 2016/11/30 19:43:32 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -1134,6 +1134,21 @@ do_dlsym(void *handle, const char *name,
 	break;
 }
 			}
+			/*
+			 * Search the dynamic linker itself, and possibly * resolve the symbol from there if it is not defined
+			 * already or weak. This is how the application links
+			 * to dynamic linker services such as dlopen. Only the
+			 * values listed in the "_rtld_exports" array can be
+			 * resolved from the dynamic linker.
+			 */
+			if (!def || ELF_ST_BIND(def->st_info) == STB_WEAK) {
+const Elf_Sym *symp = _rtld_symlook_obj(name,
+hash, &_rtld_objself, flags, ventry);
+if (symp != NULL && _rtld_is_exported(symp)) {
+	def = symp;
+	defobj = &_rtld_objself;
+}
+			}
 			break;
 
 		case (intptr_t)RTLD_DEFAULT:

Index: src/libexec/ld.elf_so/rtld.h
diff -u src/libexec/ld.elf_so/rtld.h:1.125 src/libexec/ld.elf_so/rtld.h:1.126
--- src/libexec/ld.elf_so/rtld.h:1.125	Tue Jun 14 09:06:41 2016
+++ src/libexec/ld.elf_so/rtld.h	Wed Nov 30 14:43:32 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.h,v 1.125 2016/06/14 13:06:41 christos Exp $	 */
+/*	$NetBSD: rtld.h,v 1.126 2016/11/30 19:43:32 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -416,6 +416,7 @@ Elf_Addr _rtld_resolve_ifunc(const Obj_E
 Obj_Entry *_rtld_load_library(const char *, const Obj_Entry *, int);
 
 /* symbol.c */
+bool _rtld_is_exported(const Elf_Sym *);
 unsigned long _rtld_elf_hash(const char *);
 const Elf_Sym *_rtld_symlook_obj(const char *, unsigned long,
 const Obj_Entry *, u_int, const Ver_Entry *);

Index: src/libexec/ld.elf_so/symbol.c
diff -u src/libexec/ld.elf_so/symbol.c:1.65 src/libexec/ld.elf_so/symbol.c:1.66
--- src/libexec/ld.elf_so/symbol.c:1.65	Sun Aug 10 19:35:26 2014
+++ src/libexec/ld.elf_so/symbol.c	Wed Nov 30 14:43:32 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: symbol.c,v 1.65 2014/08/10 23:35:26 matt Exp $	 */
+/*	$NetBSD: symbol.c,v 1.66 2016/11/30 19:43:32 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: symbol.c,v 1.65 2014/08/10 23:35:26 matt Exp $");
+__RCSID("$NetBSD: symbol.c,v 1.66 2016/11/30 19:43:32 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -80,7 +80,7 @@ _rtld_donelist_check(DoneList *dlp, cons
 	return false;
 }
 
-static bool
+bool
 _rtld_is_exported(const Elf_Sym *def)
 {
 	static const fptr_t _rtld_exports[] = {



CVS commit: src/libexec/ld.elf_so

2016-11-30 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Nov 30 20:25:23 UTC 2016

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

Log Message:
add missing newline in comment


To generate a diff of this commit:
cvs rdiff -u -r1.179 -r1.180 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.179 src/libexec/ld.elf_so/rtld.c:1.180
--- src/libexec/ld.elf_so/rtld.c:1.179	Wed Nov 30 14:43:32 2016
+++ src/libexec/ld.elf_so/rtld.c	Wed Nov 30 15:25:23 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.179 2016/11/30 19:43:32 christos Exp $	 */
+/*	$NetBSD: rtld.c,v 1.180 2016/11/30 20:25:23 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.179 2016/11/30 19:43:32 christos Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.180 2016/11/30 20:25:23 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -1135,7 +1135,8 @@ do_dlsym(void *handle, const char *name,
 }
 			}
 			/*
-			 * Search the dynamic linker itself, and possibly * resolve the symbol from there if it is not defined
+			 * Search the dynamic linker itself, and possibly
+			 * resolve the symbol from there if it is not defined
 			 * already or weak. This is how the application links
 			 * to dynamic linker services such as dlopen. Only the
 			 * values listed in the "_rtld_exports" array can be



CVS commit: src/libexec/ld.elf_so

2016-12-01 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Dec  1 14:29:15 UTC 2016

Modified Files:
src/libexec/ld.elf_so: Makefile rtld.c symbol.c
Added Files:
src/libexec/ld.elf_so: symbols.map

Log Message:
Instead of using a function to resolve symbols that should be supplied by
the dynamic linker itself, use a version script that exposes them. From joerg@


To generate a diff of this commit:
cvs rdiff -u -r1.135 -r1.136 src/libexec/ld.elf_so/Makefile
cvs rdiff -u -r1.180 -r1.181 src/libexec/ld.elf_so/rtld.c
cvs rdiff -u -r1.66 -r1.67 src/libexec/ld.elf_so/symbol.c
cvs rdiff -u -r0 -r1.1 src/libexec/ld.elf_so/symbols.map

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.135 src/libexec/ld.elf_so/Makefile:1.136
--- src/libexec/ld.elf_so/Makefile:1.135	Fri Oct  7 15:10:03 2016
+++ src/libexec/ld.elf_so/Makefile	Thu Dec  1 09:29:15 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.135 2016/10/07 19:10:03 christos Exp $
+#	$NetBSD: Makefile,v 1.136 2016/12/01 14:29:15 christos Exp $
 #
 # NOTE: when changing ld.so, ensure that ldd still compiles.
 #
@@ -124,6 +124,7 @@ CPPFLAGS+=	-DRTLD_DEFAULT_LIBRARY_PATH=\
 COPTS.rtld.c+=	-Wno-stack-protector
 COPTS.symbol.c+=-Wno-stack-protector
 
+LDADD+=		-Wl,--version-script=${.CURDIR}/symbols.map
 LDADD+=		-L${CLIBOBJ} -L${DESTDIR}${LIBDIR}
 .if ${MKPICLIB} != "no"
 LDADD+=		-lc_pic

Index: src/libexec/ld.elf_so/rtld.c
diff -u src/libexec/ld.elf_so/rtld.c:1.180 src/libexec/ld.elf_so/rtld.c:1.181
--- src/libexec/ld.elf_so/rtld.c:1.180	Wed Nov 30 15:25:23 2016
+++ src/libexec/ld.elf_so/rtld.c	Thu Dec  1 09:29:15 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.180 2016/11/30 20:25:23 christos Exp $	 */
+/*	$NetBSD: rtld.c,v 1.181 2016/12/01 14:29:15 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.180 2016/11/30 20:25:23 christos Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.181 2016/12/01 14:29:15 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -1138,14 +1138,12 @@ do_dlsym(void *handle, const char *name,
 			 * Search the dynamic linker itself, and possibly
 			 * resolve the symbol from there if it is not defined
 			 * already or weak. This is how the application links
-			 * to dynamic linker services such as dlopen. Only the
-			 * values listed in the "_rtld_exports" array can be
-			 * resolved from the dynamic linker.
+			 * to dynamic linker services such as dlopen.
 			 */
 			if (!def || ELF_ST_BIND(def->st_info) == STB_WEAK) {
 const Elf_Sym *symp = _rtld_symlook_obj(name,
 hash, &_rtld_objself, flags, ventry);
-if (symp != NULL && _rtld_is_exported(symp)) {
+if (symp != NULL) {
 	def = symp;
 	defobj = &_rtld_objself;
 }

Index: src/libexec/ld.elf_so/symbol.c
diff -u src/libexec/ld.elf_so/symbol.c:1.66 src/libexec/ld.elf_so/symbol.c:1.67
--- src/libexec/ld.elf_so/symbol.c:1.66	Wed Nov 30 14:43:32 2016
+++ src/libexec/ld.elf_so/symbol.c	Thu Dec  1 09:29:15 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: symbol.c,v 1.66 2016/11/30 19:43:32 christos Exp $	 */
+/*	$NetBSD: symbol.c,v 1.67 2016/12/01 14:29:15 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: symbol.c,v 1.66 2016/11/30 19:43:32 christos Exp $");
+__RCSID("$NetBSD: symbol.c,v 1.67 2016/12/01 14:29:15 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -80,43 +80,6 @@ _rtld_donelist_check(DoneList *dlp, cons
 	return false;
 }
 
-bool
-_rtld_is_exported(const Elf_Sym *def)
-{
-	static const fptr_t _rtld_exports[] = {
-		(fptr_t)dlopen,
-		(fptr_t)dlclose,
-		(fptr_t)dlsym,
-		(fptr_t)dlvsym,
-		(fptr_t)dlerror,
-		(fptr_t)dladdr,
-		(fptr_t)dlinfo,
-		(fptr_t)dl_iterate_phdr,
-		(fptr_t)_dlauxinfo,
-#if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II)
-		(fptr_t)_rtld_tls_allocate,
-		(fptr_t)_rtld_tls_free,
-		(fptr_t)__tls_get_addr,
-#ifdef __i386__
-		(fptr_t)___tls_get_addr,
-#endif
-#endif
-#if defined(__ARM_EABI__) && !defined(__ARM_DWARF_EH__)
-		(fptr_t)__gnu_Unwind_Find_exidx,	/* for gcc EHABI */
-#endif
-		NULL
-	};
-	int i;
-	fptr_t value;
-
-	value = (fptr_t)(_rtld_objself.relocbase + def->st_value);
-	for (i = 0; _rtld_exports[i] != NULL; i++) {
-		if (value == _rtld_exports[i])
-			return true;
-	}
-	return false;
-}
-
 /*
  * Hash function for symbol table lookup.  Don't even think about changing
  * this.  It is specified by the System V ABI.
@@ -565,15 +528,13 @@ _rtld_symlook_default(const char *name, 
 	/*
 	 * Search the dynamic linker itself, and possibly resolve the
 	 * symbol from there.  This is how the application links to
-	 * dynamic linker services such as dlopen.  Only the values listed
-	 * in the "_rtld_exports" array can be resolved from the dynamic
-	 * linker.
+	 * dynamic linker services su

CVS commit: src/libexec/ld.elf_so

2016-12-01 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Dec  1 18:21:39 UTC 2016

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

Log Message:
n dl_iterate_phdr return the path not the name.


To generate a diff of this commit:
cvs rdiff -u -r1.181 -r1.182 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.181 src/libexec/ld.elf_so/rtld.c:1.182
--- src/libexec/ld.elf_so/rtld.c:1.181	Thu Dec  1 09:29:15 2016
+++ src/libexec/ld.elf_so/rtld.c	Thu Dec  1 13:21:39 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.181 2016/12/01 14:29:15 christos Exp $	 */
+/*	$NetBSD: rtld.c,v 1.182 2016/12/01 18:21:39 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.181 2016/12/01 14:29:15 christos Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.182 2016/12/01 18:21:39 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -1402,8 +1402,7 @@ dl_iterate_phdr(int (*callback)(struct d
 	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 = SIMPLEQ_FIRST(&obj->names) ?
-		SIMPLEQ_FIRST(&obj->names)->name : obj->path;
+		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)



CVS commit: src/libexec/ld.elf_so

2015-03-05 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Mar  5 09:49:53 UTC 2015

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

Log Message:
HPPA hack for a problem where gdb doesn't see _rtld_debug_state when
it's a single bv,n %r0(%rp) instruction.

The nullify confuses something.


To generate a diff of this commit:
cvs rdiff -u -r1.174 -r1.175 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.174 src/libexec/ld.elf_so/rtld.c:1.175
--- src/libexec/ld.elf_so/rtld.c:1.174	Mon Aug 25 20:40:52 2014
+++ src/libexec/ld.elf_so/rtld.c	Thu Mar  5 09:49:53 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.174 2014/08/25 20:40:52 joerg Exp $	 */
+/*	$NetBSD: rtld.c,v 1.175 2015/03/05 09:49:53 skrll Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.174 2014/08/25 20:40:52 joerg Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.175 2015/03/05 09:49:53 skrll Exp $");
 #endif /* not lint */
 
 #include 
@@ -1431,6 +1431,9 @@ _rtld_error(const char *fmt,...)
 void
 _rtld_debug_state(void)
 {
+#if defined(__hppa__)
+	__asm volatile("nop" ::: "memory");
+#endif
 
 	/* Prevent optimizer from removing calls to this function */
 	__insn_barrier();



CVS commit: src/libexec/ld.elf_so

2015-04-04 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sat Apr  4 18:51:58 UTC 2015

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

Log Message:
lib/49813: Release mutex on error.


To generate a diff of this commit:
cvs rdiff -u -r1.175 -r1.176 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.175 src/libexec/ld.elf_so/rtld.c:1.176
--- src/libexec/ld.elf_so/rtld.c:1.175	Thu Mar  5 09:49:53 2015
+++ src/libexec/ld.elf_so/rtld.c	Sat Apr  4 18:51:57 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.175 2015/03/05 09:49:53 skrll Exp $	 */
+/*	$NetBSD: rtld.c,v 1.176 2015/04/04 18:51:57 joerg Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.175 2015/03/05 09:49:53 skrll Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.176 2015/04/04 18:51:57 joerg Exp $");
 #endif /* not lint */
 
 #include 
@@ -1269,7 +1269,7 @@ dladdr(const void *addr, Dl_info *info)
 	obj = _rtld_obj_from_addr(addr);
 	if (obj == NULL) {
 		_rtld_error("No shared object contains address");
-		lookup_mutex_enter();
+		lookup_mutex_exit();
 		return 0;
 	}
 	info->dli_fname = obj->path;



CVS commit: src/libexec/ld.elf_so

2015-04-06 Thread YAMAMOTO Takashi
Module Name:src
Committed By:   yamt
Date:   Mon Apr  6 09:34:15 UTC 2015

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

Log Message:
Fix membars around rtld internal mutex.

This fixes the most of lockups i observed with Open vSwitch
on NetBSD/amd64.  ("most of" because it still occasionally
locks up because of other problems.  see PR/49816)


To generate a diff of this commit:
cvs rdiff -u -r1.176 -r1.177 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.176 src/libexec/ld.elf_so/rtld.c:1.177
--- src/libexec/ld.elf_so/rtld.c:1.176	Sat Apr  4 18:51:57 2015
+++ src/libexec/ld.elf_so/rtld.c	Mon Apr  6 09:34:15 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.176 2015/04/04 18:51:57 joerg Exp $	 */
+/*	$NetBSD: rtld.c,v 1.177 2015/04/06 09:34:15 yamt Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.176 2015/04/04 18:51:57 joerg Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.177 2015/04/06 09:34:15 yamt Exp $");
 #endif /* not lint */
 
 #include 
@@ -1544,6 +1544,7 @@ _rtld_shared_enter(void)
 			/* Yes, so increment use counter */
 			if (atomic_cas_uint(&_rtld_mutex, cur, cur + 1) != cur)
 continue;
+			membar_enter();
 			return;
 		}
 		/*
@@ -1561,6 +1562,7 @@ _rtld_shared_enter(void)
 		/*
 		 * Check for race against _rtld_exclusive_exit before sleeping.
 		 */
+		membar_sync();
 		if ((_rtld_mutex & RTLD_EXCLUSIVE_MASK) ||
 		_rtld_waiter_exclusive)
 			_lwp_park(CLOCK_REALTIME, 0, NULL, 0,
@@ -1588,12 +1590,12 @@ _rtld_shared_exit(void)
 	 * Wakeup LWPs waiting for an exclusive lock if this is the last
 	 * LWP on the shared lock.
 	 */
+	membar_exit();
 	if (atomic_dec_uint_nv(&_rtld_mutex))
 		return;
+	membar_sync();
 	if ((waiter = _rtld_waiter_exclusive) != 0)
 		_lwp_unpark(waiter, __UNVOLATILE(&_rtld_mutex));
-
-	membar_exit();
 }
 
 void
@@ -1608,12 +1610,13 @@ _rtld_exclusive_enter(sigset_t *mask)
 	sigdelset(&blockmask, SIGTRAP);	/* Allow the debugger */
 	sigprocmask(SIG_BLOCK, &blockmask, mask);
 
-	membar_enter();
-
 	for (;;) {
-		if (atomic_cas_uint(&_rtld_mutex, 0, locked_value) == 0)
+		if (atomic_cas_uint(&_rtld_mutex, 0, locked_value) == 0) {
+			membar_enter();
 			break;
+		}
 		waiter = atomic_swap_uint(&_rtld_waiter_exclusive, self);
+		membar_sync();
 		cur = _rtld_mutex;
 		if (cur == locked_value) {
 			_rtld_error("dead lock detected");
@@ -1633,13 +1636,14 @@ _rtld_exclusive_exit(sigset_t *mask)
 {
 	lwpid_t waiter;
 
+	membar_exit();
 	_rtld_mutex = 0;
+	membar_sync();
 	if ((waiter = _rtld_waiter_exclusive) != 0)
 		_lwp_unpark(waiter, __UNVOLATILE(&_rtld_mutex));
 
 	if ((waiter = _rtld_waiter_shared) != 0)
 		_lwp_unpark(waiter, __UNVOLATILE(&_rtld_mutex));
 
-	membar_exit();
 	sigprocmask(SIG_SETMASK, mask, NULL);
 }



CVS commit: src/libexec/ld.elf_so

2016-05-22 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Sun May 22 19:28:39 UTC 2016

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

Log Message:
obj->phdr must be the absolute address, not the virtual offset from the
main binary. Historically, this has been the same. For PIE though,
relocbase can be pretty much anywhere. Fixes PR toolchain/51159.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 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.59 src/libexec/ld.elf_so/headers.c:1.60
--- src/libexec/ld.elf_so/headers.c:1.59	Tue Aug 26 21:20:05 2014
+++ src/libexec/ld.elf_so/headers.c	Sun May 22 19:28:39 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: headers.c,v 1.59 2014/08/26 21:20:05 joerg Exp $	 */
+/*	$NetBSD: headers.c,v 1.60 2016/05/22 19:28:39 joerg Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: headers.c,v 1.59 2014/08/26 21:20:05 joerg Exp $");
+__RCSID("$NetBSD: headers.c,v 1.60 2016/05/22 19:28:39 joerg Exp $");
 #endif /* not lint */
 
 #include 
@@ -389,9 +389,9 @@ _rtld_digest_phdr(const Elf_Phdr *phdr, 
 		if (ph->p_type != PT_PHDR)
 			continue;
 
-		obj->phdr = (void *)(uintptr_t)ph->p_vaddr;
-		obj->phsize = ph->p_memsz;
 		obj->relocbase = (caddr_t)((uintptr_t)phdr - (uintptr_t)ph->p_vaddr);
+		obj->phdr = phdr; /* Equivalent to relocbase + p_vaddr. */
+		obj->phsize = ph->p_memsz;
 		dbg(("headers: phdr %p (%p) phsize %zu relocbase %p",
 		obj->phdr, phdr, obj->phsize, obj->relocbase));
 		break;



CVS commit: src/libexec/ld.elf_so

2016-05-24 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue May 24 20:32:33 UTC 2016

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

Log Message:
Put the name of the dynamic linker in allocated memory, so that it becomes
part of the core file link-map, so that gdb can find it.


To generate a diff of this commit:
cvs rdiff -u -r1.177 -r1.178 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.177 src/libexec/ld.elf_so/rtld.c:1.178
--- src/libexec/ld.elf_so/rtld.c:1.177	Mon Apr  6 05:34:15 2015
+++ src/libexec/ld.elf_so/rtld.c	Tue May 24 16:32:33 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtld.c,v 1.177 2015/04/06 09:34:15 yamt Exp $	 */
+/*	$NetBSD: rtld.c,v 1.178 2016/05/24 20:32:33 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.177 2015/04/06 09:34:15 yamt Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.178 2016/05/24 20:32:33 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -654,6 +654,7 @@ _rtld(Elf_Addr *sp, Elf_Addr relocbase)
 	_rtld_objloads++;
 
 	_rtld_linkmap_add(_rtld_objmain);
+	_rtld_objself.path = xstrdup(_rtld_objself.path);
 	_rtld_linkmap_add(&_rtld_objself);
 
 	++_rtld_objmain->refcount;



CVS commit: src/libexec/ld.elf_so

2016-06-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Jun 14 13:06:41 UTC 2016

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

Log Message:
Add support for GNU RELRO headers from Matthias Weckbecker.


To generate a diff of this commit:
cvs rdiff -u -r1.130 -r1.131 src/libexec/ld.elf_so/Makefile
cvs rdiff -u -r1.60 -r1.61 src/libexec/ld.elf_so/headers.c
cvs rdiff -u -r1.53 -r1.54 src/libexec/ld.elf_so/map_object.c
cvs rdiff -u -r1.108 -r1.109 src/libexec/ld.elf_so/reloc.c
cvs rdiff -u -r1.124 -r1.125 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.

Modified files:

Index: src/libexec/ld.elf_so/Makefile
diff -u src/libexec/ld.elf_so/Makefile:1.130 src/libexec/ld.elf_so/Makefile:1.131
--- src/libexec/ld.elf_so/Makefile:1.130	Sat Jan 23 16:22:47 2016
+++ src/libexec/ld.elf_so/Makefile	Tue Jun 14 09:06:41 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.130 2016/01/23 21:22:47 christos Exp $
+#	$NetBSD: Makefile,v 1.131 2016/06/14 13:06:41 christos Exp $
 #
 # NOTE: when changing ld.so, ensure that ldd still compiles.
 #
@@ -93,6 +93,7 @@ BINDIR=		${SHLINKINSTALLDIR}
 CPPFLAGS+=	-DLIBDIR=\"${LIBDIR}\" -D_PATH_RTLD=\"${BINDIR}/${PROG}\"
 CPPFLAGS+=	-I${.CURDIR} -I. -D_KERNTYPES
 CPPFLAGS+=	-DRTLD_LOADER
+CPPFLAGS+=	-DGNU_RELRO
 CPPFLAGS+=	-D_RTLD_SOURCE
 CPPFLAGS+=	-DCOMBRELOC
 #CPPFLAGS+=	-DDEBUG

Index: src/libexec/ld.elf_so/headers.c
diff -u src/libexec/ld.elf_so/headers.c:1.60 src/libexec/ld.elf_so/headers.c:1.61
--- src/libexec/ld.elf_so/headers.c:1.60	Sun May 22 15:28:39 2016
+++ src/libexec/ld.elf_so/headers.c	Tue Jun 14 09:06:41 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: headers.c,v 1.60 2016/05/22 19:28:39 joerg Exp $	 */
+/*	$NetBSD: headers.c,v 1.61 2016/06/14 13:06:41 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: headers.c,v 1.60 2016/05/22 19:28:39 joerg Exp $");
+__RCSID("$NetBSD: headers.c,v 1.61 2016/06/14 13:06:41 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -432,6 +432,17 @@ _rtld_digest_phdr(const Elf_Phdr *phdr, 
 			 ph->p_memsz));
 			break;
 
+#ifdef GNU_RELRO
+		case PT_GNU_RELRO:
+			obj->relro_page = obj->relocbase
+			+ round_down(ph->p_vaddr);
+			obj->relro_size = round_up(ph->p_memsz);
+			dbg(("headers: %s %p phsize %" PRImemsz,
+			"PT_GNU_RELRO", (void *)(uintptr_t)vaddr,
+			 ph->p_memsz));
+			break;
+#endif
+
 #if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II)
 		case PT_TLS:
 			obj->tlsindex = 1;

Index: src/libexec/ld.elf_so/map_object.c
diff -u src/libexec/ld.elf_so/map_object.c:1.53 src/libexec/ld.elf_so/map_object.c:1.54
--- src/libexec/ld.elf_so/map_object.c:1.53	Thu Oct 30 03:53:41 2014
+++ src/libexec/ld.elf_so/map_object.c	Tue Jun 14 09:06:41 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: map_object.c,v 1.53 2014/10/30 07:53:41 martin Exp $	 */
+/*	$NetBSD: map_object.c,v 1.54 2016/06/14 13:06:41 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -34,7 +34,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: map_object.c,v 1.53 2014/10/30 07:53:41 martin Exp $");
+__RCSID("$NetBSD: map_object.c,v 1.54 2016/06/14 13:06:41 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -103,6 +103,10 @@ _rtld_map_object(const char *path, int f
 	caddr_t		 clear_addr;
 	size_t		 nclear;
 #endif
+#ifdef GNU_RELRO
+	Elf_Addr 	 relro_page;
+	size_t		 relro_size;
+#endif
 
 	if (sb != NULL && sb->st_size < (off_t)sizeof (Elf_Ehdr)) {
 		_rtld_error("%s: not ELF file (too short)", path);
@@ -173,6 +177,10 @@ _rtld_map_object(const char *path, int f
 #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;
@@ -200,6 +208,13 @@ _rtld_map_object(const char *path, int f
 			(void *)(uintptr_t)phdr->p_vaddr, phdr->p_memsz));
 			break;
 
+#ifdef GNU_RELRO
+		case PT_GNU_RELRO:
+			relro_page = phdr->p_vaddr;
+			relro_size = phdr->p_memsz;
+			break;
+#endif
+
 		case PT_DYNAMIC:
 			obj->dynamic = (void *)(uintptr_t)phdr->p_vaddr;
 			dbg(("%s: %s %p phsize %" PRImemsz, obj->path, "PT_DYNAMIC",
@@ -267,6 +282,11 @@ _rtld_map_object(const char *path, int f
 	obj->vaddrbase = base_vaddr;
 	obj->isdynamic = ehdr->e_type == ET_DYN;
 
+#ifdef GNU_RELRO
+	obj->relro_page = obj->relocbase + round_down(relro_page);
+	obj->relro_size = round_up(relro_size);
+#endif
+
 #if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II)
 	if (phtls != NULL) {
 		++_rtld_tls_dtv_generation;

Index: src/libexec/ld.elf_so/reloc.c
diff -u src/libexec/ld.elf_so/reloc.c:1.108 src/libexec/ld.elf_so/reloc.c:1.109
--- src/libexec/ld.elf_so/reloc.c:1.108	Tue Apr 12 15:10:48 2016
+++ src/libexec/ld.elf_so/reloc.c	Tue Jun 14 09:06:41 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: reloc.c,v 1.108 2016/04/12 19

CVS commit: src/libexec/ld.elf_so

2016-06-15 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Jun 15 12:08:47 UTC 2016

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

Log Message:
Turn off GNU_RELRO for now.


To generate a diff of this commit:
cvs rdiff -u -r1.131 -r1.132 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.131 src/libexec/ld.elf_so/Makefile:1.132
--- src/libexec/ld.elf_so/Makefile:1.131	Tue Jun 14 09:06:41 2016
+++ src/libexec/ld.elf_so/Makefile	Wed Jun 15 08:08:47 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.131 2016/06/14 13:06:41 christos Exp $
+#	$NetBSD: Makefile,v 1.132 2016/06/15 12:08:47 christos Exp $
 #
 # NOTE: when changing ld.so, ensure that ldd still compiles.
 #
@@ -93,7 +93,7 @@ BINDIR=		${SHLINKINSTALLDIR}
 CPPFLAGS+=	-DLIBDIR=\"${LIBDIR}\" -D_PATH_RTLD=\"${BINDIR}/${PROG}\"
 CPPFLAGS+=	-I${.CURDIR} -I. -D_KERNTYPES
 CPPFLAGS+=	-DRTLD_LOADER
-CPPFLAGS+=	-DGNU_RELRO
+#CPPFLAGS+=	-DGNU_RELRO
 CPPFLAGS+=	-D_RTLD_SOURCE
 CPPFLAGS+=	-DCOMBRELOC
 #CPPFLAGS+=	-DDEBUG



CVS commit: src/libexec/ld.elf_so

2016-06-16 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jun 16 11:34:13 UTC 2016

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

Log Message:
Move relro after we've computed out relocbase and re-enable it.
(Matthias Weckbecker)


To generate a diff of this commit:
cvs rdiff -u -r1.132 -r1.133 src/libexec/ld.elf_so/Makefile
cvs rdiff -u -r1.54 -r1.55 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/Makefile
diff -u src/libexec/ld.elf_so/Makefile:1.132 src/libexec/ld.elf_so/Makefile:1.133
--- src/libexec/ld.elf_so/Makefile:1.132	Wed Jun 15 08:08:47 2016
+++ src/libexec/ld.elf_so/Makefile	Thu Jun 16 07:34:13 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.132 2016/06/15 12:08:47 christos Exp $
+#	$NetBSD: Makefile,v 1.133 2016/06/16 11:34:13 christos Exp $
 #
 # NOTE: when changing ld.so, ensure that ldd still compiles.
 #
@@ -93,7 +93,7 @@ BINDIR=		${SHLINKINSTALLDIR}
 CPPFLAGS+=	-DLIBDIR=\"${LIBDIR}\" -D_PATH_RTLD=\"${BINDIR}/${PROG}\"
 CPPFLAGS+=	-I${.CURDIR} -I. -D_KERNTYPES
 CPPFLAGS+=	-DRTLD_LOADER
-#CPPFLAGS+=	-DGNU_RELRO
+CPPFLAGS+=	-DGNU_RELRO
 CPPFLAGS+=	-D_RTLD_SOURCE
 CPPFLAGS+=	-DCOMBRELOC
 #CPPFLAGS+=	-DDEBUG

Index: src/libexec/ld.elf_so/map_object.c
diff -u src/libexec/ld.elf_so/map_object.c:1.54 src/libexec/ld.elf_so/map_object.c:1.55
--- src/libexec/ld.elf_so/map_object.c:1.54	Tue Jun 14 09:06:41 2016
+++ src/libexec/ld.elf_so/map_object.c	Thu Jun 16 07:34:13 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: map_object.c,v 1.54 2016/06/14 13:06:41 christos Exp $	 */
+/*	$NetBSD: map_object.c,v 1.55 2016/06/16 11:34:13 christos Exp $	 */
 
 /*
  * Copyright 1996 John D. Polstra.
@@ -34,7 +34,7 @@
 
 #include 
 #ifndef lint
-__RCSID("$NetBSD: map_object.c,v 1.54 2016/06/14 13:06:41 christos Exp $");
+__RCSID("$NetBSD: map_object.c,v 1.55 2016/06/16 11:34:13 christos Exp $");
 #endif /* not lint */
 
 #include 
@@ -282,11 +282,6 @@ _rtld_map_object(const char *path, int f
 	obj->vaddrbase = base_vaddr;
 	obj->isdynamic = ehdr->e_type == ET_DYN;
 
-#ifdef GNU_RELRO
-	obj->relro_page = obj->relocbase + round_down(relro_page);
-	obj->relro_size = round_up(relro_size);
-#endif
-
 #if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II)
 	if (phtls != NULL) {
 		++_rtld_tls_dtv_generation;
@@ -408,6 +403,11 @@ _rtld_map_object(const char *path, int f
 	obj->mapsize = mapsize;
 	obj->relocbase = mapbase - base_vaddr;
 
+#ifdef GNU_RELRO
+	obj->relro_page = obj->relocbase + round_down(relro_page);
+	obj->relro_size = round_up(relro_size);
+#endif
+
 	if (obj->dynamic)
 		obj->dynamic = (void *)(obj->relocbase + (Elf_Addr)(uintptr_t)obj->dynamic);
 	if (obj->entry)



  1   2   3   4   >