@@ -1841,6 +1841,39 @@ class VMAddressProvider {
1841
1841
};
1842
1842
}
1843
1843
1844
+ // We have to do this because ELF doesn't have section IDs, and also
1845
+ // doesn't require section names to be unique. (We use the section index
1846
+ // for section IDs, but that isn't guaranteed to be the same in separate
1847
+ // debug images.)
1848
+ static SectionSP FindMatchingSection (const SectionList §ion_list,
1849
+ SectionSP section) {
1850
+ SectionSP sect_sp;
1851
+
1852
+ addr_t vm_addr = section->GetFileAddress ();
1853
+ ConstString name = section->GetName ();
1854
+ offset_t byte_size = section->GetByteSize ();
1855
+ bool thread_specific = section->IsThreadSpecific ();
1856
+ uint32_t permissions = section->GetPermissions ();
1857
+ uint32_t alignment = section->GetLog2Align ();
1858
+
1859
+ for (auto sect : section_list) {
1860
+ if (sect->GetName () == name &&
1861
+ sect->IsThreadSpecific () == thread_specific &&
1862
+ sect->GetPermissions () == permissions &&
1863
+ sect->GetByteSize () == byte_size && sect->GetFileAddress () == vm_addr &&
1864
+ sect->GetLog2Align () == alignment) {
1865
+ sect_sp = sect;
1866
+ break ;
1867
+ } else {
1868
+ sect_sp = FindMatchingSection (sect->GetChildren (), section);
1869
+ if (sect_sp)
1870
+ break ;
1871
+ }
1872
+ }
1873
+
1874
+ return sect_sp;
1875
+ }
1876
+
1844
1877
void ObjectFileELF::CreateSections (SectionList &unified_section_list) {
1845
1878
if (m_sections_up)
1846
1879
return ;
@@ -2054,10 +2087,12 @@ unsigned ObjectFileELF::ParseSymbols(Symtab *symtab, user_id_t start_id,
2054
2087
SectionList *module_section_list =
2055
2088
module_sp ? module_sp->GetSectionList () : nullptr ;
2056
2089
2057
- // Local cache to avoid doing a FindSectionByName for each symbol. The "const
2058
- // char*" key must came from a ConstString object so they can be compared by
2059
- // pointer
2060
- std::unordered_map<const char *, lldb::SectionSP> section_name_to_section;
2090
+ // We might have debug information in a separate object, in which case
2091
+ // we need to map the sections from that object to the sections in the
2092
+ // main object during symbol lookup. If we had to compare the sections
2093
+ // for every single symbol, that would be expensive, so this map is
2094
+ // used to accelerate the process.
2095
+ std::unordered_map<lldb::SectionSP, lldb::SectionSP> section_map;
2061
2096
2062
2097
unsigned i;
2063
2098
for (i = 0 ; i < num_symbols; ++i) {
@@ -2262,14 +2297,14 @@ unsigned ObjectFileELF::ParseSymbols(Symtab *symtab, user_id_t start_id,
2262
2297
2263
2298
if (symbol_section_sp && module_section_list &&
2264
2299
module_section_list != section_list) {
2265
- ConstString sect_name = symbol_section_sp-> GetName ( );
2266
- auto section_it = section_name_to_section. find (sect_name. GetCString ());
2267
- if ( section_it == section_name_to_section. end ())
2268
- section_it =
2269
- section_name_to_section
2270
- . emplace (sect_name. GetCString (),
2271
- module_section_list-> FindSectionByName (sect_name))
2272
- . first ;
2300
+ auto section_it = section_map. find (symbol_section_sp );
2301
+ if ( section_it == section_map. end ()) {
2302
+ section_it = section_map
2303
+ . emplace (symbol_section_sp,
2304
+ FindMatchingSection (*module_section_list,
2305
+ symbol_section_sp))
2306
+ . first ;
2307
+ }
2273
2308
if (section_it->second )
2274
2309
symbol_section_sp = section_it->second ;
2275
2310
}
0 commit comments