summaryrefslogtreecommitdiff
path: root/libexec
diff options
context:
space:
mode:
authormatt <matt@NetBSD.org>2008-07-24 04:39:25 +0000
committermatt <matt@NetBSD.org>2008-07-24 04:39:25 +0000
commit38bdc8954faf336615dbc8fd5777d30f55ab4aa1 (patch)
tree9dcaf78b6980bb9d4ad164f33778ba23db00abee /libexec
parentee372c7d111fd8e4adc373a36b0c1667c4ec3361 (diff)
Refactor common code to _rtld_relocate_plt_object to i386 and arm so they
act like the other versions. In _rtld_bind, if the result is 0, call _rtld_die. Initialize _rtld_sym_zero.st_value to -_rtld_objself.maprelocbase. Now when the symbol is resolved, st_value + maprelocbase will equal 0 and the above check in _rtld_bind will fire and a call to NULL will be avoided.
Diffstat (limited to 'libexec')
-rw-r--r--libexec/ld.elf_so/arch/alpha/alpha_reloc.c6
-rw-r--r--libexec/ld.elf_so/arch/arm/mdreloc.c57
-rw-r--r--libexec/ld.elf_so/arch/hppa/hppa_reloc.c6
-rw-r--r--libexec/ld.elf_so/arch/i386/mdreloc.c63
-rw-r--r--libexec/ld.elf_so/arch/m68k/mdreloc.c6
-rw-r--r--libexec/ld.elf_so/arch/mips/mips_reloc.c6
-rw-r--r--libexec/ld.elf_so/arch/powerpc/ppc_reloc.c6
-rw-r--r--libexec/ld.elf_so/arch/sh3/mdreloc.c6
-rw-r--r--libexec/ld.elf_so/arch/sparc/mdreloc.c6
-rw-r--r--libexec/ld.elf_so/arch/sparc64/mdreloc.c6
-rw-r--r--libexec/ld.elf_so/arch/vax/mdreloc.c6
-rw-r--r--libexec/ld.elf_so/arch/x86_64/mdreloc.c8
-rw-r--r--libexec/ld.elf_so/rtld.c29
-rw-r--r--libexec/ld.elf_so/symbol.c5
14 files changed, 113 insertions, 103 deletions
diff --git a/libexec/ld.elf_so/arch/alpha/alpha_reloc.c b/libexec/ld.elf_so/arch/alpha/alpha_reloc.c
index c8f9f2e1225..92264800ac3 100644
--- a/libexec/ld.elf_so/arch/alpha/alpha_reloc.c
+++ b/libexec/ld.elf_so/arch/alpha/alpha_reloc.c
@@ -1,4 +1,4 @@
-/* $NetBSD: alpha_reloc.c,v 1.30 2007/02/23 01:17:11 matt Exp $ */
+/* $NetBSD: alpha_reloc.c,v 1.31 2008/07/24 04:39:25 matt Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
@@ -62,7 +62,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: alpha_reloc.c,v 1.30 2007/02/23 01:17:11 matt Exp $");
+__RCSID("$NetBSD: alpha_reloc.c,v 1.31 2008/07/24 04:39:25 matt Exp $");
#endif /* not lint */
#include <sys/types.h>
@@ -480,7 +480,7 @@ _rtld_bind(const Obj_Entry *obj, Elf_Word reloff)
int err;
err = _rtld_relocate_plt_object(obj, rela, &result);
- if (err)
+ if (err || result == 0)
_rtld_die();
return (caddr_t)result;
diff --git a/libexec/ld.elf_so/arch/arm/mdreloc.c b/libexec/ld.elf_so/arch/arm/mdreloc.c
index f6e03b62ffb..d99973e1919 100644
--- a/libexec/ld.elf_so/arch/arm/mdreloc.c
+++ b/libexec/ld.elf_so/arch/arm/mdreloc.c
@@ -1,8 +1,8 @@
-/* $NetBSD: mdreloc.c,v 1.27 2005/12/24 20:59:30 perry Exp $ */
+/* $NetBSD: mdreloc.c,v 1.28 2008/07/24 04:39:25 matt Exp $ */
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: mdreloc.c,v 1.27 2005/12/24 20:59:30 perry Exp $");
+__RCSID("$NetBSD: mdreloc.c,v 1.28 2008/07/24 04:39:25 matt Exp $");
#endif /* not lint */
#include <sys/types.h>
@@ -217,10 +217,10 @@ _rtld_relocate_plt_lazy(const Obj_Entry *obj)
return 0;
}
-caddr_t
-_rtld_bind(const Obj_Entry *obj, Elf_Word reloff)
+static int
+_rtld_relocate_plt_object(const Obj_Entry *obj, const Elf_Rel *rel,
+ Elf_Addr *tp)
{
- const Elf_Rel *rel = (const Elf_Rel *)((caddr_t)obj->pltrel + reloff);
Elf_Addr *where = (Elf_Addr *)(obj->relocbase + rel->r_offset);
Elf_Addr new_value;
const Elf_Sym *def;
@@ -230,7 +230,7 @@ _rtld_bind(const Obj_Entry *obj, Elf_Word reloff)
def = _rtld_find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj, true);
if (def == NULL)
- _rtld_die();
+ return -1;
new_value = (Elf_Addr)(defobj->relocbase + def->st_value);
/* Set the Thumb bit, if needed. */
@@ -240,37 +240,36 @@ _rtld_bind(const Obj_Entry *obj, Elf_Word reloff)
defobj->strtab + def->st_name, (void *)*where, (void *)new_value));
if (*where != new_value)
*where = new_value;
+ if (tp)
+ *tp = new_value;
- return (caddr_t)new_value;
+ return 0;
}
+caddr_t
+_rtld_bind(const Obj_Entry *obj, Elf_Word reloff)
+{
+ const Elf_Rel *rel = (const Elf_Rel *)((caddr_t)obj->pltrel + reloff);
+ Elf_Addr new_value;
+ int err;
+
+ err = _rtld_relocate_plt_object(obj, rel, &new_value);
+ if (err || new_value == 0)
+ _rtld_die();
+
+ return (caddr_t)new_value;
+}
int
_rtld_relocate_plt_objects(const Obj_Entry *obj)
{
const Elf_Rel *rel;
+ int err = 0;
for (rel = obj->pltrel; rel < obj->pltrellim; rel++) {
- Elf_Addr *where = (Elf_Addr *)(obj->relocbase + rel->r_offset);
- Elf_Addr target;
- const Elf_Sym *def;
- const Obj_Entry *defobj;
-
- assert(ELF_R_TYPE(rel->r_info) == R_TYPE(JUMP_SLOT));
-
- def = _rtld_find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj,
- true);
- if (def == NULL)
- return -1;
- target = (Elf_Addr)(defobj->relocbase + def->st_value);
- /* Set the Thumb bit, if needed. */
- if (ELF_ST_TYPE(def->st_info) == STT_ARM_TFUNC)
- target |= 1;
-
- rdbg(("bind now/fixup in %s --> old=%p new=%p",
- defobj->strtab + def->st_name, (void *)*where,
- (void *)target));
- if (*where != target)
- *where = target;
+ err = _rtld_relocate_plt_object(obj, rel, NULL);
+ if (err)
+ break;
}
- return 0;
+
+ return err;
}
diff --git a/libexec/ld.elf_so/arch/hppa/hppa_reloc.c b/libexec/ld.elf_so/arch/hppa/hppa_reloc.c
index 04b65258986..36f451d029e 100644
--- a/libexec/ld.elf_so/arch/hppa/hppa_reloc.c
+++ b/libexec/ld.elf_so/arch/hppa/hppa_reloc.c
@@ -1,4 +1,4 @@
-/* $NetBSD: hppa_reloc.c,v 1.26 2008/04/28 20:23:03 martin Exp $ */
+/* $NetBSD: hppa_reloc.c,v 1.27 2008/07/24 04:39:25 matt Exp $ */
/*-
* Copyright (c) 2002, 2004 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: hppa_reloc.c,v 1.26 2008/04/28 20:23:03 martin Exp $");
+__RCSID("$NetBSD: hppa_reloc.c,v 1.27 2008/07/24 04:39:25 matt Exp $");
#endif /* not lint */
#include <stdlib.h>
@@ -592,7 +592,7 @@ _rtld_bind(const Obj_Entry *obj, Elf_Word reloff)
assert(ELF_R_SYM(rela->r_info) != 0);
err = _rtld_relocate_plt_object(obj, rela, &new_value);
- if (err)
+ if (err || new_value == 0)
_rtld_die();
return (caddr_t)new_value;
diff --git a/libexec/ld.elf_so/arch/i386/mdreloc.c b/libexec/ld.elf_so/arch/i386/mdreloc.c
index 45d887d6ef8..2353350d57d 100644
--- a/libexec/ld.elf_so/arch/i386/mdreloc.c
+++ b/libexec/ld.elf_so/arch/i386/mdreloc.c
@@ -1,8 +1,8 @@
-/* $NetBSD: mdreloc.c,v 1.25 2008/07/23 18:16:42 christos Exp $ */
+/* $NetBSD: mdreloc.c,v 1.26 2008/07/24 04:39:25 matt Exp $ */
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: mdreloc.c,v 1.25 2008/07/23 18:16:42 christos Exp $");
+__RCSID("$NetBSD: mdreloc.c,v 1.26 2008/07/24 04:39:25 matt Exp $");
#endif /* not lint */
#include <sys/types.h>
@@ -156,25 +156,41 @@ _rtld_relocate_plt_lazy(const Obj_Entry *obj)
return 0;
}
-caddr_t
-_rtld_bind(const Obj_Entry *obj, Elf_Word reloff)
+static inline int
+_rtld_relocate_plt_object(const Obj_Entry *obj, const Elf_Rel *rel,
+ Elf_Addr *tp)
{
- const Elf_Rel *rel = (const Elf_Rel *)((caddr_t)obj->pltrel + reloff);
Elf_Addr *where = (Elf_Addr *)(obj->relocbase + rel->r_offset);
- Elf_Addr new_value;
- const Elf_Sym *def;
+ Elf_Addr target;
+ const Elf_Sym *def;
const Obj_Entry *defobj;
assert(ELF_R_TYPE(rel->r_info) == R_TYPE(JMP_SLOT));
def = _rtld_find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj, true);
if (def == NULL)
- _rtld_die();
- new_value = (Elf_Addr)(defobj->relocbase + def->st_value);
+ return -1;
+ target = (Elf_Addr)(defobj->relocbase + def->st_value);
rdbg(("bind now/fixup in %s --> old=%p new=%p",
- defobj->strtab + def->st_name, (void *)*where, (void *)new_value));
- if (*where != new_value)
- *where = new_value;
+ defobj->strtab + def->st_name, (void *)*where,
+ (void *)target));
+ if (*where != target)
+ *where = target;
+ if (tp)
+ *tp = target;
+ return 0;
+}
+
+caddr_t
+_rtld_bind(const Obj_Entry *obj, Elf_Word reloff)
+{
+ const Elf_Rel *rel = (const Elf_Rel *)((caddr_t)obj->pltrel + reloff);
+ Elf_Addr new_value;
+ int err;
+
+ err = _rtld_relocate_plt_object(obj, rel, &new_value);
+ if (err || new_value == 0)
+ _rtld_die();
return (caddr_t)new_value;
}
@@ -183,25 +199,12 @@ int
_rtld_relocate_plt_objects(const Obj_Entry *obj)
{
const Elf_Rel *rel;
+ int err = 0;
for (rel = obj->pltrel; rel < obj->pltrellim; rel++) {
- Elf_Addr *where = (Elf_Addr *)(obj->relocbase + rel->r_offset);
- Elf_Addr target;
- const Elf_Sym *def;
- const Obj_Entry *defobj;
-
- assert(ELF_R_TYPE(rel->r_info) == R_TYPE(JMP_SLOT));
-
- def = _rtld_find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj,
- true);
- if (def == NULL)
- return -1;
- target = (Elf_Addr)(defobj->relocbase + def->st_value);
- rdbg(("bind now/fixup in %s --> old=%p new=%p",
- defobj->strtab + def->st_name, (void *)*where,
- (void *)target));
- if (*where != target)
- *where = target;
+ err = _rtld_relocate_plt_object(obj, rel, NULL);
+ if (err)
+ break;
}
- return 0;
+ return err;
}
diff --git a/libexec/ld.elf_so/arch/m68k/mdreloc.c b/libexec/ld.elf_so/arch/m68k/mdreloc.c
index d1662ea4a3b..707dffe2d96 100644
--- a/libexec/ld.elf_so/arch/m68k/mdreloc.c
+++ b/libexec/ld.elf_so/arch/m68k/mdreloc.c
@@ -1,8 +1,8 @@
-/* $NetBSD: mdreloc.c,v 1.20 2006/05/20 07:09:44 mrg Exp $ */
+/* $NetBSD: mdreloc.c,v 1.21 2008/07/24 04:39:25 matt Exp $ */
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: mdreloc.c,v 1.20 2006/05/20 07:09:44 mrg Exp $");
+__RCSID("$NetBSD: mdreloc.c,v 1.21 2008/07/24 04:39:25 matt Exp $");
#endif /* not lint */
#include <sys/types.h>
@@ -197,7 +197,7 @@ _rtld_bind(const Obj_Entry *obj, Elf_Word reloff)
result = 0; /* XXX gcc */
err = _rtld_relocate_plt_object(obj, rela, &result);
- if (err)
+ if (err || result == 0)
_rtld_die();
return (caddr_t)result;
diff --git a/libexec/ld.elf_so/arch/mips/mips_reloc.c b/libexec/ld.elf_so/arch/mips/mips_reloc.c
index 50f3e392add..4e559d95628 100644
--- a/libexec/ld.elf_so/arch/mips/mips_reloc.c
+++ b/libexec/ld.elf_so/arch/mips/mips_reloc.c
@@ -1,4 +1,4 @@
-/* $NetBSD: mips_reloc.c,v 1.52 2006/06/28 16:48:38 simonb Exp $ */
+/* $NetBSD: mips_reloc.c,v 1.53 2008/07/24 04:39:25 matt Exp $ */
/*
* Copyright 1997 Michael L. Hitch <mhitch@montana.edu>
@@ -30,7 +30,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: mips_reloc.c,v 1.52 2006/06/28 16:48:38 simonb Exp $");
+__RCSID("$NetBSD: mips_reloc.c,v 1.53 2008/07/24 04:39:25 matt Exp $");
#endif /* not lint */
#include <sys/types.h>
@@ -360,7 +360,7 @@ _rtld_bind(Elf_Word a0, Elf_Addr a1, Elf_Addr a2, Elf_Addr a3)
int err;
err = _rtld_relocate_plt_object(obj, a0, &new_value);
- if (err)
+ if (err || new_value == 0)
_rtld_die();
return (caddr_t)new_value;
diff --git a/libexec/ld.elf_so/arch/powerpc/ppc_reloc.c b/libexec/ld.elf_so/arch/powerpc/ppc_reloc.c
index 9a60f308540..c3003453070 100644
--- a/libexec/ld.elf_so/arch/powerpc/ppc_reloc.c
+++ b/libexec/ld.elf_so/arch/powerpc/ppc_reloc.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ppc_reloc.c,v 1.40 2006/05/23 16:27:41 mrg Exp $ */
+/* $NetBSD: ppc_reloc.c,v 1.41 2008/07/24 04:39:25 matt Exp $ */
/*-
* Copyright (C) 1998 Tsubai Masanari
@@ -30,7 +30,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: ppc_reloc.c,v 1.40 2006/05/23 16:27:41 mrg Exp $");
+__RCSID("$NetBSD: ppc_reloc.c,v 1.41 2008/07/24 04:39:25 matt Exp $");
#endif /* not lint */
#include <stdarg.h>
@@ -312,7 +312,7 @@ _rtld_bind(const Obj_Entry *obj, Elf_Word reloff)
new_value = 0; /* XXX gcc */
err = _rtld_relocate_plt_object(obj, rela, reloff, &new_value);
- if (err)
+ if (err || new_value == 0)
_rtld_die();
return (caddr_t)new_value;
diff --git a/libexec/ld.elf_so/arch/sh3/mdreloc.c b/libexec/ld.elf_so/arch/sh3/mdreloc.c
index 42ce04d8c9d..c4f0962b08d 100644
--- a/libexec/ld.elf_so/arch/sh3/mdreloc.c
+++ b/libexec/ld.elf_so/arch/sh3/mdreloc.c
@@ -1,8 +1,8 @@
-/* $NetBSD: mdreloc.c,v 1.22 2006/05/21 04:17:35 mrg Exp $ */
+/* $NetBSD: mdreloc.c,v 1.23 2008/07/24 04:39:25 matt Exp $ */
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: mdreloc.c,v 1.22 2006/05/21 04:17:35 mrg Exp $");
+__RCSID("$NetBSD: mdreloc.c,v 1.23 2008/07/24 04:39:25 matt Exp $");
#endif /* not lint */
#include <sys/types.h>
@@ -197,7 +197,7 @@ _rtld_bind(const Obj_Entry *obj, Elf_Word reloff)
new_value = 0; /* XXX gcc */
err = _rtld_relocate_plt_object(obj, rela, &new_value);
- if (err)
+ if (err || new_value == 0)
_rtld_die();
return (caddr_t)new_value;
diff --git a/libexec/ld.elf_so/arch/sparc/mdreloc.c b/libexec/ld.elf_so/arch/sparc/mdreloc.c
index 2d07ccf3937..3abc6da2c17 100644
--- a/libexec/ld.elf_so/arch/sparc/mdreloc.c
+++ b/libexec/ld.elf_so/arch/sparc/mdreloc.c
@@ -1,4 +1,4 @@
-/* $NetBSD: mdreloc.c,v 1.40 2008/04/28 20:23:03 martin Exp $ */
+/* $NetBSD: mdreloc.c,v 1.41 2008/07/24 04:39:25 matt Exp $ */
/*-
* Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: mdreloc.c,v 1.40 2008/04/28 20:23:03 martin Exp $");
+__RCSID("$NetBSD: mdreloc.c,v 1.41 2008/07/24 04:39:25 matt Exp $");
#endif /* not lint */
#include <errno.h>
@@ -327,7 +327,7 @@ _rtld_bind(const Obj_Entry *obj, Elf_Word reloff)
value = 0; /* XXX gcc */
err = _rtld_relocate_plt_object(obj, rela, &value);
- if (err)
+ if (err || value == 0)
_rtld_die();
return (caddr_t)value;
diff --git a/libexec/ld.elf_so/arch/sparc64/mdreloc.c b/libexec/ld.elf_so/arch/sparc64/mdreloc.c
index 06988f93bd9..7d349d8d725 100644
--- a/libexec/ld.elf_so/arch/sparc64/mdreloc.c
+++ b/libexec/ld.elf_so/arch/sparc64/mdreloc.c
@@ -1,4 +1,4 @@
-/* $NetBSD: mdreloc.c,v 1.42 2008/04/28 20:23:04 martin Exp $ */
+/* $NetBSD: mdreloc.c,v 1.43 2008/07/24 04:39:25 matt Exp $ */
/*-
* Copyright (c) 2000 Eduardo Horvath.
@@ -32,7 +32,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: mdreloc.c,v 1.42 2008/04/28 20:23:04 martin Exp $");
+__RCSID("$NetBSD: mdreloc.c,v 1.43 2008/07/24 04:39:25 matt Exp $");
#endif /* not lint */
#include <errno.h>
@@ -473,7 +473,7 @@ _rtld_bind(const Obj_Entry *obj, Elf_Word reloff)
}
err = _rtld_relocate_plt_object(obj, rela, &result);
- if (err)
+ if (err || result == 0)
_rtld_die();
return (caddr_t)result;
diff --git a/libexec/ld.elf_so/arch/vax/mdreloc.c b/libexec/ld.elf_so/arch/vax/mdreloc.c
index 609d914f8b2..71201e5f924 100644
--- a/libexec/ld.elf_so/arch/vax/mdreloc.c
+++ b/libexec/ld.elf_so/arch/vax/mdreloc.c
@@ -1,8 +1,8 @@
-/* $NetBSD: mdreloc.c,v 1.21 2006/05/21 04:17:35 mrg Exp $ */
+/* $NetBSD: mdreloc.c,v 1.22 2008/07/24 04:39:26 matt Exp $ */
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: mdreloc.c,v 1.21 2006/05/21 04:17:35 mrg Exp $");
+__RCSID("$NetBSD: mdreloc.c,v 1.22 2008/07/24 04:39:26 matt Exp $");
#endif /* not lint */
#include <sys/types.h>
@@ -181,7 +181,7 @@ _rtld_bind(const Obj_Entry *obj, Elf_Word reloff)
result = 0; /* XXX gcc */
err = _rtld_relocate_plt_object(obj, rela, &result);
- if (err)
+ if (err || result == 0)
_rtld_die();
return (caddr_t)result;
diff --git a/libexec/ld.elf_so/arch/x86_64/mdreloc.c b/libexec/ld.elf_so/arch/x86_64/mdreloc.c
index 4e65be6fb73..28b89f2bb51 100644
--- a/libexec/ld.elf_so/arch/x86_64/mdreloc.c
+++ b/libexec/ld.elf_so/arch/x86_64/mdreloc.c
@@ -1,4 +1,4 @@
-/* $NetBSD: mdreloc.c,v 1.31 2008/07/23 18:16:42 christos Exp $ */
+/* $NetBSD: mdreloc.c,v 1.32 2008/07/24 04:39:26 matt Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
@@ -68,7 +68,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: mdreloc.c,v 1.31 2008/07/23 18:16:42 christos Exp $");
+__RCSID("$NetBSD: mdreloc.c,v 1.32 2008/07/24 04:39:26 matt Exp $");
#endif /* not lint */
#include <sys/types.h>
@@ -268,7 +268,7 @@ _rtld_relocate_plt_object(const Obj_Entry *obj, const Elf_Rela *rela, Elf_Addr *
return -1;
new_value = (Elf_Addr)(defobj->relocbase + def->st_value +
rela->r_addend);
- rdbg(("bind now/fixup in %s --> old=%p new=%p", name,
+ rdbg(("bind now/fixup in %s --> old=%p new=%p",
defobj->strtab + def->st_name, (void *)*where, (void *)new_value));
if (*where != new_value)
*where = new_value;
@@ -289,7 +289,7 @@ _rtld_bind(const Obj_Entry *obj, Elf_Word reloff)
new_value = 0; /* XXX GCC4 */
err = _rtld_relocate_plt_object(obj, rela, &new_value);
- if (err)
+ if (err || new_value == 0)
_rtld_die();
return (caddr_t)new_value;
diff --git a/libexec/ld.elf_so/rtld.c b/libexec/ld.elf_so/rtld.c
index 90c212ede53..40ae558ed75 100644
--- a/libexec/ld.elf_so/rtld.c
+++ b/libexec/ld.elf_so/rtld.c
@@ -1,4 +1,4 @@
-/* $NetBSD: rtld.c,v 1.119 2008/07/23 18:16:42 christos Exp $ */
+/* $NetBSD: rtld.c,v 1.120 2008/07/24 04:39:25 matt Exp $ */
/*
* Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.119 2008/07/23 18:16:42 christos Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.120 2008/07/24 04:39:25 matt Exp $");
#endif /* not lint */
#include <err.h>
@@ -85,8 +85,13 @@ Obj_Entry *_rtld_objlist; /* Head of linked list of shared objects */
Obj_Entry **_rtld_objtail; /* Link field of last object in list */
Obj_Entry *_rtld_objmain; /* The main program shared object */
Obj_Entry _rtld_objself; /* The dynamic linker shared object */
-char *_rtld_path = _PATH_RTLD;
-Elf_Sym _rtld_sym_zero; /* For resolving undefined weak refs. */
+const char _rtld_path[] = _PATH_RTLD;
+
+/* Initialize a fake symbol for resolving undefined weak references. */
+Elf_Sym _rtld_sym_zero = {
+ .st_info = ELF_ST_INFO(STB_GLOBAL, STT_NOTYPE),
+ .st_shndx = SHN_ABS,
+};
int _rtld_pagesz; /* Page size, as provided by kernel */
Search_Path *_rtld_default_paths;
@@ -217,14 +222,22 @@ _rtld_init(caddr_t mapbase, caddr_t relocbase, const char *execname)
{
/* Conjure up an Obj_Entry structure for the dynamic linker. */
- _rtld_objself.path = _rtld_path;
- _rtld_objself.pathlen = strlen(_rtld_path);
+ _rtld_objself.path = __UNCONST(_rtld_path);
+ _rtld_objself.pathlen = sizeof(_rtld_path)-1;
_rtld_objself.rtld = true;
_rtld_objself.mapbase = mapbase;
_rtld_objself.relocbase = relocbase;
_rtld_objself.dynamic = (Elf_Dyn *) &_DYNAMIC;
_rtld_objself.strtab = "_rtld_sym_zero";
+ /*
+ * Set value to -relocabase so that
+ * _rtld_objself.relocbase + _rtld_smy_zero.st_value == 0
+ * This allows unresolved references to weak symbols to be computed
+ * to value a value of 0.
+ */
+ _rtld_sym_zero.st_value = -(uintptr_t)relocbase;
+
_rtld_digest_dynamic(_rtld_path, &_rtld_objself);
assert(!_rtld_objself.needed);
#if !defined(__hppa__)
@@ -487,10 +500,6 @@ _rtld(Elf_Addr *sp, Elf_Addr relocbase)
_rtld_objmain->mainref = 1;
_rtld_objlist_push_tail(&_rtld_list_main, _rtld_objmain);
- /* Initialize a fake symbol for resolving undefined weak references. */
- _rtld_sym_zero.st_info = ELF_ST_INFO(STB_GLOBAL, STT_NOTYPE);
- _rtld_sym_zero.st_shndx = SHN_ABS;
-
if (_rtld_trust) {
/*
* Pre-load user-specified objects after the main program
diff --git a/libexec/ld.elf_so/symbol.c b/libexec/ld.elf_so/symbol.c
index e7883fec628..ee77a631c99 100644
--- a/libexec/ld.elf_so/symbol.c
+++ b/libexec/ld.elf_so/symbol.c
@@ -1,4 +1,4 @@
-/* $NetBSD: symbol.c,v 1.45 2008/07/23 18:16:42 christos Exp $ */
+/* $NetBSD: symbol.c,v 1.46 2008/07/24 04:39:25 matt Exp $ */
/*
* Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: symbol.c,v 1.45 2008/07/23 18:16:42 christos Exp $");
+__RCSID("$NetBSD: symbol.c,v 1.46 2008/07/24 04:39:25 matt Exp $");
#endif /* not lint */
#include <err.h>
@@ -253,7 +253,6 @@ _rtld_find_symdef(unsigned long symnum, const Obj_Entry *refobj,
_rtld_error(
"%s: Trying to call undefined weak symbol `%s'",
refobj->path, name);
- abort();
}
rdbg((" returning _rtld_sym_zero@_rtld_objself"));
def = &_rtld_sym_zero;