diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp index b1e36f2ecff7..508c6b9df90b 100644 --- a/lld/wasm/Driver.cpp +++ b/lld/wasm/Driver.cpp @@ -885,7 +885,7 @@ static void writeWhyExtract() { // Equivalent of demote demoteSharedAndLazySymbols() in the ELF linker static void demoteLazySymbols() { for (Symbol *sym : symtab->symbols()) { - if (auto* s = dyn_cast(sym)) { + if (auto *s = dyn_cast(sym)) { if (s->signature) { LLVM_DEBUG(llvm::dbgs() << "demoting lazy func: " << s->getName() << "\n"); @@ -1026,15 +1026,15 @@ static void processStubLibrariesPreLTO() { for (auto &stub_file : ctx.stubFiles) { LLVM_DEBUG(llvm::dbgs() << "processing stub file: " << stub_file->getName() << "\n"); - for (auto [name, deps]: stub_file->symbolDependencies) { - auto* sym = symtab->find(name); + for (auto [name, deps] : stub_file->symbolDependencies) { + auto *sym = symtab->find(name); // If the symbol is not present at all (yet), or if it is present but // undefined, then mark the dependent symbols as used by a regular // object so they will be preserved and exported by the LTO process. if (!sym || sym->isUndefined()) { for (const auto dep : deps) { - auto* needed = symtab->find(dep); - if (needed ) { + auto *needed = symtab->find(dep); + if (needed) { needed->isUsedInRegularObj = true; // Like with handleLibcall we have to extract any LTO archive // members that might need to be exported due to stub library @@ -1106,8 +1106,8 @@ static void processStubLibraries() { // First look for any imported symbols that directly match // the names of the stub imports - for (auto [name, deps]: stub_file->symbolDependencies) { - auto* sym = symtab->find(name); + for (auto [name, deps] : stub_file->symbolDependencies) { + auto *sym = symtab->find(name); if (sym && sym->isUndefined() && sym->isUsedInRegularObj) { depsAdded |= addStubSymbolDeps(stub_file, sym, deps); } else { diff --git a/lld/wasm/InputChunks.cpp b/lld/wasm/InputChunks.cpp index 14e02e600931..79bac5f44440 100644 --- a/lld/wasm/InputChunks.cpp +++ b/lld/wasm/InputChunks.cpp @@ -423,8 +423,7 @@ bool InputChunk::generateRelocationCode(raw_ostream &os) const { bool is64 = ctx.arg.is64.value_or(false); bool generated = false; - unsigned opcode_ptr_add = is64 ? WASM_OPCODE_I64_ADD - : WASM_OPCODE_I32_ADD; + unsigned opcode_ptr_add = is64 ? WASM_OPCODE_I64_ADD : WASM_OPCODE_I32_ADD; uint64_t tombstone = getTombstone(); // TODO(sbc): Encode the relocations in the data section and write a loop @@ -585,12 +584,12 @@ uint64_t InputSection::getTombstoneForSection(StringRef name) { return UINT64_C(-2); if (name.starts_with(".debug_")) return UINT64_C(-1); - // If the function occurs in an function attribute section change it to -1 since - // 0 is a valid function index. + // If the function occurs in an function attribute section change it to -1 + // since 0 is a valid function index. if (name.starts_with("llvm.func_attr.")) return UINT64_C(-1); - // Returning 0 means there is no tombstone value for this section, and relocation - // will just use the addend. + // Returning 0 means there is no tombstone value for this section, and + // relocation will just use the addend. return 0; } diff --git a/lld/wasm/InputFiles.cpp b/lld/wasm/InputFiles.cpp index 5e59b3af83f9..dcdd138508c1 100644 --- a/lld/wasm/InputFiles.cpp +++ b/lld/wasm/InputFiles.cpp @@ -143,7 +143,7 @@ int64_t ObjFile::calcNewAddend(const WasmRelocation &reloc) const { // Translate from the relocation's index into the final linked output value. uint64_t ObjFile::calcNewValue(const WasmRelocation &reloc, uint64_t tombstone, const InputChunk *chunk) const { - const Symbol* sym = nullptr; + const Symbol *sym = nullptr; if (reloc.Type != R_WASM_TYPE_INDEX_LEB) { sym = symbols[reloc.Index]; @@ -562,7 +562,6 @@ void ObjFile::parse(bool ignoreComdats) { typeMap.resize(getWasmObj()->types().size()); typeIsUsed.resize(getWasmObj()->types().size(), false); - // Populate `Segments`. for (const WasmSegment &s : wasmObj->dataSegments()) { InputChunk *seg; @@ -886,7 +885,8 @@ void BitcodeFile::parseLazy() { void BitcodeFile::parse(StringRef symName) { if (doneLTO) { - error(toString(this) + ": attempt to add bitcode file after LTO (" + symName + ")"); + error(toString(this) + ": attempt to add bitcode file after LTO (" + + symName + ")"); return; } diff --git a/lld/wasm/Relocations.cpp b/lld/wasm/Relocations.cpp index a3f87ea3d69c..a1840abe88b3 100644 --- a/lld/wasm/Relocations.cpp +++ b/lld/wasm/Relocations.cpp @@ -33,7 +33,7 @@ static bool requiresGOTAccess(const Symbol *sym) { return true; } -static bool allowUndefined(const Symbol* sym) { +static bool allowUndefined(const Symbol *sym) { // Symbols that are explicitly imported are always allowed to be undefined at // link time. if (sym->isImported()) diff --git a/lld/wasm/SymbolTable.cpp b/lld/wasm/SymbolTable.cpp index 011e4341519c..9bd93f317c3c 100644 --- a/lld/wasm/SymbolTable.cpp +++ b/lld/wasm/SymbolTable.cpp @@ -101,7 +101,7 @@ Symbol *SymbolTable::find(StringRef name) { return symVector[it->second]; } -void SymbolTable::replace(StringRef name, Symbol* sym) { +void SymbolTable::replace(StringRef name, Symbol *sym) { auto it = symMap.find(CachedHashStringRef(name)); symVector[it->second] = sym; } @@ -224,8 +224,8 @@ DefinedFunction *SymbolTable::addSyntheticFunction(StringRef name, LLVM_DEBUG(dbgs() << "addSyntheticFunction: " << name << "\n"); assert(!find(name)); ctx.syntheticFunctions.emplace_back(function); - return replaceSymbol(insertName(name).first, name, - flags, nullptr, function); + return replaceSymbol(insertName(name).first, name, flags, + nullptr, function); } // Adds an optional, linker generated, data symbol. The symbol will only be @@ -439,7 +439,8 @@ Symbol *SymbolTable::addDefinedFunction(StringRef name, uint32_t flags, // If the new defined function doesn't have signature (i.e. bitcode // functions) but the old symbol does, then preserve the old signature const WasmSignature *oldSig = s->getSignature(); - auto* newSym = replaceSymbol(sym, name, flags, file, function); + auto *newSym = + replaceSymbol(sym, name, flags, file, function); if (!newSym->signature) newSym->signature = oldSig; }; @@ -459,8 +460,9 @@ Symbol *SymbolTable::addDefinedFunction(StringRef name, uint32_t flags, if (auto ud = dyn_cast(existingFunction)) checkSig = ud->isCalledDirectly; - if (checkSig && function && !signatureMatches(existingFunction, &function->signature)) { - Symbol* variant; + if (checkSig && function && + !signatureMatches(existingFunction, &function->signature)) { + Symbol *variant; if (getFunctionVariant(s, &function->signature, file, &variant)) // New variant, always replace replaceSym(variant); @@ -909,7 +911,7 @@ bool SymbolTable::addComdat(StringRef name) { // The new signature doesn't match. Create a variant to the symbol with the // signature encoded in the name and return that instead. These symbols are // then unified later in handleSymbolVariants. -bool SymbolTable::getFunctionVariant(Symbol* sym, const WasmSignature *sig, +bool SymbolTable::getFunctionVariant(Symbol *sym, const WasmSignature *sig, const InputFile *file, Symbol **out) { LLVM_DEBUG(dbgs() << "getFunctionVariant: " << sym->getName() << " -> " << " " << toString(*sig) << "\n"); @@ -921,7 +923,7 @@ bool SymbolTable::getFunctionVariant(Symbol* sym, const WasmSignature *sig, if (variants.empty()) variants.push_back(sym); - for (Symbol* v : variants) { + for (Symbol *v : variants) { if (*v->getSignature() == *sig) { variant = v; break; @@ -940,7 +942,8 @@ bool SymbolTable::getFunctionVariant(Symbol* sym, const WasmSignature *sig, variant->forceExport = false; variants.push_back(variant); } else { - LLVM_DEBUG(dbgs() << "variant already exists: " << toString(*variant) << "\n"); + LLVM_DEBUG(dbgs() << "variant already exists: " << toString(*variant) + << "\n"); assert(*variant->getSignature() == *sig); } @@ -957,7 +960,7 @@ void SymbolTable::trace(StringRef name) { void SymbolTable::wrap(Symbol *sym, Symbol *real, Symbol *wrap) { // Swap symbols as instructed by -wrap. int &origIdx = symMap[CachedHashStringRef(sym->getName())]; - int &realIdx= symMap[CachedHashStringRef(real->getName())]; + int &realIdx = symMap[CachedHashStringRef(real->getName())]; int &wrapIdx = symMap[CachedHashStringRef(wrap->getName())]; LLVM_DEBUG(dbgs() << "wrap: " << sym->getName() << "\n"); @@ -1049,7 +1052,7 @@ void SymbolTable::handleSymbolVariants() { #ifndef NDEBUG LLVM_DEBUG(dbgs() << "symbol with (" << variants.size() << ") variants: " << symName << "\n"); - for (auto *s: variants) { + for (auto *s : variants) { auto *f = cast(s); LLVM_DEBUG(dbgs() << " variant: " + f->getName() << " " << toString(*f->signature) << "\n"); @@ -1087,4 +1090,4 @@ void SymbolTable::handleSymbolVariants() { } } -} // namespace wasm::lld +} // namespace lld::wasm diff --git a/lld/wasm/SymbolTable.h b/lld/wasm/SymbolTable.h index 5d09d8b68571..649614298c52 100644 --- a/lld/wasm/SymbolTable.h +++ b/lld/wasm/SymbolTable.h @@ -46,7 +46,7 @@ public: Symbol *find(StringRef name); - void replace(StringRef name, Symbol* sym); + void replace(StringRef name, Symbol *sym); void trace(StringRef name); @@ -108,7 +108,7 @@ private: std::pair insert(StringRef name, const InputFile *file); std::pair insertName(StringRef name); - bool getFunctionVariant(Symbol* sym, const WasmSignature *sig, + bool getFunctionVariant(Symbol *sym, const WasmSignature *sig, const InputFile *file, Symbol **out); InputFunction *replaceWithUnreachable(Symbol *sym, const WasmSignature &sig, StringRef debugName); diff --git a/lld/wasm/Symbols.cpp b/lld/wasm/Symbols.cpp index f2040441e625..97a9871a0630 100644 --- a/lld/wasm/Symbols.cpp +++ b/lld/wasm/Symbols.cpp @@ -95,7 +95,7 @@ WasmSymbolType Symbol::getWasmType() const { } const WasmSignature *Symbol::getSignature() const { - if (auto* f = dyn_cast(this)) + if (auto *f = dyn_cast(this)) return f->signature; if (auto *t = dyn_cast(this)) return t->signature; @@ -223,9 +223,7 @@ bool Symbol::isExportedExplicit() const { return forceExport || flags & WASM_SYMBOL_EXPORTED; } -bool Symbol::isNoStrip() const { - return flags & WASM_SYMBOL_NO_STRIP; -} +bool Symbol::isNoStrip() const { return flags & WASM_SYMBOL_NO_STRIP; } uint32_t FunctionSymbol::getFunctionIndex() const { if (const auto *u = dyn_cast(this)) @@ -413,7 +411,7 @@ void LazySymbol::setWeak() { flags |= (flags & ~WASM_SYMBOL_BINDING_MASK) | WASM_SYMBOL_BINDING_WEAK; } -void printTraceSymbolUndefined(StringRef name, const InputFile* file) { +void printTraceSymbolUndefined(StringRef name, const InputFile *file) { message(toString(file) + ": reference to " + name); } diff --git a/lld/wasm/Symbols.h b/lld/wasm/Symbols.h index 55ee21939ce0..3dda36f88d5e 100644 --- a/lld/wasm/Symbols.h +++ b/lld/wasm/Symbols.h @@ -127,7 +127,7 @@ public: // or similar. bool isNoStrip() const; - const WasmSignature* getSignature() const; + const WasmSignature *getSignature() const; uint32_t getGOTIndex() const { assert(gotIndex != INVALID_INDEX); @@ -561,10 +561,10 @@ union SymbolUnion { static_assert(sizeof(SymbolUnion) <= 120, "SymbolUnion too large"); void printTraceSymbol(Symbol *sym); -void printTraceSymbolUndefined(StringRef name, const InputFile* file); +void printTraceSymbolUndefined(StringRef name, const InputFile *file); template -T *replaceSymbol(Symbol *s, ArgT &&... arg) { +T *replaceSymbol(Symbol *s, ArgT &&...arg) { static_assert(std::is_trivially_destructible(), "Symbol types must be trivially destructible"); static_assert(sizeof(T) <= sizeof(SymbolUnion), "SymbolUnion too small"); diff --git a/lld/wasm/SyntheticSections.cpp b/lld/wasm/SyntheticSections.cpp index ede6ac4da77b..81d4b0327c44 100644 --- a/lld/wasm/SyntheticSections.cpp +++ b/lld/wasm/SyntheticSections.cpp @@ -466,8 +466,7 @@ void GlobalSection::addInternalGOTEntry(Symbol *sym) { void GlobalSection::generateRelocationCode(raw_ostream &os, bool TLS) const { assert(!ctx.arg.extendedConst); bool is64 = ctx.arg.is64.value_or(false); - unsigned opcode_ptr_add = is64 ? WASM_OPCODE_I64_ADD - : WASM_OPCODE_I32_ADD; + unsigned opcode_ptr_add = is64 ? WASM_OPCODE_I64_ADD : WASM_OPCODE_I32_ADD; for (const Symbol *sym : internalGotSymbols) { if (TLS != sym->isTLS()) @@ -646,7 +645,7 @@ void ElemSection::writeBody() { uint32_t tableIndex = ctx.arg.tableBase; for (const FunctionSymbol *sym : indirectFunctions) { assert(sym->getTableIndex() == tableIndex); - (void) tableIndex; + (void)tableIndex; writeUleb128(os, sym->getFunctionIndex(), "function index"); ++tableIndex; } @@ -992,4 +991,4 @@ void BuildIdSection::writeBuildId(llvm::ArrayRef buf) { memcpy(hashPlaceholderPtr, buf.data(), hashSize); } -} // namespace wasm::lld +} // namespace lld::wasm diff --git a/lld/wasm/SyntheticSections.h b/lld/wasm/SyntheticSections.h index 313cbd63ecbf..2862b22da86b 100644 --- a/lld/wasm/SyntheticSections.h +++ b/lld/wasm/SyntheticSections.h @@ -125,7 +125,7 @@ inline bool operator==(const ImportKey &lhs, const ImportKey &rhs) { lhs.importName == rhs.importName && lhs.type == rhs.type; } -} // namespace wasm::lld +} // namespace lld::wasm // `ImportKey` can be used as a key in a `DenseMap` if `T` can be used as a // key in a `DenseMap`. @@ -324,8 +324,7 @@ public: class ElemSection : public SyntheticSection { public: - ElemSection() - : SyntheticSection(llvm::wasm::WASM_SEC_ELEM) {} + ElemSection() : SyntheticSection(llvm::wasm::WASM_SEC_ELEM) {} bool isNeeded() const override { return indirectFunctions.size() > 0; }; void writeBody() override; void addEntry(FunctionSymbol *sym); diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp index dfd856f2faee..128931513b21 100644 --- a/lld/wasm/Writer.cpp +++ b/lld/wasm/Writer.cpp @@ -311,7 +311,8 @@ void Writer::writeBuildId() { } static void setGlobalPtr(DefinedGlobal *g, uint64_t memoryPtr) { - LLVM_DEBUG(dbgs() << "setGlobalPtr " << g->getName() << " -> " << memoryPtr << "\n"); + LLVM_DEBUG(dbgs() << "setGlobalPtr " << g->getName() << " -> " << memoryPtr + << "\n"); g->global->setPointerValue(memoryPtr); } @@ -358,7 +359,8 @@ void Writer::layoutMemory() { placeStack(); if (ctx.arg.globalBase) { if (ctx.arg.globalBase < memoryPtr) { - error("--global-base cannot be less than stack size when --stack-first is used"); + error("--global-base cannot be less than stack size when --stack-first " + "is used"); return; } memoryPtr = ctx.arg.globalBase; @@ -1183,7 +1185,7 @@ void Writer::createSyntheticInitFunctions() { auto hasTLSRelocs = [](const OutputSegment *segment) { if (segment->isTLS()) - for (const auto* is: segment->inputSegments) + for (const auto *is : segment->inputSegments) if (is->getRelocations().size()) return true; return false; @@ -1635,7 +1637,8 @@ void Writer::createInitTLSFunction() { writeU8(os, WASM_OPCODE_GLOBAL_SET, "global.set"); writeUleb128(os, ctx.sym.tlsBase->getGlobalIndex(), "global index"); - // FIXME(wvo): this local needs to be I64 in wasm64, or we need an extend op. + // FIXME(wvo): this local needs to be I64 in wasm64, or we need an extend + // op. writeU8(os, WASM_OPCODE_LOCAL_GET, "local.get"); writeUleb128(os, 0, "local index"); @@ -1901,4 +1904,4 @@ void Writer::createHeader() { void writeResult() { Writer().run(); } -} // namespace wasm::lld +} // namespace lld::wasm diff --git a/lld/wasm/WriterUtils.cpp b/lld/wasm/WriterUtils.cpp index a23d0febb364..fee25a725579 100644 --- a/lld/wasm/WriterUtils.cpp +++ b/lld/wasm/WriterUtils.cpp @@ -97,7 +97,7 @@ void writeSleb128(raw_ostream &os, int64_t number, const Twine &msg) { } void writeBytes(raw_ostream &os, const char *bytes, size_t count, - const Twine &msg) { + const Twine &msg) { debugWrite(os.tell(), msg + " [data[" + Twine(count) + "]]"); os.write(bytes, count); }