[DynInst_API:] PATCH: have SymtabAPI properly use ELF contents to set architecture


Date: Wed, 12 Nov 2014 13:33:47 -0600
From: Bill Williams <bill@xxxxxxxxxxx>
Subject: [DynInst_API:] PATCH: have SymtabAPI properly use ELF contents to set architecture
SymtabAPI has, historically, assumed that it's opening files for the architecture it was built for (modulo 32/64 bit flipping). Per Jim's bug report from a MIC system, this is not necessarily the case.

This patch converts Object::getArch to return a Dyninst::Architecture that's actually based on the contents of an ELF file. This may cause different failures than you'd expect if you try to use Dyninst as a whole on a binary from a different architecture than your mutator, but I'm throwing it out to the list for general testing and feedback.

--
--bw

Bill Williams
Paradyn Project
bill@xxxxxxxxxxx
diff --git a/symtabAPI/src/Object-elf.C b/symtabAPI/src/Object-elf.C
index b08ecef..8fbe5ce 100644
--- a/symtabAPI/src/Object-elf.C
+++ b/symtabAPI/src/Object-elf.C
@@ -5563,19 +5563,23 @@ bool Object::getTruncateLinePaths()
 
 Dyninst::Architecture Object::getArch()
 {
-#if defined(arch_power)
-  if (getAddressWidth() == 4) {
+  switch(elfHdr->e_machine())
+  {
+  case EM_PPC:
     return Dyninst::Arch_ppc32;
-  }
-  return Dyninst::Arch_ppc64;
-#elif defined(arch_x86) || defined(arch_x86_64)
-  if (getAddressWidth() == 4) {
+  case EM_PPC64:
+    return Dyninst::Arch_ppc64;
+  case EM_386:
     return Dyninst::Arch_x86;
+  case EM_X86_64:
+    return Dyninst::Arch_x86_64;
+  case EM_ARM:
+  default:
+    return Dyninst::Arch_none;
   }
-  return Dyninst::Arch_x86_64;
-#else
-  return Arch_none;
-#endif
+  assert (0 && "default not taken!");
+  return Dyninst::Arch_none;
+  
 }
 
 Offset Object::getTOCoffset(Offset off) const {
[← Prev in Thread] Current Thread [Next in Thread→]
  • [DynInst_API:] PATCH: have SymtabAPI properly use ELF contents to set architecture, Bill Williams <=