summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorart <art@openbsd.org>2003-06-01 16:19:00 +0000
committerart <art@openbsd.org>2003-06-01 16:19:00 +0000
commite66861089bb2ed9a51cf1e78c11ff1a7ff12c17f (patch)
tree250650fa73e38865c5264a24e18e20f3011a3536
parentvarious format string cleanups; tedu ok (diff)
downloadwireguard-openbsd-e66861089bb2ed9a51cf1e78c11ff1a7ff12c17f.tar.xz
wireguard-openbsd-e66861089bb2ed9a51cf1e78c11ff1a7ff12c17f.zip
When searching for the symbol table and string table we were looking
for ".symtab" and ".strtab" in the section names. Instead of doing that, look for section type SHT_SYMTAB for the symbol table and follow the link in sh_link to find the corresponding string table. This is a more correct way of doing things and will work better when the toolchain doesn't generate ".symtab" and ".strtab" names and it will work when there are multiple symbol tables. noone objected to this diff for at least a week.
-rw-r--r--sys/ddb/db_elf.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/sys/ddb/db_elf.c b/sys/ddb/db_elf.c
index bcdc8dc0aa0..16ff6d43a21 100644
--- a/sys/ddb/db_elf.c
+++ b/sys/ddb/db_elf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: db_elf.c,v 1.5 2002/03/14 03:16:03 millert Exp $ */
+/* $OpenBSD: db_elf.c,v 1.6 2003/06/01 16:19:00 art Exp $ */
/* $NetBSD: db_elf.c,v 1.13 2000/07/07 21:55:18 jhawk Exp $ */
/*-
@@ -158,6 +158,28 @@ db_elf_sym_init(symsize, symtab, esymtab, name)
shp = (Elf_Shdr *)((char *)symtab + elf->e_shoff);
shstrtab = (char *)symtab + shp[elf->e_shstrndx].sh_offset;
for (i = 0; i < elf->e_shnum; i++) {
+ if (shp[i].sh_type == SHT_SYMTAB) {
+ int j;
+
+ if (shp[i].sh_offset == 0)
+ continue;
+ symtab_start = (Elf_Sym *)((char *)symtab +
+ shp[i].sh_offset);
+ symtab_end = (Elf_Sym *)((char *)symtab +
+ shp[i].sh_offset + shp[i].sh_size);
+ j = shp[i].sh_link;
+ if (shp[j].sh_offset == 0)
+ continue;
+ strtab_start = (char *)symtab + shp[j].sh_offset;
+ strtab_end = (char *)symtab + shp[j].sh_offset +
+ shp[j].sh_size;
+ break;
+ }
+
+ /*
+ * This is the old way of doing things.
+ * XXX - verify that it's not needed.
+ */
if (strcmp(".strtab", shstrtab+shp[i].sh_name) == 0) {
strtab_start = (char *)symtab + shp[i].sh_offset;
strtab_end = (char *)symtab + shp[i].sh_offset +
@@ -218,6 +240,8 @@ db_elf_find_strtab(stab)
shstrtab = (char *)elf + shp[elf->e_shstrndx].sh_offset;
for (i = 0; i < elf->e_shnum; i++) {
+ if (shp[i].sh_type == SHT_SYMTAB)
+ return ((char *)elf + shp[shp[i].sh_link].sh_offset);
if (strcmp(".strtab", shstrtab+shp[i].sh_name) == 0)
return ((char *)elf + shp[i].sh_offset);
}