[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
diff --git a/lld/wasm/InputChunks.h b/lld/wasm/InputChunks.h
index d5a9e5c..d8d0358 100644
--- a/lld/wasm/InputChunks.h
+++ b/lld/wasm/InputChunks.h
@@ -112,8 +112,9 @@
public:
InputFunction(const WasmSignature &S, const WasmFunction *Func,
const ObjFile *F)
- : InputChunk(F), Signature(S), WrittenToNameSec(false), Function(Func) {}
+ : InputChunk(F), Signature(S), Function(Func) {}
+ virtual StringRef getName() const { return Function->Name; }
StringRef getComdat() const override { return Function->Comdat; }
uint32_t getOutputIndex() const { return OutputIndex.getValue(); }
bool hasOutputIndex() const { return OutputIndex.hasValue(); }
@@ -121,8 +122,6 @@
const WasmSignature &Signature;
- unsigned WrittenToNameSec : 1;
-
protected:
ArrayRef<uint8_t> data() const override {
return File->CodeSection->Content.slice(getInputSectionOffset(),
@@ -138,12 +137,16 @@
class SyntheticFunction : public InputFunction {
public:
- SyntheticFunction(const WasmSignature &S, ArrayRef<uint8_t> Body)
- : InputFunction(S, nullptr, nullptr), Body(Body) {}
+ SyntheticFunction(const WasmSignature &S, ArrayRef<uint8_t> Body,
+ StringRef Name)
+ : InputFunction(S, nullptr, nullptr), Name(Name), Body(Body) {}
+
+ StringRef getName() const override { return Name; }
protected:
ArrayRef<uint8_t> data() const override { return Body; }
+ StringRef Name;
ArrayRef<uint8_t> Body;
};