[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.
This commit is contained in:
parent
353ab41001
commit
f8e394b6f8
@ -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;
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user