[Lldb-commits] [lldb] r261859 - Add support for handling absolute symbols in ELF

Tamas Berghammer via lldb-commits lldb-commits at lists.llvm.org
Thu Feb 25 04:23:44 PST 2016


Author: tberghammer
Date: Thu Feb 25 06:23:43 2016
New Revision: 261859

URL: http://llvm.org/viewvc/llvm-project?rev=261859&view=rev
Log:
Add support for handling absolute symbols in ELF

Most address represented in lldb as section plus offset and handling of
absolute addresses is problematic in several location because of lack
of necessary information (e.g. Target) or because of performance issues.

This CL change the way ObjectFileELF handle the absolute symbols with
creating a pseudo section for each symbol. With this change all existing
code designed to work with addresses in the form of section plus offset
will work with absolute symbols as well.

Differential revision: http://reviews.llvm.org/D17450

Modified:
    lldb/trunk/include/lldb/lldb-enumerations.h
    lldb/trunk/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp
    lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
    lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
    lldb/trunk/source/Symbol/ObjectFile.cpp
    lldb/trunk/source/Utility/ConvertEnum.cpp

Modified: lldb/trunk/include/lldb/lldb-enumerations.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-enumerations.h?rev=261859&r1=261858&r2=261859&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-enumerations.h (original)
+++ lldb/trunk/include/lldb/lldb-enumerations.h Thu Feb 25 06:23:43 2016
@@ -622,6 +622,7 @@ namespace lldb {
         eSectionTypeARMextab,
         eSectionTypeCompactUnwind,        // compact unwind section in Mach-O, __TEXT,__unwind_info
         eSectionTypeGoSymtab,
+        eSectionTypeAbsoluteAddress,      // Dummy section for symbols with absolute address
         eSectionTypeOther
     };
 

