diff options
| author | Sam Clegg <sbc@chromium.org> | 2017-06-20 04:04:59 +0000 |
|---|---|---|
| committer | Sam Clegg <sbc@chromium.org> | 2017-06-20 04:04:59 +0000 |
| commit | b7787fd076f307a09075108525bdbabb44cd7373 (patch) | |
| tree | 38f834ba14026325cff7e288ed91c1b735528c0d /llvm/include | |
| parent | 47a78a2502f058f7c528d9e94efa6b51138c8929 (diff) | |
| download | bcm5719-llvm-b7787fd076f307a09075108525bdbabb44cd7373.tar.gz bcm5719-llvm-b7787fd076f307a09075108525bdbabb44cd7373.zip | |
[WebAssembly] Add support for weak symbols in the binary format
This also introduces the updated format for the
"linking" section which can represent extra
symbol information. See:
https://github.com/WebAssembly/tool-conventions/pull/10
Differential Revision: https://reviews.llvm.org/D34019
llvm-svn: 305769
Diffstat (limited to 'llvm/include')
| -rw-r--r-- | llvm/include/llvm/BinaryFormat/Wasm.h | 5 | ||||
| -rw-r--r-- | llvm/include/llvm/MC/MCSymbolWasm.h | 4 | ||||
| -rw-r--r-- | llvm/include/llvm/Object/Wasm.h | 31 | ||||
| -rw-r--r-- | llvm/include/llvm/ObjectYAML/WasmYAML.h | 36 |
4 files changed, 70 insertions, 6 deletions
diff --git a/llvm/include/llvm/BinaryFormat/Wasm.h b/llvm/include/llvm/BinaryFormat/Wasm.h index fcd8ad95704..470c20ddc7d 100644 --- a/llvm/include/llvm/BinaryFormat/Wasm.h +++ b/llvm/include/llvm/BinaryFormat/Wasm.h @@ -176,6 +176,11 @@ enum class ValType { // Linking metadata kinds. enum : unsigned { WASM_STACK_POINTER = 0x1, + WASM_SYMBOL_INFO = 0x2, +}; + +enum : unsigned { + WASM_SYMBOL_FLAG_WEAK = 0x1, }; #define WASM_RELOC(name, value) name = value, diff --git a/llvm/include/llvm/MC/MCSymbolWasm.h b/llvm/include/llvm/MC/MCSymbolWasm.h index 1b87095552d..7ea89629efd 100644 --- a/llvm/include/llvm/MC/MCSymbolWasm.h +++ b/llvm/include/llvm/MC/MCSymbolWasm.h @@ -17,6 +17,7 @@ namespace llvm { class MCSymbolWasm : public MCSymbol { private: bool IsFunction = false; + bool IsWeak = false; std::string ModuleName; SmallVector<wasm::ValType, 1> Returns; SmallVector<wasm::ValType, 4> Params; @@ -39,6 +40,9 @@ public: bool isFunction() const { return IsFunction; } void setIsFunction(bool isFunc) { IsFunction = isFunc; } + bool isWeak() const { return IsWeak; } + void setWeak(bool isWeak) { IsWeak = isWeak; } + const StringRef getModuleName() const { return ModuleName; } const SmallVector<wasm::ValType, 1> &getReturns() const { return Returns; } diff --git a/llvm/include/llvm/Object/Wasm.h b/llvm/include/llvm/Object/Wasm.h index 10edc461b9e..9d53131234f 100644 --- a/llvm/include/llvm/Object/Wasm.h +++ b/llvm/include/llvm/Object/Wasm.h @@ -19,6 +19,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/StringMap.h" #include "llvm/BinaryFormat/Wasm.h" #include "llvm/Object/Binary.h" #include "llvm/Object/ObjectFile.h" @@ -48,7 +49,24 @@ public: StringRef Name; SymbolType Type; uint32_t Section; + uint32_t Flags = 0; + + // Index into the imports, exports or functions array of the object depending + // on the type uint32_t ElementIndex; + + bool isWeak() const { + return Flags & wasm::WASM_SYMBOL_FLAG_WEAK; + } + + void print(raw_ostream &Out) const { + Out << "Name=" << Name << ", Type=" << static_cast<int>(Type) + << ", Flags=" << Flags; + } + +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) + LLVM_DUMP_METHOD void dump() const { print(dbgs()); } +#endif }; class WasmSection { @@ -63,6 +81,7 @@ public: }; class WasmObjectFile : public ObjectFile { + public: WasmObjectFile(MemoryBufferRef Object, Error &Err); @@ -176,6 +195,7 @@ private: // Custom section types Error parseNameSection(const uint8_t *Ptr, const uint8_t *End); + Error parseLinkingSection(const uint8_t *Ptr, const uint8_t *End); Error parseRelocSection(StringRef Name, const uint8_t *Ptr, const uint8_t *End); @@ -190,13 +210,22 @@ private: std::vector<wasm::WasmExport> Exports; std::vector<wasm::WasmElemSegment> ElemSegments; std::vector<wasm::WasmDataSegment> DataSegments; - std::vector<WasmSymbol> Symbols; std::vector<wasm::WasmFunction> Functions; + std::vector<WasmSymbol> Symbols; ArrayRef<uint8_t> CodeSection; uint32_t StartFunction = -1; + + StringMap<uint32_t> SymbolMap; }; } // end namespace object + +inline raw_ostream &operator<<(raw_ostream &OS, + const object::WasmSymbol &Sym) { + Sym.print(OS); + return OS; +} + } // end namespace llvm #endif // LLVM_OBJECT_WASM_H diff --git a/llvm/include/llvm/ObjectYAML/WasmYAML.h b/llvm/include/llvm/ObjectYAML/WasmYAML.h index 447dbd7a603..74f5664c43a 100644 --- a/llvm/include/llvm/ObjectYAML/WasmYAML.h +++ b/llvm/include/llvm/ObjectYAML/WasmYAML.h @@ -112,8 +112,13 @@ struct Signature { ValueType ReturnType; }; +struct SymbolInfo { + StringRef Name; + uint32_t Flags; +}; + struct Section { - Section(SectionType SecType) : Type(SecType) {} + explicit Section(SectionType SecType) : Type(SecType) {} virtual ~Section(); SectionType Type; @@ -121,20 +126,36 @@ struct Section { }; struct CustomSection : Section { - CustomSection() : Section(wasm::WASM_SEC_CUSTOM) {} + explicit CustomSection(StringRef Name) + : Section(wasm::WASM_SEC_CUSTOM), Name(Name) {} static bool classof(const Section *S) { return S->Type == wasm::WASM_SEC_CUSTOM; } StringRef Name; yaml::BinaryRef Payload; +}; + +struct NameSection : CustomSection { + NameSection() : CustomSection("name") {} + static bool classof(const Section *S) { + auto C = dyn_cast<CustomSection>(S); + return C && C->Name == "name"; + } - // The follow is used by the "name" custom section. - // TODO(sbc): Add support for more then just functions names. The wasm - // name section can support multiple sub-sections. std::vector<NameEntry> FunctionNames; }; +struct LinkingSection : CustomSection { + LinkingSection() : CustomSection("linking") {} + static bool classof(const Section *S) { + auto C = dyn_cast<CustomSection>(S); + return C && C->Name == "linking"; + } + + std::vector<SymbolInfo> SymbolInfos; +}; + struct TypeSection : Section { TypeSection() : Section(wasm::WASM_SEC_TYPE) {} static bool classof(const Section *S) { @@ -256,6 +277,7 @@ LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Function) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::LocalDecl) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::Relocation) LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::NameEntry) +LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::WasmYAML::SymbolInfo) LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(uint32_t) namespace llvm { @@ -329,6 +351,10 @@ template <> struct MappingTraits<WasmYAML::ElemSegment> { static void mapping(IO &IO, WasmYAML::ElemSegment &Segment); }; +template <> struct MappingTraits<WasmYAML::SymbolInfo> { + static void mapping(IO &IO, WasmYAML::SymbolInfo &Info); +}; + template <> struct ScalarEnumerationTraits<WasmYAML::ValueType> { static void enumeration(IO &IO, WasmYAML::ValueType &Type); }; |

