diff options
author | Sam Clegg <sbc@chromium.org> | 2018-01-17 20:19:04 +0000 |
---|---|---|
committer | Sam Clegg <sbc@chromium.org> | 2018-01-17 20:19:04 +0000 |
commit | 1963d71cb8b8b4e66d71d83cde3d23f059386bcc (patch) | |
tree | d5569898cfbdf1db3ccfdeb2924a7718c49a6e75 /lld/wasm/Writer.cpp | |
parent | 6d83f34afdb0833ae5d7173daf0f8e009e95afa0 (diff) | |
download | bcm5719-llvm-1963d71cb8b8b4e66d71d83cde3d23f059386bcc.tar.gz bcm5719-llvm-1963d71cb8b8b4e66d71d83cde3d23f059386bcc.zip |
[WebAssembly] Simplify generation of "names" section
Simplify generation of "names" section by simply iterating
over the DefinedFunctions array.
This even fixes some bugs, judging by the test changes required.
Some tests are asserting that functions are named multiple times,
other tests are asserting that the "names" section contains the
function's alias rather than its original name
Patch by Nicholas Wilson!
Differential Revision: https://reviews.llvm.org/D42076
llvm-svn: 322751
Diffstat (limited to 'lld/wasm/Writer.cpp')
-rw-r--r-- | lld/wasm/Writer.cpp | 66 |
1 files changed, 21 insertions, 45 deletions
diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp index 5cb5d55277a..14fc90e9751 100644 --- a/lld/wasm/Writer.cpp +++ b/lld/wasm/Writer.cpp @@ -469,59 +469,33 @@ void Writer::createLinkingSection() { // Create the custom "name" section containing debug symbol names. void Writer::createNameSection() { - // Create an array of all function sorted by function index space - std::vector<const Symbol *> Names; - - auto AddToNames = [&](Symbol* S) { - if (!S->isFunction() || S->WrittenToNameSec) - return; - // We also need to guard against two different symbols (two different - // names) for the same wasm function. While this is possible (aliases) - // it is not legal in the "name" section. - InputFunction *Function = S->getFunction(); - if (Function) { - if (Function->WrittenToNameSec) - return; - Function->WrittenToNameSec = true; - } - S->WrittenToNameSec = true; - Names.emplace_back(S); - }; + unsigned NumNames = ImportedFunctions.size(); + for (const InputFunction *F : DefinedFunctions) + if (!F->getName().empty()) + ++NumNames; - for (ObjFile *File : Symtab->ObjectFiles) { - Names.reserve(Names.size() + File->getSymbols().size()); - DEBUG(dbgs() << "adding names from: " << File->getName() << "\n"); - for (Symbol *S : File->getSymbols()) { - if (S->isWeak()) - continue; - AddToNames(S); - } - } - - DEBUG(dbgs() << "adding symtab names\n"); - for (Symbol *S : Symtab->getSymbols()) { - DEBUG(dbgs() << "sym: " << S->getName() << "\n"); - if (S->getFile()) - continue; - AddToNames(S); - } + if (NumNames == 0) + return; SyntheticSection *Section = createSyntheticSection(WASM_SEC_CUSTOM, "name"); - std::sort(Names.begin(), Names.end(), [](const Symbol *A, const Symbol *B) { - return A->getOutputIndex() < B->getOutputIndex(); - }); - SubSection FunctionSubsection(WASM_NAMES_FUNCTION); raw_ostream &OS = FunctionSubsection.getStream(); - writeUleb128(OS, Names.size(), "name count"); + writeUleb128(OS, NumNames, "name count"); - // We have to iterate through the inputs twice so that all the imports - // appear first before any of the local function names. - for (const Symbol *S : Names) { - writeUleb128(OS, S->getOutputIndex(), "func index"); + // Names must appear in function index order. As it happens ImportedFunctions + // and DefinedFunctions are numbers in order with imported functions coming + // first. + for (const Symbol *S : ImportedFunctions) { + writeUleb128(OS, S->getOutputIndex(), "import index"); writeStr(OS, S->getName(), "symbol name"); } + for (const InputFunction *F : DefinedFunctions) { + if (!F->getName().empty()) { + writeUleb128(OS, F->getOutputIndex(), "func index"); + writeStr(OS, F->getName(), "symbol name"); + } + } FunctionSubsection.finalizeContents(); FunctionSubsection.writeToStream(Section->getStream()); @@ -784,7 +758,9 @@ void Writer::createCtorFunction() { ArrayRef<uint8_t> BodyArray( reinterpret_cast<const uint8_t *>(CtorFunctionBody.data()), CtorFunctionBody.size()); - CtorFunction = llvm::make_unique<SyntheticFunction>(Signature, BodyArray); + CtorFunction = llvm::make_unique<SyntheticFunction>( + Signature, BodyArray, Config->CtorSymbol->getName()); + CtorFunction->setOutputIndex(FunctionIndex); DefinedFunctions.emplace_back(CtorFunction.get()); } |