Lines Matching refs:sym

68 static std::optional<std::string> getLinkerScriptLocation(const Symbol &sym) {  in getLinkerScriptLocation()  argument
71 if (assign->sym == &sym) in getLinkerScriptLocation()
76 static std::string getDefinedLocation(const Symbol &sym) { in getDefinedLocation() argument
78 if (sym.file) in getDefinedLocation()
79 return msg + toString(sym.file); in getDefinedLocation()
80 if (std::optional<std::string> loc = getLinkerScriptLocation(sym)) in getDefinedLocation()
90 static std::string getLocation(InputSectionBase &s, const Symbol &sym, in getLocation() argument
92 std::string msg = getDefinedLocation(sym) + "\n>>> referenced by "; in getLocation()
93 std::string src = s.getSrcMsg(sym, off); in getLocation()
103 if (rel.sym) { in reportRangeError()
104 if (!rel.sym->isSection()) in reportRangeError()
105 hint = "; references '" + lld::toString(*rel.sym) + '\''; in reportRangeError()
106 else if (auto *d = dyn_cast<Defined>(rel.sym)) in reportRangeError()
110 rel.sym->getOutputSection() && in reportRangeError()
111 (rel.sym->getOutputSection()->flags & SHF_X86_64_LARGE)) { in reportRangeError()
118 if (rel.sym && !rel.sym->isSection()) in reportRangeError()
119 hint += getDefinedLocation(*rel.sym); in reportRangeError()
130 void elf::reportRangeError(uint8_t *loc, int64_t v, int n, const Symbol &sym, in reportRangeError() argument
134 if (!sym.getName().empty()) in reportRangeError()
136 "; references '" + lld::toString(sym) + '\'' + getDefinedLocation(sym); in reportRangeError()
192 static bool isAbsolute(const Symbol &sym) { in isAbsolute() argument
193 if (sym.isUndefWeak()) in isAbsolute()
195 if (const auto *dr = dyn_cast<Defined>(&sym)) in isAbsolute()
200 static bool isAbsoluteValue(const Symbol &sym) { in isAbsoluteValue() argument
201 return isAbsolute(sym) || sym.isTls(); in isAbsoluteValue()
298 Symbol *sym = symtab.find(name); in getSymbolsAt() local
299 if (auto *alias = dyn_cast_or_null<SharedSymbol>(sym)) in getSymbolsAt()
317 static void replaceWithDefined(Symbol &sym, SectionBase &sec, uint64_t value, in replaceWithDefined() argument
319 Symbol old = sym; in replaceWithDefined()
320 Defined(sym.file, StringRef(), sym.binding, sym.stOther, sym.type, value, in replaceWithDefined()
322 .overwrite(sym); in replaceWithDefined()
324 sym.versionId = old.versionId; in replaceWithDefined()
325 sym.exportDynamic = true; in replaceWithDefined()
326 sym.isUsedInRegularObj = true; in replaceWithDefined()
328 sym.flags.store(old.flags.load(std::memory_order_relaxed) & NEEDS_GOT, in replaceWithDefined()
399 for (SharedSymbol *sym : getSymbolsAt<ELFT>(ss)) in addCopyRelSymbol()
400 replaceWithDefined(*sym, *sec, 0, sym->size); in addCopyRelSymbol()
474 bool isStaticLinkTimeConstant(RelExpr e, RelType type, const Symbol &sym,
476 void processAux(RelExpr expr, RelType type, uint64_t offset, Symbol &sym,
520 static std::string maybeReportDiscarded(Undefined &sym) { in maybeReportDiscarded() argument
521 auto *file = dyn_cast_or_null<ObjFile<ELFT>>(sym.file); in maybeReportDiscarded()
522 if (!file || !sym.discardedSecIdx) in maybeReportDiscarded()
528 if (sym.type == ELF::STT_SECTION) { in maybeReportDiscarded()
531 file->getObj().getSectionName(objSections[sym.discardedSecIdx]), file); in maybeReportDiscarded()
534 toString(sym); in maybeReportDiscarded()
538 Elf_Shdr_Impl<ELFT> elfSec = objSections[sym.discardedSecIdx - 1]; in maybeReportDiscarded()
548 if (sym.nonPrevailing) { in maybeReportDiscarded()
563 Undefined *sym; member
594 static const Symbol *getAlternativeSpelling(const Undefined &sym, in getAlternativeSpelling() argument
598 if (sym.file && sym.file->kind() == InputFile::ObjKind) { in getAlternativeSpelling()
599 auto *file = cast<ELFFileBase>(sym.file); in getAlternativeSpelling()
602 if (file && sym.discardedSecIdx != 0 && in getAlternativeSpelling()
603 file->getSections()[sym.discardedSecIdx] == &InputSection::discarded) in getAlternativeSpelling()
607 for (const Symbol *s : sym.file->getSymbols()) in getAlternativeSpelling()
628 StringRef name = sym.getName(); in getAlternativeSpelling()
667 for (Symbol *sym : symtab.getSymbols()) in getAlternativeSpelling()
668 if (!sym->isUndefined() && name.equals_insensitive(sym->getName())) in getAlternativeSpelling()
669 return sym; in getAlternativeSpelling()
693 for (Symbol *sym : symtab.getSymbols()) in getAlternativeSpelling()
694 if (canSuggestExternCForCXX(name, sym->getName())) { in getAlternativeSpelling()
695 s = sym; in getAlternativeSpelling()
710 Undefined &sym = *undef.sym; in reportUndefinedSymbol() local
713 switch (sym.visibility()) { in reportUndefinedSymbol()
728 msg = maybeReportDiscarded<ELF32LE>(sym); in reportUndefinedSymbol()
731 msg = maybeReportDiscarded<ELF32BE>(sym); in reportUndefinedSymbol()
734 msg = maybeReportDiscarded<ELF64LE>(sym); in reportUndefinedSymbol()
737 msg = maybeReportDiscarded<ELF64BE>(sym); in reportUndefinedSymbol()
743 msg = "undefined " + visibility() + "symbol: " + toString(sym); in reportUndefinedSymbol()
757 std::string src = sec.getSrcMsg(enclosing ? *enclosing : sym, offset); in reportUndefinedSymbol()
771 getAlternativeSpelling(sym, pre_hint, post_hint)) { in reportUndefinedSymbol()
778 if (sym.getName().starts_with("_ZTV")) in reportUndefinedSymbol()
783 sym.getName().starts_with("__start_")) { in reportUndefinedSymbol()
792 error(msg, ErrorTag::SymbolNotFound, {sym.getName()}); in reportUndefinedSymbol()
801 if (UndefinedDiag *canon = firstRef.lookup(undef.sym)) { in reportUndefinedSymbols()
805 firstRef[undef.sym] = &undef; in reportUndefinedSymbols()
817 static bool maybeReportUndefined(Undefined &sym, InputSectionBase &sec, in maybeReportUndefined() argument
822 if (sym.hasVersionSuffix) { in maybeReportUndefined()
823 undefs.push_back({&sym, {{&sec, offset}}, false}); in maybeReportUndefined()
826 if (sym.isWeak()) in maybeReportUndefined()
829 bool canBeExternal = !sym.isLocal() && sym.visibility() == STV_DEFAULT; in maybeReportUndefined()
842 if (sym.discardedSecIdx != 0 && (sec.name == ".got2" || sec.name == ".toc")) in maybeReportUndefined()
848 undefs.push_back({&sym, {{&sec, offset}}, isWarning}); in maybeReportUndefined()
870 Symbol &sym, int64_t addend, RelExpr expr, in addRelativeReloc() argument
874 if (sym.isTagged()) { in addRelativeReloc()
876 part.relaDyn->addRelativeReloc(target->relativeRel, isec, offsetInSec, sym, in addRelativeReloc()
886 if (addend < 0 || static_cast<uint64_t>(addend) >= sym.getSize()) in addRelativeReloc()
887 isec.relocations.push_back({expr, type, offsetInSec, addend, &sym}); in addRelativeReloc()
898 isec.addReloc({expr, type, offsetInSec, addend, &sym}); in addRelativeReloc()
907 sym, addend, type, expr); in addRelativeReloc()
912 RelocationBaseSection &rel, RelType type, Symbol &sym) { in addPltEntry() argument
913 plt.addEntry(sym); in addPltEntry()
914 gotPlt.addEntry(sym); in addPltEntry()
915 rel.addReloc({type, &gotPlt, sym.getGotPltOffset(), in addPltEntry()
916 sym.isPreemptible ? DynamicReloc::AgainstSymbol in addPltEntry()
918 sym, 0, R_ABS}); in addPltEntry()
921 void elf::addGotEntry(Symbol &sym) { in addGotEntry() argument
922 in.got->addEntry(sym); in addGotEntry()
923 uint64_t off = sym.getGotOffset(); in addGotEntry()
926 if (sym.isPreemptible) { in addGotEntry()
928 DynamicReloc::AgainstSymbol, sym, 0, R_ABS}); in addGotEntry()
934 if (!config->isPic || isAbsolute(sym)) in addGotEntry()
935 in.got->addConstant({R_ABS, target->symbolicRel, off, 0, &sym}); in addGotEntry()
937 addRelativeReloc(*in.got, off, sym, 0, R_ABS, target->symbolicRel); in addGotEntry()
940 static void addTpOffsetGotEntry(Symbol &sym) { in addTpOffsetGotEntry() argument
941 in.got->addEntry(sym); in addTpOffsetGotEntry()
942 uint64_t off = sym.getGotOffset(); in addTpOffsetGotEntry()
943 if (!sym.isPreemptible && !config->shared) { in addTpOffsetGotEntry()
944 in.got->addConstant({R_TPREL, target->symbolicRel, off, 0, &sym}); in addTpOffsetGotEntry()
948 target->tlsGotRel, *in.got, off, sym, target->symbolicRel); in addTpOffsetGotEntry()
954 static bool canDefineSymbolInExecutable(Symbol &sym) { in canDefineSymbolInExecutable() argument
959 if (!sym.dsoProtected) in canDefineSymbolInExecutable()
966 return ((sym.isFunc() && config->ignoreFunctionAddressEquality) || in canDefineSymbolInExecutable()
967 (sym.isObject() && config->ignoreDataAddressEquality)); in canDefineSymbolInExecutable()
981 const Symbol &sym, in isStaticLinkTimeConstant() argument
998 if (sym.isPreemptible) in isStaticLinkTimeConstant()
1009 bool absVal = isAbsoluteValue(sym); in isStaticLinkTimeConstant()
1025 if (sym.isUndefWeak()) in isStaticLinkTimeConstant()
1030 if (sym.scriptDefined) in isStaticLinkTimeConstant()
1034 toString(sym) + getLocation(*sec, sym, relOff)); in isStaticLinkTimeConstant()
1052 Symbol &sym, int64_t addend) const { in processAux() argument
1055 const bool isIfunc = sym.isGnuIFunc(); in processAux()
1056 if (!sym.isPreemptible && (!isIfunc || config->zIfuncNoplt)) { in processAux()
1069 } else if (!isAbsoluteValue(sym)) { in processAux()
1083 sym.exportDynamic = true; in processAux()
1084 mainPart->relaDyn->addSymbolReloc(type, *sec, offset, sym, addend, type); in processAux()
1097 in.mipsGot->addEntry(*sec->file, sym, addend, expr); in processAux()
1098 } else if (!sym.isTls() || config->emachine != EM_LOONGARCH) { in processAux()
1101 sym.setFlags(NEEDS_GOT); in processAux()
1104 sym.setFlags(NEEDS_PLT); in processAux()
1106 sym.setFlags(HAS_DIRECT_RELOC); in processAux()
1123 if (isStaticLinkTimeConstant(expr, type, sym, offset) || in processAux()
1124 (!config->isPic && sym.isUndefWeak())) { in processAux()
1125 sec->addReloc({expr, type, offset, addend, &sym}); in processAux()
1141 (rel == target->symbolicRel && !sym.isPreemptible)) { in processAux()
1142 addRelativeReloc<true>(*sec, offset, sym, addend, expr, type); in processAux()
1148 sec->getPartition().relaDyn->addSymbolReloc(rel, *sec, offset, sym, in processAux()
1167 in.mipsGot->addEntry(*sec->file, sym, addend, expr); in processAux()
1174 if (!config->shared && sym.isShared()) { in processAux()
1175 if (!canDefineSymbolInExecutable(sym)) { in processAux()
1176 errorOrWarn("cannot preempt symbol: " + toString(sym) + in processAux()
1177 getLocation(*sec, sym, offset)); in processAux()
1181 if (sym.isObject()) { in processAux()
1183 if (auto *ss = dyn_cast<SharedSymbol>(&sym)) { in processAux()
1188 getLocation(*sec, sym, offset)); in processAux()
1189 sym.setFlags(NEEDS_COPY); in processAux()
1191 sec->addReloc({expr, type, offset, addend, &sym}); in processAux()
1222 if (sym.isFunc()) { in processAux()
1224 errorOrWarn("symbol '" + toString(sym) + in processAux()
1226 getLocation(*sec, sym, offset)); in processAux()
1227 sym.setFlags(NEEDS_COPY | NEEDS_PLT); in processAux()
1228 sec->addReloc({expr, type, offset, addend, &sym}); in processAux()
1234 (sym.getName().empty() ? "local symbol" in processAux()
1235 : "symbol '" + toString(sym) + "'") + in processAux()
1236 "; recompile with -fPIC" + getLocation(*sec, sym, offset)); in processAux()
1245 static unsigned handleMipsTlsRelocation(RelType type, Symbol &sym, in handleMipsTlsRelocation() argument
1250 c.addReloc({expr, type, offset, addend, &sym}); in handleMipsTlsRelocation()
1254 in.mipsGot->addDynTlsEntry(*c.file, sym); in handleMipsTlsRelocation()
1255 c.addReloc({expr, type, offset, addend, &sym}); in handleMipsTlsRelocation()
1268 static unsigned handleTlsRelocation(RelType type, Symbol &sym, in handleTlsRelocation() argument
1273 errorOrWarn("relocation " + toString(type) + " against " + toString(sym) + in handleTlsRelocation()
1274 " cannot be used with -shared" + getLocation(c, sym, offset)); in handleTlsRelocation()
1281 return handleMipsTlsRelocation(type, sym, c, offset, addend, expr); in handleTlsRelocation()
1291 sym.setFlags(NEEDS_TLSDESC); in handleTlsRelocation()
1292 c.addReloc({expr, type, offset, addend, &sym}); in handleTlsRelocation()
1315 bool isLocalInExecutable = !sym.isPreemptible && !config->shared; in handleTlsRelocation()
1325 offset, addend, &sym}); in handleTlsRelocation()
1331 c.addReloc({expr, type, offset, addend, &sym}); in handleTlsRelocation()
1339 c.addReloc({expr, type, offset, addend, &sym}); in handleTlsRelocation()
1347 sym.setFlags(NEEDS_GOT_DTPREL); in handleTlsRelocation()
1348 c.addReloc({expr, type, offset, addend, &sym}); in handleTlsRelocation()
1356 sym.setFlags(NEEDS_TLSGD); in handleTlsRelocation()
1357 c.addReloc({expr, type, offset, addend, &sym}); in handleTlsRelocation()
1367 if (sym.isPreemptible) { in handleTlsRelocation()
1368 sym.setFlags(NEEDS_TLSGD_TO_IE); in handleTlsRelocation()
1370 offset, addend, &sym}); in handleTlsRelocation()
1373 offset, addend, &sym}); in handleTlsRelocation()
1384 c.addReloc({R_RELAX_TLS_IE_TO_LE, type, offset, addend, &sym}); in handleTlsRelocation()
1386 sym.setFlags(NEEDS_TLSIE); in handleTlsRelocation()
1389 addRelativeReloc<true>(c, offset, sym, addend, expr, type); in handleTlsRelocation()
1391 c.addReloc({expr, type, offset, addend, &sym}); in handleTlsRelocation()
1402 Symbol &sym = sec->getFile<ELFT>()->getSymbol(symIndex); in scanOne() local
1415 RelExpr expr = target->getRelExpr(type, sym, sec->content().data() + offset); in scanOne()
1421 addend += computeMipsAddend<ELFT>(rel, expr, sym.isLocal()); in scanOne()
1431 if (sym.isUndefined() && symIndex != 0 && in scanOne()
1432 maybeReportUndefined(cast<Undefined>(sym), *sec, offset)) in scanOne()
1449 if (type == R_PPC64_TOC16_LO && sym.isSection() && isa<Defined>(sym) && in scanOne()
1450 cast<Defined>(sym).section->name == ".toc") in scanOne()
1451 ppc64noTocRelax.insert({&sym, addend}); in scanOne()
1458 getLocation(*sec, sym, offset)); in scanOne()
1486 if (sym.isTls() || oneof<R_TLSDESC_PC, R_TLSDESC_CALL>(expr)) { in scanOne()
1488 handleTlsRelocation(type, sym, *sec, offset, addend, expr)) { in scanOne()
1494 processAux(expr, type, offset, sym, addend); in scanOne()
1627 static bool handleNonPreemptibleIfunc(Symbol &sym, uint16_t flags) { in handleNonPreemptibleIfunc() argument
1668 if (!sym.isGnuIFunc() || sym.isPreemptible || config->zIfuncNoplt) in handleNonPreemptibleIfunc()
1674 sym.isInIplt = true; in handleNonPreemptibleIfunc()
1680 auto *directSym = makeDefined(cast<Defined>(sym)); in handleNonPreemptibleIfunc()
1684 sym.allocateAux(); in handleNonPreemptibleIfunc()
1689 auto &d = cast<Defined>(sym); in handleNonPreemptibleIfunc()
1698 addGotEntry(sym); in handleNonPreemptibleIfunc()
1701 sym.gotInIgot = true; in handleNonPreemptibleIfunc()
1707 auto fn = [](Symbol &sym) { in postScanRelocations() argument
1708 auto flags = sym.flags.load(std::memory_order_relaxed); in postScanRelocations()
1709 if (handleNonPreemptibleIfunc(sym, flags)) in postScanRelocations()
1712 if (sym.isTagged() && sym.isDefined()) in postScanRelocations()
1713 mainPart->memtagGlobalDescriptors->addSymbol(sym); in postScanRelocations()
1715 if (!sym.needsDynReloc()) in postScanRelocations()
1717 sym.allocateAux(); in postScanRelocations()
1720 addGotEntry(sym); in postScanRelocations()
1722 addPltEntry(*in.plt, *in.gotPlt, *in.relaPlt, target->pltRel, sym); in postScanRelocations()
1724 if (sym.isObject()) { in postScanRelocations()
1725 invokeELFT(addCopyRelSymbol, cast<SharedSymbol>(sym)); in postScanRelocations()
1728 assert(!sym.hasFlag(NEEDS_COPY)); in postScanRelocations()
1730 assert(sym.isFunc() && sym.hasFlag(NEEDS_PLT)); in postScanRelocations()
1731 if (!sym.isDefined()) { in postScanRelocations()
1732 replaceWithDefined(sym, *in.plt, in postScanRelocations()
1734 target->pltEntrySize * sym.getPltIdx(), in postScanRelocations()
1736 sym.setFlags(NEEDS_COPY); in postScanRelocations()
1739 cast<Defined>(sym).value = in.plt->headerSize; in postScanRelocations()
1741 cast<PPC32GlinkSection>(*in.plt).canonical_plts.push_back(&sym); in postScanRelocations()
1747 if (!sym.isTls()) in postScanRelocations()
1749 bool isLocalInExecutable = !sym.isPreemptible && !config->shared; in postScanRelocations()
1753 got->addTlsDescEntry(sym); in postScanRelocations()
1755 target->tlsDescRel, *got, got->getTlsDescOffset(sym), sym, in postScanRelocations()
1759 got->addDynTlsEntry(sym); in postScanRelocations()
1760 uint64_t off = got->getGlobalDynOffset(sym); in postScanRelocations()
1763 got->addConstant({R_ADDEND, target->symbolicRel, off, 1, &sym}); in postScanRelocations()
1766 sym); in postScanRelocations()
1771 if (sym.isPreemptible) in postScanRelocations()
1773 sym); in postScanRelocations()
1775 got->addConstant({R_ABS, target->tlsOffsetRel, offsetOff, 0, &sym}); in postScanRelocations()
1778 got->addEntry(sym); in postScanRelocations()
1780 sym.getGotOffset(), sym); in postScanRelocations()
1783 got->addEntry(sym); in postScanRelocations()
1785 {R_ABS, target->tlsOffsetRel, sym.getGotOffset(), 0, &sym}); in postScanRelocations()
1789 addTpOffsetGotEntry(sym); in postScanRelocations()
1804 for (Symbol *sym : symtab.getSymbols()) in postScanRelocations()
1805 fn(*sym); in postScanRelocations()
1810 for (Symbol *sym : file->getLocalSymbols()) in postScanRelocations()
1811 fn(*sym); in postScanRelocations()
2171 if (auto *d = dyn_cast<Defined>(rel.sym)) in getThunk()
2176 thunkVec = &thunkedSymbols[{rel.sym, keyAddend}]; in getThunk()
2197 if (Thunk *t = thunks.lookup(rel.sym)) { in normalizeExistingThunk()
2198 if (target->inBranchRange(rel.type, src, rel.sym->getVA(rel.addend))) in normalizeExistingThunk()
2200 rel.sym = &t->destination; in normalizeExistingThunk()
2202 if (rel.sym->isInPlt()) in normalizeExistingThunk()
2259 *rel.sym, rel.addend)) in createThunks()
2278 rel.sym = t->getThunkTargetSym(); in createThunks()
2310 if (rel.sym->type == llvm::ELF::STT_TLS && rel.expr == R_PLT_PC) { in hexagonNeedsTLSSymbol()
2319 Symbol *sym = symtab.find("__tls_get_addr"); in hexagonTLSSymbolUpdate() local
2320 if (!sym) in hexagonTLSSymbolUpdate()
2327 if (rel.sym->type == llvm::ELF::STT_TLS && rel.expr == R_PLT_PC) { in hexagonTLSSymbolUpdate()
2329 sym->allocateAux(); in hexagonTLSSymbolUpdate()
2331 *sym); in hexagonTLSSymbolUpdate()
2334 rel.sym = sym; in hexagonTLSSymbolUpdate()