diff --git a/llvm/include/llvm/Object/XCOFFObjectFile.h b/llvm/include/llvm/Object/XCOFFObjectFile.h --- a/llvm/include/llvm/Object/XCOFFObjectFile.h +++ b/llvm/include/llvm/Object/XCOFFObjectFile.h @@ -228,7 +228,7 @@ uint8_t Pad[10]; }; // 32-bit XCOFF file only. -struct XCOFFRelocation32 { +template struct XCOFFRelocation { // Masks for packing/unpacking the r_rsize field of relocations. // The msb is used to indicate if the bits being relocated are signed or @@ -244,7 +244,7 @@ static constexpr uint8_t XR_BIASED_LENGTH_MASK = 0x3f; public: - support::ubig32_t VirtualAddress; + AddressType VirtualAddress; support::ubig32_t SymbolIndex; // Packed field, see XR_* masks for details of packing. @@ -260,6 +260,12 @@ uint8_t getRelocatedLength() const; }; +extern template struct XCOFFRelocation; +extern template struct XCOFFRelocation; + +struct XCOFFRelocation32 : XCOFFRelocation {}; +struct XCOFFRelocation64 : XCOFFRelocation {}; + class XCOFFSymbolRef; class XCOFFObjectFile : public ObjectFile { @@ -275,6 +281,7 @@ const XCOFFSectionHeader32 *sectionHeaderTable32() const; const XCOFFSectionHeader64 *sectionHeaderTable64() const; + template const T *sectionHeaderTable() const; size_t getFileHeaderSize() const; size_t getSectionHeaderSize() const; @@ -414,11 +421,12 @@ void checkSymbolEntryPointer(uintptr_t SymbolEntPtr) const; // Relocation-related interfaces. + template Expected - getLogicalNumberOfRelocationEntries(const XCOFFSectionHeader32 &Sec) const; + getNumberOfRelocationEntries(const XCOFFSectionHeader &Sec) const; - Expected> - relocations(const XCOFFSectionHeader32 &) const; + template + Expected> relocations(const T &Sec) const; // This function returns string table entry. Expected getStringTableEntry(uint32_t Offset) const; @@ -569,6 +577,7 @@ Optional ExtensionTable; XCOFFTracebackTable(const uint8_t *Ptr, uint64_t &Size, Error &Err); + public: /// Parse an XCOFF Traceback Table from \a Ptr with \a Size bytes. /// Returns an XCOFFTracebackTable upon successful parsing, otherwise an diff --git a/llvm/lib/Object/XCOFFObjectFile.cpp b/llvm/lib/Object/XCOFFObjectFile.cpp --- a/llvm/lib/Object/XCOFFObjectFile.cpp +++ b/llvm/lib/Object/XCOFFObjectFile.cpp @@ -70,15 +70,18 @@ return getSectionType() & SectionFlagsReservedMask; } -bool XCOFFRelocation32::isRelocationSigned() const { +template +bool XCOFFRelocation::isRelocationSigned() const { return Info & XR_SIGN_INDICATOR_MASK; } -bool XCOFFRelocation32::isFixupIndicated() const { +template +bool XCOFFRelocation::isFixupIndicated() const { return Info & XR_FIXUP_INDICATOR_MASK; } -uint8_t XCOFFRelocation32::getRelocatedLength() const { +template +uint8_t XCOFFRelocation::getRelocatedLength() const { // The relocation encodes the bit length being relocated minus 1. Add back // the 1 to get the actual length being relocated. return (Info & XR_BIASED_LENGTH_MASK) + 1; @@ -147,6 +150,10 @@ return static_cast(FileHeader); } +template const T *XCOFFObjectFile::sectionHeaderTable() const { + return static_cast(SectionHeaderTable); +} + const XCOFFSectionHeader32 * XCOFFObjectFile::sectionHeaderTable32() const { assert(!is64Bit() && "32-bit interface called on 64-bit object file."); @@ -318,61 +325,100 @@ } relocation_iterator XCOFFObjectFile::section_rel_begin(DataRefImpl Sec) const { - if (is64Bit()) - report_fatal_error("64-bit support not implemented yet"); - const XCOFFSectionHeader32 *SectionEntPtr = toSection32(Sec); - auto RelocationsOrErr = relocations(*SectionEntPtr); - if (Error E = RelocationsOrErr.takeError()) - return relocation_iterator(RelocationRef()); DataRefImpl Ret; - Ret.p = reinterpret_cast(&*RelocationsOrErr.get().begin()); + if (is64Bit()) { + const XCOFFSectionHeader64 *SectionEntPtr = toSection64(Sec); + auto RelocationsOrErr = + relocations(*SectionEntPtr); + if (Error E = RelocationsOrErr.takeError()) + return relocation_iterator(RelocationRef()); + Ret.p = reinterpret_cast(&*RelocationsOrErr.get().begin()); + } else { + const XCOFFSectionHeader32 *SectionEntPtr = toSection32(Sec); + auto RelocationsOrErr = + relocations(*SectionEntPtr); + if (Error E = RelocationsOrErr.takeError()) + return relocation_iterator(RelocationRef()); + Ret.p = reinterpret_cast(&*RelocationsOrErr.get().begin()); + } return relocation_iterator(RelocationRef(Ret, this)); } relocation_iterator XCOFFObjectFile::section_rel_end(DataRefImpl Sec) const { - if (is64Bit()) - report_fatal_error("64-bit support not implemented yet"); - const XCOFFSectionHeader32 *SectionEntPtr = toSection32(Sec); - auto RelocationsOrErr = relocations(*SectionEntPtr); - if (Error E = RelocationsOrErr.takeError()) - return relocation_iterator(RelocationRef()); DataRefImpl Ret; - Ret.p = reinterpret_cast(&*RelocationsOrErr.get().end()); + if (is64Bit()) { + const XCOFFSectionHeader64 *SectionEntPtr = toSection64(Sec); + auto RelocationsOrErr = + relocations(*SectionEntPtr); + if (Error E = RelocationsOrErr.takeError()) + return relocation_iterator(RelocationRef()); + Ret.p = reinterpret_cast(&*RelocationsOrErr.get().end()); + } else { + const XCOFFSectionHeader32 *SectionEntPtr = toSection32(Sec); + auto RelocationsOrErr = + relocations(*SectionEntPtr); + if (Error E = RelocationsOrErr.takeError()) + return relocation_iterator(RelocationRef()); + Ret.p = reinterpret_cast(&*RelocationsOrErr.get().end()); + } return relocation_iterator(RelocationRef(Ret, this)); } void XCOFFObjectFile::moveRelocationNext(DataRefImpl &Rel) const { - Rel.p = reinterpret_cast(viewAs(Rel.p) + 1); + if (is64Bit()) + Rel.p = reinterpret_cast(viewAs(Rel.p) + 1); + else + Rel.p = reinterpret_cast(viewAs(Rel.p) + 1); } uint64_t XCOFFObjectFile::getRelocationOffset(DataRefImpl Rel) const { - if (is64Bit()) - report_fatal_error("64-bit support not implemented yet"); - const XCOFFRelocation32 *Reloc = viewAs(Rel.p); - const XCOFFSectionHeader32 *Sec32 = sectionHeaderTable32(); - const uint32_t RelocAddress = Reloc->VirtualAddress; - const uint16_t NumberOfSections = getNumberOfSections(); - for (uint16_t i = 0; i < NumberOfSections; ++i) { - // Find which section this relocation is belonging to, and get the - // relocation offset relative to the start of the section. - if (Sec32->VirtualAddress <= RelocAddress && - RelocAddress < Sec32->VirtualAddress + Sec32->SectionSize) { - return RelocAddress - Sec32->VirtualAddress; + if (is64Bit()) { + const XCOFFRelocation64 *Reloc = viewAs(Rel.p); + const XCOFFSectionHeader64 *Sec64 = sectionHeaderTable64(); + const uint64_t RelocAddress = Reloc->VirtualAddress; + const uint16_t NumberOfSections = getNumberOfSections(); + for (uint16_t I = 0; I < NumberOfSections; ++I) { + // Find which section this relocation belongs to, and get the + // relocation offset relative to the start of the section. + if (Sec64->VirtualAddress <= RelocAddress && + RelocAddress < Sec64->VirtualAddress + Sec64->SectionSize) { + return RelocAddress - Sec64->VirtualAddress; + } + ++Sec64; + } + } else { + const XCOFFRelocation32 *Reloc = viewAs(Rel.p); + const XCOFFSectionHeader32 *Sec32 = sectionHeaderTable32(); + const uint32_t RelocAddress = Reloc->VirtualAddress; + const uint16_t NumberOfSections = getNumberOfSections(); + for (uint16_t I = 0; I < NumberOfSections; ++I) { + // Find which section this relocation belongs to, and get the + // relocation offset relative to the start of the section. + if (Sec32->VirtualAddress <= RelocAddress && + RelocAddress < Sec32->VirtualAddress + Sec32->SectionSize) { + return RelocAddress - Sec32->VirtualAddress; + } + ++Sec32; } - ++Sec32; } return InvalidRelocOffset; } symbol_iterator XCOFFObjectFile::getRelocationSymbol(DataRefImpl Rel) const { - if (is64Bit()) - report_fatal_error("64-bit support not implemented yet"); - const XCOFFRelocation32 *Reloc = viewAs(Rel.p); - const uint32_t Index = Reloc->SymbolIndex; - - if (Index >= getLogicalNumberOfSymbolTableEntries32()) - return symbol_end(); - + uint32_t Index; + if (is64Bit()) { + const XCOFFRelocation64 *Reloc = viewAs(Rel.p); + Index = Reloc->SymbolIndex; + + if (Index >= getNumberOfSymbolTableEntries64()) + return symbol_end(); + } else { + const XCOFFRelocation32 *Reloc = viewAs(Rel.p); + Index = Reloc->SymbolIndex; + + if (Index >= getLogicalNumberOfSymbolTableEntries32()) + return symbol_end(); + } DataRefImpl SymDRI; SymDRI.p = getSymbolEntryAddressByIndex(Index); return symbol_iterator(SymbolRef(SymDRI, this)); @@ -380,16 +426,20 @@ uint64_t XCOFFObjectFile::getRelocationType(DataRefImpl Rel) const { if (is64Bit()) - report_fatal_error("64-bit support not implemented yet"); + return viewAs(Rel.p)->Type; return viewAs(Rel.p)->Type; } void XCOFFObjectFile::getRelocationTypeName( DataRefImpl Rel, SmallVectorImpl &Result) const { - if (is64Bit()) - report_fatal_error("64-bit support not implemented yet"); - const XCOFFRelocation32 *Reloc = viewAs(Rel.p); - StringRef Res = XCOFF::getRelocationTypeString(Reloc->Type); + StringRef Res; + if (is64Bit()) { + const XCOFFRelocation64 *Reloc = viewAs(Rel.p); + Res = XCOFF::getRelocationTypeString(Reloc->Type); + } else { + const XCOFFRelocation32 *Reloc = viewAs(Rel.p); + Res = XCOFF::getRelocationTypeString(Reloc->Type); + } Result.append(Res.begin(), Res.end()); } @@ -441,7 +491,7 @@ bool XCOFFObjectFile::isRelocatableObject() const { if (is64Bit()) - report_fatal_error("64-bit support not implemented yet"); + return !(fileHeader64()->Flags & NoRelMask); return !(fileHeader32()->Flags & NoRelMask); } @@ -645,13 +695,16 @@ // section header contains the actual count of relocation entries in the s_paddr // field. STYP_OVRFLO headers contain the section index of their corresponding // sections as their raw "NumberOfRelocations" field value. -Expected XCOFFObjectFile::getLogicalNumberOfRelocationEntries( - const XCOFFSectionHeader32 &Sec) const { - - uint16_t SectionIndex = &Sec - sectionHeaderTable32() + 1; +template +Expected XCOFFObjectFile::getNumberOfRelocationEntries( + const XCOFFSectionHeader &Sec) const { + const T &Section = static_cast(Sec); + if (is64Bit()) + return Section.NumberOfRelocations; - if (Sec.NumberOfRelocations < XCOFF::RelocOverflow) - return Sec.NumberOfRelocations; + uint16_t SectionIndex = &Section - sectionHeaderTable() + 1; + if (Section.NumberOfRelocations < XCOFF::RelocOverflow) + return Section.NumberOfRelocations; for (const auto &Sec : sections32()) { if (Sec.Flags == XCOFF::STYP_OVRFLO && Sec.NumberOfRelocations == SectionIndex) @@ -660,27 +713,26 @@ return errorCodeToError(object_error::parse_failed); } -Expected> -XCOFFObjectFile::relocations(const XCOFFSectionHeader32 &Sec) const { +template +Expected> XCOFFObjectFile::relocations(const T &Sec) const { uintptr_t RelocAddr = getWithOffset(reinterpret_cast(FileHeader), Sec.FileOffsetToRelocationInfo); - auto NumRelocEntriesOrErr = getLogicalNumberOfRelocationEntries(Sec); + auto NumRelocEntriesOrErr = getNumberOfRelocationEntries(Sec); if (Error E = NumRelocEntriesOrErr.takeError()) return std::move(E); uint32_t NumRelocEntries = NumRelocEntriesOrErr.get(); - - static_assert( - sizeof(XCOFFRelocation32) == XCOFF::RelocationSerializationSize32, ""); - auto RelocationOrErr = - getObject(Data, reinterpret_cast(RelocAddr), - NumRelocEntries * sizeof(XCOFFRelocation32)); + static_assert((sizeof(V) == XCOFF::RelocationSerializationSize64 || + sizeof(V) == XCOFF::RelocationSerializationSize32), + ""); + auto RelocationOrErr = getObject(Data, reinterpret_cast(RelocAddr), + NumRelocEntries * sizeof(V)); if (Error E = RelocationOrErr.takeError()) return std::move(E); - const XCOFFRelocation32 *StartReloc = RelocationOrErr.get(); + const V *StartReloc = RelocationOrErr.get(); - return ArrayRef(StartReloc, StartReloc + NumRelocEntries); + return ArrayRef(StartReloc, StartReloc + NumRelocEntries); } Expected @@ -884,6 +936,18 @@ template struct XCOFFSectionHeader; template struct XCOFFSectionHeader; +template struct XCOFFRelocation; +template struct XCOFFRelocation; + +template llvm::Expected> +llvm::object::XCOFFObjectFile::relocations( + llvm::object::XCOFFSectionHeader64 const &) const; +template llvm::Expected> +llvm::object::XCOFFObjectFile::relocations( + llvm::object::XCOFFSectionHeader32 const &) const; + bool doesXCOFFTracebackTableBegin(ArrayRef Bytes) { if (Bytes.size() < 4) return false; diff --git a/llvm/test/CodeGen/PowerPC/aix-llvm-intrinsic.ll b/llvm/test/CodeGen/PowerPC/aix-llvm-intrinsic.ll --- a/llvm/test/CodeGen/PowerPC/aix-llvm-intrinsic.ll +++ b/llvm/test/CodeGen/PowerPC/aix-llvm-intrinsic.ll @@ -11,8 +11,8 @@ ; RUN: llc -verify-machineinstrs -mcpu=pwr4 -mtriple powerpc64-ibm-aix-xcoff \ ; RUN: -mattr=-altivec -filetype=obj -o %t.o < %s -; RUN: not --crash llvm-objdump -r -d --symbol-description %t.o 2>&1 | FileCheck --check-prefix=XCOFF64 %s -; XCOFF64: LLVM ERROR: 64-bit support not implemented yet +; RUN: llvm-readobj --symbols %t.o | FileCheck --check-prefix=CHECKSYM64 %s +; RUN: llvm-objdump -r -d --symbol-description %t.o | FileCheck --check-prefix=CHECKRELOC64 %s %struct.S = type { i32, i32 } @@ -78,3 +78,44 @@ ; CHECKRELOC-NEXT: 14: 7c 85 23 78 mr 5, 4 ; CHECKRELOC-NEXT: 18: 4b ff ff e9 bl 0x0 ; CHECKRELOC-NEXT: 00000018: R_RBR (idx: 1) .memset[PR] + +; CHECKSYM64: Symbol { +; CHECKSYM64-NEXT: Index: 0 +; CHECKSYM64-NEXT: Name: .file +; CHECKSYM64-NEXT: Value (SymbolTableIndex): 0x0 +; CHECKSYM64-NEXT: Section: N_DEBUG +; CHECKSYM64-NEXT: Source Language ID: TB_C (0x0) +; CHECKSYM64-NEXT: CPU Version ID: 0x0 +; CHECKSYM64-NEXT: StorageClass: C_FILE (0x67) +; CHECKSYM64-NEXT: NumberOfAuxEntries: 0 +; CHECKSYM64-NEXT: } +; CHECKSYM64-NEXT: Symbol { +; CHECKSYM64-NEXT: Index: 1 +; CHECKSYM64-NEXT: Name: .memset +; CHECKSYM64-NEXT: Value (RelocatableAddress): 0x0 +; CHECKSYM64-NEXT: Section: N_UNDEF +; CHECKSYM64-NEXT: Type: 0x0 +; CHECKSYM64-NEXT: StorageClass: C_EXT (0x2) +; CHECKSYM64-NEXT: NumberOfAuxEntries: 1 +; CHECKSYM64-NEXT: CSECT Auxiliary Entry { +; CHECKSYM64-NEXT: Index: 2 +; CHECKSYM64-NEXT: SectionLen: 0 +; CHECKSYM64-NEXT: ParameterHashIndex: 0x0 +; CHECKSYM64-NEXT: TypeChkSectNum: 0x0 +; CHECKSYM64-NEXT: SymbolAlignmentLog2: 0 +; CHECKSYM64-NEXT: SymbolType: XTY_ER (0x0) +; CHECKSYM64-NEXT: StorageMappingClass: XMC_PR (0x0) +; CHECKSYM64-NEXT: Auxiliary Type: AUX_CSECT (0xFB) +; CHECKSYM64-NEXT: } +; CHECKSYM64-NEXT: } + +; CHECKRELOC64: 00000000 (idx: 7) .bar: +; CHECKRELOC64-NEXT: 0: 7c 08 02 a6 mflr 0 +; CHECKRELOC64-NEXT: 4: f8 01 00 10 std 0, 16(1) +; CHECKRELOC64-NEXT: 8: f8 21 ff 91 stdu 1, -112(1) +; CHECKRELOC64-NEXT: c: e8 62 00 00 ld 3, 0(2) +; CHECKRELOC64-NEXT: 0000000e: R_TOC (idx: 13) s[TC] +; CHECKRELOC64-NEXT: 10: 80 83 00 04 lwz 4, 4(3) +; CHECKRELOC64-NEXT: 14: 7c 85 23 78 mr 5, 4 +; CHECKRELOC64-NEXT: 18: 4b ff ff e9 bl 0x0 +; CHECKRELOC64-NEXT: 00000018: R_RBR (idx: 1) .memset[PR] diff --git a/llvm/test/CodeGen/PowerPC/aix-overflow-toc.py b/llvm/test/CodeGen/PowerPC/aix-overflow-toc.py --- a/llvm/test/CodeGen/PowerPC/aix-overflow-toc.py +++ b/llvm/test/CodeGen/PowerPC/aix-overflow-toc.py @@ -11,10 +11,9 @@ # RUN: -filetype=obj -o %t.o < %t.ll # RUN: llvm-objdump -D -r --symbol-description %t.o | FileCheck --check-prefix=DIS32 %s -# RUN: llc -mtriple powerpc64-ibm-aix-xcoff -data-sections=false \ -# RUN: -mcpu=pwr4 -mattr=-altivec -filetype=obj -o %t.o < %t.ll -# RUN: not --crash llvm-objdump -D -r --symbol-description %t.o 2>&1 | FileCheck --check-prefix=XCOFF64 %s -# XCOFF64: LLVM ERROR: 64-bit support not implemented yet +# RUN: llc -mtriple powerpc64-ibm-aix-xcoff -code-model=small -data-sections=false -mcpu=pwr4 -mattr=-altivec -O0 \ +# RUN: -filetype=obj -o %t.o < %t.ll +# RUN: llvm-objdump -D -r --symbol-description %t.o | FileCheck --check-prefix=DIS64 %s numentries = 12290 for x in range(0, numentries): @@ -66,3 +65,20 @@ # DIS32: 00018006: R_TOC (idx: 49167) a12288[TC] # DIS32: 1800c: 80 82 c0 04 lwz 4, -16380(2) # DIS32: 0001800e: R_TOC (idx: 49169) a12289[TC] + +# DIS64: 0: e8 82 00 00 ld 4, 0(2) +# DIS64: 00000002: R_TOC (idx: 24591) a0[TC] +# DIS64: c: e8 82 00 08 ld 4, 8(2) +# DIS64: 0000000e: R_TOC (idx: 24593) a1[TC] + +# DIS64: fffc: e8 82 ff f8 ld 4, -8(2) +# DIS64: 0000fffe: R_TOC (idx: 40973) a8191[TC] +# DIS64: 10004: e8 82 00 00 ld 4, 0(2) +# DIS64: 00010006: R_TOC (idx: 40975) a8192[TC] +# DIS64: 1000c: e8 82 00 08 ld 4, 8(2) +# DIS64: 0001000e: R_TOC (idx: 40977) a8193[TC] + +# DIS64: 18004: e8 82 80 00 ld 4, -32768(2) +# DIS64: 00018006: R_TOC (idx: 49167) a12288[TC] +# DIS64: 1800c: e8 82 80 08 ld 4, -32760(2) +# DIS64: 0001800e: R_TOC (idx: 49169) a12289[TC] diff --git a/llvm/test/CodeGen/PowerPC/aix-user-defined-memcpy.ll b/llvm/test/CodeGen/PowerPC/aix-user-defined-memcpy.ll --- a/llvm/test/CodeGen/PowerPC/aix-user-defined-memcpy.ll +++ b/llvm/test/CodeGen/PowerPC/aix-user-defined-memcpy.ll @@ -15,7 +15,16 @@ ; RUN: llc -verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff -mcpu=pwr4 \ ; RUN: -mattr=-altivec -filetype=obj -xcoff-traceback-table=false -o %t.o < %s -; RUN: not --crash llvm-objdump -D -r %t.o 2>&1 | FileCheck --check-prefix=64-CHECK %s +; RUN: llvm-readobj --syms %t.o | FileCheck --check-prefix=64-SYM %s + +; RUN: llvm-readobj --relocs --expand-relocs %t.o | FileCheck \ +; RUN: --check-prefix=64-REL %s + +; RUN: llvm-objdump -D %t.o | FileCheck --check-prefix=64-DIS %s + +; RUN: llc -verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff \ +; RUN: -mcpu=pwr4 -mattr=-altivec < %s | \ +; RUN: FileCheck %s ; Test verifies: ; If there exists a user-defined function whose name is the same as the @@ -119,4 +128,78 @@ ; 32-DIS-NEXT: 2c: 7c 08 03 a6 mtlr 0 ; 32-DIS-NEXT: 30: 4e 80 00 20 blr -; 64-CHECK: LLVM ERROR: 64-bit support not implemented yet +; 64-SYM: Symbol {{[{][[:space:]] *}}Index: [[#Index:]]{{[[:space:]] *}}Name: .memcpy +; 64-SYM-NEXT: Value (RelocatableAddress): 0x0 +; 64-SYM-NEXT: Section: .text +; 64-SYM-NEXT: Type: 0x0 +; 64-SYM-NEXT: StorageClass: C_EXT (0x2) +; 64-SYM-NEXT: NumberOfAuxEntries: 1 +; 64-SYM-NEXT: CSECT Auxiliary Entry { +; 64-SYM-NEXT: Index: 4 +; 64-SYM-NEXT: ContainingCsectSymbolIndex: 1 +; 64-SYM-NEXT: ParameterHashIndex: 0x0 +; 64-SYM-NEXT: TypeChkSectNum: 0x0 +; 64-SYM-NEXT: SymbolAlignmentLog2: 0 +; 64-SYM-NEXT: SymbolType: XTY_LD (0x2) +; 64-SYM-NEXT: StorageMappingClass: XMC_PR (0x0) +; 64-SYM-NEXT: Auxiliary Type: AUX_CSECT (0xFB) +; 64-SYM-NEXT: } +; 64-SYM-NEXT: } + +; 64-SYM-NOT: .memcpy + +; 64-REL: Relocations [ +; 64-REL-NEXT: Section (index: 2) .data { +; 64-REL-NEXT: Relocation { +; 64-REL-NEXT: Virtual Address: 0x38 +; 64-REL-NEXT: Symbol: .memcpy (3) +; 64-REL-NEXT: IsSigned: No +; 64-REL-NEXT: FixupBitValue: 0 +; 64-REL-NEXT: Length: 64 +; 64-REL-NEXT: Type: R_POS (0x0) +; 64-REL-NEXT: } +; 64-REL-NEXT: Relocation { +; 64-REL-NEXT: Virtual Address: 0x40 +; 64-REL-NEXT: Symbol: TOC (11) +; 64-REL-NEXT: IsSigned: No +; 64-REL-NEXT: FixupBitValue: 0 +; 64-REL-NEXT: Length: 64 +; 64-REL-NEXT: Type: R_POS (0x0) +; 64-REL-NEXT: } +; 64-REL-NEXT: Relocation { +; 64-REL-NEXT: Virtual Address: 0x50 +; 64-REL-NEXT: Symbol: .call_memcpy (5) +; 64-REL-NEXT: IsSigned: No +; 64-REL-NEXT: FixupBitValue: 0 +; 64-REL-NEXT: Length: 64 +; 64-REL-NEXT: Type: R_POS (0x0) +; 64-REL-NEXT: } +; 64-REL-NEXT: Relocation { +; 64-REL-NEXT: Virtual Address: 0x58 +; 64-REL-NEXT: Symbol: TOC (11) +; 64-REL-NEXT: IsSigned: No +; 64-REL-NEXT: FixupBitValue: 0 +; 64-REL-NEXT: Length: 64 +; 64-REL-NEXT: Type: R_POS (0x0) +; 64-REL-NEXT: } +; 64-REL-NEXT: } +; 64-REL-NEXT: ] + +; 64-REL-NOT: Type: R_RBR (0x1A) + +; 64-DIS: Disassembly of section .text: +; 64-DIS: 00000000 <.text>: +; 64-DIS-NEXT: 0: 38 60 00 03 li 3, 3 +; 64-DIS-NEXT: 4: 4e 80 00 20 blr +; 64-DIS-NEXT: 8: 60 00 00 00 nop +; 64-DIS-NEXT: c: 60 00 00 00 nop +; 64-DIS: 00000010 <.call_memcpy>: +; 64-DIS-NEXT: 10: 7c 08 02 a6 mflr 0 +; 64-DIS-NEXT: 14: f8 01 00 10 std 0, 16(1) +; 64-DIS-NEXT: 18: f8 21 ff 91 stdu 1, -112(1) +; 64-DIS-NEXT: 1c: 4b ff ff e5 bl 0x0 +; 64-DIS-NEXT: 20: 60 00 00 00 nop +; 64-DIS-NEXT: 24: 38 21 00 70 addi 1, 1, 112 +; 64-DIS-NEXT: 28: e8 01 00 10 ld 0, 16(1) +; 64-DIS-NEXT: 2c: 7c 08 03 a6 mtlr 0 +; 64-DIS-NEXT: 30: 4e 80 00 20 blr diff --git a/llvm/test/CodeGen/PowerPC/aix-xcoff-reloc.ll b/llvm/test/CodeGen/PowerPC/aix-xcoff-reloc.ll --- a/llvm/test/CodeGen/PowerPC/aix-xcoff-reloc.ll +++ b/llvm/test/CodeGen/PowerPC/aix-xcoff-reloc.ll @@ -7,9 +7,14 @@ ; RUN: llvm-objdump -D %t.o | FileCheck --check-prefix=DIS %s ; RUN: llvm-objdump -r %t.o | FileCheck --check-prefix=DIS_REL %s -; RUN: llc -verify-machineinstrs -mcpu=pwr4 -mtriple powerpc64-ibm-aix-xcoff -mattr=-altivec -data-sections=false -filetype=obj -o %t.o < %s -; RUN: not --crash llvm-objdump -r %t.o 2>&1 | FileCheck --check-prefix=XCOFF64 %s -; XCOFF64: LLVM ERROR: 64-bit support not implemented yet +; RUN: llc -verify-machineinstrs -mcpu=pwr4 -mtriple powerpc64-ibm-aix-xcoff -mattr=-altivec \ +; RUN: -xcoff-traceback-table=false -data-sections=false -filetype=obj -o %t.o < %s +; RUN: llvm-readobj --section-headers --file-header %t.o | \ +; RUN: FileCheck --check-prefix=OBJ64 %s +; RUN: llvm-readobj --relocs --expand-relocs %t.o | FileCheck --check-prefix=RELOC64 %s +; RUN: llvm-readobj -t %t.o | FileCheck --check-prefix=SYM64 %s +; RUN: llvm-objdump -D %t.o | FileCheck --check-prefix=DIS64 %s +; RUN: llvm-objdump -r %t.o | FileCheck --check-prefix=DIS_REL64 %s @globalA = global i32 1, align 4 @globalB = global i32 2, align 4 @@ -472,3 +477,437 @@ ; DIS_REL-NEXT: 00000038 R_POS TOC ; DIS_REL-NEXT: 00000040 R_POS globalA ; DIS_REL-NEXT: 00000044 R_POS globalB + +; OBJ64: File: {{.*}}aix-xcoff-reloc.ll.tmp.o +; OBJ64-NEXT: Format: aix5coff64-rs6000 +; OBJ64-NEXT: Arch: powerpc64 +; OBJ64-NEXT: AddressSize: 64bit +; OBJ64-NEXT: FileHeader { +; OBJ64-NEXT: Magic: 0x1F7 +; OBJ64-NEXT: NumberOfSections: 2 +; OBJ64-NEXT: TimeStamp: None (0x0) +; OBJ64-NEXT: SymbolTableOffset: 0x1B8 +; OBJ64-NEXT: SymbolTableEntries: 27 +; OBJ64-NEXT: OptionalHeaderSize: 0x0 +; OBJ64-NEXT: Flags: 0x0 +; OBJ64-NEXT: } +; OBJ64-NEXT: Sections [ +; OBJ64-NEXT: Section { +; OBJ64-NEXT: Index: 1 +; OBJ64-NEXT: Name: .text +; OBJ64-NEXT: PhysicalAddress: 0x0 +; OBJ64-NEXT: VirtualAddress: 0x0 +; OBJ64-NEXT: Size: 0x40 +; OBJ64-NEXT: RawDataOffset: 0xA8 +; OBJ64-NEXT: RelocationPointer: 0x148 +; OBJ64-NEXT: LineNumberPointer: 0x0 +; OBJ64-NEXT: NumberOfRelocations: 3 +; OBJ64-NEXT: NumberOfLineNumbers: 0 +; OBJ64-NEXT: Type: STYP_TEXT (0x20) +; OBJ64-NEXT: } +; OBJ64-NEXT: Section { +; OBJ64-NEXT: Index: 2 +; OBJ64-NEXT: Name: .data +; OBJ64-NEXT: PhysicalAddress: 0x40 +; OBJ64-NEXT: VirtualAddress: 0x40 +; OBJ64-NEXT: Size: 0x60 +; OBJ64-NEXT: RawDataOffset: 0xE8 +; OBJ64-NEXT: RelocationPointer: 0x172 +; OBJ64-NEXT: LineNumberPointer: 0x0 +; OBJ64-NEXT: NumberOfRelocations: 5 +; OBJ64-NEXT: NumberOfLineNumbers: 0 +; OBJ64-NEXT: Type: STYP_DATA (0x40) +; OBJ64-NEXT: } +; OBJ64-NEXT: ] + + +; RELOC64: File: {{.*}}aix-xcoff-reloc.ll.tmp.o +; RELOC64-NEXT: Format: aix5coff64-rs6000 +; RELOC64-NEXT: Arch: powerpc64 +; RELOC64-NEXT: AddressSize: 64bit +; RELOC64-NEXT: Relocations [ +; RELOC64-NEXT: Section (index: 1) .text { +; RELOC64-NEXT: Relocation { +; RELOC64-NEXT: Virtual Address: 0x10 +; RELOC64-NEXT: Symbol: .bar (1) +; RELOC64-NEXT: IsSigned: Yes +; RELOC64-NEXT: FixupBitValue: 0 +; RELOC64-NEXT: Length: 26 +; RELOC64-NEXT: Type: R_RBR (0x1A) +; RELOC64-NEXT: } +; RELOC64-NEXT: Relocation { +; RELOC64-NEXT: Virtual Address: 0x1A +; RELOC64-NEXT: Symbol: globalA (23) +; RELOC64-NEXT: IsSigned: No +; RELOC64-NEXT: FixupBitValue: 0 +; RELOC64-NEXT: Length: 16 +; RELOC64-NEXT: Type: R_TOC (0x3) +; RELOC64-NEXT: } +; RELOC64-NEXT: Relocation { +; RELOC64-NEXT: Virtual Address: 0x1E +; RELOC64-NEXT: Symbol: globalB (25) +; RELOC64-NEXT: IsSigned: No +; RELOC64-NEXT: FixupBitValue: 0 +; RELOC64-NEXT: Length: 16 +; RELOC64-NEXT: Type: R_TOC (0x3) +; RELOC64-NEXT: } +; RELOC64-NEXT: } +; RELOC64-NEXT: Section (index: 2) .data { +; RELOC64-NEXT: Relocation { +; RELOC64-NEXT: Virtual Address: 0x70 +; RELOC64-NEXT: Symbol: arr (15) +; RELOC64-NEXT: IsSigned: No +; RELOC64-NEXT: FixupBitValue: 0 +; RELOC64-NEXT: Length: 64 +; RELOC64-NEXT: Type: R_POS (0x0) +; RELOC64-NEXT: } +; RELOC64-NEXT: Relocation { +; RELOC64-NEXT: Virtual Address: 0x78 +; RELOC64-NEXT: Symbol: .foo (7) +; RELOC64-NEXT: IsSigned: No +; RELOC64-NEXT: FixupBitValue: 0 +; RELOC64-NEXT: Length: 64 +; RELOC64-NEXT: Type: R_POS (0x0) +; RELOC64-NEXT: } +; RELOC64-NEXT: Relocation { +; RELOC64-NEXT: Virtual Address: 0x80 +; RELOC64-NEXT: Symbol: TOC (21) +; RELOC64-NEXT: IsSigned: No +; RELOC64-NEXT: FixupBitValue: 0 +; RELOC64-NEXT: Length: 64 +; RELOC64-NEXT: Type: R_POS (0x0) +; RELOC64-NEXT: } +; RELOC64-NEXT: Relocation { +; RELOC64-NEXT: Virtual Address: 0x90 +; RELOC64-NEXT: Symbol: globalA (11) +; RELOC64-NEXT: IsSigned: No +; RELOC64-NEXT: FixupBitValue: 0 +; RELOC64-NEXT: Length: 64 +; RELOC64-NEXT: Type: R_POS (0x0) +; RELOC64-NEXT: } +; RELOC64-NEXT: Relocation { +; RELOC64-NEXT: Virtual Address: 0x98 +; RELOC64-NEXT: Symbol: globalB (13) +; RELOC64-NEXT: IsSigned: No +; RELOC64-NEXT: FixupBitValue: 0 +; RELOC64-NEXT: Length: 64 +; RELOC64-NEXT: Type: R_POS (0x0) +; RELOC64-NEXT: } +; RELOC64-NEXT: } +; RELOC64-NEXT: ] + +; SYM64: Symbols [ +; SYM64-NEXT: Symbol { +; SYM64-NEXT: Index: 0 +; SYM64-NEXT: Name: .file +; SYM64-NEXT: Value (SymbolTableIndex): 0x0 +; SYM64-NEXT: Section: N_DEBUG +; SYM64-NEXT: Source Language ID: TB_C (0x0) +; SYM64-NEXT: CPU Version ID: 0x0 +; SYM64-NEXT: StorageClass: C_FILE (0x67) +; SYM64-NEXT: NumberOfAuxEntries: 0 +; SYM64-NEXT: } +; SYM64-NEXT: Symbol { +; SYM64-NEXT: Index: [[#INDX:]] +; SYM64-NEXT: Name: .bar +; SYM64-NEXT: Value (RelocatableAddress): 0x0 +; SYM64-NEXT: Section: N_UNDEF +; SYM64-NEXT: Type: 0x0 +; SYM64-NEXT: StorageClass: C_EXT (0x2) +; SYM64-NEXT: NumberOfAuxEntries: 1 +; SYM64-NEXT: CSECT Auxiliary Entry { +; SYM64-NEXT: Index: [[#INDX+1]] +; SYM64-NEXT: SectionLen: 0 +; SYM64-NEXT: ParameterHashIndex: 0x0 +; SYM64-NEXT: TypeChkSectNum: 0x0 +; SYM64-NEXT: SymbolAlignmentLog2: 0 +; SYM64-NEXT: SymbolType: XTY_ER (0x0) +; SYM64-NEXT: StorageMappingClass: XMC_PR (0x0) +; SYM64-NEXT: Auxiliary Type: AUX_CSECT (0xFB) +; SYM64-NEXT: } +; SYM64-NEXT: } +; SYM64-NEXT: Symbol { +; SYM64-NEXT: Index: [[#INDX+2]] +; SYM64-NEXT: Name: bar +; SYM64-NEXT: Value (RelocatableAddress): 0x0 +; SYM64-NEXT: Section: N_UNDEF +; SYM64-NEXT: Type: 0x0 +; SYM64-NEXT: StorageClass: C_EXT (0x2) +; SYM64-NEXT: NumberOfAuxEntries: 1 +; SYM64-NEXT: CSECT Auxiliary Entry { +; SYM64-NEXT: Index: [[#INDX+3]] +; SYM64-NEXT: SectionLen: 0 +; SYM64-NEXT: ParameterHashIndex: 0x0 +; SYM64-NEXT: TypeChkSectNum: 0x0 +; SYM64-NEXT: SymbolAlignmentLog2: 0 +; SYM64-NEXT: SymbolType: XTY_ER (0x0) +; SYM64-NEXT: StorageMappingClass: XMC_DS (0xA) +; SYM64-NEXT: Auxiliary Type: AUX_CSECT (0xFB) +; SYM64-NEXT: } +; SYM64-NEXT: } +; SYM64-NEXT: Symbol { +; SYM64-NEXT: Index: [[#INDX+4]] +; SYM64-NEXT: Name: .text +; SYM64-NEXT: Value (RelocatableAddress): 0x0 +; SYM64-NEXT: Section: .text +; SYM64-NEXT: Type: 0x0 +; SYM64-NEXT: StorageClass: C_HIDEXT (0x6B) +; SYM64-NEXT: NumberOfAuxEntries: 1 +; SYM64-NEXT: CSECT Auxiliary Entry { +; SYM64-NEXT: Index: [[#INDX+5]] +; SYM64-NEXT: SectionLen: 64 +; SYM64-NEXT: ParameterHashIndex: 0x0 +; SYM64-NEXT: TypeChkSectNum: 0x0 +; SYM64-NEXT: SymbolAlignmentLog2: 4 +; SYM64-NEXT: SymbolType: XTY_SD (0x1) +; SYM64-NEXT: StorageMappingClass: XMC_PR (0x0) +; SYM64-NEXT: Auxiliary Type: AUX_CSECT (0xFB) +; SYM64-NEXT: } +; SYM64-NEXT: } +; SYM64-NEXT: Symbol { +; SYM64-NEXT: Index: [[#INDX+6]] +; SYM64-NEXT: Name: .foo +; SYM64-NEXT: Value (RelocatableAddress): 0x0 +; SYM64-NEXT: Section: .text +; SYM64-NEXT: Type: 0x0 +; SYM64-NEXT: StorageClass: C_EXT (0x2) +; SYM64-NEXT: NumberOfAuxEntries: 1 +; SYM64-NEXT: CSECT Auxiliary Entry { +; SYM64-NEXT: Index: [[#INDX+7]] +; SYM64-NEXT: ContainingCsectSymbolIndex: [[#INDX+4]] +; SYM64-NEXT: ParameterHashIndex: 0x0 +; SYM64-NEXT: TypeChkSectNum: 0x0 +; SYM64-NEXT: SymbolAlignmentLog2: 0 +; SYM64-NEXT: SymbolType: XTY_LD (0x2) +; SYM64-NEXT: StorageMappingClass: XMC_PR (0x0) +; SYM64-NEXT: Auxiliary Type: AUX_CSECT (0xFB) +; SYM64-NEXT: } +; SYM64-NEXT: } +; SYM64-NEXT: Symbol { +; SYM64-NEXT: Index: [[#INDX+8]] +; SYM64-NEXT: Name: .data +; SYM64-NEXT: Value (RelocatableAddress): 0x40 +; SYM64-NEXT: Section: .data +; SYM64-NEXT: Type: 0x0 +; SYM64-NEXT: StorageClass: C_HIDEXT (0x6B) +; SYM64-NEXT: NumberOfAuxEntries: 1 +; SYM64-NEXT: CSECT Auxiliary Entry { +; SYM64-NEXT: Index: [[#INDX+9]] +; SYM64-NEXT: SectionLen: 56 +; SYM64-NEXT: ParameterHashIndex: 0x0 +; SYM64-NEXT: TypeChkSectNum: 0x0 +; SYM64-NEXT: SymbolAlignmentLog2: 3 +; SYM64-NEXT: SymbolType: XTY_SD (0x1) +; SYM64-NEXT: StorageMappingClass: XMC_RW (0x5) +; SYM64-NEXT: Auxiliary Type: AUX_CSECT (0xFB) +; SYM64-NEXT: } +; SYM64-NEXT: } +; SYM64-NEXT: Symbol { +; SYM64-NEXT: Index: [[#INDX+10]] +; SYM64-NEXT: Name: globalA +; SYM64-NEXT: Value (RelocatableAddress): 0x40 +; SYM64-NEXT: Section: .data +; SYM64-NEXT: Type: 0x0 +; SYM64-NEXT: StorageClass: C_EXT (0x2) +; SYM64-NEXT: NumberOfAuxEntries: 1 +; SYM64-NEXT: CSECT Auxiliary Entry { +; SYM64-NEXT: Index: [[#INDX+11]] +; SYM64-NEXT: ContainingCsectSymbolIndex: [[#INDX+8]] +; SYM64-NEXT: ParameterHashIndex: 0x0 +; SYM64-NEXT: TypeChkSectNum: 0x0 +; SYM64-NEXT: SymbolAlignmentLog2: 0 +; SYM64-NEXT: SymbolType: XTY_LD (0x2) +; SYM64-NEXT: StorageMappingClass: XMC_RW (0x5) +; SYM64-NEXT: Auxiliary Type: AUX_CSECT (0xFB) +; SYM64-NEXT: } +; SYM64-NEXT: } +; SYM64-NEXT: Symbol { +; SYM64-NEXT: Index: [[#INDX+12]] +; SYM64-NEXT: Name: globalB +; SYM64-NEXT: Value (RelocatableAddress): 0x44 +; SYM64-NEXT: Section: .data +; SYM64-NEXT: Type: 0x0 +; SYM64-NEXT: StorageClass: C_EXT (0x2) +; SYM64-NEXT: NumberOfAuxEntries: 1 +; SYM64-NEXT: CSECT Auxiliary Entry { +; SYM64-NEXT: Index: [[#INDX+13]] +; SYM64-NEXT: ContainingCsectSymbolIndex: [[#INDX+8]] +; SYM64-NEXT: ParameterHashIndex: 0x0 +; SYM64-NEXT: TypeChkSectNum: 0x0 +; SYM64-NEXT: SymbolAlignmentLog2: 0 +; SYM64-NEXT: SymbolType: XTY_LD (0x2) +; SYM64-NEXT: StorageMappingClass: XMC_RW (0x5) +; SYM64-NEXT: Auxiliary Type: AUX_CSECT (0xFB) +; SYM64-NEXT: } +; SYM64-NEXT: } +; SYM64-NEXT: Symbol { +; SYM64-NEXT: Index: [[#INDX+14]] +; SYM64-NEXT: Name: arr +; SYM64-NEXT: Value (RelocatableAddress): 0x48 +; SYM64-NEXT: Section: .data +; SYM64-NEXT: Type: 0x0 +; SYM64-NEXT: StorageClass: C_EXT (0x2) +; SYM64-NEXT: NumberOfAuxEntries: 1 +; SYM64-NEXT: CSECT Auxiliary Entry { +; SYM64-NEXT: Index: [[#INDX+15]] +; SYM64-NEXT: ContainingCsectSymbolIndex: [[#INDX+8]] +; SYM64-NEXT: ParameterHashIndex: 0x0 +; SYM64-NEXT: TypeChkSectNum: 0x0 +; SYM64-NEXT: SymbolAlignmentLog2: 0 +; SYM64-NEXT: SymbolType: XTY_LD (0x2) +; SYM64-NEXT: StorageMappingClass: XMC_RW (0x5) +; SYM64-NEXT: Auxiliary Type: AUX_CSECT (0xFB) +; SYM64-NEXT: } +; SYM64-NEXT: } +; SYM64-NEXT: Symbol { +; SYM64-NEXT: Index: [[#INDX+16]] +; SYM64-NEXT: Name: p +; SYM64-NEXT: Value (RelocatableAddress): 0x70 +; SYM64-NEXT: Section: .data +; SYM64-NEXT: Type: 0x0 +; SYM64-NEXT: StorageClass: C_EXT (0x2) +; SYM64-NEXT: NumberOfAuxEntries: 1 +; SYM64-NEXT: CSECT Auxiliary Entry { +; SYM64-NEXT: Index: [[#INDX+17]] +; SYM64-NEXT: ContainingCsectSymbolIndex: [[#INDX+8]] +; SYM64-NEXT: ParameterHashIndex: 0x0 +; SYM64-NEXT: TypeChkSectNum: 0x0 +; SYM64-NEXT: SymbolAlignmentLog2: 0 +; SYM64-NEXT: SymbolType: XTY_LD (0x2) +; SYM64-NEXT: StorageMappingClass: XMC_RW (0x5) +; SYM64-NEXT: Auxiliary Type: AUX_CSECT (0xFB) +; SYM64-NEXT: } +; SYM64-NEXT: } +; SYM64-NEXT: Symbol { +; SYM64-NEXT: Index: [[#INDX+18]] +; SYM64-NEXT: Name: foo +; SYM64-NEXT: Value (RelocatableAddress): 0x78 +; SYM64-NEXT: Section: .data +; SYM64-NEXT: Type: 0x0 +; SYM64-NEXT: StorageClass: C_EXT (0x2) +; SYM64-NEXT: NumberOfAuxEntries: 1 +; SYM64-NEXT: CSECT Auxiliary Entry { +; SYM64-NEXT: Index: [[#INDX+19]] +; SYM64-NEXT: SectionLen: 24 +; SYM64-NEXT: ParameterHashIndex: 0x0 +; SYM64-NEXT: TypeChkSectNum: 0x0 +; SYM64-NEXT: SymbolAlignmentLog2: 3 +; SYM64-NEXT: SymbolType: XTY_SD (0x1) +; SYM64-NEXT: StorageMappingClass: XMC_DS (0xA) +; SYM64-NEXT: Auxiliary Type: AUX_CSECT (0xFB) +; SYM64-NEXT: } +; SYM64-NEXT: } +; SYM64-NEXT: Symbol { +; SYM64-NEXT: Index: [[#INDX+20]] +; SYM64-NEXT: Name: TOC +; SYM64-NEXT: Value (RelocatableAddress): 0x90 +; SYM64-NEXT: Section: .data +; SYM64-NEXT: Type: 0x0 +; SYM64-NEXT: StorageClass: C_HIDEXT (0x6B) +; SYM64-NEXT: NumberOfAuxEntries: 1 +; SYM64-NEXT: CSECT Auxiliary Entry { +; SYM64-NEXT: Index: [[#INDX+21]] +; SYM64-NEXT: SectionLen: 0 +; SYM64-NEXT: ParameterHashIndex: 0x0 +; SYM64-NEXT: TypeChkSectNum: 0x0 +; SYM64-NEXT: SymbolAlignmentLog2: 2 +; SYM64-NEXT: SymbolType: XTY_SD (0x1) +; SYM64-NEXT: StorageMappingClass: XMC_TC0 (0xF) +; SYM64-NEXT: Auxiliary Type: AUX_CSECT (0xFB) +; SYM64-NEXT: } +; SYM64-NEXT: } +; SYM64-NEXT: Symbol { +; SYM64-NEXT: Index: [[#INDX+22]] +; SYM64-NEXT: Name: globalA +; SYM64-NEXT: Value (RelocatableAddress): 0x90 +; SYM64-NEXT: Section: .data +; SYM64-NEXT: Type: 0x0 +; SYM64-NEXT: StorageClass: C_HIDEXT (0x6B) +; SYM64-NEXT: NumberOfAuxEntries: 1 +; SYM64-NEXT: CSECT Auxiliary Entry { +; SYM64-NEXT: Index: [[#INDX+23]] +; SYM64-NEXT: SectionLen: 8 +; SYM64-NEXT: ParameterHashIndex: 0x0 +; SYM64-NEXT: TypeChkSectNum: 0x0 +; SYM64-NEXT: SymbolAlignmentLog2: 3 +; SYM64-NEXT: SymbolType: XTY_SD (0x1) +; SYM64-NEXT: StorageMappingClass: XMC_TC (0x3) +; SYM64-NEXT: Auxiliary Type: AUX_CSECT (0xFB) +; SYM64-NEXT: } +; SYM64-NEXT: } +; SYM64-NEXT: Symbol { +; SYM64-NEXT: Index: [[#INDX+24]] +; SYM64-NEXT: Name: globalB +; SYM64-NEXT: Value (RelocatableAddress): 0x98 +; SYM64-NEXT: Section: .data +; SYM64-NEXT: Type: 0x0 +; SYM64-NEXT: StorageClass: C_HIDEXT (0x6B) +; SYM64-NEXT: NumberOfAuxEntries: 1 +; SYM64-NEXT: CSECT Auxiliary Entry { +; SYM64-NEXT: Index: [[#INDX+25]] +; SYM64-NEXT: SectionLen: 8 +; SYM64-NEXT: ParameterHashIndex: 0x0 +; SYM64-NEXT: TypeChkSectNum: 0x0 +; SYM64-NEXT: SymbolAlignmentLog2: 3 +; SYM64-NEXT: SymbolType: XTY_SD (0x1) +; SYM64-NEXT: StorageMappingClass: XMC_TC (0x3) +; SYM64-NEXT: Auxiliary Type: AUX_CSECT (0xFB) +; SYM64-NEXT: } +; SYM64-NEXT: } +; SYM64-NEXT: ] + + +; DIS64: {{.*}}aix-xcoff-reloc.ll.tmp.o: file format aix5coff64-rs6000 +; DIS64: Disassembly of section .text: +; DIS64: 00000000 <.text>: +; DIS64-NEXT: 0: 7c 08 02 a6 mflr 0 +; DIS64-NEXT: 4: f8 01 00 10 std 0, 16(1) +; DIS64-NEXT: 8: f8 21 ff 91 stdu 1, -112(1) +; DIS64-NEXT: c: 38 60 00 01 li 3, 1 +; DIS64-NEXT: 10: 4b ff ff f1 bl 0x0 +; DIS64-NEXT: 14: 60 00 00 00 nop +; DIS64-NEXT: 18: e8 82 00 00 ld 4, 0(2) +; DIS64-NEXT: 1c: e8 a2 00 08 ld 5, 8(2) +; DIS64-NEXT: 20: 80 84 00 00 lwz 4, 0(4) +; DIS64-NEXT: 24: 80 a5 00 00 lwz 5, 0(5) +; DIS64-NEXT: 28: 7c 63 22 14 add 3, 3, 4 +; DIS64-NEXT: 2c: 7c 63 2a 14 add 3, 3, 5 +; DIS64-NEXT: 30: 38 21 00 70 addi 1, 1, 112 +; DIS64-NEXT: 34: e8 01 00 10 ld 0, 16(1) +; DIS64-NEXT: 38: 7c 08 03 a6 mtlr 0 +; DIS64-NEXT: 3c: 4e 80 00 20 blr + +; DIS64: Disassembly of section .data: +; DIS64: 00000040 : +; DIS64-NEXT: 40: 00 00 00 01 +; DIS64: 00000044 : +; DIS64-NEXT: 44: 00 00 00 02 +; DIS64: 00000048 : +; DIS64-NEXT: 48: 00 00 00 03 +; DIS64-NEXT: ... +; DIS64: 00000070

