diff options
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r-- | llvm/tools/llvm-objdump/llvm-objdump.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index 39ce32d..48ae92f 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -736,6 +736,43 @@ addDynamicElfSymbols(const ObjectFile *Obj, llvm_unreachable("Unsupported binary format"); } +static Optional<SectionRef> getWasmCodeSection(const WasmObjectFile *Obj) { + for (auto SecI : Obj->sections()) { + const WasmSection &Section = Obj->getWasmSection(SecI); + if (Section.Type == wasm::WASM_SEC_CODE) + return SecI; + } + return None; +} + +static void +addMissingWasmCodeSymbols(const WasmObjectFile *Obj, + std::map<SectionRef, SectionSymbolsTy> &AllSymbols) { + Optional<SectionRef> Section = getWasmCodeSection(Obj); + if (!Section) + return; + SectionSymbolsTy &Symbols = AllSymbols[*Section]; + + std::set<uint64_t> SymbolAddresses; + for (const auto &Sym : Symbols) + SymbolAddresses.insert(Sym.Addr); + + for (const wasm::WasmFunction &Function : Obj->functions()) { + uint64_t Address = Function.CodeSectionOffset; + // Only add fallback symbols for functions not already present in the symbol + // table. + if (SymbolAddresses.count(Address)) + continue; + // This function has no symbol, so it should have no SymbolName. + assert(Function.SymbolName.empty()); + // We use DebugName for the name, though it may be empty if there is no + // "name" custom section, or that section is missing a name for this + // function. + StringRef Name = Function.DebugName; + Symbols.emplace_back(Address, Name, ELF::STT_NOTYPE); + } +} + static void addPltEntries(const ObjectFile *Obj, std::map<SectionRef, SectionSymbolsTy> &AllSymbols, StringSaver &Saver) { @@ -1126,6 +1163,9 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj, if (AllSymbols.empty() && Obj->isELF()) addDynamicElfSymbols(Obj, AllSymbols); + if (Obj->isWasm()) + addMissingWasmCodeSymbols(cast<WasmObjectFile>(Obj), AllSymbols); + BumpPtrAllocator A; StringSaver Saver(A); addPltEntries(Obj, AllSymbols, Saver); |