Skip to content

Commit dd66036

Browse files
committed
[LLDB][ELF] Address review feedback, add test.
Fixed a couple of nits from review, and fixed up formatting. Also added a test. rdar://124467787
1 parent 881fe80 commit dd66036

File tree

3 files changed

+49
-45
lines changed

3 files changed

+49
-45
lines changed

lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp

Lines changed: 41 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,47 +1841,40 @@ class VMAddressProvider {
18411841
};
18421842
}
18431843

1844-
namespace {
1845-
// We have to do this because ELF doesn't have section IDs, and also
1846-
// doesn't require section names to be unique. (We use the section index
1847-
// for section IDs, but that isn't guaranteed to be the same in separate
1848-
// debug images.)
1849-
SectionSP FindMatchingSection(const SectionList &section_list,
1850-
SectionSP section) {
1851-
SectionSP sect_sp;
1852-
1853-
addr_t vm_addr = section->GetFileAddress();
1854-
ConstString name = section->GetName();
1855-
offset_t file_size = section->GetFileSize();
1856-
offset_t byte_size = section->GetByteSize();
1857-
SectionType type = section->GetType();
1858-
bool thread_specific = section->IsThreadSpecific();
1859-
uint32_t permissions = section->GetPermissions();
1860-
uint32_t alignment = section->GetLog2Align();
1861-
1862-
for (auto sect_iter = section_list.begin();
1863-
sect_iter != section_list.end();
1864-
++sect_iter) {
1865-
if ((*sect_iter)->GetName() == name
1866-
&& (*sect_iter)->GetType() == type
1867-
&& (*sect_iter)->IsThreadSpecific() == thread_specific
1868-
&& (*sect_iter)->GetPermissions() == permissions
1869-
&& (*sect_iter)->GetFileSize() == file_size
1870-
&& (*sect_iter)->GetByteSize() == byte_size
1871-
&& (*sect_iter)->GetFileAddress() == vm_addr
1872-
&& (*sect_iter)->GetLog2Align() == alignment) {
1873-
sect_sp = *sect_iter;
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 &section_list,
1849+
SectionSP section) {
1850+
SectionSP sect_sp;
1851+
1852+
addr_t vm_addr = section->GetFileAddress();
1853+
ConstString name = section->GetName();
1854+
offset_t file_size = section->GetFileSize();
1855+
offset_t byte_size = section->GetByteSize();
1856+
SectionType type = section->GetType();
1857+
bool thread_specific = section->IsThreadSpecific();
1858+
uint32_t permissions = section->GetPermissions();
1859+
uint32_t alignment = section->GetLog2Align();
1860+
1861+
for (auto sect : section_list) {
1862+
if (sect->GetName() == name && sect->GetType() == type &&
1863+
sect->IsThreadSpecific() == thread_specific &&
1864+
sect->GetPermissions() == permissions &&
1865+
sect->GetFileSize() == file_size && sect->GetByteSize() == byte_size &&
1866+
sect->GetFileAddress() == vm_addr &&
1867+
sect->GetLog2Align() == alignment) {
1868+
sect_sp = sect;
1869+
break;
1870+
} else {
1871+
sect_sp = FindMatchingSection(sect->GetChildren(), section);
1872+
if (sect_sp)
18741873
break;
1875-
} else {
1876-
sect_sp = FindMatchingSection((*sect_iter)->GetChildren(),
1877-
section);
1878-
if (sect_sp)
1879-
break;
1880-
}
18811874
}
1882-
1883-
return sect_sp;
18841875
}
1876+
1877+
return sect_sp;
18851878
}
18861879

18871880
void ObjectFileELF::CreateSections(SectionList &unified_section_list) {
@@ -2097,7 +2090,11 @@ unsigned ObjectFileELF::ParseSymbols(Symtab *symtab, user_id_t start_id,
20972090
SectionList *module_section_list =
20982091
module_sp ? module_sp->GetSectionList() : nullptr;
20992092

2100-
// Cache the section mapping
2093+
// We might have debug information in a separate object, in which case
2094+
// we need to map the sections from that object to the sections in the
2095+
// main object during symbol lookup. If we had to compare the sections
2096+
// for every single symbol, that would be expensive, so this map is
2097+
// used to accelerate the process.
21012098
std::unordered_map<lldb::SectionSP, lldb::SectionSP> section_map;
21022099

21032100
unsigned i;
@@ -2305,12 +2302,11 @@ unsigned ObjectFileELF::ParseSymbols(Symtab *symtab, user_id_t start_id,
23052302
module_section_list != section_list) {
23062303
auto section_it = section_map.find(symbol_section_sp);
23072304
if (section_it == section_map.end()) {
2308-
section_it =
2309-
section_map
2310-
.emplace(symbol_section_sp,
2311-
FindMatchingSection(*module_section_list,
2312-
symbol_section_sp))
2313-
.first;
2305+
section_it = section_map
2306+
.emplace(symbol_section_sp,
2307+
FindMatchingSection(*module_section_list,
2308+
symbol_section_sp))
2309+
.first;
23142310
}
23152311
if (section_it->second)
23162312
symbol_section_sp = section_it->second;
Binary file not shown.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Test symbol lookup when we have duplicate section names.
2+
#
3+
# (See https://github.com/llvm/llvm-project/issues/88001)
4+
5+
# RUN: lldb-test symbols %S/Inputs/two-text-sections.elf
6+
7+
# CHECK: 0x00000000004000b0 {{.*}} my_function
8+
# CHECK: 0x00000000004000e0 {{.*}} my_other_function

0 commit comments

Comments
 (0)