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
Show file tree
Hide file tree
Changes from all 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
50 changes: 49 additions & 1 deletion lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,55 @@ 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)
return;

std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());

int idx = 0;
for (const llvm::object::XCOFFSectionHeader64 &section :
m_binary->sections64()) {

ConstString const_sect_name(section.Name);

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

SectionSP section_sp(new Section(
module_sp, this, ++idx, const_sect_name, section_type,
section.VirtualAddress, section.SectionSize,
section.FileOffsetToRawData, section.SectionSize, 0, section.Flags));

uint32_t permissions = ePermissionsReadable;
if (section.Flags & (XCOFF::STYP_DATA | XCOFF::STYP_BSS))
permissions |= ePermissionsWritable;
if (section.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) {}

Expand Down
85 changes: 83 additions & 2 deletions lldb/test/Shell/ObjectFile/XCOFF/basic-info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,32 @@
# CHECK: Stripped: false
# CHECK: Type: executable
# CHECK: Strata: unknown
# CHECK: Name: .text
# CHECK-NEXT: Type: code
# CHECK-NEXT: Permissions: r-x
# CHECK: Name: .data
# CHECK-NEXT: Type: data
# CHECK-NEXT: Permissions: rw-
# CHECK: Name: .bss
# CHECK-NEXT: Type: zero-fill
# CHECK-NEXT: Permissions: rw-
# CHECK: Name: .loader
# CHECK-NEXT: Type: regular
# CHECK-NEXT: Permissions: r--
# CHECK: Name: .dwline
# CHECK-NEXT: Type: dwarf-line
# CHECK-NEXT: Permissions: r--
# CHECK: Name: .dwinfo
# CHECK-NEXT: Type: dwarf-info
# CHECK-NEXT: Permissions: r--
# CHECK: Name: .dwabrev
# CHECK-NEXT: Type: dwarf-abbrev
# CHECK-NEXT: Permissions: r--

--- !XCOFF
FileHeader:
MagicNumber: 0x1F7
NumberOfSections: 1
NumberOfSections: 7
CreationTime: 000000000
Flags: 0x0002
Sections:
Expand All @@ -22,6 +43,66 @@ Sections:
FileOffsetToLineNumbers: 0x0
NumberOfLineNumbers: 0x0
Flags: [ STYP_TEXT ]
SectionData: E8C20000E94204
SectionData: E8C20000
- Name: .data
Address: 0x1100008D2
Size: 0x2AE
FileOffsetToData: 0x8D2
FileOffsetToRelocations: 0x132E
FileOffsetToLineNumbers: 0x0
NumberOfRelocations: 0x22
NumberOfLineNumbers: 0x0
Flags: [ STYP_DATA ]
SectionData: ''
- Name: .bss
Address: 0x110000B80
Size: 0x28
FileOffsetToData: 0x0
FileOffsetToRelocations: 0x0
FileOffsetToLineNumbers: 0x0
NumberOfRelocations: 0x0
NumberOfLineNumbers: 0x0
Flags: [ STYP_BSS ]
SectionData: ''
- Name: .loader
Address: 0x0
Size: 0x413
FileOffsetToData: 0xB80
FileOffsetToRelocations: 0x0
FileOffsetToLineNumbers: 0x0
NumberOfRelocations: 0x0
NumberOfLineNumbers: 0x0
Flags: [ STYP_LOADER ]
SectionData: 00000001
- Name: .dwline
Address: 0x0
Size: 0x9C
FileOffsetToData: 0xF94
FileOffsetToRelocations: 0x150A
FileOffsetToLineNumbers: 0x0
NumberOfRelocations: 0x5
NumberOfLineNumbers: 0x0
Flags: [ STYP_DWARF ]
SectionData: FFFFFFFF
- Name: .dwinfo
Address: 0x0
Size: 0xDD
FileOffsetToData: 0x1030
FileOffsetToRelocations: 0x1550
FileOffsetToLineNumbers: 0x0
NumberOfRelocations: 0x6
NumberOfLineNumbers: 0x0
Flags: [ STYP_DWARF ]
SectionData: FFFFFFFF
- Name: .dwabrev
Address: 0x0
Size: 0x43
FileOffsetToData: 0x110E
FileOffsetToRelocations: 0x0
FileOffsetToLineNumbers: 0x0
NumberOfRelocations: 0x0
NumberOfLineNumbers: 0x0
Flags: [ STYP_DWARF ]
SectionData: 01110125
StringTable: {}
...
Loading