Skip to content
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
6 changes: 5 additions & 1 deletion llvm/include/llvm/Object/XCOFFObjectFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,19 @@ struct XCOFFAuxiliaryHeader64 : XCOFFAuxiliaryHeader<XCOFFAuxiliaryHeader64> {
};

template <typename T> struct XCOFFSectionHeader {
// Least significant 3 bits are reserved.
// The section flags definitions are the same in both 32- and 64-bit objects.
// Least significant 3 bits are reserved.
static constexpr unsigned SectionFlagsReservedMask = 0x7;

// The low order 16 bits of section flags denotes the section type.
// The high order 16 bits of section flags denotes the section subtype.
// For now, this is only used for DWARF sections.
static constexpr unsigned SectionFlagsTypeMask = 0xffffu;

public:
StringRef getName() const;
uint16_t getSectionType() const;
uint32_t getSectionSubtype() const;
bool isReservedSectionType() const;
};

Expand Down
5 changes: 5 additions & 0 deletions llvm/include/llvm/ObjectYAML/XCOFFYAML.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ struct Section {
llvm::yaml::Hex16 NumberOfRelocations;
llvm::yaml::Hex16 NumberOfLineNumbers; // Line number counts. Not supported yet.
uint32_t Flags;
std::optional<XCOFF::DwarfSectionSubtypeFlags> SectionSubtype;
yaml::BinaryRef SectionData;
std::vector<Relocation> Relocations;
};
Expand Down Expand Up @@ -232,6 +233,10 @@ template <> struct ScalarBitSetTraits<XCOFF::SectionTypeFlags> {
static void bitset(IO &IO, XCOFF::SectionTypeFlags &Value);
};

template <> struct ScalarEnumerationTraits<XCOFF::DwarfSectionSubtypeFlags> {
static void enumeration(IO &IO, XCOFF::DwarfSectionSubtypeFlags &Value);
};

template <> struct ScalarEnumerationTraits<XCOFF::StorageClass> {
static void enumeration(IO &IO, XCOFF::StorageClass &Value);
};
Expand Down
6 changes: 6 additions & 0 deletions llvm/lib/Object/XCOFFObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ template <typename T> uint16_t XCOFFSectionHeader<T>::getSectionType() const {
return DerivedXCOFFSectionHeader.Flags & SectionFlagsTypeMask;
}

template <typename T>
uint32_t XCOFFSectionHeader<T>::getSectionSubtype() const {
const T &DerivedXCOFFSectionHeader = static_cast<const T &>(*this);
return DerivedXCOFFSectionHeader.Flags & ~SectionFlagsTypeMask;
}

template <typename T>
bool XCOFFSectionHeader<T>::isReservedSectionType() const {
return getSectionType() & SectionFlagsReservedMask;
Expand Down
15 changes: 15 additions & 0 deletions llvm/lib/ObjectYAML/XCOFFEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,21 @@ bool XCOFFWriter::initSectionHeaders(uint64_t &CurrentOffset) {
return false;
}
}
if (InitSections[I].SectionSubtype) {
uint32_t DWARFSubtype =
static_cast<uint32_t>(*InitSections[I].SectionSubtype);
if (InitSections[I].Flags != XCOFF::STYP_DWARF) {
ErrHandler("a DWARFSectionSubtype is only allowed for a DWARF section");
return false;
}
unsigned Mask = Is64Bit ? XCOFFSectionHeader64::SectionFlagsTypeMask
: XCOFFSectionHeader32::SectionFlagsTypeMask;
if (DWARFSubtype & Mask) {
ErrHandler("the low-order bits of DWARFSectionSubtype must be 0");
return false;
}
InitSections[I].Flags |= DWARFSubtype;
}
}
return initRelocations(CurrentOffset);
}
Expand Down
19 changes: 19 additions & 0 deletions llvm/lib/ObjectYAML/XCOFFYAML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,24 @@ void ScalarBitSetTraits<XCOFF::SectionTypeFlags>::bitset(
#undef ECase
}

void ScalarEnumerationTraits<XCOFF::DwarfSectionSubtypeFlags>::enumeration(
IO &IO, XCOFF::DwarfSectionSubtypeFlags &Value) {
#define ECase(X) IO.enumCase(Value, #X, XCOFF::X)
ECase(SSUBTYP_DWINFO);
ECase(SSUBTYP_DWLINE);
ECase(SSUBTYP_DWPBNMS);
ECase(SSUBTYP_DWPBTYP);
ECase(SSUBTYP_DWARNGE);
ECase(SSUBTYP_DWABREV);
ECase(SSUBTYP_DWSTR);
ECase(SSUBTYP_DWRNGES);
ECase(SSUBTYP_DWLOC);
ECase(SSUBTYP_DWFRAME);
ECase(SSUBTYP_DWMAC);
#undef ECase
IO.enumFallback<Hex32>(Value);
}

