diff --git a/llvm/include/llvm/BinaryFormat/XCOFF.h b/llvm/include/llvm/BinaryFormat/XCOFF.h index 6705cdd324fbea..cffd8618f1e3a2 100644 --- a/llvm/include/llvm/BinaryFormat/XCOFF.h +++ b/llvm/include/llvm/BinaryFormat/XCOFF.h @@ -29,6 +29,8 @@ constexpr size_t FileNamePadSize = 6; constexpr size_t NameSize = 8; constexpr size_t FileHeaderSize32 = 20; constexpr size_t FileHeaderSize64 = 24; +constexpr size_t AuxFileHeaderSize32 = 72; +constexpr size_t AuxFileHeaderSize64 = 110; constexpr size_t SectionHeaderSize32 = 40; constexpr size_t SectionHeaderSize64 = 72; constexpr size_t SymbolTableEntrySize = 18; @@ -41,6 +43,17 @@ enum ReservedSectionNum : int16_t { N_DEBUG = -2, N_ABS = -1, N_UNDEF = 0 }; enum MagicNumber : uint16_t { XCOFF32 = 0x01DF, XCOFF64 = 0x01F7 }; +// This field only exists in the XCOFF64 definition. +enum AuxHeaderFlags64 : uint16_t { + SHR_SYMTAB = 0x8000, ///< At exec time, create shared symbol table for program + ///< (main program only). + FORK_POLICY = 0x4000, ///< Forktree policy specified (main program only). + FORK_COR = 0x2000 ///< If _AOUT_FORK_POLICY is set, specify copy-on-reference + ///< if this bit is set. Specify copy-on- write otherwise. + ///< If _AOUT_FORK_POLICY is 0, this bit is reserved for + ///< future use and should be set to 0. +}; + // x_smclas field of x_csect from system header: /usr/include/syms.h /// Storage Mapping Class definitions. enum StorageMappingClass : uint8_t { diff --git a/llvm/include/llvm/ObjectYAML/XCOFFYAML.h b/llvm/include/llvm/ObjectYAML/XCOFFYAML.h index 4f07e245862243..aa1bc396f13453 100644 --- a/llvm/include/llvm/ObjectYAML/XCOFFYAML.h +++ b/llvm/include/llvm/ObjectYAML/XCOFFYAML.h @@ -29,6 +29,38 @@ struct FileHeader { llvm::yaml::Hex16 Flags; }; +struct AuxiliaryHeader { + Optional Magic; + Optional Version; + Optional TextStartAddr; + Optional DataStartAddr; + Optional TOCAnchorAddr; + Optional SecNumOfEntryPoint; + Optional SecNumOfText; + Optional SecNumOfData; + Optional SecNumOfTOC; + Optional SecNumOfLoader; + Optional SecNumOfBSS; + Optional MaxAlignOfText; + Optional MaxAlignOfData; + Optional ModuleType; + Optional CpuFlag; + Optional CpuType; + Optional TextPageSize; + Optional DataPageSize; + Optional StackPageSize; + Optional FlagAndTDataAlignment; + Optional TextSize; + Optional InitDataSize; + Optional BssDataSize; + Optional EntryPointAddr; + Optional MaxStackSize; + Optional MaxDataSize; + Optional SecNumOfTData; + Optional SecNumOfTBSS; + Optional Flag; +}; + struct Relocation { llvm::yaml::Hex64 VirtualAddress; llvm::yaml::Hex64 SymbolIndex; @@ -70,6 +102,7 @@ struct StringTable { struct Object { FileHeader Header; + Optional AuxHeader; std::vector
Sections; std::vector Symbols; StringTable StrTbl; @@ -97,6 +130,9 @@ template <> struct MappingTraits { static void mapping(IO &IO, XCOFFYAML::FileHeader &H); }; +template <> struct MappingTraits { + static void mapping(IO &IO, XCOFFYAML::AuxiliaryHeader &AuxHdr); +}; template <> struct MappingTraits { static void mapping(IO &IO, XCOFFYAML::Symbol &S); diff --git a/llvm/lib/ObjectYAML/XCOFFEmitter.cpp b/llvm/lib/ObjectYAML/XCOFFEmitter.cpp index 3b4b8c9de52096..85d1f82bfafc4e 100644 --- a/llvm/lib/ObjectYAML/XCOFFEmitter.cpp +++ b/llvm/lib/ObjectYAML/XCOFFEmitter.cpp @@ -42,11 +42,13 @@ class XCOFFWriter { private: bool nameShouldBeInStringTable(StringRef SymbolName); bool initFileHeader(uint64_t CurrentOffset); + void initAuxFileHeader(); bool initSectionHeader(uint64_t &CurrentOffset); bool initRelocations(uint64_t &CurrentOffset); bool initStringTable(); bool assignAddressesAndIndices(); void writeFileHeader(); + void writeAuxFileHeader(); void writeSectionHeader(); bool writeSectionData(); bool writeRelocations(); @@ -65,6 +67,7 @@ class XCOFFWriter { {StringRef("N_ABS"), XCOFF::N_ABS}, {StringRef("N_UNDEF"), XCOFF::N_UNDEF}}; XCOFFYAML::FileHeader InitFileHdr = Obj.Header; + XCOFFYAML::AuxiliaryHeader InitAuxFileHdr; std::vector InitSections = Obj.Sections; }; @@ -232,22 +235,85 @@ bool XCOFFWriter::initFileHeader(uint64_t CurrentOffset) { return true; } +void XCOFFWriter::initAuxFileHeader() { + InitAuxFileHdr = *Obj.AuxHeader; + // In general, an object file might contain multiple sections of a given type, + // but in a loadable module, there must be exactly one .text, .data, .bss, and + // .loader section. A loadable object might also have one .tdata section and + // one .tbss section. + // Set these section-related values if not set explicitly. We assume that the + // input YAML matches the format of the loadable object, but if multiple input + // sections still have the same type, the first section with that type + // prevails. + for (uint16_t I = 0, E = InitSections.size(); I < E; ++I) { + switch (InitSections[I].Flags) { + case XCOFF::STYP_TEXT: + if (!InitAuxFileHdr.TextSize) + InitAuxFileHdr.TextSize = InitSections[I].Size; + if (!InitAuxFileHdr.TextStartAddr) + InitAuxFileHdr.TextStartAddr = InitSections[I].Address; + if (!InitAuxFileHdr.SecNumOfText) + InitAuxFileHdr.SecNumOfText = I + 1; + break; + case XCOFF::STYP_DATA: + if (!InitAuxFileHdr.InitDataSize) + InitAuxFileHdr.InitDataSize = InitSections[I].Size; + if (!InitAuxFileHdr.DataStartAddr) + InitAuxFileHdr.DataStartAddr = InitSections[I].Address; + if (!InitAuxFileHdr.SecNumOfData) + InitAuxFileHdr.SecNumOfData = I + 1; + break; + case XCOFF::STYP_BSS: + if (!InitAuxFileHdr.BssDataSize) + InitAuxFileHdr.BssDataSize = InitSections[I].Size; + if (!InitAuxFileHdr.SecNumOfBSS) + InitAuxFileHdr.SecNumOfBSS = I + 1; + break; + case XCOFF::STYP_TDATA: + if (!InitAuxFileHdr.SecNumOfTData) + InitAuxFileHdr.SecNumOfTData = I + 1; + break; + case XCOFF::STYP_TBSS: + if (!InitAuxFileHdr.SecNumOfTBSS) + InitAuxFileHdr.SecNumOfTBSS = I + 1; + break; + case XCOFF::STYP_LOADER: + if (!InitAuxFileHdr.SecNumOfLoader) + InitAuxFileHdr.SecNumOfLoader = I + 1; + break; + default: + break; + } + } +} + bool XCOFFWriter::assignAddressesAndIndices() { uint64_t FileHdrSize = Is64Bit ? XCOFF::FileHeaderSize64 : XCOFF::FileHeaderSize32; + uint64_t AuxFileHdrSize = 0; + if (Obj.AuxHeader) + AuxFileHdrSize = Obj.Header.AuxHeaderSize + ? Obj.Header.AuxHeaderSize + : (Is64Bit ? XCOFF::AuxFileHeaderSize64 + : XCOFF::AuxFileHeaderSize32); uint64_t SecHdrSize = Is64Bit ? XCOFF::SectionHeaderSize64 : XCOFF::SectionHeaderSize32; - uint64_t CurrentOffset = FileHdrSize /* TODO: + auxiliaryHeaderSize() */ + - InitSections.size() * SecHdrSize; + uint64_t CurrentOffset = + FileHdrSize + AuxFileHdrSize + InitSections.size() * SecHdrSize; // Calculate section header info. if (!initSectionHeader(CurrentOffset)) return false; + InitFileHdr.AuxHeaderSize = AuxFileHdrSize; // Calculate file header info. if (!initFileHeader(CurrentOffset)) return false; + // Initialize the auxiliary file header. + if (Obj.AuxHeader) + initAuxFileHeader(); + // Initialize the string table. return initStringTable(); } @@ -261,7 +327,7 @@ void XCOFFWriter::writeFileHeader() { W.write(Obj.Header.SymbolTableOffset ? Obj.Header.SymbolTableOffset : InitFileHdr.SymbolTableOffset); - W.write(Obj.Header.AuxHeaderSize); + W.write(InitFileHdr.AuxHeaderSize); W.write(Obj.Header.Flags); W.write(Obj.Header.NumberOfSymTableEntries ? Obj.Header.NumberOfSymTableEntries @@ -273,11 +339,72 @@ void XCOFFWriter::writeFileHeader() { W.write(Obj.Header.NumberOfSymTableEntries ? Obj.Header.NumberOfSymTableEntries : InitFileHdr.NumberOfSymTableEntries); - W.write(Obj.Header.AuxHeaderSize); + W.write(InitFileHdr.AuxHeaderSize); W.write(Obj.Header.Flags); } } +void XCOFFWriter::writeAuxFileHeader() { + W.write(InitAuxFileHdr.Magic.getValueOr(yaml::Hex16(1))); + W.write(InitAuxFileHdr.Version.getValueOr(yaml::Hex16(1))); + if (Is64Bit) { + W.OS.write_zeros(4); // Reserved for debugger. + W.write(InitAuxFileHdr.TextStartAddr.getValueOr(yaml::Hex64(0))); + W.write(InitAuxFileHdr.DataStartAddr.getValueOr(yaml::Hex64(0))); + W.write(InitAuxFileHdr.TOCAnchorAddr.getValueOr(yaml::Hex64(0))); + } else { + W.write(InitAuxFileHdr.TextSize.getValueOr(yaml::Hex64(0))); + W.write(InitAuxFileHdr.InitDataSize.getValueOr(yaml::Hex64(0))); + W.write(InitAuxFileHdr.BssDataSize.getValueOr(yaml::Hex64(0))); + W.write(InitAuxFileHdr.EntryPointAddr.getValueOr(yaml::Hex64(0))); + W.write(InitAuxFileHdr.TextStartAddr.getValueOr(yaml::Hex64(0))); + W.write(InitAuxFileHdr.DataStartAddr.getValueOr(yaml::Hex64(0))); + W.write(InitAuxFileHdr.TOCAnchorAddr.getValueOr(yaml::Hex64(0))); + } + W.write(InitAuxFileHdr.SecNumOfEntryPoint.getValueOr(0)); + W.write(InitAuxFileHdr.SecNumOfText.getValueOr(0)); + W.write(InitAuxFileHdr.SecNumOfData.getValueOr(0)); + W.write(InitAuxFileHdr.SecNumOfTOC.getValueOr(0)); + W.write(InitAuxFileHdr.SecNumOfLoader.getValueOr(0)); + W.write(InitAuxFileHdr.SecNumOfBSS.getValueOr(0)); + W.write(InitAuxFileHdr.MaxAlignOfText.getValueOr(yaml::Hex16(0))); + W.write(InitAuxFileHdr.MaxAlignOfData.getValueOr(yaml::Hex16(0))); + W.write(InitAuxFileHdr.ModuleType.getValueOr(yaml::Hex16(0))); + W.write(InitAuxFileHdr.CpuFlag.getValueOr(yaml::Hex8(0))); + W.write(0); // Reserved for CPU type. + if (Is64Bit) { + W.write(InitAuxFileHdr.TextPageSize.getValueOr(yaml::Hex8(0))); + W.write(InitAuxFileHdr.DataPageSize.getValueOr(yaml::Hex8(0))); + W.write(InitAuxFileHdr.StackPageSize.getValueOr(yaml::Hex8(0))); + W.write( + InitAuxFileHdr.FlagAndTDataAlignment.getValueOr(yaml::Hex8(0x80))); + W.write(InitAuxFileHdr.TextSize.getValueOr(yaml::Hex64(0))); + W.write(InitAuxFileHdr.InitDataSize.getValueOr(yaml::Hex64(0))); + W.write(InitAuxFileHdr.BssDataSize.getValueOr(yaml::Hex64(0))); + W.write(InitAuxFileHdr.EntryPointAddr.getValueOr(yaml::Hex64(0))); + W.write(InitAuxFileHdr.MaxStackSize.getValueOr(yaml::Hex64(0))); + W.write(InitAuxFileHdr.MaxDataSize.getValueOr(yaml::Hex64(0))); + } else { + W.write(InitAuxFileHdr.MaxStackSize.getValueOr(yaml::Hex64(0))); + W.write(InitAuxFileHdr.MaxDataSize.getValueOr(yaml::Hex64(0))); + W.OS.write_zeros(4); // Reserved for debugger. + W.write(InitAuxFileHdr.TextPageSize.getValueOr(yaml::Hex8(0))); + W.write(InitAuxFileHdr.DataPageSize.getValueOr(yaml::Hex8(0))); + W.write(InitAuxFileHdr.StackPageSize.getValueOr(yaml::Hex8(0))); + W.write( + InitAuxFileHdr.FlagAndTDataAlignment.getValueOr(yaml::Hex8(0))); + } + W.write(InitAuxFileHdr.SecNumOfTData.getValueOr(0)); + W.write(InitAuxFileHdr.SecNumOfTBSS.getValueOr(0)); + if (Is64Bit) { + W.write(InitAuxFileHdr.Flag.getValueOr(yaml::Hex16(XCOFF::SHR_SYMTAB))); + if (InitFileHdr.AuxHeaderSize > XCOFF::AuxFileHeaderSize64) + W.OS.write_zeros(InitFileHdr.AuxHeaderSize - XCOFF::AuxFileHeaderSize64); + } else if (InitFileHdr.AuxHeaderSize > XCOFF::AuxFileHeaderSize32) { + W.OS.write_zeros(InitFileHdr.AuxHeaderSize - XCOFF::AuxFileHeaderSize32); + } +} + void XCOFFWriter::writeSectionHeader() { for (uint16_t I = 0, E = Obj.Sections.size(); I < E; ++I) { XCOFFYAML::Section YamlSec = Obj.Sections[I]; @@ -468,6 +595,8 @@ bool XCOFFWriter::writeXCOFF() { return false; StartOffset = W.OS.tell(); writeFileHeader(); + if (Obj.AuxHeader) + writeAuxFileHeader(); if (!Obj.Sections.empty()) { writeSectionHeader(); if (!writeSectionData()) diff --git a/llvm/lib/ObjectYAML/XCOFFYAML.cpp b/llvm/lib/ObjectYAML/XCOFFYAML.cpp index 699577988de6d3..221cf3b064c05e 100644 --- a/llvm/lib/ObjectYAML/XCOFFYAML.cpp +++ b/llvm/lib/ObjectYAML/XCOFFYAML.cpp @@ -118,6 +118,37 @@ void MappingTraits::mapping( IO.mapOptional("Flags", FileHdr.Flags); } +void MappingTraits::mapping( + IO &IO, XCOFFYAML::AuxiliaryHeader &AuxHdr) { + IO.mapOptional("Magic", AuxHdr.Magic); + IO.mapOptional("Version", AuxHdr.Version); + IO.mapOptional("TextStartAddr", AuxHdr.TextStartAddr); + IO.mapOptional("DataStartAddr", AuxHdr.DataStartAddr); + IO.mapOptional("TOCAnchorAddr", AuxHdr.TOCAnchorAddr); + IO.mapOptional("TextSectionSize", AuxHdr.TextSize); + IO.mapOptional("DataSectionSize", AuxHdr.InitDataSize); + IO.mapOptional("BssSectionSize", AuxHdr.BssDataSize); + IO.mapOptional("SecNumOfEntryPoint", AuxHdr.SecNumOfEntryPoint); + IO.mapOptional("SecNumOfText", AuxHdr.SecNumOfText); + IO.mapOptional("SecNumOfData", AuxHdr.SecNumOfData); + IO.mapOptional("SecNumOfTOC", AuxHdr.SecNumOfTOC); + IO.mapOptional("SecNumOfLoader", AuxHdr.SecNumOfLoader); + IO.mapOptional("SecNumOfBSS", AuxHdr.SecNumOfBSS); + IO.mapOptional("MaxAlignOfText", AuxHdr.MaxAlignOfText); + IO.mapOptional("MaxAlignOfData", AuxHdr.MaxAlignOfData); + IO.mapOptional("ModuleType", AuxHdr.CpuFlag); + IO.mapOptional("TextPageSize", AuxHdr.TextPageSize); + IO.mapOptional("DataPageSize", AuxHdr.DataPageSize); + IO.mapOptional("StackPageSize", AuxHdr.StackPageSize); + IO.mapOptional("FlagAndTDataAlignment", AuxHdr.FlagAndTDataAlignment); + IO.mapOptional("EntryPointAddr", AuxHdr.EntryPointAddr); + IO.mapOptional("MaxStackSize", AuxHdr.MaxStackSize); + IO.mapOptional("MaxDataSize", AuxHdr.MaxDataSize); + IO.mapOptional("SecNumOfTData", AuxHdr.SecNumOfTData); + IO.mapOptional("SecNumOfTBSS", AuxHdr.SecNumOfTBSS); + IO.mapOptional("Flag", AuxHdr.Flag); +} + void MappingTraits::mapping(IO &IO, XCOFFYAML::Relocation &R) { IO.mapOptional("Address", R.VirtualAddress); @@ -162,6 +193,7 @@ void MappingTraits::mapping(IO &IO, XCOFFYAML::StringTab void MappingTraits::mapping(IO &IO, XCOFFYAML::Object &Obj) { IO.mapTag("!XCOFF", true); IO.mapRequired("FileHeader", Obj.Header); + IO.mapOptional("AuxiliaryHeader", Obj.AuxHeader); IO.mapOptional("Sections", Obj.Sections); IO.mapOptional("Symbols", Obj.Symbols); IO.mapOptional("StringTable", Obj.StrTbl); diff --git a/llvm/test/tools/yaml2obj/XCOFF/aux-hdr-defaults.yaml b/llvm/test/tools/yaml2obj/XCOFF/aux-hdr-defaults.yaml new file mode 100644 index 00000000000000..1aa832eb6d83d1 --- /dev/null +++ b/llvm/test/tools/yaml2obj/XCOFF/aux-hdr-defaults.yaml @@ -0,0 +1,199 @@ +## Test that yaml2obj automatically sets fields of the auxiliary file header +## if not set explicitly. + +## Case1: if text/data/bss/tdata/tbss/loader sections are set and corresponding +## fields in the aux header are omitted, we use the derived values of +## those sections to set corresponding fields. +# RUN: yaml2obj %s --docnum=1 -o %t1 +# RUN: llvm-readobj --auxiliary-header %t1 | FileCheck %s --check-prefix=CASE1 + +# CASE1: AuxiliaryHeader { +# CASE1-NEXT: Magic: 0x10B +# CASE1-NEXT: Version: 0x1 +# CASE1-NEXT: Size of .text section: 0x8 +# CASE1-NEXT: Size of .data section: 0x8 +# CASE1-NEXT: Size of .bss section: 0x8 +# CASE1-NEXT: Entry point address: 0x0 +# CASE1-NEXT: .text section start address: 0x4 +# CASE1-NEXT: .data section start address: 0x10 +# CASE1-NEXT: TOC anchor address: 0x0 +# CASE1-NEXT: Section number of entryPoint: 0 +# CASE1-NEXT: Section number of .text: 2 +# CASE1-NEXT: Section number of .data: 4 +# CASE1-NEXT: Section number of TOC: 0 +# CASE1-NEXT: Section number of loader data: 12 +# CASE1-NEXT: Section number of .bss: 6 +# CASE1-NEXT: Maxium alignment of .text: 0x0 +# CASE1-NEXT: Maxium alignment of .data: 0x0 +# CASE1-NEXT: Module type: 0x0 +# CASE1-NEXT: CPU type of objects: 0x0 +# CASE1-NEXT: (Reserved): 0x0 +# CASE1-NEXT: Maximum stack size: 0x0 +# CASE1-NEXT: Maximum data size: 0x0 +# CASE1-NEXT: Reserved for debugger: 0x0 +# CASE1-NEXT: Text page size: 0x0 +# CASE1-NEXT: Data page size: 0x0 +# CASE1-NEXT: Stack page size: 0x0 +# CASE1-NEXT: Flag: 0x0 +# CASE1-NEXT: Alignment of thread-local storage: 0x0 +# CASE1-NEXT: Section number for .tdata: 8 +# CASE1-NEXT: Section number for .tbss: 10 +# CASE1-NEXT: } + +--- !XCOFF +FileHeader: + MagicNumber: [[MAGIC=0x1DF]] +AuxiliaryHeader: + Magic: 0x10B +Sections: + - Flags: [ STYP_PAD ] + SectionData: "1234" +## Set two sections with different contents for a given type to +## demonstrate that the values in the aux header depend on the first one. + - Flags: [ STYP_TEXT ] + SectionData: "1234000000" + - Flags: [ STYP_TEXT ] + SectionData: "1234" + - Flags: [ STYP_DATA ] + SectionData: "1234000000" + - Flags: [ STYP_DATA ] + SectionData: "1234" + - Flags: [ STYP_BSS ] + SectionData: "1234000000" + - Flags: [ STYP_BSS ] + SectionData: "1234" + - Flags: [ STYP_TDATA ] + SectionData: "1234000000" + - Flags: [ STYP_TDATA ] + SectionData: "1234" + - Flags: [ STYP_TBSS ] + SectionData: "1234000000" + - Flags: [ STYP_TBSS ] + SectionData: "1234" + - Flags: [ STYP_LOADER ] + SectionData: "1234000000" + - Flags: [ STYP_LOADER ] + SectionData: "1234" + +## Case2: same as case1, except producing 64-bit output. +# RUN: yaml2obj %s --docnum=1 -DMAGIC=0x1F7 -o %t2 +# RUN: llvm-readobj --auxiliary-header %t2 | FileCheck %s --check-prefix=CASE2 + +## Case2: same as case1, except it is 64-bit. +# RUN: yaml2obj %s --docnum=1 -DMAGIC=0x1F7 -o %t2 +# RUN: llvm-readobj --auxiliary-header %t2 | FileCheck %s --check-prefix=CASE2 + +# CASE2: AuxiliaryHeader { +# CASE2-NEXT: Magic: 0x10B +# CASE2-NEXT: Version: 0x1 +# CASE2-NEXT: Reserved for debugger: 0x0 +# CASE2-NEXT: .text section start address: 0x2 +# CASE2-NEXT: .data section start address: 0xE +# CASE2-NEXT: TOC anchor address: 0x0 +# CASE2-NEXT: Section number of entryPoint: 0 +# CASE2-NEXT: Section number of .text: 2 +# CASE2-NEXT: Section number of .data: 4 +# CASE2-NEXT: Section number of TOC: 0 +# CASE2-NEXT: Section number of loader data: 12 +# CASE2-NEXT: Section number of .bss: 6 +# CASE2-NEXT: Maxium alignment of .text: 0x0 +# CASE2-NEXT: Maxium alignment of .data: 0x0 +# CASE2-NEXT: Module type: 0x0 +# CASE2-NEXT: CPU type of objects: 0x0 +# CASE2-NEXT: (Reserved): 0x0 +# CASE2-NEXT: Text page size: 0x0 +# CASE2-NEXT: Data page size: 0x0 +# CASE2-NEXT: Stack page size: 0x0 +# CASE2-NEXT: Flag: 0x0 +# CASE2-NEXT: Alignment of thread-local storage: 0x0 +# CASE2-NEXT: Size of .text section: 0x8 +# CASE2-NEXT: Size of .data section: 0x8 +# CASE2-NEXT: Size of .bss section: 0x8 +# CASE2-NEXT: Entry point address: 0x0 +# CASE2-NEXT: Maximum stack size: 0x0 +# CASE2-NEXT: Maximum data size: 0x0 +# CASE2-NEXT: Section number for .tdata: 8 +# CASE2-NEXT: Section number for .tbss: 10 +# CASE2-NEXT: Additional flags 64-bit XCOFF: 0x8000 +# CASE2-NEXT: } + +## Case3: if all fields in the aux header are omitted and text/data/bss/tdata/tbss/loader +## sections are not set, we set the fields using default values. +# RUN: yaml2obj %s --docnum=2 -o %t3 +# RUN: llvm-readobj --auxiliary-header %t3 | FileCheck %s --check-prefix=CASE3 + +# CASE3: AuxiliaryHeader { +# CASE3-NEXT: Magic: 0x1 +# CASE3-NEXT: Version: 0x1 +# CASE3-NEXT: Size of .text section: 0x0 +# CASE3-NEXT: Size of .data section: 0x0 +# CASE3-NEXT: Size of .bss section: 0x0 +# CASE3-NEXT: Entry point address: 0x0 +# CASE3-NEXT: .text section start address: 0x0 +# CASE3-NEXT: .data section start address: 0x0 +# CASE3-NEXT: TOC anchor address: 0x0 +# CASE3-NEXT: Section number of entryPoint: 0 +# CASE3-NEXT: Section number of .text: 0 +# CASE3-NEXT: Section number of .data: 0 +# CASE3-NEXT: Section number of TOC: 0 +# CASE3-NEXT: Section number of loader data: 0 +# CASE3-NEXT: Section number of .bss: 0 +# CASE3-NEXT: Maxium alignment of .text: 0x0 +# CASE3-NEXT: Maxium alignment of .data: 0x0 +# CASE3-NEXT: Module type: 0x0 +# CASE3-NEXT: CPU type of objects: 0x0 +# CASE3-NEXT: (Reserved): 0x0 +# CASE3-NEXT: Maximum stack size: 0x0 +# CASE3-NEXT: Maximum data size: 0x0 +# CASE3-NEXT: Reserved for debugger: 0x0 +# CASE3-NEXT: Text page size: 0x0 +# CASE3-NEXT: Data page size: 0x0 +# CASE3-NEXT: Stack page size: 0x0 +# CASE3-NEXT: Flag: 0x0 +# CASE3-NEXT: Alignment of thread-local storage: 0x0 +# CASE3-NEXT: Section number for .tdata: 0 +# CASE3-NEXT: Section number for .tbss: 0 +# CASE3-NEXT: } + +--- !XCOFF +FileHeader: + MagicNumber: [[MAGIC=0x1DF]] +AuxiliaryHeader: + +## Case4: same as case3, except producing 64-bit output. +# RUN: yaml2obj %s --docnum=2 -DMAGIC=0x1F7 -o %t4 +# RUN: llvm-readobj --auxiliary-header %t4 | FileCheck %s --check-prefix=CASE4 + +# CASE4: AuxiliaryHeader { +# CASE4-NEXT: Magic: 0x1 +# CASE4-NEXT: Version: 0x1 +# CASE4-NEXT: Reserved for debugger: 0x0 +# CASE4-NEXT: .text section start address: 0x0 +# CASE4-NEXT: .data section start address: 0x0 +# CASE4-NEXT: TOC anchor address: 0x0 +# CASE4-NEXT: Section number of entryPoint: 0 +# CASE4-NEXT: Section number of .text: 0 +# CASE4-NEXT: Section number of .data: 0 +# CASE4-NEXT: Section number of TOC: 0 +# CASE4-NEXT: Section number of loader data: 0 +# CASE4-NEXT: Section number of .bss: 0 +# CASE4-NEXT: Maxium alignment of .text: 0x0 +# CASE4-NEXT: Maxium alignment of .data: 0x0 +# CASE4-NEXT: Module type: 0x0 +# CASE4-NEXT: CPU type of objects: 0x0 +# CASE4-NEXT: (Reserved): 0x0 +# CASE4-NEXT: Text page size: 0x0 +# CASE4-NEXT: Data page size: 0x0 +# CASE4-NEXT: Stack page size: 0x0 +# CASE4-NEXT: Flag: 0x0 +# CASE4-NEXT: Alignment of thread-local storage: 0x0 +# CASE4-NEXT: Size of .text section: 0x0 +# CASE4-NEXT: Size of .data section: 0x0 +# CASE4-NEXT: Size of .bss section: 0x0 +# CASE4-NEXT: Entry point address: 0x0 +# CASE4-NEXT: Maximum stack size: 0x0 +# CASE4-NEXT: Maximum data size: 0x0 +# CASE4-NEXT: Section number for .tdata: 0 +# CASE4-NEXT: Section number for .tbss: 0 +# CASE4-NEXT: Additional flags 64-bit XCOFF: 0x8000 +# CASE4-NEXT: } diff --git a/llvm/test/tools/yaml2obj/XCOFF/aux-hdr-full-contents.yaml b/llvm/test/tools/yaml2obj/XCOFF/aux-hdr-full-contents.yaml new file mode 100644 index 00000000000000..f9368bdbe27565 --- /dev/null +++ b/llvm/test/tools/yaml2obj/XCOFF/aux-hdr-full-contents.yaml @@ -0,0 +1,123 @@ +## Test that we can explicitly specify all fields of the auxiliary file header. +## Notice that the values aren't derived from the sections if we explicitly set the fields. + +# RUN: yaml2obj %s -o %t1 +# RUN: llvm-readobj --auxiliary-header %t1 | FileCheck %s --check-prefix=CHECK32 +# RUN: yaml2obj %s -DMAGIC=0x1F7 -DFLAG64=0x2 -o %t2 +# RUN: llvm-readobj --auxiliary-header %t2 | FileCheck %s --check-prefix=CHECK64 + +# CHECK32: Format: aixcoff-rs6000 +# CHECK32-NEXT: Arch: powerpc +# CHECK32-NEXT: AddressSize: 32bit +# CHECK32-NEXT: AuxiliaryHeader { +# CHECK32-NEXT: Magic: 0x10B +# CHECK32-NEXT: Version: 0x1 +# CHECK32-NEXT: Size of .text section: 0x8 +# CHECK32-NEXT: Size of .data section: 0x9 +# CHECK32-NEXT: Size of .bss section: 0x10 +# CHECK32-NEXT: Entry point address: 0x1111 +# CHECK32-NEXT: .text section start address: 0x2222 +# CHECK32-NEXT: .data section start address: 0x3333 +# CHECK32-NEXT: TOC anchor address: 0x4444 +# CHECK32-NEXT: Section number of entryPoint: 1 +# CHECK32-NEXT: Section number of .text: 2 +# CHECK32-NEXT: Section number of .data: 3 +# CHECK32-NEXT: Section number of TOC: 4 +# CHECK32-NEXT: Section number of loader data: 5 +# CHECK32-NEXT: Section number of .bss: 6 +# CHECK32-NEXT: Maxium alignment of .text: 0x7 +# CHECK32-NEXT: Maxium alignment of .data: 0x3 +# CHECK32-NEXT: Module type: 0x0 +# CHECK32-NEXT: CPU type of objects: 0x1 +# CHECK32-NEXT: (Reserved): 0x0 +# CHECK32-NEXT: Maximum stack size: 0x0 +# CHECK32-NEXT: Maximum data size: 0x0 +# CHECK32-NEXT: Reserved for debugger: 0x0 +# CHECK32-NEXT: Text page size: 0x1 +# CHECK32-NEXT: Data page size: 0x1 +# CHECK32-NEXT: Stack page size: 0x1 +# CHECK32-NEXT: Flag: 0x0 +# CHECK32-NEXT: Alignment of thread-local storage: 0x1 +# CHECK32-NEXT: Section number for .tdata: 7 +# CHECK32-NEXT: Section number for .tbss: 8 +# CHECK32-NEXT: } + +# CHECK64: Format: aix5coff64-rs6000 +# CHECK64-NEXT: Arch: powerpc64 +# CHECK64-NEXT: AddressSize: 64bit +# CHECK64-NEXT: AuxiliaryHeader { +# CHECK64-NEXT: Magic: 0x10B +# CHECK64-NEXT: Version: 0x1 +# CHECK64-NEXT: Reserved for debugger: 0x0 +# CHECK64-NEXT: .text section start address: 0x2222 +# CHECK64-NEXT: .data section start address: 0x3333 +# CHECK64-NEXT: TOC anchor address: 0x4444 +# CHECK64-NEXT: Section number of entryPoint: 1 +# CHECK64-NEXT: Section number of .text: 2 +# CHECK64-NEXT: Section number of .data: 3 +# CHECK64-NEXT: Section number of TOC: 4 +# CHECK64-NEXT: Section number of loader data: 5 +# CHECK64-NEXT: Section number of .bss: 6 +# CHECK64-NEXT: Maxium alignment of .text: 0x7 +# CHECK64-NEXT: Maxium alignment of .data: 0x3 +# CHECK64-NEXT: Module type: 0x0 +# CHECK64-NEXT: CPU type of objects: 0x1 +# CHECK64-NEXT: (Reserved): 0x0 +# CHECK64-NEXT: Text page size: 0x1 +# CHECK64-NEXT: Data page size: 0x1 +# CHECK64-NEXT: Stack page size: 0x1 +# CHECK64-NEXT: Flag: 0x0 +# CHECK64-NEXT: Alignment of thread-local storage: 0x0 +# CHECK64-NEXT: Size of .text section: 0x8 +# CHECK64-NEXT: Size of .data section: 0x9 +# CHECK64-NEXT: Size of .bss section: 0x10 +# CHECK64-NEXT: Entry point address: 0x1111 +# CHECK64-NEXT: Maximum stack size: 0x0 +# CHECK64-NEXT: Maximum data size: 0x0 +# CHECK64-NEXT: Section number for .tdata: 7 +# CHECK64-NEXT: Section number for .tbss: 8 +# CHECK64-NEXT: Additional flags 64-bit XCOFF: 0x2 +# CHECK64-NEXT: } + +--- !XCOFF +FileHeader: + MagicNumber: [[MAGIC=0x1DF]] +AuxiliaryHeader: + Magic: 0x10B + Version: 0x1 + TextSectionSize: 0x8 + DataSectionSize: 0x9 + BssSectionSize: 0x10 + EntryPointAddr: 0x1111 + TextStartAddr: 0x2222 + DataStartAddr: 0x3333 + TOCAnchorAddr: 0x4444 + SecNumOfEntryPoint: 1 + SecNumOfText: 2 + SecNumOfData: 3 + SecNumOfTOC: 4 + SecNumOfLoader: 5 + SecNumOfBSS: 6 + MaxAlignOfText: 0x7 + MaxAlignOfData: 0x3 + ModuleType: 0x1 + TextPageSize: 0x1 + DataPageSize: 0x1 + StackPageSize: 0x1 + SecNumOfTData: 7 + SecNumOfTBSS: 8 + FlagAndTDataAlignment: 0x1 + Flag: [[FLAG64=]] +Sections: + - Flags: [ STYP_TEXT ] + SectionData: "1232" + - Flags: [ STYP_DATA ] + SectionData: "5678" + - Flags: [ STYP_BSS ] + SectionData: "9101" + - Flags: [ STYP_TDATA ] + SectionData: "1112" + - Flags: [ STYP_TBSS ] + SectionData: "1314" + - Flags: [ STYP_LOADER ] + SectionData: "1516"