diff options
author | Sam Clegg <sbc@chromium.org> | 2018-01-17 19:28:43 +0000 |
---|---|---|
committer | Sam Clegg <sbc@chromium.org> | 2018-01-17 19:28:43 +0000 |
commit | 9f3fe42e19e693c59295abeb5a1d9463140ccaae (patch) | |
tree | 6efe7982cccc29f8a26b2c395c3fbc264efc9eb9 /llvm/lib/Object | |
parent | d122baec226e438031e56efa398f666d80a39b74 (diff) | |
download | bcm5719-llvm-9f3fe42e19e693c59295abeb5a1d9463140ccaae.tar.gz bcm5719-llvm-9f3fe42e19e693c59295abeb5a1d9463140ccaae.zip |
[WebAssembly] Remove debug names from symbol table
Get rid of DEBUG_FUNCTION_NAME symbols. When we actually debug
data, maybe we'll want somewhere to put it... but having a symbol
that just stores the name of another symbol seems odd.
It means you have multiple Symbols with the same name, one
containing the actual function and another containing the name!
Store the names in a vector on the WasmObjectFile when reading
them in. Also stash them on the WasmFunctions themselves.
The names are //not// "symbol names" or aliases or anything,
they're just the name that a debugger should show against the
function body itself. NB. The WasmObjectFile stores them so that
they can be exported in the YAML losslessly, and hence the tests
can be precise.
Enforce that the CODE section has been read in before reading
the "names" section. Requires minor adjustment to some tests.
Patch by Nicholas Wilson!
Differential Revision: https://reviews.llvm.org/D42075
llvm-svn: 322741
Diffstat (limited to 'llvm/lib/Object')
-rw-r--r-- | llvm/lib/Object/WasmObjectFile.cpp | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp index 60c87caca0a..132471ab7f5 100644 --- a/llvm/lib/Object/WasmObjectFile.cpp +++ b/llvm/lib/Object/WasmObjectFile.cpp @@ -270,6 +270,10 @@ Error WasmObjectFile::parseSection(WasmSection &Sec) { Error WasmObjectFile::parseNameSection(const uint8_t *Ptr, const uint8_t *End) { llvm::DenseSet<uint64_t> Seen; + if (Functions.size() != FunctionTypes.size()) { + return make_error<GenericBinaryError>("Names must come after code section", + object_error::parse_failed); + } while (Ptr < End) { uint8_t Type = readVarint7(Ptr); @@ -284,10 +288,15 @@ Error WasmObjectFile::parseNameSection(const uint8_t *Ptr, const uint8_t *End) { return make_error<GenericBinaryError>("Function named more than once", object_error::parse_failed); StringRef Name = readString(Ptr); - if (!Name.empty()) - Symbols.emplace_back(Name, - WasmSymbol::SymbolType::DEBUG_FUNCTION_NAME, - Sections.size(), Index); + if (!isValidFunctionIndex(Index) || Name.empty()) + return make_error<GenericBinaryError>("Invalid name entry", + object_error::parse_failed); + DebugNames.push_back(wasm::WasmFunctionName{Index, Name}); + if (Index >= NumImportedFunctions) { + // Override any existing name; the name specified by the "names" + // section is the Function's canonical name. + Functions[Index - NumImportedFunctions].Name = Name; + } } break; } @@ -360,12 +369,24 @@ void WasmObjectFile::populateSymbolTable() { << " sym index:" << SymIndex << "\n"); } } + if (Export.Kind == wasm::WASM_EXTERNAL_FUNCTION) { + auto &Function = Functions[Export.Index - NumImportedFunctions]; + if (Function.Name.empty()) { + // Use the export's name to set a name for the Function, but only if one + // hasn't already been set. + Function.Name = Export.Name; + } + } } } Error WasmObjectFile::parseLinkingSection(const uint8_t *Ptr, const uint8_t *End) { HasLinkingSection = true; + if (Functions.size() != FunctionTypes.size()) { + return make_error<GenericBinaryError>( + "Linking data must come after code section", object_error::parse_failed); + } // Only populate the symbol table with imports and exports if the object // has a linking section (i.e. its a relocatable object file). Otherwise @@ -867,10 +888,6 @@ uint32_t WasmObjectFile::getSymbolFlags(DataRefImpl Symb) const { case WasmSymbol::SymbolType::FUNCTION_EXPORT: Result |= SymbolRef::SF_Executable; break; - case WasmSymbol::SymbolType::DEBUG_FUNCTION_NAME: - Result |= SymbolRef::SF_Executable; - Result |= SymbolRef::SF_FormatSpecific; - break; case WasmSymbol::SymbolType::GLOBAL_IMPORT: Result |= SymbolRef::SF_Undefined; break; @@ -914,7 +931,6 @@ uint64_t WasmObjectFile::getWasmSymbolValue(const WasmSymbol& Sym) const { case WasmSymbol::SymbolType::FUNCTION_IMPORT: case WasmSymbol::SymbolType::GLOBAL_IMPORT: case WasmSymbol::SymbolType::FUNCTION_EXPORT: - case WasmSymbol::SymbolType::DEBUG_FUNCTION_NAME: return Sym.ElementIndex; case WasmSymbol::SymbolType::GLOBAL_EXPORT: { uint32_t GlobalIndex = Sym.ElementIndex - NumImportedGlobals; @@ -949,7 +965,6 @@ WasmObjectFile::getSymbolType(DataRefImpl Symb) const { switch (Sym.Type) { case WasmSymbol::SymbolType::FUNCTION_IMPORT: case WasmSymbol::SymbolType::FUNCTION_EXPORT: - case WasmSymbol::SymbolType::DEBUG_FUNCTION_NAME: return SymbolRef::ST_Function; case WasmSymbol::SymbolType::GLOBAL_IMPORT: case WasmSymbol::SymbolType::GLOBAL_EXPORT: |