diff options
author | Nicholas Wilson <nicholas@nicholaswilson.me.uk> | 2018-03-05 12:16:32 +0000 |
---|---|---|
committer | Nicholas Wilson <nicholas@nicholaswilson.me.uk> | 2018-03-05 12:16:32 +0000 |
commit | 959e7371180b14465e88ac4c1961f749800badb6 (patch) | |
tree | de58317c5ebe0ffb6ed49fe694a1cdc43fd7898c | |
parent | c699eaa3119bf808971a067b34532b8cf4530766 (diff) | |
download | bcm5719-llvm-959e7371180b14465e88ac4c1961f749800badb6.tar.gz bcm5719-llvm-959e7371180b14465e88ac4c1961f749800badb6.zip |
[WebAssembly] Attach a name to globals similarly to function naming
This allows LLD to print the name for an InputGlobal when encountering
an error.
Differential Revision: https://reviews.llvm.org/D44033
llvm-svn: 326691
-rw-r--r-- | llvm/include/llvm/BinaryFormat/Wasm.h | 3 | ||||
-rw-r--r-- | llvm/lib/Object/WasmObjectFile.cpp | 10 |
2 files changed, 10 insertions, 3 deletions
diff --git a/llvm/include/llvm/BinaryFormat/Wasm.h b/llvm/include/llvm/BinaryFormat/Wasm.h index b35ad7253bb..893eab8925a 100644 --- a/llvm/include/llvm/BinaryFormat/Wasm.h +++ b/llvm/include/llvm/BinaryFormat/Wasm.h @@ -74,6 +74,7 @@ struct WasmGlobal { uint32_t Index; WasmGlobalType Type; WasmInitExpr InitExpr; + StringRef Name; // from the "linking" or "names" section }; struct WasmImport { @@ -99,7 +100,7 @@ struct WasmFunction { ArrayRef<uint8_t> Body; uint32_t CodeSectionOffset; uint32_t Size; - StringRef Name; // from the "names" section + StringRef Name; // from the "linking" or "names" section StringRef Comdat; // from the "comdat info" section }; diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp index 491a4cf70ab..23f25ea9aed 100644 --- a/llvm/lib/Object/WasmObjectFile.cpp +++ b/llvm/lib/Object/WasmObjectFile.cpp @@ -403,7 +403,7 @@ Error WasmObjectFile::parseLinkingSectionSymtab(const uint8_t *&Ptr, Info.Name = readString(Ptr); unsigned FuncIndex = Info.ElementIndex - NumImportedFunctions; FunctionType = &Signatures[FunctionTypes[FuncIndex]]; - auto &Function = Functions[FuncIndex]; + wasm::WasmFunction &Function = Functions[FuncIndex]; if (Function.Name.empty()) { // Use the symbol's name to set a name for the Function, but only if // one hasn't already been set. @@ -425,7 +425,13 @@ Error WasmObjectFile::parseLinkingSectionSymtab(const uint8_t *&Ptr, if (IsDefined) { Info.Name = readString(Ptr); unsigned GlobalIndex = Info.ElementIndex - NumImportedGlobals; - GlobalType = &Globals[GlobalIndex].Type; + wasm::WasmGlobal &Global = Globals[GlobalIndex]; + GlobalType = &Global.Type; + if (Global.Name.empty()) { + // Use the symbol's name to set a name for the Global, but only if + // one hasn't already been set. + Global.Name = Info.Name; + } } else { wasm::WasmImport &Import = *ImportedGlobals[Info.ElementIndex]; Info.Name = Import.Field; |