@@ -1854,6 +1854,39 @@ class VMAddressProvider {
1854
1854
};
1855
1855
}
1856
1856
1857
+ // We have to do this because ELF doesn't have section IDs, and also
1858
+ // doesn't require section names to be unique. (We use the section index
1859
+ // for section IDs, but that isn't guaranteed to be the same in separate
1860
+ // debug images.)
1861
+ static SectionSP FindMatchingSection (const SectionList §ion_list,
1862
+ SectionSP section) {
1863
+ SectionSP sect_sp;
1864
+
1865
+ addr_t vm_addr = section->GetFileAddress ();
1866
+ ConstString name = section->GetName ();
1867
+ offset_t byte_size = section->GetByteSize ();
1868
+ bool thread_specific = section->IsThreadSpecific ();
1869
+ uint32_t permissions = section->GetPermissions ();
1870
+ uint32_t alignment = section->GetLog2Align ();
1871
+
1872
+ for (auto sect : section_list) {
1873
+ if (sect->GetName () == name &&
1874
+ sect->IsThreadSpecific () == thread_specific &&
1875
+ sect->GetPermissions () == permissions &&
1876
+ sect->GetByteSize () == byte_size && sect->GetFileAddress () == vm_addr &&
1877
+ sect->GetLog2Align () == alignment) {
1878
+ sect_sp = sect;
1879
+ break ;
1880
+ } else {
1881
+ sect_sp = FindMatchingSection (sect->GetChildren (), section);
1882
+ if (sect_sp)
1883
+ break ;
1884
+ }
1885
+ }
1886
+
1887
+ return sect_sp;
1888
+ }
1889
+
1857
1890
void ObjectFileELF::CreateSections (SectionList &unified_section_list) {
1858
1891
if (m_sections_up)
1859
1892
return ;
@@ -2067,10 +2100,12 @@ unsigned ObjectFileELF::ParseSymbols(Symtab *symtab, user_id_t start_id,
2067
2100
SectionList *module_section_list =
2068
2101
module_sp ? module_sp->GetSectionList () : nullptr ;
2069
2102
2070
- // Local cache to avoid doing a FindSectionByName for each symbol. The "const
2071
- // char*" key must came from a ConstString object so they can be compared by
2072
- // pointer
2073
- std::unordered_map<const char *, lldb::SectionSP> section_name_to_section;
2103
+ // We might have debug information in a separate object, in which case
2104
+ // we need to map the sections from that object to the sections in the
2105
+ // main object during symbol lookup. If we had to compare the sections
2106
+ // for every single symbol, that would be expensive, so this map is
2107
+ // used to accelerate the process.
2108
+ std::unordered_map<lldb::SectionSP, lldb::SectionSP> section_map;
2074
2109
2075
2110
unsigned i;
2076
2111
for (i = 0 ; i < num_symbols; ++i) {
@@ -2275,14 +2310,14 @@ unsigned ObjectFileELF::ParseSymbols(Symtab *symtab, user_id_t start_id,
2275
2310
2276
2311
if (symbol_section_sp && module_section_list &&
2277
2312
module_section_list != section_list) {
2278
- ConstString sect_name = symbol_section_sp-> GetName ( );
2279
- auto section_it = section_name_to_section. find (sect_name. GetCString ());
2280
- if ( section_it == section_name_to_section. end ())
2281
- section_it =
2282
- section_name_to_section
2283
- . emplace (sect_name. GetCString (),
2284
- module_section_list-> FindSectionByName (sect_name))
2285
- . first ;
2313
+ auto section_it = section_map. find (symbol_section_sp );
2314
+ if ( section_it == section_map. end ()) {
2315
+ section_it = section_map
2316
+ . emplace (symbol_section_sp,
2317
+ FindMatchingSection (*module_section_list,
2318
+ symbol_section_sp))
2319
+ . first ;
2320
+ }
2286
2321
if (section_it->second )
2287
2322
symbol_section_sp = section_it->second ;
2288
2323
}
0 commit comments