[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
//===--- XCOFFObjectFile.cpp - XCOFF object file implementation -----------===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the XCOFFObjectFile class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Object/XCOFFObjectFile.h"
|
2020-05-27 20:10:37 +08:00
|
|
|
#include "llvm/MC/SubtargetFeature.h"
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
#include <cstddef>
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace object {
|
|
|
|
|
2020-03-28 00:02:27 +08:00
|
|
|
static const uint8_t FunctionSym = 0x20;
|
|
|
|
static const uint8_t SymTypeMask = 0x07;
|
|
|
|
static const uint16_t NoRelMask = 0x0001;
|
2019-08-28 02:54:46 +08:00
|
|
|
|
2019-07-10 02:09:11 +08:00
|
|
|
// Checks that [Ptr, Ptr + Size) bytes fall inside the memory buffer
|
|
|
|
// 'M'. Returns a pointer to the underlying object on success.
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
template <typename T>
|
2019-07-10 02:09:11 +08:00
|
|
|
static Expected<const T *> getObject(MemoryBufferRef M, const void *Ptr,
|
|
|
|
const uint64_t Size = sizeof(T)) {
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
uintptr_t Addr = uintptr_t(Ptr);
|
2020-06-06 07:12:38 +08:00
|
|
|
if (Error E = Binary::checkOffset(M, Addr, Size))
|
|
|
|
return std::move(E);
|
2019-07-10 02:09:11 +08:00
|
|
|
return reinterpret_cast<const T *>(Addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static uintptr_t getWithOffset(uintptr_t Base, ptrdiff_t Offset) {
|
|
|
|
return reinterpret_cast<uintptr_t>(reinterpret_cast<const char *>(Base) +
|
|
|
|
Offset);
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
}
|
|
|
|
|
2019-04-26 05:36:04 +08:00
|
|
|
template <typename T> static const T *viewAs(uintptr_t in) {
|
|
|
|
return reinterpret_cast<const T *>(in);
|
|
|
|
}
|
|
|
|
|
2019-08-28 02:54:46 +08:00
|
|
|
static StringRef generateXCOFFFixedNameStringRef(const char *Name) {
|
2019-08-12 23:27:40 +08:00
|
|
|
auto NulCharPtr =
|
|
|
|
static_cast<const char *>(memchr(Name, '\0', XCOFF::NameSize));
|
2019-05-28 22:37:59 +08:00
|
|
|
return NulCharPtr ? StringRef(Name, NulCharPtr - Name)
|
2019-08-12 23:27:40 +08:00
|
|
|
: StringRef(Name, XCOFF::NameSize);
|
2019-05-28 22:37:59 +08:00
|
|
|
}
|
|
|
|
|
2019-11-08 00:51:34 +08:00
|
|
|
template <typename T> StringRef XCOFFSectionHeader<T>::getName() const {
|
|
|
|
const T &DerivedXCOFFSectionHeader = static_cast<const T &>(*this);
|
|
|
|
return generateXCOFFFixedNameStringRef(DerivedXCOFFSectionHeader.Name);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T> uint16_t XCOFFSectionHeader<T>::getSectionType() const {
|
|
|
|
const T &DerivedXCOFFSectionHeader = static_cast<const T &>(*this);
|
|
|
|
return DerivedXCOFFSectionHeader.Flags & SectionFlagsTypeMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
bool XCOFFSectionHeader<T>::isReservedSectionType() const {
|
|
|
|
return getSectionType() & SectionFlagsReservedMask;
|
|
|
|
}
|
|
|
|
|
2019-10-16 04:42:11 +08:00
|
|
|
bool XCOFFRelocation32::isRelocationSigned() const {
|
|
|
|
return Info & XR_SIGN_INDICATOR_MASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool XCOFFRelocation32::isFixupIndicated() const {
|
|
|
|
return Info & XR_FIXUP_INDICATOR_MASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t XCOFFRelocation32::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;
|
|
|
|
}
|
|
|
|
|
2019-07-10 02:09:11 +08:00
|
|
|
void XCOFFObjectFile::checkSectionAddress(uintptr_t Addr,
|
|
|
|
uintptr_t TableAddress) const {
|
|
|
|
if (Addr < TableAddress)
|
|
|
|
report_fatal_error("Section header outside of section header table.");
|
|
|
|
|
|
|
|
uintptr_t Offset = Addr - TableAddress;
|
|
|
|
if (Offset >= getSectionHeaderSize() * getNumberOfSections())
|
2019-04-26 05:36:04 +08:00
|
|
|
report_fatal_error("Section header outside of section header table.");
|
|
|
|
|
|
|
|
if (Offset % getSectionHeaderSize() != 0)
|
|
|
|
report_fatal_error(
|
|
|
|
"Section header pointer does not point to a valid section header.");
|
2019-07-10 02:09:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const XCOFFSectionHeader32 *
|
|
|
|
XCOFFObjectFile::toSection32(DataRefImpl Ref) const {
|
|
|
|
assert(!is64Bit() && "32-bit interface called on 64-bit object file.");
|
|
|
|
#ifndef NDEBUG
|
|
|
|
checkSectionAddress(Ref.p, getSectionHeaderTableAddress());
|
2019-04-26 05:36:04 +08:00
|
|
|
#endif
|
2019-07-10 02:09:11 +08:00
|
|
|
return viewAs<XCOFFSectionHeader32>(Ref.p);
|
|
|
|
}
|
|
|
|
|
|
|
|
const XCOFFSectionHeader64 *
|
|
|
|
XCOFFObjectFile::toSection64(DataRefImpl Ref) const {
|
|
|
|
assert(is64Bit() && "64-bit interface called on a 32-bit object file.");
|
|
|
|
#ifndef NDEBUG
|
|
|
|
checkSectionAddress(Ref.p, getSectionHeaderTableAddress());
|
|
|
|
#endif
|
|
|
|
return viewAs<XCOFFSectionHeader64>(Ref.p);
|
2019-04-26 05:36:04 +08:00
|
|
|
}
|
|
|
|
|
2019-05-28 22:37:59 +08:00
|
|
|
const XCOFFSymbolEntry *XCOFFObjectFile::toSymbolEntry(DataRefImpl Ref) const {
|
2019-07-10 02:09:11 +08:00
|
|
|
assert(!is64Bit() && "Symbol table support not implemented for 64-bit.");
|
2019-05-28 22:37:59 +08:00
|
|
|
assert(Ref.p != 0 && "Symbol table pointer can not be nullptr!");
|
2019-08-28 02:54:46 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
checkSymbolEntryPointer(Ref.p);
|
|
|
|
#endif
|
2019-05-28 22:37:59 +08:00
|
|
|
auto SymEntPtr = viewAs<XCOFFSymbolEntry>(Ref.p);
|
|
|
|
return SymEntPtr;
|
|
|
|
}
|
|
|
|
|
2019-07-10 02:09:11 +08:00
|
|
|
const XCOFFFileHeader32 *XCOFFObjectFile::fileHeader32() const {
|
|
|
|
assert(!is64Bit() && "32-bit interface called on 64-bit object file.");
|
|
|
|
return static_cast<const XCOFFFileHeader32 *>(FileHeader);
|
2019-04-26 05:36:04 +08:00
|
|
|
}
|
|
|
|
|
2019-07-10 02:09:11 +08:00
|
|
|
const XCOFFFileHeader64 *XCOFFObjectFile::fileHeader64() const {
|
|
|
|
assert(is64Bit() && "64-bit interface called on a 32-bit object file.");
|
|
|
|
return static_cast<const XCOFFFileHeader64 *>(FileHeader);
|
2019-04-26 05:36:04 +08:00
|
|
|
}
|
|
|
|
|
2019-07-10 02:09:11 +08:00
|
|
|
const XCOFFSectionHeader32 *
|
|
|
|
XCOFFObjectFile::sectionHeaderTable32() const {
|
|
|
|
assert(!is64Bit() && "32-bit interface called on 64-bit object file.");
|
|
|
|
return static_cast<const XCOFFSectionHeader32 *>(SectionHeaderTable);
|
|
|
|
}
|
|
|
|
|
|
|
|
const XCOFFSectionHeader64 *
|
|
|
|
XCOFFObjectFile::sectionHeaderTable64() const {
|
|
|
|
assert(is64Bit() && "64-bit interface called on a 32-bit object file.");
|
|
|
|
return static_cast<const XCOFFSectionHeader64 *>(SectionHeaderTable);
|
|
|
|
}
|
2019-05-28 22:37:59 +08:00
|
|
|
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
void XCOFFObjectFile::moveSymbolNext(DataRefImpl &Symb) const {
|
2019-05-28 22:37:59 +08:00
|
|
|
const XCOFFSymbolEntry *SymEntPtr = toSymbolEntry(Symb);
|
|
|
|
SymEntPtr += SymEntPtr->NumberOfAuxEntries + 1;
|
2019-08-28 02:54:46 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
// This function is used by basic_symbol_iterator, which allows to
|
|
|
|
// point to the end-of-symbol-table address.
|
|
|
|
if (reinterpret_cast<uintptr_t>(SymEntPtr) != getEndOfSymbolTableAddress())
|
|
|
|
checkSymbolEntryPointer(reinterpret_cast<uintptr_t>(SymEntPtr));
|
|
|
|
#endif
|
2019-05-28 22:37:59 +08:00
|
|
|
Symb.p = reinterpret_cast<uintptr_t>(SymEntPtr);
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
}
|
|
|
|
|
2019-08-28 02:54:46 +08:00
|
|
|
Expected<StringRef>
|
|
|
|
XCOFFObjectFile::getStringTableEntry(uint32_t Offset) const {
|
|
|
|
// The byte offset is relative to the start of the string table.
|
|
|
|
// A byte offset value of 0 is a null or zero-length symbol
|
2019-05-28 22:37:59 +08:00
|
|
|
// name. A byte offset in the range 1 to 3 (inclusive) points into the length
|
|
|
|
// field; as a soft-error recovery mechanism, we treat such cases as having an
|
|
|
|
// offset of 0.
|
|
|
|
if (Offset < 4)
|
|
|
|
return StringRef(nullptr, 0);
|
|
|
|
|
|
|
|
if (StringTable.Data != nullptr && StringTable.Size > Offset)
|
|
|
|
return (StringTable.Data + Offset);
|
|
|
|
|
2019-08-28 02:54:46 +08:00
|
|
|
return make_error<GenericBinaryError>("Bad offset for string table entry",
|
2019-05-28 22:37:59 +08:00
|
|
|
object_error::parse_failed);
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
}
|
|
|
|
|
2019-08-28 02:54:46 +08:00
|
|
|
Expected<StringRef>
|
|
|
|
XCOFFObjectFile::getCFileName(const XCOFFFileAuxEnt *CFileEntPtr) const {
|
|
|
|
if (CFileEntPtr->NameInStrTbl.Magic !=
|
|
|
|
XCOFFSymbolEntry::NAME_IN_STR_TBL_MAGIC)
|
|
|
|
return generateXCOFFFixedNameStringRef(CFileEntPtr->Name);
|
|
|
|
return getStringTableEntry(CFileEntPtr->NameInStrTbl.Offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
Expected<StringRef> XCOFFObjectFile::getSymbolName(DataRefImpl Symb) const {
|
|
|
|
const XCOFFSymbolEntry *SymEntPtr = toSymbolEntry(Symb);
|
|
|
|
|
|
|
|
// A storage class value with the high-order bit on indicates that the name is
|
|
|
|
// a symbolic debugger stabstring.
|
|
|
|
if (SymEntPtr->StorageClass & 0x80)
|
|
|
|
return StringRef("Unimplemented Debug Name");
|
|
|
|
|
|
|
|
if (SymEntPtr->NameInStrTbl.Magic != XCOFFSymbolEntry::NAME_IN_STR_TBL_MAGIC)
|
|
|
|
return generateXCOFFFixedNameStringRef(SymEntPtr->SymbolName);
|
|
|
|
|
|
|
|
return getStringTableEntry(SymEntPtr->NameInStrTbl.Offset);
|
|
|
|
}
|
|
|
|
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
Expected<uint64_t> XCOFFObjectFile::getSymbolAddress(DataRefImpl Symb) const {
|
2019-11-20 02:29:09 +08:00
|
|
|
assert(!is64Bit() && "Symbol table support not implemented for 64-bit.");
|
|
|
|
return toSymbolEntry(Symb)->Value;
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t XCOFFObjectFile::getSymbolValueImpl(DataRefImpl Symb) const {
|
2019-08-28 02:54:46 +08:00
|
|
|
assert(!is64Bit() && "Symbol table support not implemented for 64-bit.");
|
2019-05-28 22:37:59 +08:00
|
|
|
return toSymbolEntry(Symb)->Value;
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t XCOFFObjectFile::getCommonSymbolSizeImpl(DataRefImpl Symb) const {
|
|
|
|
uint64_t Result = 0;
|
|
|
|
llvm_unreachable("Not yet implemented!");
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Expected<SymbolRef::Type>
|
|
|
|
XCOFFObjectFile::getSymbolType(DataRefImpl Symb) const {
|
|
|
|
llvm_unreachable("Not yet implemented!");
|
|
|
|
return SymbolRef::ST_Other;
|
|
|
|
}
|
|
|
|
|
|
|
|
Expected<section_iterator>
|
|
|
|
XCOFFObjectFile::getSymbolSection(DataRefImpl Symb) const {
|
2019-05-28 22:37:59 +08:00
|
|
|
const XCOFFSymbolEntry *SymEntPtr = toSymbolEntry(Symb);
|
|
|
|
int16_t SectNum = SymEntPtr->SectionNumber;
|
|
|
|
|
|
|
|
if (isReservedSectionNumber(SectNum))
|
|
|
|
return section_end();
|
|
|
|
|
2019-07-10 02:09:11 +08:00
|
|
|
Expected<DataRefImpl> ExpSec = getSectionByNum(SectNum);
|
|
|
|
if (!ExpSec)
|
|
|
|
return ExpSec.takeError();
|
2019-05-28 22:37:59 +08:00
|
|
|
|
2019-07-10 02:09:11 +08:00
|
|
|
return section_iterator(SectionRef(ExpSec.get(), this));
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void XCOFFObjectFile::moveSectionNext(DataRefImpl &Sec) const {
|
2019-04-26 05:36:04 +08:00
|
|
|
const char *Ptr = reinterpret_cast<const char *>(Sec.p);
|
|
|
|
Sec.p = reinterpret_cast<uintptr_t>(Ptr + getSectionHeaderSize());
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
}
|
|
|
|
|
2019-05-02 18:32:03 +08:00
|
|
|
Expected<StringRef> XCOFFObjectFile::getSectionName(DataRefImpl Sec) const {
|
2019-08-28 02:54:46 +08:00
|
|
|
return generateXCOFFFixedNameStringRef(getSectionNameInternal(Sec));
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t XCOFFObjectFile::getSectionAddress(DataRefImpl Sec) const {
|
2019-07-10 02:44:28 +08:00
|
|
|
// Avoid ternary due to failure to convert the ubig32_t value to a unit64_t
|
|
|
|
// with MSVC.
|
|
|
|
if (is64Bit())
|
|
|
|
return toSection64(Sec)->VirtualAddress;
|
|
|
|
|
|
|
|
return toSection32(Sec)->VirtualAddress;
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t XCOFFObjectFile::getSectionIndex(DataRefImpl Sec) const {
|
2019-04-26 05:36:04 +08:00
|
|
|
// Section numbers in XCOFF are numbered beginning at 1. A section number of
|
|
|
|
// zero is used to indicate that a symbol is being imported or is undefined.
|
2019-07-10 02:09:11 +08:00
|
|
|
if (is64Bit())
|
|
|
|
return toSection64(Sec) - sectionHeaderTable64() + 1;
|
|
|
|
else
|
|
|
|
return toSection32(Sec) - sectionHeaderTable32() + 1;
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t XCOFFObjectFile::getSectionSize(DataRefImpl Sec) const {
|
2019-07-10 02:44:28 +08:00
|
|
|
// Avoid ternary due to failure to convert the ubig32_t value to a unit64_t
|
|
|
|
// with MSVC.
|
|
|
|
if (is64Bit())
|
|
|
|
return toSection64(Sec)->SectionSize;
|
|
|
|
|
|
|
|
return toSection32(Sec)->SectionSize;
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
}
|
|
|
|
|
2019-05-14 12:22:51 +08:00
|
|
|
Expected<ArrayRef<uint8_t>>
|
|
|
|
XCOFFObjectFile::getSectionContents(DataRefImpl Sec) const {
|
2019-11-20 02:29:09 +08:00
|
|
|
if (isSectionVirtual(Sec))
|
|
|
|
return ArrayRef<uint8_t>();
|
|
|
|
|
2019-11-20 04:17:32 +08:00
|
|
|
uint64_t OffsetToRaw;
|
|
|
|
if (is64Bit())
|
|
|
|
OffsetToRaw = toSection64(Sec)->FileOffsetToRawData;
|
|
|
|
else
|
|
|
|
OffsetToRaw = toSection32(Sec)->FileOffsetToRawData;
|
2019-11-20 02:29:09 +08:00
|
|
|
|
|
|
|
const uint8_t * ContentStart = base() + OffsetToRaw;
|
|
|
|
uint64_t SectionSize = getSectionSize(Sec);
|
|
|
|
if (checkOffset(Data, uintptr_t(ContentStart), SectionSize))
|
|
|
|
return make_error<BinaryError>();
|
|
|
|
|
|
|
|
return makeArrayRef(ContentStart,SectionSize);
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t XCOFFObjectFile::getSectionAlignment(DataRefImpl Sec) const {
|
|
|
|
uint64_t Result = 0;
|
|
|
|
llvm_unreachable("Not yet implemented!");
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool XCOFFObjectFile::isSectionCompressed(DataRefImpl Sec) const {
|
|
|
|
bool Result = false;
|
|
|
|
llvm_unreachable("Not yet implemented!");
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool XCOFFObjectFile::isSectionText(DataRefImpl Sec) const {
|
2019-07-10 02:09:11 +08:00
|
|
|
return getSectionFlags(Sec) & XCOFF::STYP_TEXT;
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool XCOFFObjectFile::isSectionData(DataRefImpl Sec) const {
|
2019-07-10 02:09:11 +08:00
|
|
|
uint32_t Flags = getSectionFlags(Sec);
|
2019-04-26 05:36:04 +08:00
|
|
|
return Flags & (XCOFF::STYP_DATA | XCOFF::STYP_TDATA);
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool XCOFFObjectFile::isSectionBSS(DataRefImpl Sec) const {
|
2019-07-10 02:09:11 +08:00
|
|
|
uint32_t Flags = getSectionFlags(Sec);
|
2019-04-26 05:36:04 +08:00
|
|
|
return Flags & (XCOFF::STYP_BSS | XCOFF::STYP_TBSS);
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool XCOFFObjectFile::isSectionVirtual(DataRefImpl Sec) const {
|
2019-11-20 02:29:09 +08:00
|
|
|
return is64Bit() ? toSection64(Sec)->FileOffsetToRawData == 0
|
|
|
|
: toSection32(Sec)->FileOffsetToRawData == 0;
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
relocation_iterator XCOFFObjectFile::section_rel_begin(DataRefImpl Sec) const {
|
2020-03-28 00:02:27 +08:00
|
|
|
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<uintptr_t>(&*RelocationsOrErr.get().begin());
|
|
|
|
return relocation_iterator(RelocationRef(Ret, this));
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
relocation_iterator XCOFFObjectFile::section_rel_end(DataRefImpl Sec) const {
|
2020-03-28 00:02:27 +08:00
|
|
|
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<uintptr_t>(&*RelocationsOrErr.get().end());
|
|
|
|
return relocation_iterator(RelocationRef(Ret, this));
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void XCOFFObjectFile::moveRelocationNext(DataRefImpl &Rel) const {
|
2020-03-28 00:02:27 +08:00
|
|
|
Rel.p = reinterpret_cast<uintptr_t>(viewAs<XCOFFRelocation32>(Rel.p) + 1);
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t XCOFFObjectFile::getRelocationOffset(DataRefImpl Rel) const {
|
2020-03-28 00:02:27 +08:00
|
|
|
if (is64Bit())
|
|
|
|
report_fatal_error("64-bit support not implemented yet");
|
|
|
|
const XCOFFRelocation32 *Reloc = viewAs<XCOFFRelocation32>(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;
|
|
|
|
}
|
|
|
|
++Sec32;
|
|
|
|
}
|
|
|
|
return InvalidRelocOffset;
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
symbol_iterator XCOFFObjectFile::getRelocationSymbol(DataRefImpl Rel) const {
|
2020-03-28 00:02:27 +08:00
|
|
|
if (is64Bit())
|
|
|
|
report_fatal_error("64-bit support not implemented yet");
|
|
|
|
const XCOFFRelocation32 *Reloc = viewAs<XCOFFRelocation32>(Rel.p);
|
|
|
|
const uint32_t Index = Reloc->SymbolIndex;
|
|
|
|
|
|
|
|
if (Index >= getLogicalNumberOfSymbolTableEntries32())
|
|
|
|
return symbol_end();
|
|
|
|
|
|
|
|
DataRefImpl SymDRI;
|
|
|
|
SymDRI.p = reinterpret_cast<uintptr_t>(getPointerToSymbolTable() + Index);
|
|
|
|
return symbol_iterator(SymbolRef(SymDRI, this));
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t XCOFFObjectFile::getRelocationType(DataRefImpl Rel) const {
|
2020-03-28 00:02:27 +08:00
|
|
|
if (is64Bit())
|
|
|
|
report_fatal_error("64-bit support not implemented yet");
|
|
|
|
return viewAs<XCOFFRelocation32>(Rel.p)->Type;
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void XCOFFObjectFile::getRelocationTypeName(
|
|
|
|
DataRefImpl Rel, SmallVectorImpl<char> &Result) const {
|
2020-03-28 00:02:27 +08:00
|
|
|
if (is64Bit())
|
|
|
|
report_fatal_error("64-bit support not implemented yet");
|
|
|
|
const XCOFFRelocation32 *Reloc = viewAs<XCOFFRelocation32>(Rel.p);
|
|
|
|
StringRef Res = XCOFF::getRelocationTypeString(Reloc->Type);
|
|
|
|
Result.append(Res.begin(), Res.end());
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
}
|
|
|
|
|
2020-04-10 20:24:21 +08:00
|
|
|
Expected<uint32_t> XCOFFObjectFile::getSymbolFlags(DataRefImpl Symb) const {
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
uint32_t Result = 0;
|
|
|
|
llvm_unreachable("Not yet implemented!");
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
basic_symbol_iterator XCOFFObjectFile::symbol_begin() const {
|
2020-03-28 00:02:27 +08:00
|
|
|
if (is64Bit())
|
|
|
|
report_fatal_error("64-bit support not implemented yet");
|
2019-05-28 22:37:59 +08:00
|
|
|
DataRefImpl SymDRI;
|
|
|
|
SymDRI.p = reinterpret_cast<uintptr_t>(SymbolTblPtr);
|
|
|
|
return basic_symbol_iterator(SymbolRef(SymDRI, this));
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
basic_symbol_iterator XCOFFObjectFile::symbol_end() const {
|
2020-03-28 00:02:27 +08:00
|
|
|
if (is64Bit())
|
|
|
|
report_fatal_error("64-bit support not implemented yet");
|
2019-05-28 22:37:59 +08:00
|
|
|
DataRefImpl SymDRI;
|
|
|
|
SymDRI.p = reinterpret_cast<uintptr_t>(
|
2019-07-10 02:09:11 +08:00
|
|
|
SymbolTblPtr + getLogicalNumberOfSymbolTableEntries32());
|
2019-05-28 22:37:59 +08:00
|
|
|
return basic_symbol_iterator(SymbolRef(SymDRI, this));
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
section_iterator XCOFFObjectFile::section_begin() const {
|
2019-04-26 05:36:04 +08:00
|
|
|
DataRefImpl DRI;
|
2019-07-10 02:09:11 +08:00
|
|
|
DRI.p = getSectionHeaderTableAddress();
|
2019-04-26 05:36:04 +08:00
|
|
|
return section_iterator(SectionRef(DRI, this));
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
section_iterator XCOFFObjectFile::section_end() const {
|
2019-04-26 05:36:04 +08:00
|
|
|
DataRefImpl DRI;
|
2019-07-10 02:09:11 +08:00
|
|
|
DRI.p = getWithOffset(getSectionHeaderTableAddress(),
|
|
|
|
getNumberOfSections() * getSectionHeaderSize());
|
2019-04-26 05:36:04 +08:00
|
|
|
return section_iterator(SectionRef(DRI, this));
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
}
|
|
|
|
|
2019-07-10 02:09:11 +08:00
|
|
|
uint8_t XCOFFObjectFile::getBytesInAddress() const { return is64Bit() ? 8 : 4; }
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
|
|
|
|
StringRef XCOFFObjectFile::getFileFormatName() const {
|
2019-07-10 02:09:11 +08:00
|
|
|
return is64Bit() ? "aix5coff64-rs6000" : "aixcoff-rs6000";
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Triple::ArchType XCOFFObjectFile::getArch() const {
|
2019-07-10 02:09:11 +08:00
|
|
|
return is64Bit() ? Triple::ppc64 : Triple::ppc;
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SubtargetFeatures XCOFFObjectFile::getFeatures() const {
|
|
|
|
return SubtargetFeatures();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool XCOFFObjectFile::isRelocatableObject() const {
|
2020-03-28 00:02:27 +08:00
|
|
|
if (is64Bit())
|
|
|
|
report_fatal_error("64-bit support not implemented yet");
|
|
|
|
return !(fileHeader32()->Flags & NoRelMask);
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
}
|
|
|
|
|
2019-04-26 05:36:04 +08:00
|
|
|
Expected<uint64_t> XCOFFObjectFile::getStartAddress() const {
|
|
|
|
// TODO FIXME Should get from auxiliary_header->o_entry when support for the
|
|
|
|
// auxiliary_header is added.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-10 02:09:11 +08:00
|
|
|
size_t XCOFFObjectFile::getFileHeaderSize() const {
|
|
|
|
return is64Bit() ? sizeof(XCOFFFileHeader64) : sizeof(XCOFFFileHeader32);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t XCOFFObjectFile::getSectionHeaderSize() const {
|
|
|
|
return is64Bit() ? sizeof(XCOFFSectionHeader64) :
|
|
|
|
sizeof(XCOFFSectionHeader32);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool XCOFFObjectFile::is64Bit() const {
|
|
|
|
return Binary::ID_XCOFF64 == getType();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t XCOFFObjectFile::getMagic() const {
|
|
|
|
return is64Bit() ? fileHeader64()->Magic : fileHeader32()->Magic;
|
|
|
|
}
|
|
|
|
|
|
|
|
Expected<DataRefImpl> XCOFFObjectFile::getSectionByNum(int16_t Num) const {
|
|
|
|
if (Num <= 0 || Num > getNumberOfSections())
|
|
|
|
return errorCodeToError(object_error::invalid_section_index);
|
2019-05-28 22:37:59 +08:00
|
|
|
|
2019-07-10 02:09:11 +08:00
|
|
|
DataRefImpl DRI;
|
|
|
|
DRI.p = getWithOffset(getSectionHeaderTableAddress(),
|
|
|
|
getSectionHeaderSize() * (Num - 1));
|
|
|
|
return DRI;
|
2019-05-28 22:37:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Expected<StringRef>
|
|
|
|
XCOFFObjectFile::getSymbolSectionName(const XCOFFSymbolEntry *SymEntPtr) const {
|
2019-07-10 02:09:11 +08:00
|
|
|
assert(!is64Bit() && "Symbol table support not implemented for 64-bit.");
|
2019-05-28 22:37:59 +08:00
|
|
|
int16_t SectionNum = SymEntPtr->SectionNumber;
|
|
|
|
|
|
|
|
switch (SectionNum) {
|
|
|
|
case XCOFF::N_DEBUG:
|
|
|
|
return "N_DEBUG";
|
|
|
|
case XCOFF::N_ABS:
|
|
|
|
return "N_ABS";
|
|
|
|
case XCOFF::N_UNDEF:
|
|
|
|
return "N_UNDEF";
|
2019-07-10 02:09:11 +08:00
|
|
|
default:
|
|
|
|
Expected<DataRefImpl> SecRef = getSectionByNum(SectionNum);
|
|
|
|
if (SecRef)
|
2019-08-28 02:54:46 +08:00
|
|
|
return generateXCOFFFixedNameStringRef(
|
|
|
|
getSectionNameInternal(SecRef.get()));
|
2019-07-10 02:09:11 +08:00
|
|
|
return SecRef.takeError();
|
2019-05-28 22:37:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool XCOFFObjectFile::isReservedSectionNumber(int16_t SectionNumber) {
|
|
|
|
return (SectionNumber <= 0 && SectionNumber >= -2);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t XCOFFObjectFile::getNumberOfSections() const {
|
2019-07-10 02:09:11 +08:00
|
|
|
return is64Bit() ? fileHeader64()->NumberOfSections
|
|
|
|
: fileHeader32()->NumberOfSections;
|
2019-05-28 22:37:59 +08:00
|
|
|
}
|
|
|
|
|
2019-07-10 02:09:11 +08:00
|
|
|
int32_t XCOFFObjectFile::getTimeStamp() const {
|
|
|
|
return is64Bit() ? fileHeader64()->TimeStamp : fileHeader32()->TimeStamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t XCOFFObjectFile::getOptionalHeaderSize() const {
|
|
|
|
return is64Bit() ? fileHeader64()->AuxHeaderSize
|
|
|
|
: fileHeader32()->AuxHeaderSize;
|
|
|
|
}
|
2019-05-28 22:37:59 +08:00
|
|
|
|
2019-07-10 02:09:11 +08:00
|
|
|
uint32_t XCOFFObjectFile::getSymbolTableOffset32() const {
|
|
|
|
return fileHeader32()->SymbolTableOffset;
|
2019-05-28 22:37:59 +08:00
|
|
|
}
|
|
|
|
|
2019-07-10 02:09:11 +08:00
|
|
|
int32_t XCOFFObjectFile::getRawNumberOfSymbolTableEntries32() const {
|
|
|
|
// As far as symbol table size is concerned, if this field is negative it is
|
|
|
|
// to be treated as a 0. However since this field is also used for printing we
|
|
|
|
// don't want to truncate any negative values.
|
|
|
|
return fileHeader32()->NumberOfSymTableEntries;
|
2019-05-28 22:37:59 +08:00
|
|
|
}
|
|
|
|
|
2019-07-10 02:09:11 +08:00
|
|
|
uint32_t XCOFFObjectFile::getLogicalNumberOfSymbolTableEntries32() const {
|
|
|
|
return (fileHeader32()->NumberOfSymTableEntries >= 0
|
|
|
|
? fileHeader32()->NumberOfSymTableEntries
|
2019-05-28 22:37:59 +08:00
|
|
|
: 0);
|
|
|
|
}
|
|
|
|
|
2019-07-10 02:09:11 +08:00
|
|
|
uint64_t XCOFFObjectFile::getSymbolTableOffset64() const {
|
|
|
|
return fileHeader64()->SymbolTableOffset;
|
2019-05-28 22:37:59 +08:00
|
|
|
}
|
|
|
|
|
2019-07-10 02:09:11 +08:00
|
|
|
uint32_t XCOFFObjectFile::getNumberOfSymbolTableEntries64() const {
|
|
|
|
return fileHeader64()->NumberOfSymTableEntries;
|
|
|
|
}
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
|
2019-08-28 02:54:46 +08:00
|
|
|
uintptr_t XCOFFObjectFile::getEndOfSymbolTableAddress() const {
|
|
|
|
uint32_t NumberOfSymTableEntries =
|
|
|
|
is64Bit() ? getNumberOfSymbolTableEntries64()
|
|
|
|
: getLogicalNumberOfSymbolTableEntries32();
|
|
|
|
return getWithOffset(reinterpret_cast<uintptr_t>(SymbolTblPtr),
|
|
|
|
XCOFF::SymbolTableEntrySize * NumberOfSymTableEntries);
|
|
|
|
}
|
|
|
|
|
|
|
|
void XCOFFObjectFile::checkSymbolEntryPointer(uintptr_t SymbolEntPtr) const {
|
|
|
|
if (SymbolEntPtr < reinterpret_cast<uintptr_t>(SymbolTblPtr))
|
|
|
|
report_fatal_error("Symbol table entry is outside of symbol table.");
|
|
|
|
|
|
|
|
if (SymbolEntPtr >= getEndOfSymbolTableAddress())
|
|
|
|
report_fatal_error("Symbol table entry is outside of symbol table.");
|
|
|
|
|
|
|
|
ptrdiff_t Offset = reinterpret_cast<const char *>(SymbolEntPtr) -
|
|
|
|
reinterpret_cast<const char *>(SymbolTblPtr);
|
|
|
|
|
|
|
|
if (Offset % XCOFF::SymbolTableEntrySize != 0)
|
|
|
|
report_fatal_error(
|
|
|
|
"Symbol table entry position is not valid inside of symbol table.");
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t XCOFFObjectFile::getSymbolIndex(uintptr_t SymbolEntPtr) const {
|
|
|
|
return (reinterpret_cast<const char *>(SymbolEntPtr) -
|
|
|
|
reinterpret_cast<const char *>(SymbolTblPtr)) /
|
|
|
|
XCOFF::SymbolTableEntrySize;
|
|
|
|
}
|
|
|
|
|
2019-10-16 04:42:11 +08:00
|
|
|
Expected<StringRef>
|
|
|
|
XCOFFObjectFile::getSymbolNameByIndex(uint32_t Index) const {
|
|
|
|
if (is64Bit())
|
|
|
|
report_fatal_error("64-bit symbol table support not implemented yet.");
|
|
|
|
|
|
|
|
if (Index >= getLogicalNumberOfSymbolTableEntries32())
|
|
|
|
return errorCodeToError(object_error::invalid_symbol_index);
|
|
|
|
|
|
|
|
DataRefImpl SymDRI;
|
|
|
|
SymDRI.p = reinterpret_cast<uintptr_t>(getPointerToSymbolTable() + Index);
|
|
|
|
return getSymbolName(SymDRI);
|
|
|
|
}
|
|
|
|
|
2019-07-10 02:09:11 +08:00
|
|
|
uint16_t XCOFFObjectFile::getFlags() const {
|
|
|
|
return is64Bit() ? fileHeader64()->Flags : fileHeader32()->Flags;
|
|
|
|
}
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
|
2019-07-10 02:09:11 +08:00
|
|
|
const char *XCOFFObjectFile::getSectionNameInternal(DataRefImpl Sec) const {
|
|
|
|
return is64Bit() ? toSection64(Sec)->Name : toSection32(Sec)->Name;
|
|
|
|
}
|
2019-04-26 05:36:04 +08:00
|
|
|
|
2019-07-10 02:09:11 +08:00
|
|
|
uintptr_t XCOFFObjectFile::getSectionHeaderTableAddress() const {
|
|
|
|
return reinterpret_cast<uintptr_t>(SectionHeaderTable);
|
|
|
|
}
|
2019-04-26 05:36:04 +08:00
|
|
|
|
2019-07-10 02:09:11 +08:00
|
|
|
int32_t XCOFFObjectFile::getSectionFlags(DataRefImpl Sec) const {
|
|
|
|
return is64Bit() ? toSection64(Sec)->Flags : toSection32(Sec)->Flags;
|
|
|
|
}
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
|
2019-07-10 02:09:11 +08:00
|
|
|
XCOFFObjectFile::XCOFFObjectFile(unsigned int Type, MemoryBufferRef Object)
|
|
|
|
: ObjectFile(Type, Object) {
|
|
|
|
assert(Type == Binary::ID_XCOFF32 || Type == Binary::ID_XCOFF64);
|
|
|
|
}
|
2019-05-03 20:57:07 +08:00
|
|
|
|
2019-07-10 02:09:11 +08:00
|
|
|
ArrayRef<XCOFFSectionHeader64> XCOFFObjectFile::sections64() const {
|
|
|
|
assert(is64Bit() && "64-bit interface called for non 64-bit file.");
|
|
|
|
const XCOFFSectionHeader64 *TablePtr = sectionHeaderTable64();
|
|
|
|
return ArrayRef<XCOFFSectionHeader64>(TablePtr,
|
|
|
|
TablePtr + getNumberOfSections());
|
|
|
|
}
|
2019-05-03 20:57:07 +08:00
|
|
|
|
2019-07-10 02:09:11 +08:00
|
|
|
ArrayRef<XCOFFSectionHeader32> XCOFFObjectFile::sections32() const {
|
|
|
|
assert(!is64Bit() && "32-bit interface called for non 32-bit file.");
|
|
|
|
const XCOFFSectionHeader32 *TablePtr = sectionHeaderTable32();
|
|
|
|
return ArrayRef<XCOFFSectionHeader32>(TablePtr,
|
|
|
|
TablePtr + getNumberOfSections());
|
|
|
|
}
|
2019-05-03 20:57:07 +08:00
|
|
|
|
2019-10-16 04:42:11 +08:00
|
|
|
// In an XCOFF32 file, when the field value is 65535, then an STYP_OVRFLO
|
|
|
|
// 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<uint32_t> XCOFFObjectFile::getLogicalNumberOfRelocationEntries(
|
|
|
|
const XCOFFSectionHeader32 &Sec) const {
|
|
|
|
|
|
|
|
uint16_t SectionIndex = &Sec - sectionHeaderTable32() + 1;
|
|
|
|
|
2020-06-09 02:51:33 +08:00
|
|
|
if (Sec.NumberOfRelocations < XCOFF::RelocOverflow)
|
2019-10-16 04:42:11 +08:00
|
|
|
return Sec.NumberOfRelocations;
|
|
|
|
for (const auto &Sec : sections32()) {
|
|
|
|
if (Sec.Flags == XCOFF::STYP_OVRFLO &&
|
|
|
|
Sec.NumberOfRelocations == SectionIndex)
|
|
|
|
return Sec.PhysicalAddress;
|
|
|
|
}
|
|
|
|
return errorCodeToError(object_error::parse_failed);
|
|
|
|
}
|
|
|
|
|
|
|
|
Expected<ArrayRef<XCOFFRelocation32>>
|
|
|
|
XCOFFObjectFile::relocations(const XCOFFSectionHeader32 &Sec) const {
|
|
|
|
uintptr_t RelocAddr = getWithOffset(reinterpret_cast<uintptr_t>(FileHeader),
|
|
|
|
Sec.FileOffsetToRelocationInfo);
|
|
|
|
auto NumRelocEntriesOrErr = getLogicalNumberOfRelocationEntries(Sec);
|
|
|
|
if (Error E = NumRelocEntriesOrErr.takeError())
|
2020-02-10 23:06:45 +08:00
|
|
|
return std::move(E);
|
2019-10-16 04:42:11 +08:00
|
|
|
|
|
|
|
uint32_t NumRelocEntries = NumRelocEntriesOrErr.get();
|
|
|
|
|
2020-01-30 23:50:49 +08:00
|
|
|
assert(sizeof(XCOFFRelocation32) == XCOFF::RelocationSerializationSize32);
|
2019-10-16 04:42:11 +08:00
|
|
|
auto RelocationOrErr =
|
|
|
|
getObject<XCOFFRelocation32>(Data, reinterpret_cast<void *>(RelocAddr),
|
|
|
|
NumRelocEntries * sizeof(XCOFFRelocation32));
|
|
|
|
if (Error E = RelocationOrErr.takeError())
|
2020-02-10 23:06:45 +08:00
|
|
|
return std::move(E);
|
2019-10-16 04:42:11 +08:00
|
|
|
|
|
|
|
const XCOFFRelocation32 *StartReloc = RelocationOrErr.get();
|
|
|
|
|
|
|
|
return ArrayRef<XCOFFRelocation32>(StartReloc, StartReloc + NumRelocEntries);
|
|
|
|
}
|
|
|
|
|
2019-07-10 02:09:11 +08:00
|
|
|
Expected<XCOFFStringTable>
|
|
|
|
XCOFFObjectFile::parseStringTable(const XCOFFObjectFile *Obj, uint64_t Offset) {
|
|
|
|
// If there is a string table, then the buffer must contain at least 4 bytes
|
|
|
|
// for the string table's size. Not having a string table is not an error.
|
2020-06-06 07:12:38 +08:00
|
|
|
if (Error E = Binary::checkOffset(
|
|
|
|
Obj->Data, reinterpret_cast<uintptr_t>(Obj->base() + Offset), 4)) {
|
|
|
|
consumeError(std::move(E));
|
2019-07-10 02:09:11 +08:00
|
|
|
return XCOFFStringTable{0, nullptr};
|
2020-06-06 07:12:38 +08:00
|
|
|
}
|
2019-05-03 20:57:07 +08:00
|
|
|
|
2019-07-10 02:09:11 +08:00
|
|
|
// Read the size out of the buffer.
|
|
|
|
uint32_t Size = support::endian::read32be(Obj->base() + Offset);
|
2019-05-03 20:57:07 +08:00
|
|
|
|
2019-07-10 02:09:11 +08:00
|
|
|
// If the size is less then 4, then the string table is just a size and no
|
|
|
|
// string data.
|
|
|
|
if (Size <= 4)
|
|
|
|
return XCOFFStringTable{4, nullptr};
|
2019-05-28 22:37:59 +08:00
|
|
|
|
2019-07-10 02:09:11 +08:00
|
|
|
auto StringTableOrErr =
|
|
|
|
getObject<char>(Obj->Data, Obj->base() + Offset, Size);
|
|
|
|
if (Error E = StringTableOrErr.takeError())
|
2020-02-10 23:06:45 +08:00
|
|
|
return std::move(E);
|
2019-05-28 22:37:59 +08:00
|
|
|
|
2019-07-10 02:09:11 +08:00
|
|
|
const char *StringTablePtr = StringTableOrErr.get();
|
|
|
|
if (StringTablePtr[Size - 1] != '\0')
|
|
|
|
return errorCodeToError(object_error::string_table_non_null_end);
|
2019-05-03 20:57:07 +08:00
|
|
|
|
2019-07-10 02:09:11 +08:00
|
|
|
return XCOFFStringTable{Size, StringTablePtr};
|
|
|
|
}
|
|
|
|
|
|
|
|
Expected<std::unique_ptr<XCOFFObjectFile>>
|
|
|
|
XCOFFObjectFile::create(unsigned Type, MemoryBufferRef MBR) {
|
2019-08-15 23:54:37 +08:00
|
|
|
// Can't use std::make_unique because of the private constructor.
|
2019-07-10 02:09:11 +08:00
|
|
|
std::unique_ptr<XCOFFObjectFile> Obj;
|
|
|
|
Obj.reset(new XCOFFObjectFile(Type, MBR));
|
|
|
|
|
|
|
|
uint64_t CurOffset = 0;
|
|
|
|
const auto *Base = Obj->base();
|
|
|
|
MemoryBufferRef Data = Obj->Data;
|
|
|
|
|
|
|
|
// Parse file header.
|
|
|
|
auto FileHeaderOrErr =
|
|
|
|
getObject<void>(Data, Base + CurOffset, Obj->getFileHeaderSize());
|
|
|
|
if (Error E = FileHeaderOrErr.takeError())
|
2020-02-10 23:06:45 +08:00
|
|
|
return std::move(E);
|
2019-07-10 02:09:11 +08:00
|
|
|
Obj->FileHeader = FileHeaderOrErr.get();
|
|
|
|
|
|
|
|
CurOffset += Obj->getFileHeaderSize();
|
|
|
|
// TODO FIXME we don't have support for an optional header yet, so just skip
|
|
|
|
// past it.
|
|
|
|
CurOffset += Obj->getOptionalHeaderSize();
|
|
|
|
|
|
|
|
// Parse the section header table if it is present.
|
|
|
|
if (Obj->getNumberOfSections()) {
|
|
|
|
auto SecHeadersOrErr = getObject<void>(Data, Base + CurOffset,
|
|
|
|
Obj->getNumberOfSections() *
|
|
|
|
Obj->getSectionHeaderSize());
|
|
|
|
if (Error E = SecHeadersOrErr.takeError())
|
2020-02-10 23:06:45 +08:00
|
|
|
return std::move(E);
|
2019-07-10 02:09:11 +08:00
|
|
|
Obj->SectionHeaderTable = SecHeadersOrErr.get();
|
2019-05-28 22:37:59 +08:00
|
|
|
}
|
2019-07-10 02:09:11 +08:00
|
|
|
|
|
|
|
// 64-bit object supports only file header and section headers for now.
|
|
|
|
if (Obj->is64Bit())
|
2020-02-10 23:06:45 +08:00
|
|
|
return std::move(Obj);
|
2019-07-10 02:09:11 +08:00
|
|
|
|
|
|
|
// If there is no symbol table we are done parsing the memory buffer.
|
|
|
|
if (Obj->getLogicalNumberOfSymbolTableEntries32() == 0)
|
2020-02-10 23:06:45 +08:00
|
|
|
return std::move(Obj);
|
2019-07-10 02:09:11 +08:00
|
|
|
|
|
|
|
// Parse symbol table.
|
|
|
|
CurOffset = Obj->fileHeader32()->SymbolTableOffset;
|
|
|
|
uint64_t SymbolTableSize = (uint64_t)(sizeof(XCOFFSymbolEntry)) *
|
|
|
|
Obj->getLogicalNumberOfSymbolTableEntries32();
|
|
|
|
auto SymTableOrErr =
|
|
|
|
getObject<XCOFFSymbolEntry>(Data, Base + CurOffset, SymbolTableSize);
|
|
|
|
if (Error E = SymTableOrErr.takeError())
|
2020-02-10 23:06:45 +08:00
|
|
|
return std::move(E);
|
2019-07-10 02:09:11 +08:00
|
|
|
Obj->SymbolTblPtr = SymTableOrErr.get();
|
|
|
|
CurOffset += SymbolTableSize;
|
|
|
|
|
|
|
|
// Parse String table.
|
|
|
|
Expected<XCOFFStringTable> StringTableOrErr =
|
|
|
|
parseStringTable(Obj.get(), CurOffset);
|
|
|
|
if (Error E = StringTableOrErr.takeError())
|
2020-02-10 23:06:45 +08:00
|
|
|
return std::move(E);
|
2019-07-10 02:09:11 +08:00
|
|
|
Obj->StringTable = StringTableOrErr.get();
|
|
|
|
|
2020-02-10 23:06:45 +08:00
|
|
|
return std::move(Obj);
|
2019-05-03 20:57:07 +08:00
|
|
|
}
|
|
|
|
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
Expected<std::unique_ptr<ObjectFile>>
|
2019-07-10 02:09:11 +08:00
|
|
|
ObjectFile::createXCOFFObjectFile(MemoryBufferRef MemBufRef,
|
|
|
|
unsigned FileType) {
|
|
|
|
return XCOFFObjectFile::create(FileType, MemBufRef);
|
|
|
|
}
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
|
2019-08-28 02:54:46 +08:00
|
|
|
XCOFF::StorageClass XCOFFSymbolRef::getStorageClass() const {
|
|
|
|
return OwningObjectPtr->toSymbolEntry(SymEntDataRef)->StorageClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t XCOFFSymbolRef::getNumberOfAuxEntries() const {
|
|
|
|
return OwningObjectPtr->toSymbolEntry(SymEntDataRef)->NumberOfAuxEntries;
|
|
|
|
}
|
|
|
|
|
2020-04-06 22:09:12 +08:00
|
|
|
// TODO: The function needs to return an error if there is no csect auxiliary
|
|
|
|
// entry.
|
2019-08-28 02:54:46 +08:00
|
|
|
const XCOFFCsectAuxEnt32 *XCOFFSymbolRef::getXCOFFCsectAuxEnt32() const {
|
|
|
|
assert(!OwningObjectPtr->is64Bit() &&
|
|
|
|
"32-bit interface called on 64-bit object file.");
|
|
|
|
assert(hasCsectAuxEnt() && "No Csect Auxiliary Entry is found.");
|
|
|
|
|
|
|
|
// In XCOFF32, the csect auxilliary entry is always the last auxiliary
|
|
|
|
// entry for the symbol.
|
|
|
|
uintptr_t AuxAddr = getWithOffset(
|
|
|
|
SymEntDataRef.p, XCOFF::SymbolTableEntrySize * getNumberOfAuxEntries());
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
OwningObjectPtr->checkSymbolEntryPointer(AuxAddr);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return reinterpret_cast<const XCOFFCsectAuxEnt32 *>(AuxAddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t XCOFFSymbolRef::getType() const {
|
|
|
|
return OwningObjectPtr->toSymbolEntry(SymEntDataRef)->SymbolType;
|
|
|
|
}
|
|
|
|
|
|
|
|
int16_t XCOFFSymbolRef::getSectionNumber() const {
|
|
|
|
return OwningObjectPtr->toSymbolEntry(SymEntDataRef)->SectionNumber;
|
|
|
|
}
|
|
|
|
|
2020-04-06 22:09:12 +08:00
|
|
|
// TODO: The function name needs to be changed to express the purpose of the
|
|
|
|
// function.
|
2019-08-28 02:54:46 +08:00
|
|
|
bool XCOFFSymbolRef::hasCsectAuxEnt() const {
|
|
|
|
XCOFF::StorageClass SC = getStorageClass();
|
|
|
|
return (SC == XCOFF::C_EXT || SC == XCOFF::C_WEAKEXT ||
|
|
|
|
SC == XCOFF::C_HIDEXT);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool XCOFFSymbolRef::isFunction() const {
|
|
|
|
if (OwningObjectPtr->is64Bit())
|
|
|
|
report_fatal_error("64-bit support is unimplemented yet.");
|
|
|
|
|
2020-03-28 00:02:27 +08:00
|
|
|
if (getType() & FunctionSym)
|
2019-08-28 02:54:46 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if (!hasCsectAuxEnt())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const XCOFFCsectAuxEnt32 *CsectAuxEnt = getXCOFFCsectAuxEnt32();
|
|
|
|
|
|
|
|
// A function definition should be a label definition.
|
2020-03-28 00:02:27 +08:00
|
|
|
if ((CsectAuxEnt->SymbolAlignmentAndType & SymTypeMask) != XCOFF::XTY_LD)
|
2019-08-28 02:54:46 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (CsectAuxEnt->StorageMappingClass != XCOFF::XMC_PR)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
int16_t SectNum = getSectionNumber();
|
|
|
|
Expected<DataRefImpl> SI = OwningObjectPtr->getSectionByNum(SectNum);
|
|
|
|
if (!SI)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return (OwningObjectPtr->getSectionFlags(SI.get()) & XCOFF::STYP_TEXT);
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
}
|
|
|
|
|
2019-11-08 01:25:31 +08:00
|
|
|
// Explictly instantiate template classes.
|
|
|
|
template struct XCOFFSectionHeader<XCOFFSectionHeader32>;
|
|
|
|
template struct XCOFFSectionHeader<XCOFFSectionHeader64>;
|
|
|
|
|
[XCOFF] Add functionality for parsing AIX XCOFF object file headers
Summary:
1. Add functionality for parsing AIX XCOFF object files headers.
2. Only support 32-bit AIX XCOFF object files in this patch.
3. Print out the AIX XCOFF object file header in YAML format.
Reviewers: sfertile, hubert.reinterpretcast, jasonliu, mstorsjo, zturner, rnk
Reviewed By: sfertile, hubert.reinterpretcast
Subscribers: jsji, mgorny, hiraditya, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59419
Patch by Digger Lin
llvm-svn: 357663
2019-04-04 08:53:21 +08:00
|
|
|
} // namespace object
|
|
|
|
} // namespace llvm
|