void ScalarEnumerationTraits<XCOFF::StorageClass>::enumeration(
IO &IO, XCOFF::StorageClass &Value) {
#define ECase(X) IO.enumCase(Value, #X, XCOFF::X)
Expand Down Expand Up @@ -232,6 +250,7 @@ void MappingTraits<XCOFFYAML::Section>::mapping(IO &IO,
IO.mapOptional("NumberOfRelocations", Sec.NumberOfRelocations);
IO.mapOptional("NumberOfLineNumbers", Sec.NumberOfLineNumbers);
IO.mapOptional("Flags", NC->Flags);
IO.mapOptional("DWARFSectionSubtype", Sec.SectionSubtype);
IO.mapOptional("SectionData", Sec.SectionData);
IO.mapOptional("Relocations", Sec.Relocations);
}
Expand Down
3 changes: 3 additions & 0 deletions llvm/test/CodeGen/PowerPC/aix-dwarf.ll
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ entry:
; SEC-NEXT: NumberOfRelocations: 0
; SEC-NEXT: NumberOfLineNumbers: 0
; SEC-NEXT: Type: STYP_DWARF (0x10)
; SEC-NEXT: DWARFSubType: SSUBTYP_DWABREV (0x60000)
; SEC-NEXT: }
; SEC-NEXT: Section {
; SEC-NEXT: Index: 4
Expand All @@ -100,6 +101,7 @@ entry:
; SEC-NEXT: NumberOfRelocations: 4
; SEC-NEXT: NumberOfLineNumbers: 0
; SEC-NEXT: Type: STYP_DWARF (0x10)
; SEC-NEXT: DWARFSubType: SSUBTYP_DWINFO (0x10000)
; SEC-NEXT: }
; SEC-NEXT: Section {
; SEC-NEXT: Index: 5
Expand All @@ -116,6 +118,7 @@ entry:
; SEC-NEXT: NumberOfRelocations: 1
; SEC-NEXT: NumberOfLineNumbers: 0
; SEC-NEXT: Type: STYP_DWARF (0x10)
; SEC-NEXT: DWARFSubType: SSUBTYP_DWLINE (0x20000)
; SEC-NEXT: }
; SEC-NEXT: ]

Expand Down
128 changes: 63 additions & 65 deletions llvm/test/tools/llvm-readobj/XCOFF/sections.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,61 @@

# RUN: yaml2obj %s -o %t1
# RUN: llvm-readobj --section-headers %t1 | \
# RUN: FileCheck --strict-whitespace --match-full-lines --check-prefix=SEC32 %s
# RUN: FileCheck --strict-whitespace --match-full-lines --check-prefixes=SEC,SEC32 %s

# RUN: yaml2obj -DMAGIC=0x01F7 %s -o %t2
# RUN: llvm-readobj --section-headers %t2 | \
# RUN: FileCheck --strict-whitespace --match-full-lines --check-prefixes=SEC,SEC64 %s

