[Lldb-commits] [lldb] 39f5a42 - [lldb][AIX] Support for XCOFF Sections (#131304)
via lldb-commits
lldb-commits at lists.llvm.org
Mon May 12 05:22:05 PDT 2025
Author: Dhruv Srivastava
Date: 2025-05-12T17:52:02+05:30
New Revision: 39f5a420b6801c0cb6035ec77c53154674786a60
URL: https://github.com/llvm/llvm-project/commit/39f5a420b6801c0cb6035ec77c53154674786a60
DIFF: https://github.com/llvm/llvm-project/commit/39f5a420b6801c0cb6035ec77c53154674786a60.diff
LOG: [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. https://github.com/llvm/llvm-project/issues/101657
The complete changes for porting are present in this draft PR:
https://github.com/llvm/llvm-project/pull/102601
Incremental PR on ObjectFileXCOFF.cpp
This PR is intended to handle XCOFF sections.
Added:
Modified:
lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp
lldb/test/Shell/ObjectFile/XCOFF/basic-info.yaml
Removed:
################################################################################
diff --git a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp
index b54d43c5dd737..1666677c360ba 100644
--- a/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp
+++ b/lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp
@@ -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 §ion :
+ 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) {}
diff --git a/lldb/test/Shell/ObjectFile/XCOFF/basic-info.yaml b/lldb/test/Shell/ObjectFile/XCOFF/basic-info.yaml
index 3c0037db36dbb..17ff2f31c2fff 100644
--- a/lldb/test/Shell/ObjectFile/XCOFF/basic-info.yaml
+++ b/lldb/test/Shell/ObjectFile/XCOFF/basic-info.yaml
@@ -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:
@@ -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: {}
...
More information about the lldb-commits
mailing list