Blame SOURCES/ltrace-0.7.91-arm.patch

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