Modified: lldb/trunk/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp?rev=261859&r1=261858&r2=261859&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp (original)
+++ lldb/trunk/source/Plugins/JITLoader/GDB/JITLoaderGDB.cpp Thu Feb 25 06:23:43 2016
@@ -340,7 +340,9 @@ JITLoaderGDB::ReadJITDescriptorImpl(bool
 
             if (module_sp && module_sp->GetObjectFile())
             {
-                bool changed;
+                // load the symbol table right away
+                module_sp->GetObjectFile()->GetSymtab();
+
                 m_jit_objects.insert(std::make_pair(symbolfile_addr, module_sp));
                 if (module_sp->GetObjectFile()->GetPluginName() == ConstString("mach-o"))
                 {
@@ -360,12 +362,10 @@ JITLoaderGDB::ReadJITDescriptorImpl(bool
                 }
                 else
                 {
+                    bool changed = false;
                     module_sp->SetLoadAddress(target, 0, true, changed);
                 }
 
-                // load the symbol table right away
-                module_sp->GetObjectFile()->GetSymtab();
-
                 module_list.AppendIfNeeded(module_sp);
 
                 ModuleList module_list;

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=261859&r1=261858&r2=261859&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp Thu Feb 25 06:23:43 2016
@@ -921,10 +921,14 @@ ObjectFileELF::SetLoadAddress (Target &t
                 // Iterate through the object file sections to find all
                 // of the sections that have SHF_ALLOC in their flag bits.
                 SectionSP section_sp (section_list->GetSectionAtIndex (sect_idx));
-                // if (section_sp && !section_sp->IsThreadSpecific())
                 if (section_sp && section_sp->Test(SHF_ALLOC))
                 {
-                    lldb::addr_t load_addr = section_sp->GetFileAddress() + value;
+                    lldb::addr_t load_addr = section_sp->GetFileAddress();
+                    // We don't want to update the load address of a section with type
+                    // eSectionTypeAbsoluteAddress as they already have the absolute load address
+                    // already specified
+                    if (section_sp->GetType() != eSectionTypeAbsoluteAddress)
+                        load_addr += value;
 
                     // On 32-bit systems the load address have to fit into 4 bytes. The rest of
                     // the bytes are the overflow from the addition.
@@ -2058,6 +2062,8 @@ ObjectFileELF::ParseSymbols (Symtab *sym
 
     ArchSpec arch;
     GetArchitecture(arch);
+    ModuleSP module_sp(GetModule());
+    SectionList* module_section_list = module_sp ? module_sp->GetSectionList() : nullptr;
 
     // Local cache to avoid doing a FindSectionByName for each symbol. The "const char*" key must
     // came from a ConstString object so they can be compared by pointer
@@ -2083,9 +2089,9 @@ ObjectFileELF::ParseSymbols (Symtab *sym
 
         SectionSP symbol_section_sp;
         SymbolType symbol_type = eSymbolTypeInvalid;
-        Elf64_Half symbol_idx = symbol.st_shndx;
+        Elf64_Half section_idx = symbol.st_shndx;
 
-        switch (symbol_idx)
+        switch (section_idx)
         {
         case SHN_ABS:
             symbol_type = eSymbolTypeAbsolute;
@@ -2094,7 +2100,7 @@ ObjectFileELF::ParseSymbols (Symtab *sym
             symbol_type = eSymbolTypeUndefined;
             break;
         default:
-            symbol_section_sp = section_list->GetSectionAtIndex(symbol_idx);
+            symbol_section_sp = section_list->GetSectionAtIndex(section_idx);
             break;
         }
 
@@ -2278,30 +2284,44 @@ ObjectFileELF::ParseSymbols (Symtab *sym
             }
         }
 
-        // symbol_value_offset may contain 0 for ARM symbols or -1 for
-        // THUMB symbols. See above for more details.
+        // symbol_value_offset may contain 0 for ARM symbols or -1 for THUMB symbols. See above for
+        // more details.
         uint64_t symbol_value = symbol.st_value + symbol_value_offset;
+
+        if (symbol_section_sp == nullptr && section_idx == SHN_ABS && symbol.st_size != 0)
+        {
+            // We don't have a section for a symbol with non-zero size. Create a new section for it
+            // so the address range covered by the symbol is also covered by the module (represented
+            // through the section list). It is needed so module lookup for the addresses covered
+            // by this symbol will be successfull. This case happens for absolute symbols.
+            ConstString fake_section_name(std::string(".absolute.") + symbol_name);
+            symbol_section_sp = std::make_shared<Section>(module_sp,
+                                                          this,
+                                                          SHN_ABS,
+                                                          fake_section_name,
+                                                          eSectionTypeAbsoluteAddress,
+                                                          symbol_value,
+                                                          symbol.st_size,
+                                                          0, 0, 0,
+                                                          SHF_ALLOC);
+
+            module_section_list->AddSection(symbol_section_sp);
+            section_list->AddSection(symbol_section_sp);
+        }
+
         if (symbol_section_sp && CalculateType() != ObjectFile::Type::eTypeObjectFile)
             symbol_value -= symbol_section_sp->GetFileAddress();
 
-        if (symbol_section_sp)
+        if (symbol_section_sp && module_section_list && module_section_list != section_list)
         {
-            ModuleSP module_sp(GetModule());
-            if (module_sp)
-            {
-                SectionList *module_section_list = module_sp->GetSectionList();
-                if (module_section_list && module_section_list != section_list)
-                {
-                    const ConstString &sect_name = symbol_section_sp->GetName();
-                    auto section_it = section_name_to_section.find(sect_name.GetCString());
-                    if (section_it == section_name_to_section.end())
-                        section_it = section_name_to_section.emplace(
-                            sect_name.GetCString(),
-                            module_section_list->FindSectionByName (sect_name)).first;
-                    if (section_it->second && section_it->second->GetFileSize())
-                        symbol_section_sp = section_it->second;
-                }
-            }
+            const ConstString &sect_name = symbol_section_sp->GetName();
+            auto section_it = section_name_to_section.find(sect_name.GetCString());
+            if (section_it == section_name_to_section.end())
+                section_it = section_name_to_section.emplace(
+                    sect_name.GetCString(),
+                    module_section_list->FindSectionByName (sect_name)).first;
+            if (section_it->second && section_it->second->GetFileSize())
+                symbol_section_sp = section_it->second;
         }
 
         bool is_global = symbol.getBinding() == STB_GLOBAL;

Modified: lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp?rev=261859&r1=261858&r2=261859&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp Thu Feb 25 06:23:43 2016
@@ -1388,6 +1388,7 @@ ObjectFileMachO::GetAddressClass (lldb::
                     case eSectionTypeCompactUnwind:
                         return eAddressClassRuntime;
 
+                    case eSectionTypeAbsoluteAddress:
                     case eSectionTypeELFSymbolTable:
                     case eSectionTypeELFDynamicSymbols:
                     case eSectionTypeELFRelocationEntries:

Modified: lldb/trunk/source/Symbol/ObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ObjectFile.cpp?rev=261859&r1=261858&r2=261859&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ObjectFile.cpp (original)
+++ lldb/trunk/source/Symbol/ObjectFile.cpp Thu Feb 25 06:23:43 2016
@@ -379,6 +379,7 @@ ObjectFile::GetAddressClass (addr_t file
                     case eSectionTypeARMextab:
                     case eSectionTypeCompactUnwind:
                         return eAddressClassRuntime;
+                    case eSectionTypeAbsoluteAddress:
                     case eSectionTypeELFSymbolTable:
                     case eSectionTypeELFDynamicSymbols:
                     case eSectionTypeELFRelocationEntries:

Modified: lldb/trunk/source/Utility/ConvertEnum.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/ConvertEnum.cpp?rev=261859&r1=261858&r2=261859&view=diff
==============================================================================
--- lldb/trunk/source/Utility/ConvertEnum.cpp (original)
+++ lldb/trunk/source/Utility/ConvertEnum.cpp Thu Feb 25 06:23:43 2016
@@ -115,6 +115,8 @@ lldb_private::GetSectionTypeAsCString(ll
             return "compact-unwind";
         case eSectionTypeGoSymtab:
             return "go-symtab";
+        case eSectionTypeAbsoluteAddress:
+            return "absolute";
         case eSectionTypeOther:
             return "regular";
     }




More information about the lldb-commits mailing list