-
Notifications
You must be signed in to change notification settings - Fork 12.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WebAssembly] Add llvm-objdump support for wasm file format
This is the first part of an effort to add wasm binary support across all llvm tools. Patch by Sam Clegg Differential Revision: https://reviews.llvm.org/D26172 llvm-svn: 288251
- Loading branch information
Showing
17 changed files
with
546 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| //===- WasmObjectFile.h - Wasm object file implementation -------*- C++ -*-===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is distributed under the University of Illinois Open Source | ||
| // License. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This file declares the WasmObjectFile class, which implements the ObjectFile | ||
| // interface for Wasm files. | ||
| // | ||
| // See: https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLVM_OBJECT_WASM_H | ||
| #define LLVM_OBJECT_WASM_H | ||
|
|
||
| #include "llvm/Object/ObjectFile.h" | ||
| #include "llvm/Support/Wasm.h" | ||
|
|
||
| namespace llvm { | ||
| namespace object { | ||
|
|
||
| class WasmObjectFile : public ObjectFile { | ||
| public: | ||
| WasmObjectFile(MemoryBufferRef Object, Error &Err); | ||
| const wasm::WasmObjectHeader &getHeader() const; | ||
| const wasm::WasmSection *getWasmSection(const SectionRef &Section) const; | ||
| static bool classof(const Binary *v) { return v->isWasm(); } | ||
|
|
||
| protected: | ||
| void moveSymbolNext(DataRefImpl &Symb) const override; | ||
|
|
||
| std::error_code printSymbolName(raw_ostream &OS, | ||
| DataRefImpl Symb) const override; | ||
|
|
||
| uint32_t getSymbolFlags(DataRefImpl Symb) const override; | ||
|
|
||
| basic_symbol_iterator symbol_begin() const override; | ||
|
|
||
| basic_symbol_iterator symbol_end() const override; | ||
| Expected<StringRef> getSymbolName(DataRefImpl Symb) const override; | ||
|
|
||
| Expected<uint64_t> getSymbolAddress(DataRefImpl Symb) const override; | ||
| uint64_t getSymbolValueImpl(DataRefImpl Symb) const override; | ||
| uint32_t getSymbolAlignment(DataRefImpl Symb) const override; | ||
| uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override; | ||
| Expected<SymbolRef::Type> getSymbolType(DataRefImpl Symb) const override; | ||
| Expected<section_iterator> getSymbolSection(DataRefImpl Symb) const override; | ||
|
|
||
| // Overrides from SectionRef. | ||
| void moveSectionNext(DataRefImpl &Sec) const override; | ||
| std::error_code getSectionName(DataRefImpl Sec, | ||
| StringRef &Res) const override; | ||
| uint64_t getSectionAddress(DataRefImpl Sec) const override; | ||
| uint64_t getSectionSize(DataRefImpl Sec) const override; | ||
| std::error_code getSectionContents(DataRefImpl Sec, | ||
| StringRef &Res) const override; | ||
| uint64_t getSectionAlignment(DataRefImpl Sec) const override; | ||
| bool isSectionCompressed(DataRefImpl Sec) const override; | ||
| bool isSectionText(DataRefImpl Sec) const override; | ||
| bool isSectionData(DataRefImpl Sec) const override; | ||
| bool isSectionBSS(DataRefImpl Sec) const override; | ||
| bool isSectionVirtual(DataRefImpl Sec) const override; | ||
| bool isSectionBitcode(DataRefImpl Sec) const override; | ||
| relocation_iterator section_rel_begin(DataRefImpl Sec) const override; | ||
| relocation_iterator section_rel_end(DataRefImpl Sec) const override; | ||
| section_iterator getRelocatedSection(DataRefImpl Sec) const override; | ||
|
|
||
| // Overrides from RelocationRef. | ||
| void moveRelocationNext(DataRefImpl &Rel) const override; | ||
| uint64_t getRelocationOffset(DataRefImpl Rel) const override; | ||
| symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override; | ||
| uint64_t getRelocationType(DataRefImpl Rel) const override; | ||
| void getRelocationTypeName(DataRefImpl Rel, | ||
| SmallVectorImpl<char> &Result) const override; | ||
|
|
||
| section_iterator section_begin() const override; | ||
| section_iterator section_end() const override; | ||
| uint8_t getBytesInAddress() const override; | ||
| StringRef getFileFormatName() const override; | ||
| unsigned getArch() const override; | ||
| SubtargetFeatures getFeatures() const override; | ||
| bool isRelocatableObject() const override; | ||
|
|
||
| private: | ||
| const uint8_t *getPtr(size_t Offset) const; | ||
| Error parseUserSection(wasm::WasmSection &Sec, const uint8_t *Ptr, | ||
| size_t Length); | ||
|
|
||
| wasm::WasmObjectHeader Header; | ||
| std::vector<wasm::WasmSection> Sections; | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| #endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| //===- Wasm.h - Wasm object file format -------------------------*- C++ -*-===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is distributed under the University of Illinois Open Source | ||
| // License. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This file defines manifest constants for the wasm object file format. | ||
| // See: https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLVM_SUPPORT_WASM_H | ||
| #define LLVM_SUPPORT_WASM_H | ||
|
|
||
| #include "llvm/ADT/ArrayRef.h" | ||
|
|
||
| namespace llvm { | ||
| namespace wasm { | ||
|
|
||
| // Object file magic string. | ||
| const char WasmMagic[] = {'\0', 'a', 's', 'm'}; | ||
| // Wasm binary format version | ||
| const uint32_t WasmVersion = 0xd; | ||
|
|
||
| struct WasmObjectHeader { | ||
| StringRef Magic; | ||
| uint32_t Version; | ||
| }; | ||
|
|
||
| struct WasmSection { | ||
| uint32_t Type; // Section type (See below) | ||
| uint32_t Offset; // Offset with in the file | ||
| StringRef Name; // Section name (User-defined sections only) | ||
| ArrayRef<uint8_t> Content; // Section content | ||
| }; | ||
|
|
||
| enum : unsigned { | ||
| WASM_SEC_USER = 0, // User-defined section | ||
| WASM_SEC_TYPE = 1, // Function signature declarations | ||
| WASM_SEC_IMPORT = 2, // Import declarations | ||
| WASM_SEC_FUNCTION = 3, // Function declarations | ||
| WASM_SEC_TABLE = 4, // Indirect function table and other tables | ||
| WASM_SEC_MEMORY = 5, // Memory attributes | ||
| WASM_SEC_GLOBAL = 6, // Global declarations | ||
| WASM_SEC_EXPORT = 7, // Exports | ||
| WASM_SEC_START = 8, // Start function declaration | ||
| WASM_SEC_ELEM = 9, // Elements section | ||
| WASM_SEC_CODE = 10, // Function bodies (code) | ||
| WASM_SEC_DATA = 11 // Data segments | ||
| }; | ||
|
|
||
| } // end namespace wasm | ||
| } // end namespace llvm | ||
|
|
||
| #endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.