# SEC32:Format: aixcoff-rs6000
# SEC64:Format: aix5coff64-rs6000
# SEC32-NEXT:Arch: powerpc
# SEC64-NEXT:Arch: powerpc64
# SEC32-NEXT:AddressSize: 32bit
# SEC32-NEXT:Sections [
# SEC32-NEXT: Section {
# SEC32-NEXT: Index: 1
# SEC32-NEXT: Name: .text
# SEC32-NEXT: PhysicalAddress: 0x0
# SEC32-NEXT: VirtualAddress: 0x0
# SEC32-NEXT: Size: 0x2
# SEC32-NEXT: RawDataOffset: 0x64
# SEC32-NEXT: RelocationPointer: 0x0
# SEC32-NEXT: LineNumberPointer: 0x0
# SEC32-NEXT: NumberOfRelocations: 0
# SEC32-NEXT: NumberOfLineNumbers: 0
# SEC32-NEXT: Type: STYP_TEXT (0x20)
# SEC32-NEXT: }
# SEC32-NEXT: Section {
# SEC32-NEXT: Index: 2
# SEC32-NEXT: Name: .data
# SEC32-NEXT: PhysicalAddress: 0x0
# SEC32-NEXT: VirtualAddress: 0x0
# SEC32-NEXT: Size: 0x2
# SEC32-NEXT: RawDataOffset: 0x68
# SEC32-NEXT: RelocationPointer: 0x6A
# SEC32-NEXT: LineNumberPointer: 0x0
# SEC32-NEXT: NumberOfRelocations: 1
# SEC32-NEXT: NumberOfLineNumbers: 0
# SEC32-NEXT: Type: STYP_DATA (0x40)
# SEC32-NEXT: }
# SEC32-NEXT:]
# SEC64-NEXT:AddressSize: 64bit
# SEC-NEXT:Sections [
# SEC-NEXT: Section {
# SEC-NEXT: Index: 1
# SEC-NEXT: Name: .text
# SEC-NEXT: PhysicalAddress: 0x0
# SEC-NEXT: VirtualAddress: 0x0
# SEC-NEXT: Size: 0x2
# SEC32-NEXT: RawDataOffset: 0xB4
# SEC64-NEXT: RawDataOffset: 0x138
# SEC-NEXT: RelocationPointer: 0x0
# SEC-NEXT: LineNumberPointer: 0x0
# SEC-NEXT: NumberOfRelocations: 0
# SEC-NEXT: NumberOfLineNumbers: 0
# SEC-NEXT: Type: STYP_TEXT (0x20)
# SEC-NEXT: }
# SEC-NEXT: Section {
# SEC-NEXT: Index: 2
# SEC-NEXT: Name: .data
# SEC-NEXT: PhysicalAddress: 0x0
# SEC-NEXT: VirtualAddress: 0x0
# SEC-NEXT: Size: 0x2
# SEC32-NEXT: RawDataOffset: 0xB8
# SEC64-NEXT: RawDataOffset: 0x13C
# SEC32-NEXT: RelocationPointer: 0xC4
# SEC64-NEXT: RelocationPointer: 0x148
# SEC-NEXT: LineNumberPointer: 0x0
# SEC-NEXT: NumberOfRelocations: 1
# SEC-NEXT: NumberOfLineNumbers: 0
# SEC-NEXT: Type: STYP_DATA (0x40)
# SEC-NEXT: }
# SEC-NEXT: Section {
# SEC-NEXT: Index: 3
# SEC-NEXT: Name: .dwabrev
# SEC: Type: STYP_DWARF (0x10)
# SEC-NEXT: DWARFSubType: SSUBTYP_DWABREV (0x60000)
# SEC-NEXT: }
# SEC-NEXT: Section {
# SEC-NEXT: Index: 4
# SEC-NEXT: Name: .dwinfo
# SEC: Type: STYP_DWARF (0x10)
# SEC-NEXT: DWARFSubType: SSUBTYP_DWINFO (0x10000)
# SEC-NEXT: }
# SEC-NEXT:]

--- !XCOFF
FileHeader:
Expand All @@ -51,39 +73,15 @@ Sections:
Symbol: 0x21
Info: 0x1F
Type: 0x0

# RUN: yaml2obj -DMAGIC=0x01F7 %s -o %t2
# RUN: llvm-readobj --section-headers %t2 | \
# RUN: FileCheck --strict-whitespace --match-full-lines --check-prefix=SEC64 %s

# SEC64:Format: aix5coff64-rs6000
# SEC64-NEXT:Arch: powerpc64
# SEC64-NEXT:AddressSize: 64bit
# SEC64-NEXT:Sections [
# SEC64-NEXT: Section {
# SEC64-NEXT: Index: 1
# SEC64-NEXT: Name: .text
# SEC64-NEXT: PhysicalAddress: 0x0
# SEC64-NEXT: VirtualAddress: 0x0
# SEC64-NEXT: Size: 0x2
# SEC64-NEXT: RawDataOffset: 0xA8
# SEC64-NEXT: RelocationPointer: 0x0
# SEC64-NEXT: LineNumberPointer: 0x0
# SEC64-NEXT: NumberOfRelocations: 0
# SEC64-NEXT: NumberOfLineNumbers: 0
# SEC64-NEXT: Type: STYP_TEXT (0x20)
# SEC64-NEXT: }
# SEC64-NEXT: Section {
# SEC64-NEXT: Index: 2
# SEC64-NEXT: Name: .data
# SEC64-NEXT: PhysicalAddress: 0x0
# SEC64-NEXT: VirtualAddress: 0x0
# SEC64-NEXT: Size: 0x2
# SEC64-NEXT: RawDataOffset: 0xAC
# SEC64-NEXT: RelocationPointer: 0xAE
# SEC64-NEXT: LineNumberPointer: 0x0
# SEC64-NEXT: NumberOfRelocations: 1
# SEC64-NEXT: NumberOfLineNumbers: 0
# SEC64-NEXT: Type: STYP_DATA (0x40)
# SEC64-NEXT: }
# SEC64-NEXT:]
- Name: .dwabrev
Address: 0x0
Size: 0x4
Flags: [ STYP_DWARF ]
DWARFSectionSubtype: SSUBTYP_DWABREV
SectionData: 01110125
- Name: .dwinfo
Address: 0x0
Size: 0x4
Flags: [ STYP_DWARF ]
DWARFSectionSubtype: SSUBTYP_DWINFO
SectionData: 00000080
105 changes: 105 additions & 0 deletions llvm/test/tools/yaml2obj/XCOFF/dwarf-subsection-types.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
## Test that we can generate and read DWARF section headers.

