Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libexecinfo Don't subtract base if not pie.
details: https://anonhg.NetBSD.org/src/rev/703adcbbdefe
branches: trunk
changeset: 344792:703adcbbdefe
user: christos <christos%NetBSD.org@localhost>
date: Wed Apr 20 14:00:16 2016 +0000
description:
Don't subtract base if not pie.
diffstat:
lib/libexecinfo/symtab.c | 32 ++++++++++++++++++++++----------
1 files changed, 22 insertions(+), 10 deletions(-)
diffs (92 lines):
diff -r ce95e23f4c42 -r 703adcbbdefe lib/libexecinfo/symtab.c
--- a/lib/libexecinfo/symtab.c Wed Apr 20 09:01:03 2016 +0000
+++ b/lib/libexecinfo/symtab.c Wed Apr 20 14:00:16 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: symtab.c,v 1.4 2016/04/11 15:30:18 christos Exp $ */
+/* $NetBSD: symtab.c,v 1.5 2016/04/20 14:00:16 christos Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -29,12 +29,13 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: symtab.c,v 1.4 2016/04/11 15:30:18 christos Exp $");
+__RCSID("$NetBSD: symtab.c,v 1.5 2016/04/20 14:00:16 christos Exp $");
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
+#include <stdbool.h>
#include <err.h>
#include <dlfcn.h>
@@ -58,6 +59,7 @@
struct symtab {
size_t nsymbols;
struct symbol *symbols;
+ bool ispie;
};
static int
@@ -85,6 +87,7 @@
Elf *elf;
symtab_t *st;
Elf_Scn *scn = NULL;
+ GElf_Ehdr ehdr;
if (elf_version(EV_CURRENT) == EV_NONE) {
warnx("Elf Library is out of date.");
@@ -102,6 +105,13 @@
elf_end(elf);
return NULL;
}
+ if (gelf_getehdr(elf, &ehdr) == NULL) {
+ warnx("Error getting ELF Ehdr");
+ elf_end(elf);
+ return NULL;
+ }
+
+ st->ispie = ehdr.e_type == ET_DYN;
while ((scn = elf_nextscn(elf, scn)) != NULL) {
GElf_Shdr shdr;
@@ -176,12 +186,14 @@
size_t hi = ns;
size_t lo = 0;
size_t mid = ns / 2;
- uintptr_t dd, sd, me = (uintptr_t)p - (uintptr_t)dli->dli_fbase;
- uintptr_t ad = (uintptr_t)dli->dli_saddr - (uintptr_t)dli->dli_fbase;
+ uintptr_t fbase = st->ispie ? (uintptr_t)dli->dli_fbase : 0;
+ uintptr_t dd, sd, me = (uintptr_t)p - fbase;
+ uintptr_t ad = (uintptr_t)dli->dli_saddr - fbase;
#ifdef SYMTAB_DEBUG
- fprintf(stderr, "%s: [fbase=%p, saddr=%p, me=%#jx]\n", __func__,
- dli->dli_fbase, dli->dli_saddr, (uintmax_t)me);
+ fprintf(stderr, "%s: [fbase=%#jx, saddr=%p, me=%#jx ad=%#jx]\n",
+ __func__, (uintmax_t)fbase, dli->dli_saddr, (uintmax_t)me,
+ (uintmax_t)ad);
#endif
for (;;) {
if (s[mid].st_value < me)
@@ -202,14 +214,14 @@
dli->dli_saddr = (void *)s[mid].st_value;
dli->dli_sname = s[mid].st_name;
#ifdef SYMTAB_DEBUG
- fprintf(stderr, "%s: %p -> [%p, %s]\n", __func__,
- p, dli->dli_saddr, dli->dli_sname);
+ fprintf(stderr, "%s: me=%#jx -> [%#jx, %s]\n", __func__,
+ (uintmax_t)me, (uintmax_t)sd, dli->dli_sname);
#endif
}
#ifdef SYMTAB_DEBUG
else
- fprintf(stderr, "%s: %p -> [%p, ***]\n", __func__,
- p, dli->dli_saddr);
+ fprintf(stderr, "%s: %#jx -> [%#jx, ***]\n", __func__,
+ (uintmax_t)me, (uintmax_t)sd);
#endif
return 1;
}
Home |
Main Index |
Thread Index |
Old Index