Skip to content

Commit a61068e

Browse files
author
aokblast
committed
feat: Support relocatable kernel module files so the section address of these files will assigned correctly
1 parent f8ed3ed commit a61068e

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,16 @@ lldb_private::Address ObjectFileELF::GetEntryPointAddress() {
935935
}
936936

937937
Address ObjectFileELF::GetBaseAddress() {
938+
if (GetType() == ObjectFile::eTypeObjectFile) {
939+
for (SectionHeaderCollIter I = std::next(m_section_headers.begin());
940+
I != m_section_headers.end(); ++I) {
941+
const ELFSectionHeaderInfo &header = *I;
942+
if (header.sh_flags & SHF_ALLOC)
943+
return Address(GetSectionList()->FindSectionByID(SectionIndex(I)), 0);
944+
}
945+
return LLDB_INVALID_ADDRESS;
946+
}
947+
938948
for (const auto &EnumPHdr : llvm::enumerate(ProgramHeaders())) {
939949
const ELFProgramHeader &H = EnumPHdr.value();
940950
if (H.p_type != PT_LOAD)
@@ -1764,7 +1774,12 @@ class VMAddressProvider {
17641774
VMRange GetVMRange(const ELFSectionHeader &H) {
17651775
addr_t Address = H.sh_addr;
17661776
addr_t Size = H.sh_flags & SHF_ALLOC ? H.sh_size : 0;
1767-
if (ObjectType == ObjectFile::Type::eTypeObjectFile && Segments.empty() && (H.sh_flags & SHF_ALLOC)) {
1777+
1778+
// When this is a debug file for relocatable file, the address is all zero
1779+
// and thus needs to use accumulate method
1780+
if ((ObjectType == ObjectFile::Type::eTypeObjectFile ||
1781+
(ObjectType == ObjectFile::Type::eTypeDebugInfo && H.sh_addr == 0)) &&
1782+
Segments.empty() && (H.sh_flags & SHF_ALLOC)) {
17681783
NextVMAddress =
17691784
llvm::alignTo(NextVMAddress, std::max<addr_t>(H.sh_addralign, 1));
17701785
Address = NextVMAddress;

0 commit comments

Comments
 (0)