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