[Lldb-commits] [lldb] r127218 - in /lldb/trunk/source/Plugins: DynamicLoader/Linux-DYLD/DynamicLoaderLinuxDYLD.cpp ObjectFile/ELF/ObjectFileELF.cpp

Stephen Wilson wilsons at start.ca
Mon Mar 7 20:12:15 PST 2011


Author: wilsons
Date: Mon Mar  7 22:12:15 2011
New Revision: 127218

URL: http://llvm.org/viewvc/llvm-project?rev=127218&view=rev
Log:
Fix ObjectFileElf::GetEntryPointAddress()

ELF object files do not implicitly have a symbol named "start" as an entry
point.  For example, on Linux it is often named "_start", but can be trivially
set to any symbol by passing an --entry argument to the linker.

Use the ELF header to determine the entry point and resolve the associated
section based on that address.

Also, update the linux dynamic loader to call GetEntryPointAddress instead of
GetEntryPoint.



Modified:
    lldb/trunk/source/Plugins/DynamicLoader/Linux-DYLD/DynamicLoaderLinuxDYLD.cpp
    lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp

Modified: lldb/trunk/source/Plugins/DynamicLoader/Linux-DYLD/DynamicLoaderLinuxDYLD.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/Linux-DYLD/DynamicLoaderLinuxDYLD.cpp?rev=127218&r1=127217&r2=127218&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/Linux-DYLD/DynamicLoaderLinuxDYLD.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/Linux-DYLD/DynamicLoaderLinuxDYLD.cpp Mon Mar  7 22:12:15 2011
@@ -353,7 +353,7 @@
 
     ModuleSP module = m_process->GetTarget().GetExecutableModule();
     ObjectFile *exe = module->GetObjectFile();
-    Address file_entry = exe->GetEntryPoint();
+    Address file_entry = exe->GetEntryPointAddress();
 
     if (!file_entry.IsValid())
         return LLDB_INVALID_ADDRESS;

Modified: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp?rev=127218&r1=127217&r2=127218&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp Mon Mar  7 22:12:15 2011
@@ -272,27 +272,27 @@
 lldb_private::Address
 ObjectFileELF::GetEntryPointAddress () 
 {
-    // If the object file is not an executable it can't hold the entry point.  m_entry_point_address
-    // is initialized to an invalid address, so we can just return that.
-    // If m_entry_point_address is valid it means we've found it already, so return the cached value.
-    
-    if (!IsExecutable() || m_entry_point_address.IsValid())
+    SectionList *sections;
+    addr_t offset;
+
+    if (m_entry_point_address.IsValid())
         return m_entry_point_address;
-    
-    // FIXME: This is just looking for the "start" symbol, but that will fail if "start" is stripped.
-    // There's probably a better way in ELF to find the start address of an executable module.
-    
-    SymbolContextList contexts;
-    SymbolContext context;
-    if (!m_module->FindSymbolsWithNameAndType(ConstString ("start"), lldb::eSymbolTypeCode, contexts))
+
+    if (!ParseHeader() || !IsExecutable())
         return m_entry_point_address;
-    
-    contexts.GetContextAtIndex(0, context);
-    
-    m_entry_point_address = context.symbol->GetValue();
-    
-    return m_entry_point_address;
 
+    sections = GetSectionList();
+    offset = m_header.e_entry;
+
+    if (!sections) 
+    {
+        m_entry_point_address.SetOffset(offset);
+        return m_entry_point_address;
+    }
+
+    m_entry_point_address.ResolveAddressUsingFileSections(offset, sections);
+
+    return m_entry_point_address;
 }
 
 //----------------------------------------------------------------------





More information about the lldb-commits mailing list