: +; DIS64-NEXT: 70: 00 00 00 00 +; DIS64-NEXT: 74: 00 00 00 58 +; DIS64: 00000078 : +; DIS64-NEXT: ... +; DIS64-NEXT: 84: 00 00 00 90 +; DIS64: 00000090 : +; DIS64-NEXT: 90: 00 00 00 00 +; DIS64-NEXT: 94: 00 00 00 40 +; DIS64: 00000098 : +; DIS64-NEXT: 98: 00 00 00 00 +; DIS64-NEXT: 9c: 00 00 00 44 + +; DIS_REL64: {{.*}}aix-xcoff-reloc.ll.tmp.o: file format aix5coff64-rs6000 +; DIS_REL64: RELOCATION RECORDS FOR [.text]: +; DIS_REL64-NEXT: OFFSET TYPE VALUE +; DIS_REL64-NEXT: 00000010 R_RBR .bar +; DIS_REL64-NEXT: 0000001a R_TOC globalA +; DIS_REL64-NEXT: 0000001e R_TOC globalB +; DIS_REL64: RELOCATION RECORDS FOR [.data]: +; DIS_REL64-NEXT: OFFSET TYPE VALUE +; DIS_REL64-NEXT: 00000030 R_POS arr +; DIS_REL64-NEXT: 00000038 R_POS .foo +; DIS_REL64-NEXT: 00000040 R_POS TOC +; DIS_REL64-NEXT: 00000050 R_POS globalA +; DIS_REL64-NEXT: 00000058 R_POS global diff --git a/llvm/tools/llvm-readobj/XCOFFDumper.cpp b/llvm/tools/llvm-readobj/XCOFFDumper.cpp --- a/llvm/tools/llvm-readobj/XCOFFDumper.cpp +++ b/llvm/tools/llvm-readobj/XCOFFDumper.cpp @@ -43,7 +43,7 @@ void printCsectAuxEnt(XCOFFCsectAuxRef AuxEntRef); void printSectAuxEntForStat(const XCOFFSectAuxEntForStat *AuxEntPtr); void printSymbol(const SymbolRef &); - void printRelocations(ArrayRef Sections); + template void printRelocations(ArrayRef Sections); const XCOFFObjectFile &Obj; }; } // anonymous namespace @@ -104,9 +104,9 @@ void XCOFFDumper::printRelocations() { if (Obj.is64Bit()) - llvm_unreachable("64-bit relocation output not implemented!"); + printRelocations(Obj.sections64()); else - printRelocations(Obj.sections32()); + printRelocations(Obj.sections32()); } static const EnumEntry RelocationTypeNameclass[] = { @@ -121,7 +121,8 @@ #undef ECase }; -void XCOFFDumper::printRelocations(ArrayRef Sections) { +template +void XCOFFDumper::printRelocations(ArrayRef Sections) { if (!opts::ExpandRelocs) report_fatal_error("Unexpanded relocation output not implemented."); @@ -133,16 +134,22 @@ if (Sec.Flags != XCOFF::STYP_TEXT && Sec.Flags != XCOFF::STYP_DATA && Sec.Flags != XCOFF::STYP_TDATA && Sec.Flags != XCOFF::STYP_DWARF) continue; - auto Relocations = unwrapOrError(Obj.getFileName(), Obj.relocations(Sec)); + auto ErrOrRelocations = Obj.relocations(Sec); + if (Error E = ErrOrRelocations.takeError()) + reportUniqueWarning(std::move(E)); + + const auto Relocations = ErrOrRelocations.get(); if (Relocations.empty()) continue; W.startLine() << "Section (index: " << Index << ") " << Sec.getName() << " {\n"; - for (auto Reloc : Relocations) { - StringRef SymbolName = unwrapOrError( - Obj.getFileName(), Obj.getSymbolNameByIndex(Reloc.SymbolIndex)); + for (const auto &Reloc : Relocations) { + auto ErrOrSymbolName = Obj.getSymbolNameByIndex(Reloc.SymbolIndex); + if (Error E = ErrOrSymbolName.takeError()) + reportUniqueWarning(std::move(E)); + StringRef SymbolName = ErrOrSymbolName.get(); DictScope RelocScope(W, "Relocation"); W.printHex("Virtual Address", Reloc.VirtualAddress); W.printNumber("Symbol", SymbolName, Reloc.SymbolIndex);