17 Expected<std::unique_ptr<WasmObjectFile>>
20 auto ObjectFile = llvm::make_unique<WasmObjectFile>(Buffer, Err);
22 return std::move(Err);
31 Ptr +=
sizeof(Result);
35 uint64_t readULEB128(
const uint8_t *&
Ptr) {
42 StringRef readString(
const uint8_t *&
Ptr) {
43 uint32_t StringLen = readULEB128(Ptr);
44 StringRef
Return = StringRef(reinterpret_cast<const char *>(Ptr), StringLen);
49 Error readSection(wasm::WasmSection &
Section,
const uint8_t *&Ptr,
50 const uint8_t *Start) {
52 Section.Offset = Ptr - Start;
53 Section.Type = readULEB128(Ptr);
56 return make_error<StringError>(
"Zero length section",
58 Section.Content = ArrayRef<uint8_t>(
Ptr, Size);
69 Err = make_error<StringError>(
"Bad magic number",
73 const uint8_t *Ptr = getPtr(4);
74 Header.
Version = readUint32(Ptr);
76 Err = make_error<StringError>(
"Bad version number",
84 if ((Err = readSection(Sec, Ptr, getPtr(0))))
90 Sections.push_back(Sec);
95 const uint8_t *Ptr,
size_t Length) {
96 Sec.
Name = readString(Ptr);
100 const uint8_t *WasmObjectFile::getPtr(
size_t Offset)
const {
174 case wasm::WASM_SEC_##X: \
196 return std::error_code();
213 return std::error_code();
291 Ref.
d.
a = Sections.size();
uint64_t getRelocationType(DataRefImpl Rel) const override
ArrayRef< uint8_t > Content
std::error_code getSectionName(DataRefImpl Sec, StringRef &Res) const override
unsigned getArch() const override
section_iterator section_end() const override
uint64_t getSectionAddress(DataRefImpl Sec) const override
This class is the base class for all object file types.
bool isSectionCompressed(DataRefImpl Sec) const override
struct llvm::object::DataRefImpl::@119 d
DataRefImpl getRawDataRefImpl() const
void moveSymbolNext(DataRefImpl &Symb) const override
std::error_code getSectionContents(DataRefImpl Sec, StringRef &Res) const override
relocation_iterator section_rel_end(DataRefImpl Sec) const override
bool isSectionVirtual(DataRefImpl Sec) const override
uint8_t getBytesInAddress() const override
The number of bytes used to represent an address in this object file format.
This is a value type class that represents a single relocation in the list of relocations in the obje...
StringRef getData() const
static Expected< std::unique_ptr< WasmObjectFile > > createWasmObjectFile(MemoryBufferRef Object)
Tagged union holding either a T or a Error.
relocation_iterator section_rel_begin(DataRefImpl Sec) const override
StringRef getFileFormatName() const override
const uint32_t WasmVersion
bool isSectionText(DataRefImpl Sec) const override
basic_symbol_iterator symbol_begin() const override
symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override
Expected< uint64_t > getSymbolAddress(DataRefImpl Symb) const override
void moveRelocationNext(DataRefImpl &Rel) const override
uint64_t getSymbolValueImpl(DataRefImpl Symb) const override
size_t size() const
size - Get the array size.
uint64_t decodeULEB128(const uint8_t *p, unsigned *n=nullptr)
Utility function to decode a ULEB128 value.
uint64_t getSectionAlignment(DataRefImpl Sec) const override
content_iterator< SectionRef > section_iterator
WasmObjectFile(MemoryBufferRef Object, Error &Err)
uint32_t getSymbolAlignment(DataRefImpl Symb) const override
void moveSectionNext(DataRefImpl &Sec) const override
Expected< SymbolRef::Type > getSymbolType(DataRefImpl Symb) const override
Expected< section_iterator > getSymbolSection(DataRefImpl Symb) const override
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
const wasm::WasmSection * getWasmSection(const SectionRef &Section) const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override
SubtargetFeatures getFeatures() const override
Expected< StringRef > getSymbolName(DataRefImpl Symb) const override
uint64_t getSectionSize(DataRefImpl Sec) const override
content_iterator< RelocationRef > relocation_iterator
basic_symbol_iterator symbol_end() const override
const wasm::WasmObjectHeader & getHeader() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
section_iterator section_begin() const override
static ErrorSuccess success()
Create a success value.
std::error_code printSymbolName(raw_ostream &OS, DataRefImpl Symb) const override
SubtargetFeatures - Manages the enabling and disabling of subtarget specific features.
Helper for Errors used as out-parameters.
This is a value type class that represents a single symbol in the list of symbols in the object file...
bool isSectionData(DataRefImpl Sec) const override
section_iterator getRelocatedSection(DataRefImpl Sec) const override
void getRelocationTypeName(DataRefImpl Rel, SmallVectorImpl< char > &Result) const override
uint32_t read32le(const void *P)
This is a value type class that represents a single symbol in the list of symbols in the object file...
bool isRelocatableObject() const override
True if this is a relocatable object (.o/.obj).
bool isSectionBitcode(DataRefImpl Sec) const override
uint32_t getSymbolFlags(DataRefImpl Symb) const override
Lightweight error class with error context and mandatory checking.
This class implements an extremely fast bulk output stream that can only output to a stream...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
StringRef - Represent a constant reference to a string, i.e.
bool isSectionBSS(DataRefImpl Sec) const override
This is a value type class that represents a single section in the list of sections in the object fil...
uint64_t getRelocationOffset(DataRefImpl Rel) const override