[Ltrace-devel] [PATCH 3/4] Fix ARM PLT lookups.

Zachary T Welch zwelch at codesourcery.com
Fri Oct 8 18:47:50 UTC 2010


An ARM PLT may not contain fixed-length records, because Thumb stubs may
be added to provide interworking.  These changes ensure the breakpoint
gets set on the ARM portion of PLT entries while skipping any Thumb
stubs that may be present.  This patch makes the testsuite work when
built for ARMv7a and Thumb-2.

Signed-off-by: Zachary T Welch <zwelch at codesourcery.com>
---
 ChangeLog                   |    4 ++++
 sysdeps/linux-gnu/arm/plt.c |   15 ++++++++++++++-
 2 files changed, 18 insertions(+), 1 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index d93acc2..526e5f2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2010-10-08  Zach Welch <zwelch at codesourcery.com>
+
+	* Allow ARM PLT lookups to work when containing Thumb stubs.
+
 2010-10-07  Zach Welch <zwelch at codesourcery.com>
 
 	* Improve breakpoint insertion to work with Thumb procedures.
diff --git a/sysdeps/linux-gnu/arm/plt.c b/sysdeps/linux-gnu/arm/plt.c
index bd92a63..9763439 100644
--- a/sysdeps/linux-gnu/arm/plt.c
+++ b/sysdeps/linux-gnu/arm/plt.c
@@ -1,9 +1,22 @@
 #include <gelf.h>
 #include "common.h"
+#include <sys/ptrace.h>
+
+int arch_plt_entry_has_stub(struct ltelf *lte, size_t off)
+{
+	uint16_t op = *(uint16_t *)((char *)lte->relplt->d_buf + off);
+	return op == 0x4778;
+}
 
 GElf_Addr
 arch_plt_sym_val(struct ltelf *lte, size_t ndx, GElf_Rela * rela) {
-	return lte->plt_addr + 20 + ndx * 12;
+	size_t start = lte->relplt->d_size + 12;
+	size_t off = start + 20, i;
+	for (i = 0; i < ndx; i++)
+		off += arch_plt_entry_has_stub(lte, off) ? 16 : 12;
+	if (arch_plt_entry_has_stub(lte, off))
+		off += 4;
+	return lte->plt_addr + off - start;
 }
 
 void *
-- 
1.7.2.2




More information about the Ltrace-devel mailing list