[DynInst_API:] [PATCH 1/2] dyninstAPI: Let image::findMain inspect PIE too


Date: Tue, 14 Jan 2014 14:20:21 -0800
From: Josh Stone <jistone@xxxxxxxxxx>
Subject: [DynInst_API:] [PATCH 1/2] dyninstAPI: Let image::findMain inspect PIE too
Position-independent executables (PIE) are generally indistinguishable
from any other shared object, but we still need to find main() in these
when they're stripped.  One clue is the presence of INTERP, which PIEs
will always have.  (Some DSOs also have INTERP, but this is rare.)
---
 dyninstAPI/src/image.C | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/dyninstAPI/src/image.C b/dyninstAPI/src/image.C
index 66c41995da31..96edd3a83ff9 100644
--- a/dyninstAPI/src/image.C
+++ b/dyninstAPI/src/image.C
@@ -362,7 +362,10 @@ void image::findMain()
 #if defined(ppc32_linux) || defined(ppc32_bgp)
     using namespace Dyninst::InstructionAPI;
 
-    if(!desc_.isSharedObject())
+    // Only look for main in executables, but do allow position-independent
+    // executables (PIE) which look like shared objects with an INTERP.
+    // (Some strange DSOs also have INTERP, but this is rare.)
+    if(!desc_.isSharedObject() || linkedFile->getInterpreterName() != NULL)
     {
     	bool foundMain = false;
     	bool foundStart = false;
@@ -445,7 +448,10 @@ void image::findMain()
 || defined(i386_unknown_solaris2_5) \
 || (defined(os_freebsd) \
     && (defined(arch_x86) || defined(arch_x86_64)))
-    if(!desc_.isSharedObject())
+    // Only look for main in executables, but do allow position-independent
+    // executables (PIE) which look like shared objects with an INTERP.
+    // (Some strange DSOs also have INTERP, but this is rare.)
+    if(!desc_.isSharedObject() || linkedFile->getInterpreterName() != NULL)
     {
     	bool foundMain = false;
     	bool foundStart = false;
-- 
1.8.4.2

[← Prev in Thread] Current Thread [Next in Thread→]