[Lldb-commits] [lldb] f8e394b - [lldb] Fix section offset of synthesized entry point symbol (#190348)
via lldb-commits
lldb-commits at lists.llvm.org
Sun Apr 5 11:39:29 PDT 2026
Author: Sergei Barannikov
Date: 2026-04-05T21:39:24+03:00
New Revision: f8e394b6f8f40b9372aca465c7f198529338ee55
URL: https://github.com/llvm/llvm-project/commit/f8e394b6f8f40b9372aca465c7f198529338ee55
DIFF: https://github.com/llvm/llvm-project/commit/f8e394b6f8f40b9372aca465c7f198529338ee55.diff
LOG: [lldb] Fix section offset of synthesized entry point symbol (#190348)
In the non-ARM case, the offset was left unset, so the symbol
synthesized for the entry point pointed to the start of the containing
section.
As a drive-by change, simplify offset adjustment in ARM case.
Added:
Modified:
lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
Removed:
################################################################################
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
index 47f8d8a844460..513f2cba4315e 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -3331,7 +3331,7 @@ void ObjectFileELF::ParseSymtab(Symtab &lldb_symtab) {
/*is_trampoline=*/false,
/*is_artificial=*/true,
/*section_sp=*/section_sp,
- /*offset=*/0,
+ /*offset=*/entry_point_addr.GetOffset(),
/*size=*/0, // FDE can span multiple symbols so don't use its size.
/*size_is_valid=*/false,
/*contains_linker_annotations=*/false,
@@ -3342,8 +3342,8 @@ void ObjectFileELF::ParseSymtab(Symtab &lldb_symtab) {
// address.
if (arch.GetMachine() == llvm::Triple::arm &&
(entry_point_file_addr & 1)) {
- symbol.GetAddressRef().SetOffset(entry_point_addr.GetOffset() ^ 1);
- m_address_class_map[entry_point_file_addr ^ 1] =
+ symbol.GetAddressRef().Slide(-1);
+ m_address_class_map[entry_point_file_addr - 1] =
AddressClass::eCodeAlternateISA;
} else {
m_address_class_map[entry_point_file_addr] = AddressClass::eCode;
diff --git a/lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp b/lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
index 21c94c5634109..6da2663ff3ae4 100644
--- a/lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
+++ b/lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
@@ -191,6 +191,43 @@ TEST_F(ObjectFileELFTest, GetModuleSpecifications_OffsetSizeWithOffsetFile) {
EXPECT_EQ(FileSystem::Instance().GetByteSize(FileSpec(SO)), 4640UL);
}
+TEST_F(ObjectFileELFTest, GetSymtab_SynthesizedEntryPointSymbol) {
+ auto ExpectedFile = TestFile::fromYaml(R"(
+--- !ELF
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_SPARC
+ Entry: 0x0000000000000042
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Address: 0x0000000000000020
+ Size: 0x0000000000000040
+...
+)");
+ ASSERT_THAT_EXPECTED(ExpectedFile, llvm::Succeeded());
+
+ auto module_sp = std::make_shared<Module>(ExpectedFile->moduleSpec());
+
+ Symtab *symtab = module_sp->GetSymtab();
+ ASSERT_NE(symtab, nullptr);
+
+ // Check that the entry point symbol was synthesized.
+ Symbol *entry_sym = symtab->FindSymbolAtFileAddress(0x42);
+ ASSERT_TRUE(entry_sym);
+ EXPECT_TRUE(entry_sym->IsSyntheticWithAutoGeneratedName());
+
+ // Check that the symbol has the correct section+offset address.
+ ASSERT_TRUE(entry_sym->ValueIsAddress());
+ Address entry_sym_addr = entry_sym->GetAddress();
+ ASSERT_TRUE(entry_sym_addr.IsSectionOffset());
+ EXPECT_EQ(entry_sym_addr.GetSection()->GetName(), ".text");
+ EXPECT_EQ(entry_sym_addr.GetOffset(), 0x42U - 0x20U);
+}
+
TEST_F(ObjectFileELFTest, GetSymtab_NoSymEntryPointArmThumbAddressClass) {
/*
// nosym-entrypoint-arm-thumb.s
More information about the lldb-commits
mailing list