elf_get_section_* should return 0 if section wasn't found
Otherwise it won't be possible to differentiate between an error and
not-found condition. It seems some callers (MIPS, PPC backends) already
count on that behavior anyway.
diff --git a/ltrace-elf.c b/ltrace-elf.c
index 7de9155..aff585e 100644
--- a/ltrace-elf.c
+++ b/ltrace-elf.c
@@ -141,8 +141,9 @@
return 0;
}
}
- return -1;
+ *tgt_sec = NULL;
+ return 0;
}
static int
diff --git a/ltrace-elf.h b/ltrace-elf.h
index b76d1eb..ab599eb 100644
--- a/ltrace-elf.h
+++ b/ltrace-elf.h
@@ -1,6 +1,6 @@
/*
* This file is part of ltrace.
- * Copyright (C) 2006,2010,2012 Petr Machata, Red Hat Inc.
+ * Copyright (C) 2006,2010,2012,2013 Petr Machata, Red Hat Inc.
* Copyright (C) 2010 Zachary T Welch
* Copyright (C) 2001,2004,2007,2009 Juan Cespedes
* Copyright (C) 2006 Ian Wienand
@@ -95,6 +95,12 @@
size_t sym_index, GElf_Rela *rela, GElf_Sym *sym);
Elf_Data *elf_loaddata(Elf_Scn *scn, GElf_Shdr *shdr);
+
+/* The following three look for sections based on various criteria.
+ * They return 0 if there was no error, or a negative value if there
+ * was. If the section was found, it is returned in *TGT_SEC, and the
+ * header is stored te TGT_SHDR. If it wasn't found, *TGT_SEC is set
+ * to NULL. */
int elf_get_section_covering(struct ltelf *lte, GElf_Addr addr,
Elf_Scn **tgt_sec, GElf_Shdr *tgt_shdr);
int elf_get_section_type(struct ltelf *lte, GElf_Word type,
diff --git a/sysdeps/linux-gnu/ppc/plt.c b/sysdeps/linux-gnu/ppc/plt.c
index 439b8e8..fe1602a 100644
--- a/sysdeps/linux-gnu/ppc/plt.c
+++ b/sysdeps/linux-gnu/ppc/plt.c
@@ -262,7 +262,8 @@
{
Elf_Scn *sec;
GElf_Shdr shdr;
- if (elf_get_section_named(lte, ".opd", &sec, &shdr) < 0) {
+ if (elf_get_section_named(lte, ".opd", &sec, &shdr) < 0
+ || sec == NULL) {
fail:
fprintf(stderr, "couldn't find .opd data\n");
return -1;
@@ -290,8 +291,9 @@
Elf_Scn *ppcgot_sec = NULL;
GElf_Shdr ppcgot_shdr;
if (ppcgot != 0
- && elf_get_section_covering(lte, ppcgot,
- &ppcgot_sec, &ppcgot_shdr) < 0)
+ && (elf_get_section_covering(lte, ppcgot,
+ &ppcgot_sec, &ppcgot_shdr) < 0
+ || ppcgot_sec == NULL))
fprintf(stderr,
"DT_PPC_GOT=%#"PRIx64", but no such section found\n",
ppcgot);