Blame SOURCES/ltrace-0.7.91-arm.patch

f84355
diff --git a/ltrace-elf.c b/ltrace-elf.c
f84355
index 92b642b..6f86d56 100644
f84355
--- a/ltrace-elf.c
f84355
+++ b/ltrace-elf.c
f84355
@@ -531,6 +531,38 @@ elf_read_relocs(struct ltelf *lte, Elf_Scn *scn, GElf_Shdr *shdr,
f84355
 	return 0;
f84355
 }
f84355
 
f84355
+int
f84355
+elf_load_dynamic_entry(struct ltelf *lte, int tag, GElf_Addr *valuep)
f84355
+{
f84355
+	Elf_Scn *scn;
f84355
+	GElf_Shdr shdr;
f84355
+	if (elf_get_section_type(lte, SHT_DYNAMIC, &scn, &shdr) < 0
f84355
+	    || scn == NULL) {
f84355
+	fail:
f84355
+		fprintf(stderr, "Couldn't get SHT_DYNAMIC: %s\n",
f84355
+			elf_errmsg(-1));
f84355
+		return -1;
f84355
+	}
f84355
+
f84355
+	Elf_Data *data = elf_loaddata(scn, &shdr);
f84355
+	if (data == NULL)
f84355
+		goto fail;
f84355
+
f84355
+	size_t j;
f84355
+	for (j = 0; j < shdr.sh_size / shdr.sh_entsize; ++j) {
f84355
+		GElf_Dyn dyn;
f84355
+		if (gelf_getdyn(data, j, &dyn) == NULL)
f84355
+			goto fail;
f84355
+
f84355
+		if(dyn.d_tag == tag) {
f84355
+			*valuep = dyn.d_un.d_ptr;
f84355
+			return 0;
f84355
+		}
f84355
+	}
f84355
+
f84355
+	return -1;
f84355
+}
f84355
+
f84355
 static int
f84355
 ltelf_read_elf(struct ltelf *lte, const char *filename)
