Skip to content

[lldb][AIX] Support for XCOFF Sections #131304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 12, 2025
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 77 additions & 2 deletions lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,83 @@ void ObjectFileXCOFF::ParseSymtab(Symtab &lldb_symtab) {}

bool ObjectFileXCOFF::IsStripped() { return false; }

void ObjectFileXCOFF::CreateSections(SectionList &unified_section_list) {}

void ObjectFileXCOFF::CreateSections(SectionList &unified_section_list) {

if (m_sections_up)
return;
m_sections_up = std::make_unique<SectionList>();
ModuleSP module_sp(GetModule());
if (module_sp) {
std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());

ModuleSP module_sp(GetModule());
for (auto sIdx = m_binary->section_begin(); sIdx != m_binary->section_end();
++sIdx) {
llvm::Expected<llvm::StringRef> name =
m_binary->getSectionName(sIdx->getRawDataRefImpl());
if (!name) {
llvm::Error err = name.takeError();
}
llvm::StringRef sect_name = *name;
ConstString const_sect_name(sect_name);
int sect_index = sIdx->getIndex(), idx = 1;
llvm::Expected<llvm::object::DataRefImpl> section =
m_binary->getSectionByNum(sect_index);
if (!section) {
llvm::Error err = section.takeError();
}
llvm::object::DataRefImpl dataref = section.get();
const llvm::object::XCOFFSectionHeader64 *sectionPtr =
reinterpret_cast<const llvm::object::XCOFFSectionHeader64 *>(
dataref.p);

SectionType section_type = lldb::eSectionTypeOther;
if (sectionPtr->Flags & XCOFF::STYP_TEXT)
section_type = eSectionTypeCode;
if (sectionPtr->Flags & XCOFF::STYP_DATA)
section_type = eSectionTypeData;
if (sectionPtr->Flags & XCOFF::STYP_BSS)
section_type = eSectionTypeZeroFill;
if (sectionPtr->Flags & XCOFF::STYP_DWARF) {
SectionType section_type =
llvm::StringSwitch<SectionType>(sect_name)
.Case(".dwinfo", eSectionTypeDWARFDebugInfo)
.Case(".dwline", eSectionTypeDWARFDebugLine)
.Case(".dwabrev", eSectionTypeDWARFDebugAbbrev)
.Default(eSectionTypeInvalid);

if (section_type == eSectionTypeInvalid)
section_type = lldb::eSectionTypeOther;
}
SectionSP section_sp(new Section(
module_sp, // Module to which this section belongs
this, // Object file to which this section belongs
idx++, // Section ID is the 1 based section index.
const_sect_name, // Name of this section
section_type,
sectionPtr->VirtualAddress, // File VM address == addresses as
// they are found in the object file
sectionPtr->SectionSize, // VM size in bytes of this section
sectionPtr->FileOffsetToRawData, // Offset to the data for this
// section in the file
sectionPtr->SectionSize, // Size in bytes of this section as found in
// the file
0, // FIXME: alignment
sectionPtr->Flags)); // Flags for this section

uint32_t permissions = 0;
permissions |= ePermissionsReadable;
if (sectionPtr->Flags & (XCOFF::STYP_DATA | XCOFF::STYP_BSS))
permissions |= ePermissionsWritable;
if (sectionPtr->Flags & XCOFF::STYP_TEXT)
permissions |= ePermissionsExecutable;
section_sp->SetPermissions(permissions);

m_sections_up->AddSection(section_sp);
unified_section_list.AddSection(section_sp);
}
}
}
void ObjectFileXCOFF::Dump(Stream *s) {}

ArchSpec ObjectFileXCOFF::GetArchitecture() {
Expand Down