summaryrefslogtreecommitdiff
path: root/include/llvm/Object/COFF.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/Object/COFF.h')
-rw-r--r--include/llvm/Object/COFF.h55
1 files changed, 37 insertions, 18 deletions
diff --git a/include/llvm/Object/COFF.h b/include/llvm/Object/COFF.h
index 89c1ba6be35f0..b072dd5ba7d91 100644
--- a/include/llvm/Object/COFF.h
+++ b/include/llvm/Object/COFF.h
@@ -25,7 +25,6 @@
#include "llvm/Support/ConvertUTF.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/ErrorOr.h"
#include <cassert>
#include <cstddef>
#include <cstdint>
@@ -276,6 +275,8 @@ struct coff_symbol_generic {
support::ulittle32_t Value;
};
+struct coff_aux_section_definition;
+
class COFFSymbolRef {
public:
COFFSymbolRef() = default;
@@ -347,6 +348,18 @@ public:
return (getType() & 0xF0) >> COFF::SCT_COMPLEX_TYPE_SHIFT;
}
+ template <typename T> const T *getAux() const {
+ return CS16 ? reinterpret_cast<const T *>(CS16 + 1)
+ : reinterpret_cast<const T *>(CS32 + 1);
+ }
+
+ const coff_aux_section_definition *getSectionDefinition() const {
+ if (!getNumberOfAuxSymbols() ||
+ getStorageClass() != COFF::IMAGE_SYM_CLASS_STATIC)
+ return nullptr;
+ return getAux<coff_aux_section_definition>();
+ }
+
bool isAbsolute() const {
return getSectionNumber() == -1;
}
@@ -730,6 +743,12 @@ struct coff_resource_dir_table {
support::ulittle16_t NumberOfIDEntries;
};
+struct debug_h_header {
+ support::ulittle32_t Magic;
+ support::ulittle16_t Version;
+ support::ulittle16_t HashAlgorithm;
+};
+
class COFFObjectFile : public ObjectFile {
private:
friend class ImportDirectoryEntryRef;
@@ -753,7 +772,7 @@ private:
const debug_directory *DebugDirectoryBegin;
const debug_directory *DebugDirectoryEnd;
// Either coff_load_configuration32 or coff_load_configuration64.
- const void *LoadConfig;
+ const void *LoadConfig = nullptr;
std::error_code getString(uint32_t offset, StringRef &Res) const;
@@ -907,7 +926,7 @@ public:
uint8_t getBytesInAddress() const override;
StringRef getFileFormatName() const override;
- unsigned getArch() const override;
+ Triple::ArchType getArch() const override;
SubtargetFeatures getFeatures() const override { return SubtargetFeatures(); }
import_directory_iterator import_directory_begin() const;
@@ -954,28 +973,28 @@ public:
Res = reinterpret_cast<coff_symbol_type *>(getSymbolTable()) + Index;
return std::error_code();
}
- ErrorOr<COFFSymbolRef> getSymbol(uint32_t index) const {
+ Expected<COFFSymbolRef> getSymbol(uint32_t index) const {
if (SymbolTable16) {
const coff_symbol16 *Symb = nullptr;
if (std::error_code EC = getSymbol(index, Symb))
- return EC;
+ return errorCodeToError(EC);
return COFFSymbolRef(Symb);
}
if (SymbolTable32) {
const coff_symbol32 *Symb = nullptr;
if (std::error_code EC = getSymbol(index, Symb))
- return EC;
+ return errorCodeToError(EC);
return COFFSymbolRef(Symb);
}
- return object_error::parse_failed;
+ return errorCodeToError(object_error::parse_failed);
}
template <typename T>
std::error_code getAuxSymbol(uint32_t index, const T *&Res) const {
- ErrorOr<COFFSymbolRef> s = getSymbol(index);
- if (std::error_code EC = s.getError())
- return EC;
- Res = reinterpret_cast<const T *>(s->getRawPtr());
+ Expected<COFFSymbolRef> S = getSymbol(index);
+ if (Error E = S.takeError())
+ return errorToErrorCode(std::move(E));
+ Res = reinterpret_cast<const T *>(S->getRawPtr());
return std::error_code();
}
@@ -1145,7 +1164,7 @@ public:
BaseRelocRef() = default;
BaseRelocRef(const coff_base_reloc_block_header *Header,
const COFFObjectFile *Owner)
- : Header(Header), Index(0), OwningObject(Owner) {}
+ : Header(Header), Index(0) {}
bool operator==(const BaseRelocRef &Other) const;
void moveNext();
@@ -1156,7 +1175,6 @@ public:
private:
const coff_base_reloc_block_header *Header;
uint32_t Index;
- const COFFObjectFile *OwningObject = nullptr;
};
class ResourceSectionRef {
@@ -1164,16 +1182,17 @@ public:
ResourceSectionRef() = default;
explicit ResourceSectionRef(StringRef Ref) : BBS(Ref, support::little) {}
- ErrorOr<ArrayRef<UTF16>> getEntryNameString(const coff_resource_dir_entry &Entry);
- ErrorOr<const coff_resource_dir_table &>
+ Expected<ArrayRef<UTF16>>
+ getEntryNameString(const coff_resource_dir_entry &Entry);
+ Expected<const coff_resource_dir_table &>
getEntrySubDir(const coff_resource_dir_entry &Entry);
- ErrorOr<const coff_resource_dir_table &> getBaseTable();
+ Expected<const coff_resource_dir_table &> getBaseTable();
private:
BinaryByteStream BBS;
- ErrorOr<const coff_resource_dir_table &> getTableAtOffset(uint32_t Offset);
- ErrorOr<ArrayRef<UTF16>> getDirStringAtOffset(uint32_t Offset);
+ Expected<const coff_resource_dir_table &> getTableAtOffset(uint32_t Offset);
+ Expected<ArrayRef<UTF16>> getDirStringAtOffset(uint32_t Offset);
};
// Corresponds to `_FPO_DATA` structure in the PE/COFF spec.