f84355
 {
f84355
diff --git a/ltrace-elf.h b/ltrace-elf.h
f84355
index ea14512..db4ffe9 100644
f84355
--- a/ltrace-elf.h
f84355
+++ b/ltrace-elf.h
f84355
@@ -139,6 +139,10 @@ struct elf_each_symbol_t {
f84355
 int elf_read_relocs(struct ltelf *lte, Elf_Scn *scn, GElf_Shdr *shdr,
f84355
 		    struct vect *rela_vec);
f84355
 
f84355
+/* Read a given DT_ TAG from LTE.  Value is returned in *VALUEP.
f84355
+ * Returns 0 on success or a negative value on failure.  */
f84355
+int elf_load_dynamic_entry(struct ltelf *lte, int tag, GElf_Addr *valuep);
f84355
+
f84355
 /* Read, respectively, 1, 2, 4, or 8 bytes from Elf data at given
f84355
  * OFFSET, and store it in *RETP.  Returns 0 on success or a negative
f84355
  * value if there's not enough data.  */
f84355
diff --git a/sysdeps/linux-gnu/arm/arch.h b/sysdeps/linux-gnu/arm/arch.h
f84355
index 58a7fdf..6d0d902 100644
f84355
--- a/sysdeps/linux-gnu/arm/arch.h
f84355
+++ b/sysdeps/linux-gnu/arm/arch.h
f84355
@@ -22,6 +22,8 @@
f84355
 #ifndef LTRACE_ARM_ARCH_H
f84355
 #define LTRACE_ARM_ARCH_H
f84355
 
f84355
+#include <libelf.h>
f84355
+
f84355
 #define ARCH_HAVE_ENABLE_BREAKPOINT 1
f84355
 #define ARCH_HAVE_DISABLE_BREAKPOINT 1
f84355
 
f84355
@@ -47,7 +49,7 @@ struct arch_breakpoint_data {
f84355
 
f84355
 #define ARCH_HAVE_LTELF_DATA
f84355
 struct arch_ltelf_data {
f84355
-	/* We have this only for the hooks.  */
f84355
+	Elf_Data *jmprel_data;
f84355
 };
f84355
 
f84355
 #define ARCH_HAVE_LIBRARY_DATA
f84355
diff --git a/sysdeps/linux-gnu/arm/fetch.c b/sysdeps/linux-gnu/arm/fetch.c
f84355
index 5081d78..b500448 100644
f84355
--- a/sysdeps/linux-gnu/arm/fetch.c
f84355
+++ b/sysdeps/linux-gnu/arm/fetch.c
f84355
@@ -32,200 +32,12 @@
f84355
 #include "backend.h"
f84355
 #include "fetch.h"
f84355
 #include "library.h"
f84355
-#include "ltrace-elf.h"
f84355
 #include "proc.h"
f84355
 #include "ptrace.h"
f84355
 #include "regs.h"
f84355
 #include "type.h"
f84355
 #include "value.h"
f84355
 
f84355
-static int
f84355
-get_hardfp(uint64_t abi_vfp_args)
f84355
-{
f84355
-	if (abi_vfp_args == 2)
f84355
-		fprintf(stderr,
f84355
-			"Tag_ABI_VFP_args value 2 (tool chain-specific "
f84355
-			"conventions) not supported.\n");
f84355
-	return abi_vfp_args == 1;
f84355
-}
f84355
-
f84355
-int
f84355
-arch_elf_init(struct ltelf *lte, struct library *lib)
f84355
-{
f84355
-	/* Nothing in this section is strictly critical.  It's not
f84355
-	 * that much of a deal if we fail to guess right whether the
f84355
-	 * ABI is softfp or hardfp.  */
f84355
-	unsigned hardfp = 0;
f84355
-
f84355
-	Elf_Scn *scn;
f84355
-	Elf_Data *data;
f84355
-	GElf_Shdr shdr;
f84355
-	if (elf_get_section_type(lte, SHT_ARM_ATTRIBUTES, &scn, &shdr) < 0
f84355
-	    || (scn != NULL && (data = elf_loaddata(scn, &shdr)) == NULL)) {
f84355
-		fprintf(stderr,
f84355
-			"Error when obtaining ARM attribute section: %s\n",
f84355
-			elf_errmsg(-1));
f84355
-		goto done;
f84355
-
f84355
-	} else if (scn != NULL && data != NULL) {
f84355
-		GElf_Xword offset = 0;
f84355
-		uint8_t version;
f84355
-		if (elf_read_next_u8(data, &offset, &version) < 0) {
f84355
-			goto done;
f84355
-		} else if (version != 'A') {
f84355
-			fprintf(stderr, "Unsupported ARM attribute section "
f84355
-				"version %d ('%c').\n", version, version);
f84355
-			goto done;
f84355
-		}
f84355
-
f84355
-		do {
f84355
-			const char signature[] = "aeabi";
f84355
-			/* N.B. LEN is including the length field
f84355
-			 * itself.  */
f84355
-			uint32_t sec_len;
f84355
-			if (elf_read_u32(data, offset, &sec_len) < 0
f84355
-			    || !elf_can_read_next(data, offset, sec_len)) {
f84355
-				goto done;
f84355
-			}
f84355
-			const GElf_Xword next_offset = offset + sec_len;
f84355
-			offset += 4;
f84355
-
f84355
-			if (sec_len < 4 + sizeof signature
f84355
-			    || strcmp(signature, data->d_buf + offset) != 0)
f84355
-				goto skip;
f84355
-			offset += sizeof signature;
f84355
-
f84355
-			const GElf_Xword offset0 = offset;
f84355
-			uint64_t tag;
f84355
-			uint32_t sub_len;
f84355
-			if (elf_read_next_uleb128(data, &offset, &tag) < 0
f84355
-			    || elf_read_next_u32(data, &offset, &sub_len) < 0
f84355
-			    || !elf_can_read_next(data, offset0, sub_len))
f84355
-				goto done;
f84355
-
f84355
-			if (tag != 1)
f84355
-				/* IHI0045D_ABI_addenda: "section and
f84355
-				 * symbol attributes are deprecated
f84355
-				 * [...] consumers are permitted to
f84355
-				 * ignore them."  */
f84355
-				goto skip;
f84355
-
f84355
-			while (offset < offset0 + sub_len) {
f84355
-				if (elf_read_next_uleb128(data,
f84355
-							  &offset, &tag) < 0)
f84355
-					goto done;
f84355
-
f84355
-				switch (tag) {
f84355
-					uint64_t v;
f84355
-				case 6: /* Tag_CPU_arch */
f84355
-				case 7: /* Tag_CPU_arch_profile */
f84355
-				case 8: /* Tag_ARM_ISA_use */
f84355
-				case 9: /* Tag_THUMB_ISA_use */
f84355
-				case 10: /* Tag_FP_arch */
f84355
-				case 11: /* Tag_WMMX_arch */
f84355
-				case 12: /* Tag_Advanced_SIMD_arch */
f84355
-				case 13: /* Tag_PCS_config */
f84355
-				case 14: /* Tag_ABI_PCS_R9_use */
f84355
-				case 15: /* Tag_ABI_PCS_RW_data */
f84355
-				case 16: /* Tag_ABI_PCS_RO_data */
f84355
-				case 17: /* Tag_ABI_PCS_GOT_use */
f84355
-				case 18: /* Tag_ABI_PCS_wchar_t */
f84355
-				case 19: /* Tag_ABI_FP_rounding */
f84355
-				case 20: /* Tag_ABI_FP_denormal */
f84355
-				case 21: /* Tag_ABI_FP_exceptions */
f84355
-				case 22: /* Tag_ABI_FP_user_exceptions */
f84355
-				case 23: /* Tag_ABI_FP_number_model */
f84355
-				case 24: /* Tag_ABI_align_needed */
f84355
-				case 25: /* Tag_ABI_align_preserved */
f84355
-				case 26: /* Tag_ABI_enum_size */
f84355
-				case 27: /* Tag_ABI_HardFP_use */
f84355
-				case 28: /* Tag_ABI_VFP_args */
f84355
-				case 29: /* Tag_ABI_WMMX_args */
f84355
-				case 30: /* Tag_ABI_optimization_goals */
f84355
-				case 31: /* Tag_ABI_FP_optimization_goals */
f84355
-				case 32: /* Tag_compatibility */
f84355
-				case 34: /* Tag_CPU_unaligned_access */
f84355
-				case 36: /* Tag_FP_HP_extension */
f84355
-				case 38: /* Tag_ABI_FP_16bit_format */
f84355
-				case 42: /* Tag_MPextension_use */
f84355
-				case 70: /* Tag_MPextension_use as well */
f84355
-				case 44: /* Tag_DIV_use */
f84355
-				case 64: /* Tag_nodefaults */
f84355
-				case 66: /* Tag_T2EE_use */
f84355
-				case 68: /* Tag_Virtualization_use */
f84355
-				uleb128:
f84355
-					if (elf_read_next_uleb128
f84355
-						(data, &offset, &v) < 0)
f84355
-						goto done;
f84355
-					if (tag == 28)
f84355
-						hardfp = get_hardfp(v);
f84355
-					if (tag != 32)
f84355
-						continue;
f84355
-
f84355
-					/* Tag 32 has two arguments,
f84355
-					 * fall through.  */
f84355
-
f84355
-				case 4:	/* Tag_CPU_raw_name */
f84355
-				case 5:	/* Tag_CPU_name */
f84355
-				case 65: /* Tag_also_compatible_with */
f84355
-				case 67: /* Tag_conformance */
f84355
-				ntbs:
f84355
-					offset += strlen(data->d_buf
f84355
-							 + offset) + 1;
f84355
-					continue;
f84355
-				}
f84355
-
f84355
-				/* Handle unknown tags in a generic
f84355
-				 * manner, if possible.  */
f84355
-				if (tag <= 32) {
f84355
-					fprintf(stderr,
f84355
-						"Unknown tag %lld "
f84355
-						"at offset %#llx "
f84355
-						"of ARM attribute section.",
f84355
-						tag, offset);
f84355
-					goto skip;
f84355
-				} else if (tag % 2 == 0) {
f84355
-					goto uleb128;
f84355
-				} else {
f84355
-					goto ntbs;
f84355
-				}
f84355
-			}
f84355
-
f84355
-		skip:
f84355
-			offset = next_offset;
f84355
-
f84355
-		} while (elf_can_read_next(data, offset, 1));
f84355
-
f84355
-	}
f84355
-
f84355
-done:
f84355
-	lib->arch.hardfp = hardfp;
f84355
-	return 0;
f84355
-}
f84355
-
f84355
-void
f84355
-arch_elf_destroy(struct ltelf *lte)
f84355
-{
f84355
-}
f84355
-
f84355
-int
f84355
-arch_library_init(struct library *lib)
f84355
-{
f84355
-	return 0;
f84355
-}
f84355
-
f84355
-void
f84355
-arch_library_destroy(struct library *lib)
f84355
-{
f84355
-}
f84355
-
f84355
-int
f84355
-arch_library_clone(struct library *retp, struct library *lib)
f84355
-{
f84355
-	retp->arch = lib->arch;
f84355
-	return 0;
f84355
-}
f84355
-
f84355
 enum {
f84355
 	/* How many (double) VFP registers the AAPCS uses for
f84355
 	 * parameter passing.  */
f84355
diff --git a/sysdeps/linux-gnu/arm/plt.c b/sysdeps/linux-gnu/arm/plt.c
f84355
index d1bf7ca..9e9e37f 100644
f84355
--- a/sysdeps/linux-gnu/arm/plt.c
f84355
+++ b/sysdeps/linux-gnu/arm/plt.c
f84355
@@ -1,5 +1,6 @@
f84355
 /*
f84355
  * This file is part of ltrace.
f84355
+ * Copyright (C) 2013 Petr Machata, Red Hat Inc.
f84355
  * Copyright (C) 2010 Zach Welch, CodeSourcery
f84355
  * Copyright (C) 2004,2008,2009 Juan Cespedes
f84355
  *
f84355
@@ -20,20 +21,205 @@
f84355
  */
f84355
 
f84355
 #include <gelf.h>
f84355
+#include <stdio.h>
f84355
+#include <string.h>
f84355
 
f84355
 #include "proc.h"
f84355
 #include "library.h"
f84355
 #include "ltrace-elf.h"
f84355
 
f84355
 static int
f84355
+get_hardfp(uint64_t abi_vfp_args)
f84355
+{
f84355
+	if (abi_vfp_args == 2)
f84355
+		fprintf(stderr,
f84355
+			"Tag_ABI_VFP_args value 2 (tool chain-specific "
f84355
+			"conventions) not supported.\n");
f84355
+	return abi_vfp_args == 1;
f84355
+}
f84355
+
f84355
+int
f84355
+arch_elf_init(struct ltelf *lte, struct library *lib)
f84355
+{
f84355
+	GElf_Addr jmprel_addr;
f84355
+	Elf_Scn *jmprel_sec;
f84355
+	GElf_Shdr jmprel_shdr;
f84355
+	if (elf_load_dynamic_entry(lte, DT_JMPREL, &jmprel_addr) < 0
f84355
+	    || elf_get_section_covering(lte, jmprel_addr,
f84355
+					&jmprel_sec, &jmprel_shdr) < 0
f84355
+	    || jmprel_sec == NULL)
f84355
+		return -1;
f84355
+
f84355
+	lte->arch.jmprel_data = elf_loaddata(jmprel_sec, &jmprel_shdr);
f84355
+	if (lte->arch.jmprel_data == NULL)
f84355
+		return -1;
f84355
+
f84355
+	/* Nothing in this section is strictly critical.  It's not
f84355
+	 * that much of a deal if we fail to guess right whether the
f84355
+	 * ABI is softfp or hardfp.  */
f84355
+	unsigned hardfp = 0;
f84355
+
f84355
+	Elf_Scn *scn;
f84355
+	Elf_Data *data;
f84355
+	GElf_Shdr shdr;
f84355
+	if (elf_get_section_type(lte, SHT_ARM_ATTRIBUTES, &scn, &shdr) < 0
f84355
+	    || (scn != NULL && (data = elf_loaddata(scn, &shdr)) == NULL)) {
f84355
+		fprintf(stderr,
f84355
+			"Error when obtaining ARM attribute section: %s\n",
f84355
+			elf_errmsg(-1));
f84355
+		goto done;
f84355
+
f84355
+	} else if (scn != NULL && data != NULL) {
f84355
+		GElf_Xword offset = 0;
f84355
+		uint8_t version;
f84355
+		if (elf_read_next_u8(data, &offset, &version) < 0) {
f84355
+			goto done;
f84355
+		} else if (version != 'A') {
f84355
+			fprintf(stderr, "Unsupported ARM attribute section "
f84355
+				"version %d ('%c').\n", version, version);
f84355
+			goto done;
f84355
+		}
f84355
+
f84355
+		do {
f84355
+			const char signature[] = "aeabi";
f84355
+			/* N.B. LEN is including the length field
f84355
+			 * itself.  */
f84355
+			uint32_t sec_len;
f84355
+			if (elf_read_u32(data, offset, &sec_len) < 0
f84355
+			    || !elf_can_read_next(data, offset, sec_len)) {
f84355
+				goto done;
f84355
+			}
f84355
+			const GElf_Xword next_offset = offset + sec_len;
f84355
+			offset += 4;
f84355
+
f84355
+			if (sec_len < 4 + sizeof signature
f84355
+			    || strcmp(signature, data->d_buf + offset) != 0)
f84355
+				goto skip;
f84355
+			offset += sizeof signature;
f84355
+
f84355
+			const GElf_Xword offset0 = offset;
f84355
+			uint64_t tag;
f84355
+			uint32_t sub_len;
f84355
+			if (elf_read_next_uleb128(data, &offset, &tag) < 0
f84355
+			    || elf_read_next_u32(data, &offset, &sub_len) < 0
f84355
+			    || !elf_can_read_next(data, offset0, sub_len))
f84355
+				goto done;
f84355
+
f84355
+			if (tag != 1)
f84355
+				/* IHI0045D_ABI_addenda: "section and
f84355
+				 * symbol attributes are deprecated
f84355
+				 * [...] consumers are permitted to
f84355
+				 * ignore them."  */
f84355
+				goto skip;
f84355
+
f84355
+			while (offset < offset0 + sub_len) {
f84355
+				if (elf_read_next_uleb128(data,
f84355
+							  &offset, &tag) < 0)
f84355
+					goto done;
f84355
+
f84355
+				switch (tag) {
f84355
+					uint64_t v;
f84355
+				case 6: /* Tag_CPU_arch */
f84355
+				case 7: /* Tag_CPU_arch_profile */
f84355
+				case 8: /* Tag_ARM_ISA_use */
f84355
+				case 9: /* Tag_THUMB_ISA_use */
f84355
+				case 10: /* Tag_FP_arch */
f84355
+				case 11: /* Tag_WMMX_arch */
f84355
+				case 12: /* Tag_Advanced_SIMD_arch */
f84355
+				case 13: /* Tag_PCS_config */
f84355
+				case 14: /* Tag_ABI_PCS_R9_use */
f84355
+				case 15: /* Tag_ABI_PCS_RW_data */
f84355
+				case 16: /* Tag_ABI_PCS_RO_data */
f84355
+				case 17: /* Tag_ABI_PCS_GOT_use */
f84355
+				case 18: /* Tag_ABI_PCS_wchar_t */
f84355
+				case 19: /* Tag_ABI_FP_rounding */
f84355
+				case 20: /* Tag_ABI_FP_denormal */
f84355
+				case 21: /* Tag_ABI_FP_exceptions */
f84355
+				case 22: /* Tag_ABI_FP_user_exceptions */
f84355
+				case 23: /* Tag_ABI_FP_number_model */
f84355
+				case 24: /* Tag_ABI_align_needed */
f84355
+				case 25: /* Tag_ABI_align_preserved */
f84355
+				case 26: /* Tag_ABI_enum_size */
f84355
+				case 27: /* Tag_ABI_HardFP_use */
f84355
+				case 28: /* Tag_ABI_VFP_args */
f84355
+				case 29: /* Tag_ABI_WMMX_args */
f84355
+				case 30: /* Tag_ABI_optimization_goals */
f84355
+				case 31: /* Tag_ABI_FP_optimization_goals */
f84355
+				case 32: /* Tag_compatibility */
f84355
+				case 34: /* Tag_CPU_unaligned_access */
f84355
+				case 36: /* Tag_FP_HP_extension */
f84355
+				case 38: /* Tag_ABI_FP_16bit_format */
f84355
+				case 42: /* Tag_MPextension_use */
f84355
+				case 70: /* Tag_MPextension_use as well */
f84355
+				case 44: /* Tag_DIV_use */
f84355
+				case 64: /* Tag_nodefaults */
f84355
+				case 66: /* Tag_T2EE_use */
f84355
+				case 68: /* Tag_Virtualization_use */
f84355
+				uleb128:
f84355
+					if (elf_read_next_uleb128
f84355
+						(data, &offset, &v) < 0)
f84355
+						goto done;
f84355
+					if (tag == 28)
f84355
+						hardfp = get_hardfp(v);
f84355
+					if (tag != 32)
f84355
+						continue;
f84355
+
f84355
+					/* Tag 32 has two arguments,
f84355
+					 * fall through.  */
f84355
+
f84355
+				case 4:	/* Tag_CPU_raw_name */
f84355
+				case 5:	/* Tag_CPU_name */
f84355
+				case 65: /* Tag_also_compatible_with */
f84355
+				case 67: /* Tag_conformance */
f84355
+				ntbs:
f84355
+					offset += strlen(data->d_buf
f84355
+							 + offset) + 1;
f84355
+					continue;
f84355
+				}
f84355
+
f84355
+				/* Handle unknown tags in a generic
f84355
+				 * manner, if possible.  */
f84355
+				if (tag <= 32) {
f84355
+					fprintf(stderr,
f84355
+						"Unknown tag %lld "
f84355
+						"at offset %#llx "
f84355
+						"of ARM attribute section.",
f84355
+						tag, offset);
f84355
+					goto skip;
f84355
+				} else if (tag % 2 == 0) {
f84355
+					goto uleb128;
f84355
+				} else {
f84355
+					goto ntbs;
f84355
+				}
f84355
+			}
f84355
+
f84355
+		skip:
f84355
+			offset = next_offset;
f84355
+
f84355
+		} while (elf_can_read_next(data, offset, 1));
f84355
+
f84355
+	}
f84355
+
f84355
+done:
f84355
+	lib->arch.hardfp = hardfp;
f84355
+	return 0;
f84355
+}
f84355
+
f84355
+void
f84355
+arch_elf_destroy(struct ltelf *lte)
f84355
+{
f84355
+}
f84355
+
f84355
+static int
f84355
 arch_plt_entry_has_stub(struct ltelf *lte, size_t off) {
f84355
-	uint16_t op = *(uint16_t *)((char *)lte->relplt->d_buf + off);
f84355
+	char *buf = (char *) lte->arch.jmprel_data->d_buf;
f84355
+	uint16_t op = *(uint16_t *) (buf + off);
f84355
 	return op == 0x4778;
f84355
 }
f84355
 
f84355
 GElf_Addr
f84355
 arch_plt_sym_val(struct ltelf *lte, size_t ndx, GElf_Rela * rela) {
f84355
-	size_t start = lte->relplt->d_size + 12;
f84355
+	size_t start = lte->arch.jmprel_data->d_size + 12;
f84355
 	size_t off = start + 20, i;
f84355
 	for (i = 0; i < ndx; i++)
f84355
 		off += arch_plt_entry_has_stub(lte, off) ? 16 : 12;
f84355
@@ -47,3 +233,21 @@ sym2addr(struct process *proc, struct library_symbol *sym)
f84355
 {
f84355
 	return sym->enter_addr;
f84355
 }
f84355
+
f84355
+int
f84355
+arch_library_init(struct library *lib)
f84355
+{
f84355
+	return 0;
f84355
+}
f84355
+
f84355
+void
f84355
+arch_library_destroy(struct library *lib)
f84355
+{
f84355
+}
f84355
+
f84355
+int
f84355
+arch_library_clone(struct library *retp, struct library *lib)
f84355
+{
f84355
+	retp->arch = lib->arch;
f84355
+	return 0;
f84355
+}
f84355
diff --git a/sysdeps/linux-gnu/ppc/plt.c b/sysdeps/linux-gnu/ppc/plt.c
f84355
index 5e3ffe1..3ec1397 100644
f84355
--- a/sysdeps/linux-gnu/ppc/plt.c
f84355
+++ b/sysdeps/linux-gnu/ppc/plt.c
f84355
@@ -402,38 +402,6 @@ get_glink_vma(struct ltelf *lte, GElf_Addr ppcgot, Elf_Data *plt_data)
f84355
 }
f84355
 
f84355
 static int
f84355
-load_dynamic_entry(struct ltelf *lte, int tag, GElf_Addr *valuep)
f84355
-{
f84355
-	Elf_Scn *scn;
f84355
-	GElf_Shdr shdr;
f84355
-	if (elf_get_section_type(lte, SHT_DYNAMIC, &scn, &shdr) < 0
f84355
-	    || scn == NULL) {
f84355
-	fail:
f84355
-		fprintf(stderr, "Couldn't get SHT_DYNAMIC: %s\n",
f84355
-			elf_errmsg(-1));
f84355
-		return -1;
f84355
-	}
f84355
-
f84355
-	Elf_Data *data = elf_loaddata(scn, &shdr);
f84355
-	if (data == NULL)
f84355
-		goto fail;
f84355
-
f84355
-	size_t j;
f84355
-	for (j = 0; j < shdr.sh_size / shdr.sh_entsize; ++j) {
f84355
-		GElf_Dyn dyn;
f84355
-		if (gelf_getdyn(data, j, &dyn) == NULL)
f84355
-			goto fail;
f84355
-
f84355
-		if(dyn.d_tag == tag) {
f84355
-			*valuep = dyn.d_un.d_ptr;
f84355
-			return 0;
f84355
-		}
f84355
-	}
f84355
-
f84355
-	return -1;
f84355
-}
f84355
-
f84355
-static int
f84355
 nonzero_data(Elf_Data *data)
f84355
 {
f84355
 	/* We are not supposed to get here if there's no PLT.  */
f84355
@@ -488,8 +456,8 @@ arch_elf_init(struct ltelf *lte, struct library *lib)
f84355
 	Elf_Scn *rela_sec;
f84355
 	GElf_Shdr rela_shdr;
f84355
 	if ((lte->ehdr.e_machine == EM_PPC64 || lte->arch.secure_plt)
f84355
-	    && load_dynamic_entry(lte, DT_RELA, &rela) == 0
f84355
-	    && load_dynamic_entry(lte, DT_RELASZ, &relasz) == 0
f84355
+	    && elf_load_dynamic_entry(lte, DT_RELA, &rela) == 0
f84355
+	    && elf_load_dynamic_entry(lte, DT_RELASZ, &relasz) == 0
f84355
 	    && elf_get_section_covering(lte, rela, &rela_sec, &rela_shdr) == 0
f84355
 	    && rela_sec != NULL) {
f84355
 
f84355
@@ -509,7 +477,7 @@ arch_elf_init(struct ltelf *lte, struct library *lib)
f84355
 
f84355
 	if (lte->ehdr.e_machine == EM_PPC && lte->arch.secure_plt) {
f84355
 		GElf_Addr ppcgot;
f84355
-		if (load_dynamic_entry(lte, DT_PPC_GOT, &ppcgot) < 0) {
f84355
+		if (elf_load_dynamic_entry(lte, DT_PPC_GOT, &ppcgot) < 0) {
f84355
 			fprintf(stderr, "couldn't find DT_PPC_GOT\n");
f84355
 			return -1;
f84355
 		}
f84355
@@ -522,7 +490,8 @@ arch_elf_init(struct ltelf *lte, struct library *lib)
f84355
 
f84355
 	} else if (lte->ehdr.e_machine == EM_PPC64) {
f84355
 		GElf_Addr glink_vma;
f84355
-		if (load_dynamic_entry(lte, DT_PPC64_GLINK, &glink_vma) < 0) {
f84355
+		if (elf_load_dynamic_entry(lte, DT_PPC64_GLINK,
f84355
+					   &glink_vma) < 0) {
f84355
 			fprintf(stderr, "couldn't find DT_PPC64_GLINK\n");
f84355
 			return -1;
f84355
 		}
f84355
@@ -532,8 +501,8 @@ arch_elf_init(struct ltelf *lte, struct library *lib)
f84355
 
f84355
 	} else {
f84355
 		/* By exhaustion--PPC32 BSS.  */
f84355
-		if (load_dynamic_entry(lte, DT_PLTGOT,
f84355
-				       &lib->arch.pltgot_addr) < 0) {
f84355
+		if (elf_load_dynamic_entry(lte, DT_PLTGOT,
f84355
+					   &lib->arch.pltgot_addr) < 0) {
f84355
 			fprintf(stderr, "couldn't find DT_PLTGOT\n");
f84355
 			return -1;
f84355
 		}