# RUN: yaml2obj --docnum=1 %s -o %t32
# RUN: obj2yaml %t32 | FileCheck --check-prefix=YAML %s

# RUN: yaml2obj --docnum=1 -DMAGIC=0x01F7 %s -o %t64
# RUN: obj2yaml %t64 | FileCheck --check-prefix=YAML %s

# YAML: - Name: .dwabrev
# YAML: Flags: [ STYP_DWARF ]
# YAML-NEXT: DWARFSectionSubtype: SSUBTYP_DWABREV
# YAML: - Name: .dwinfo
# YAML: Flags: [ STYP_DWARF ]
# YAML-NEXT: DWARFSectionSubtype: SSUBTYP_DWINFO
# YAML: - Name: .dwline
# YAML: Flags: [ STYP_DWARF ]
# YAML-NEXT: DWARFSectionSubtype: SSUBTYP_DWLINE

--- !XCOFF
FileHeader:
MagicNumber: [[MAGIC=0x01DF]]
NumberOfSections: 4
CreationTime: 0
AuxiliaryHeaderSize: 0
Flags: 0x0
Sections:
- Name: .data
Address: 0x0
Size: 0x4
Flags: [ STYP_DATA ]
SectionData: '00000001'
- Name: .dwabrev
Address: 0x0
Size: 0x4
Flags: [ STYP_DWARF ]
DWARFSectionSubtype: SSUBTYP_DWABREV
SectionData: 01110125
- Name: .dwinfo
Address: 0x0
Size: 0x4
Flags: [ STYP_DWARF ]
DWARFSectionSubtype: SSUBTYP_DWINFO
SectionData: 00000080
- Name: .dwline
Address: 0x0
Size: 0x4
Flags: [ STYP_DWARF ]
DWARFSectionSubtype: SSUBTYP_DWLINE
SectionData: 00000021
StringTable: {}
...

## Test that an invalid DWARF section subtype is diagnosed.
# RUN: not yaml2obj --docnum=2 %s -o %t 2>&1 | FileCheck --check-prefix=ERR1 %s

# ERR1: the low-order bits of DWARFSectionSubtype must be 0

--- !XCOFF
FileHeader:
MagicNumber: 0x01DF
NumberOfSections: 2
CreationTime: 0
AuxiliaryHeaderSize: 0
Flags: 0x0
Sections:
- Name: .data
Address: 0x0
Size: 0x4
Flags: [ STYP_DATA ]
SectionData: '00000001'
- Name: .dwabrev
Address: 0x0
Size: 0x4
Flags: [ STYP_DWARF ]
DWARFSectionSubtype: 0x12345
SectionData: 01110125
StringTable: {}
...

## Test that a DWARF section subtype on a non-DWARF section is diagnosed.
# RUN: not yaml2obj --docnum=3 %s -o %t 2>&1 | FileCheck --check-prefix=ERR2 %s

# ERR2: a DWARFSectionSubtype is only allowed for a DWARF section

--- !XCOFF
FileHeader:
MagicNumber: 0x01DF
NumberOfSections: 2
CreationTime: 0
AuxiliaryHeaderSize: 0
Flags: 0x0
Sections:
- Name: .data
Address: 0x0
Size: 0x4
Flags: [ STYP_DATA ]
DWARFSectionSubtype: SSUBTYP_DWABREV
SectionData: '00000001'
- Name: .dwabrev
Address: 0x0
Size: 0x4
Flags: [ STYP_DWARF ]
SectionData: 01110125
StringTable: {}
...
Loading