Skip to content

Commit 39f5a42

Browse files
[lldb][AIX] Support for XCOFF Sections (#131304)
This PR is in reference to porting LLDB on AIX. Link to discussions on llvm discourse and github: 1. https://discourse.llvm.org/t/port-lldb-to-ibm-aix/80640 2. #101657 The complete changes for porting are present in this draft PR: #102601 Incremental PR on ObjectFileXCOFF.cpp This PR is intended to handle XCOFF sections.
1 parent 6078f5e commit 39f5a42

File tree

2 files changed

+132
-3
lines changed

2 files changed

+132
-3
lines changed

lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,55 @@ void ObjectFileXCOFF::ParseSymtab(Symtab &lldb_symtab) {}
190190

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

193-
void ObjectFileXCOFF::CreateSections(SectionList &unified_section_list) {}
193+
void ObjectFileXCOFF::CreateSections(SectionList &unified_section_list) {
194+
if (m_sections_up)
195+
return;
196+
197+
m_sections_up = std::make_unique<SectionList>();
198+
ModuleSP module_sp(GetModule());
199+
200+
if (!module_sp)
201+
return;
202+
203+
std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
204+
205+
int idx = 0;
206+
for (const llvm::object::XCOFFSectionHeader64 &section :
207+
m_binary->sections64()) {
208+
209+
ConstString const_sect_name(section.Name);
210+
211+
SectionType section_type = lldb::eSectionTypeOther;
212+
if (section.Flags & XCOFF::STYP_TEXT)
213+
section_type = eSectionTypeCode;
214+
else if (section.Flags & XCOFF::STYP_DATA)
215+
section_type = eSectionTypeData;
216+
else if (section.Flags & XCOFF::STYP_BSS)
217+
section_type = eSectionTypeZeroFill;
218+
else if (section.Flags & XCOFF::STYP_DWARF) {
219+
section_type = llvm::StringSwitch<SectionType>(section.Name)
220+
.Case(".dwinfo", eSectionTypeDWARFDebugInfo)
221+
.Case(".dwline", eSectionTypeDWARFDebugLine)
222+
.Case(".dwabrev", eSectionTypeDWARFDebugAbbrev)
223+
.Default(eSectionTypeInvalid);
224+
}
225+
226+
SectionSP section_sp(new Section(
227+
module_sp, this, ++idx, const_sect_name, section_type,
228+
section.VirtualAddress, section.SectionSize,
229+
section.FileOffsetToRawData, section.SectionSize, 0, section.Flags));
230+
231+
uint32_t permissions = ePermissionsReadable;
232+
if (section.Flags & (XCOFF::STYP_DATA | XCOFF::STYP_BSS))
233+
permissions |= ePermissionsWritable;
234+
if (section.Flags & XCOFF::STYP_TEXT)
235+
permissions |= ePermissionsExecutable;
236+
237+
section_sp->SetPermissions(permissions);
238+
m_sections_up->AddSection(section_sp);
239+
unified_section_list.AddSection(section_sp);
240+
}
241+
}
194242

195243
void ObjectFileXCOFF::Dump(Stream *s) {}
196244

lldb/test/Shell/ObjectFile/XCOFF/basic-info.yaml

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,32 @@
77
# CHECK: Stripped: false
88
# CHECK: Type: executable
99
# CHECK: Strata: unknown
10+
# CHECK: Name: .text
11+
# CHECK-NEXT: Type: code
12+
# CHECK-NEXT: Permissions: r-x
13+
# CHECK: Name: .data
14+
# CHECK-NEXT: Type: data
15+
# CHECK-NEXT: Permissions: rw-
16+
# CHECK: Name: .bss
17+
# CHECK-NEXT: Type: zero-fill
18+
# CHECK-NEXT: Permissions: rw-
19+
# CHECK: Name: .loader
20+
# CHECK-NEXT: Type: regular
21+
# CHECK-NEXT: Permissions: r--
22+
# CHECK: Name: .dwline
23+
# CHECK-NEXT: Type: dwarf-line
24+
# CHECK-NEXT: Permissions: r--
25+
# CHECK: Name: .dwinfo
26+
# CHECK-NEXT: Type: dwarf-info
27+
# CHECK-NEXT: Permissions: r--
28+
# CHECK: Name: .dwabrev
29+
# CHECK-NEXT: Type: dwarf-abbrev
30+
# CHECK-NEXT: Permissions: r--
1031

1132
--- !XCOFF
1233
FileHeader:
1334
MagicNumber: 0x1F7
14-
NumberOfSections: 1
35+
NumberOfSections: 7
1536
CreationTime: 000000000
1637
Flags: 0x0002
1738
Sections:
@@ -22,6 +43,66 @@ Sections:
2243
FileOffsetToLineNumbers: 0x0
2344
NumberOfLineNumbers: 0x0
2445
Flags: [ STYP_TEXT ]
25-
SectionData: E8C20000E94204
46+
SectionData: E8C20000
47+
- Name: .data
48+
Address: 0x1100008D2
49+
Size: 0x2AE
50+
FileOffsetToData: 0x8D2
51+
FileOffsetToRelocations: 0x132E
52+
FileOffsetToLineNumbers: 0x0
53+
NumberOfRelocations: 0x22
54+
NumberOfLineNumbers: 0x0
55+
Flags: [ STYP_DATA ]
56+
SectionData: ''
57+
- Name: .bss
58+
Address: 0x110000B80
59+
Size: 0x28
60+
FileOffsetToData: 0x0
61+
FileOffsetToRelocations: 0x0
62+
FileOffsetToLineNumbers: 0x0
63+
NumberOfRelocations: 0x0
64+
NumberOfLineNumbers: 0x0
65+
Flags: [ STYP_BSS ]
66+
SectionData: ''
67+
- Name: .loader
68+
Address: 0x0
69+
Size: 0x413
70+
FileOffsetToData: 0xB80
71+
FileOffsetToRelocations: 0x0
72+
FileOffsetToLineNumbers: 0x0
73+
NumberOfRelocations: 0x0
74+
NumberOfLineNumbers: 0x0
75+
Flags: [ STYP_LOADER ]
76+
SectionData: 00000001
77+
- Name: .dwline
78+
Address: 0x0
79+
Size: 0x9C
80+
FileOffsetToData: 0xF94
81+
FileOffsetToRelocations: 0x150A
82+
FileOffsetToLineNumbers: 0x0
83+
NumberOfRelocations: 0x5
84+
NumberOfLineNumbers: 0x0
85+
Flags: [ STYP_DWARF ]
86+
SectionData: FFFFFFFF
87+
- Name: .dwinfo
88+
Address: 0x0
89+
Size: 0xDD
90+
FileOffsetToData: 0x1030
91+
FileOffsetToRelocations: 0x1550
92+
FileOffsetToLineNumbers: 0x0
93+
NumberOfRelocations: 0x6
94+
NumberOfLineNumbers: 0x0
95+
Flags: [ STYP_DWARF ]
96+
SectionData: FFFFFFFF
97+
- Name: .dwabrev
98+
Address: 0x0
99+
Size: 0x43
100+
FileOffsetToData: 0x110E
101+
FileOffsetToRelocations: 0x0
102+
FileOffsetToLineNumbers: 0x0
103+
NumberOfRelocations: 0x0
104+
NumberOfLineNumbers: 0x0
105+
Flags: [ STYP_DWARF ]
106+
SectionData: 01110125
26107
StringTable: {}
27108
...

0 commit comments

Comments
 (0)