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()
475 bool isStaticLinkTimeConstant(RelExpr e, RelType type, const Symbol &sym,
477 void processAux(RelExpr expr, RelType type, uint64_t offset, Symbol &sym,
523 static std::string maybeReportDiscarded(Undefined &sym) { in maybeReportDiscarded() argument
524 auto *file = dyn_cast_or_null<ObjFile<ELFT>>(sym.file); in maybeReportDiscarded()
525 if (!file || !sym.discardedSecIdx) in maybeReportDiscarded()
531 if (sym.type == ELF::STT_SECTION) { in maybeReportDiscarded()
534 file->getObj().getSectionName(objSections[sym.discardedSecIdx]), file); in maybeReportDiscarded()
537 toString(sym); in maybeReportDiscarded()
541 Elf_Shdr_Impl<ELFT> elfSec = objSections[sym.discardedSecIdx - 1]; in maybeReportDiscarded()
551 if (sym.nonPrevailing) { in maybeReportDiscarded()
566 Undefined *sym; member
597 static const Symbol *getAlternativeSpelling(const Undefined &sym, in getAlternativeSpelling() argument
601 if (sym.file && sym.file->kind() == InputFile::ObjKind) { in getAlternativeSpelling()
602 auto *file = cast<ELFFileBase>(sym.file); in getAlternativeSpelling()
605 if (file && sym.discardedSecIdx != 0 && in getAlternativeSpelling()
606 file->getSections()[sym.discardedSecIdx] == &InputSection::discarded) in getAlternativeSpelling()
610 for (const Symbol *s : sym.file->getSymbols()) in getAlternativeSpelling()
631 StringRef name = sym.getName(); in getAlternativeSpelling()
670 for (Symbol *sym : symtab.getSymbols()) in getAlternativeSpelling()
671 if (!sym->isUndefined() && name.equals_insensitive(sym->getName())) in getAlternativeSpelling()
672 return sym; in getAlternativeSpelling()
696 for (Symbol *sym : symtab.getSymbols()) in getAlternativeSpelling()
697 if (canSuggestExternCForCXX(name, sym->getName())) { in getAlternativeSpelling()
698 s = sym; in getAlternativeSpelling()
713 Undefined &sym = *undef.sym; in reportUndefinedSymbol() local
716 switch (sym.visibility()) { in reportUndefinedSymbol()
731 msg = maybeReportDiscarded<ELF32LE>(sym); in reportUndefinedSymbol()
734 msg = maybeReportDiscarded<ELF32BE>(sym); in reportUndefinedSymbol()
737 msg = maybeReportDiscarded<ELF64LE>(sym); in reportUndefinedSymbol()
740 msg = maybeReportDiscarded<ELF64BE>(sym); in reportUndefinedSymbol()
746 msg = "undefined " + visibility() + "symbol: " + toString(sym); in reportUndefinedSymbol()
760 std::string src = sec.getSrcMsg(enclosing ? *enclosing : sym, offset); in reportUndefinedSymbol()
774 getAlternativeSpelling(sym, pre_hint, post_hint)) { in reportUndefinedSymbol()
781 if (sym.getName().starts_with("_ZTV")) in reportUndefinedSymbol()
786 sym.getName().starts_with("__start_")) { in reportUndefinedSymbol()
795 error(msg, ErrorTag::SymbolNotFound, {sym.getName()}); in reportUndefinedSymbol()
804 if (UndefinedDiag *canon = firstRef.lookup(undef.sym)) { in reportUndefinedSymbols()
808 firstRef[undef.sym] = &undef; in reportUndefinedSymbols()
820 static bool maybeReportUndefined(Undefined &sym, InputSectionBase &sec, in maybeReportUndefined() argument
825 if (sym.hasVersionSuffix) { in maybeReportUndefined()
826 undefs.push_back({&sym, {{&sec, offset}}, false}); in maybeReportUndefined()
829 if (sym.isWeak()) in maybeReportUndefined()
832 bool canBeExternal = !sym.isLocal() && sym.visibility() == STV_DEFAULT; in maybeReportUndefined()
845 if (sym.discardedSecIdx != 0 && (sec.name == ".got2" || sec.name == ".toc")) in maybeReportUndefined()
851 undefs.push_back({&sym, {{&sec, offset}}, isWarning}); in maybeReportUndefined()
873 Symbol &sym, int64_t addend, RelExpr expr, in addRelativeReloc() argument
877 if (sym.isTagged()) { in addRelativeReloc()
879 part.relaDyn->addRelativeReloc(target->relativeRel, isec, offsetInSec, sym, in addRelativeReloc()
889 if (addend < 0 || static_cast<uint64_t>(addend) >= sym.getSize()) in addRelativeReloc()
890 isec.relocations.push_back({expr, type, offsetInSec, addend, &sym}); in addRelativeReloc()
901 isec.addReloc({expr, type, offsetInSec, addend, &sym}); in addRelativeReloc()
910 sym, addend, type, expr); in addRelativeReloc()
915 RelocationBaseSection &rel, RelType type, Symbol &sym) { in addPltEntry() argument
916 plt.addEntry(sym); in addPltEntry()
917 gotPlt.addEntry(sym); in addPltEntry()
918 rel.addReloc({type, &gotPlt, sym.getGotPltOffset(), in addPltEntry()
919 sym.isPreemptible ? DynamicReloc::AgainstSymbol in addPltEntry()
921 sym, 0, R_ABS}); in addPltEntry()
924 void elf::addGotEntry(Symbol &sym) { in addGotEntry() argument
925 in.got->addEntry(sym); in addGotEntry()
926 uint64_t off = sym.getGotOffset(); in addGotEntry()
929 if (sym.isPreemptible) { in addGotEntry()
931 DynamicReloc::AgainstSymbol, sym, 0, R_ABS}); in addGotEntry()
937 if (!config->isPic || isAbsolute(sym)) in addGotEntry()
938 in.got->addConstant({R_ABS, target->symbolicRel, off, 0, &sym}); in addGotEntry()
940 addRelativeReloc(*in.got, off, sym, 0, R_ABS, target->symbolicRel); in addGotEntry()
943 static void addTpOffsetGotEntry(Symbol &sym) { in addTpOffsetGotEntry() argument
944 in.got->addEntry(sym); in addTpOffsetGotEntry()
945 uint64_t off = sym.getGotOffset(); in addTpOffsetGotEntry()
946 if (!sym.isPreemptible && !config->shared) { in addTpOffsetGotEntry()
947 in.got->addConstant({R_TPREL, target->symbolicRel, off, 0, &sym}); in addTpOffsetGotEntry()
951 target->tlsGotRel, *in.got, off, sym, target->symbolicRel); in addTpOffsetGotEntry()
957 static bool canDefineSymbolInExecutable(Symbol &sym) { in canDefineSymbolInExecutable() argument
962 if (!sym.dsoProtected) in canDefineSymbolInExecutable()
969 return ((sym.isFunc() && config->ignoreFunctionAddressEquality) || in canDefineSymbolInExecutable()
970 (sym.isObject() && config->ignoreDataAddressEquality)); in canDefineSymbolInExecutable()
984 const Symbol &sym, in isStaticLinkTimeConstant() argument
1002 if (sym.isPreemptible || e == R_AARCH64_AUTH) in isStaticLinkTimeConstant()
1013 bool absVal = isAbsoluteValue(sym); in isStaticLinkTimeConstant()
1029 if (sym.isUndefWeak()) in isStaticLinkTimeConstant()
1034 if (sym.scriptDefined) in isStaticLinkTimeConstant()
1038 toString(sym) + getLocation(*sec, sym, relOff)); in isStaticLinkTimeConstant()
1056 Symbol &sym, int64_t addend) const { in processAux() argument
1059 const bool isIfunc = sym.isGnuIFunc(); in processAux()
1060 if (!sym.isPreemptible && (!isIfunc || config->zIfuncNoplt)) { in processAux()
1073 } else if (!isAbsoluteValue(sym)) { in processAux()
1087 sym.exportDynamic = true; in processAux()
1088 mainPart->relaDyn->addSymbolReloc(type, *sec, offset, sym, addend, type); in processAux()
1101 in.mipsGot->addEntry(*sec->file, sym, addend, expr); in processAux()
1102 } else if (!sym.isTls() || config->emachine != EM_LOONGARCH) { in processAux()
1105 sym.setFlags(NEEDS_GOT); in processAux()
1108 sym.setFlags(NEEDS_PLT); in processAux()
1110 sym.setFlags(HAS_DIRECT_RELOC); in processAux()
1127 if (isStaticLinkTimeConstant(expr, type, sym, offset) || in processAux()
1128 (!config->isPic && sym.isUndefWeak())) { in processAux()
1129 sec->addReloc({expr, type, offset, addend, &sym}); in processAux()
1145 (rel == target->symbolicRel && !sym.isPreemptible)) { in processAux()
1146 addRelativeReloc<true>(*sec, offset, sym, addend, expr, type); in processAux()
1158 if (sym.isPreemptible) { in processAux()
1159 part.relaDyn->addSymbolReloc(type, *sec, offset, sym, addend, type); in processAux()
1164 sec->addReloc({expr, type, offset, addend, &sym}); in processAux()
1168 DynamicReloc::AddendOnlyWithTargetVA, sym, in processAux()
1173 part.relaDyn->addSymbolReloc(rel, *sec, offset, sym, addend, type); in processAux()
1191 in.mipsGot->addEntry(*sec->file, sym, addend, expr); in processAux()
1200 if (!config->shared && sym.isShared() && in processAux()
1202 if (!canDefineSymbolInExecutable(sym)) { in processAux()
1203 errorOrWarn("cannot preempt symbol: " + toString(sym) + in processAux()
1204 getLocation(*sec, sym, offset)); in processAux()
1208 if (sym.isObject()) { in processAux()
1210 if (auto *ss = dyn_cast<SharedSymbol>(&sym)) { in processAux()
1215 getLocation(*sec, sym, offset)); in processAux()
1216 sym.setFlags(NEEDS_COPY); in processAux()
1218 sec->addReloc({expr, type, offset, addend, &sym}); in processAux()
1249 if (sym.isFunc()) { in processAux()
1251 errorOrWarn("symbol '" + toString(sym) + in processAux()
1253 getLocation(*sec, sym, offset)); in processAux()
1254 sym.setFlags(NEEDS_COPY | NEEDS_PLT); in processAux()
1255 sec->addReloc({expr, type, offset, addend, &sym}); in processAux()
1261 (sym.getName().empty() ? "local symbol" in processAux()
1262 : "symbol '" + toString(sym) + "'") + in processAux()
1263 "; recompile with -fPIC" + getLocation(*sec, sym, offset)); in processAux()
1272 static unsigned handleMipsTlsRelocation(RelType type, Symbol &sym, in handleMipsTlsRelocation() argument
1277 c.addReloc({expr, type, offset, addend, &sym}); in handleMipsTlsRelocation()
1281 in.mipsGot->addDynTlsEntry(*c.file, sym); in handleMipsTlsRelocation()
1282 c.addReloc({expr, type, offset, addend, &sym}); in handleMipsTlsRelocation()
1295 static unsigned handleTlsRelocation(RelType type, Symbol &sym, in handleTlsRelocation() argument
1300 errorOrWarn("relocation " + toString(type) + " against " + toString(sym) + in handleTlsRelocation()
1301 " cannot be used with -shared" + getLocation(c, sym, offset)); in handleTlsRelocation()
1308 return handleMipsTlsRelocation(type, sym, c, offset, addend, expr); in handleTlsRelocation()
1316 sym.setFlags(NEEDS_TLSDESC); in handleTlsRelocation()
1317 c.addReloc({expr, type, offset, addend, &sym}); in handleTlsRelocation()
1331 sym.setFlags(NEEDS_TLSDESC); in handleTlsRelocation()
1332 c.addReloc({expr, type, offset, addend, &sym}); in handleTlsRelocation()
1355 bool isLocalInExecutable = !sym.isPreemptible && !config->shared; in handleTlsRelocation()
1365 offset, addend, &sym}); in handleTlsRelocation()
1371 c.addReloc({expr, type, offset, addend, &sym}); in handleTlsRelocation()
1379 c.addReloc({expr, type, offset, addend, &sym}); in handleTlsRelocation()
1387 sym.setFlags(NEEDS_GOT_DTPREL); in handleTlsRelocation()
1388 c.addReloc({expr, type, offset, addend, &sym}); in handleTlsRelocation()
1396 sym.setFlags(NEEDS_TLSGD); in handleTlsRelocation()
1397 c.addReloc({expr, type, offset, addend, &sym}); in handleTlsRelocation()
1407 if (sym.isPreemptible) { in handleTlsRelocation()
1408 sym.setFlags(NEEDS_TLSGD_TO_IE); in handleTlsRelocation()
1410 offset, addend, &sym}); in handleTlsRelocation()
1413 offset, addend, &sym}); in handleTlsRelocation()
1424 c.addReloc({R_RELAX_TLS_IE_TO_LE, type, offset, addend, &sym}); in handleTlsRelocation()
1426 sym.setFlags(NEEDS_TLSIE); in handleTlsRelocation()
1429 addRelativeReloc<true>(c, offset, sym, addend, expr, type); in handleTlsRelocation()
1431 c.addReloc({expr, type, offset, addend, &sym}); in handleTlsRelocation()
1443 Symbol &sym = sec->getFile<ELFT>()->getSymbol(symIndex); in scanOne() local
1462 RelExpr expr = target->getRelExpr(type, sym, sec->content().data() + offset); in scanOne()
1468 addend += computeMipsAddend<ELFT>(rel, expr, sym.isLocal()); in scanOne()
1478 if (sym.isUndefined() && symIndex != 0 && in scanOne()
1479 maybeReportUndefined(cast<Undefined>(sym), *sec, offset)) in scanOne()
1496 if (type == R_PPC64_TOC16_LO && sym.isSection() && isa<Defined>(sym) && in scanOne()
1497 cast<Defined>(sym).section->name == ".toc") in scanOne()
1498 ppc64noTocRelax.insert({&sym, addend}); in scanOne()
1507 getLocation(*sec, sym, offset)); in scanOne()
1536 if (sym.isTls() || oneof<R_TLSDESC_PC, R_TLSDESC_CALL>(expr)) { in scanOne()
1538 handleTlsRelocation(type, sym, *sec, offset, addend, expr)) { in scanOne()
1544 processAux(expr, type, offset, sym, addend); in scanOne()
1686 static bool handleNonPreemptibleIfunc(Symbol &sym, uint16_t flags) { in handleNonPreemptibleIfunc() argument
1723 if (!sym.isGnuIFunc() || sym.isPreemptible || config->zIfuncNoplt) in handleNonPreemptibleIfunc()
1729 sym.isInIplt = true; in handleNonPreemptibleIfunc()
1742 auto *directSym = makeDefined(cast<Defined>(sym)); in handleNonPreemptibleIfunc()
1746 sym.allocateAux(); in handleNonPreemptibleIfunc()
1751 auto &d = cast<Defined>(sym); in handleNonPreemptibleIfunc()
1760 addGotEntry(sym); in handleNonPreemptibleIfunc()
1763 sym.gotInIgot = true; in handleNonPreemptibleIfunc()
1769 auto fn = [](Symbol &sym) { in postScanRelocations() argument
1770 auto flags = sym.flags.load(std::memory_order_relaxed); in postScanRelocations()
1771 if (handleNonPreemptibleIfunc(sym, flags)) in postScanRelocations()
1774 if (sym.isTagged() && sym.isDefined()) in postScanRelocations()
1775 mainPart->memtagGlobalDescriptors->addSymbol(sym); in postScanRelocations()
1777 if (!sym.needsDynReloc()) in postScanRelocations()
1779 sym.allocateAux(); in postScanRelocations()
1782 addGotEntry(sym); in postScanRelocations()
1784 addPltEntry(*in.plt, *in.gotPlt, *in.relaPlt, target->pltRel, sym); in postScanRelocations()
1786 if (sym.isObject()) { in postScanRelocations()
1787 invokeELFT(addCopyRelSymbol, cast<SharedSymbol>(sym)); in postScanRelocations()
1790 assert(!sym.hasFlag(NEEDS_COPY)); in postScanRelocations()
1792 assert(sym.isFunc() && sym.hasFlag(NEEDS_PLT)); in postScanRelocations()
1793 if (!sym.isDefined()) { in postScanRelocations()
1794 replaceWithDefined(sym, *in.plt, in postScanRelocations()
1796 target->pltEntrySize * sym.getPltIdx(), in postScanRelocations()
1798 sym.setFlags(NEEDS_COPY); in postScanRelocations()
1801 cast<Defined>(sym).value = in.plt->headerSize; in postScanRelocations()
1803 cast<PPC32GlinkSection>(*in.plt).canonical_plts.push_back(&sym); in postScanRelocations()
1809 if (!sym.isTls()) in postScanRelocations()
1811 bool isLocalInExecutable = !sym.isPreemptible && !config->shared; in postScanRelocations()
1815 got->addTlsDescEntry(sym); in postScanRelocations()
1817 target->tlsDescRel, *got, got->getTlsDescOffset(sym), sym, in postScanRelocations()
1821 got->addDynTlsEntry(sym); in postScanRelocations()
1822 uint64_t off = got->getGlobalDynOffset(sym); in postScanRelocations()
1825 got->addConstant({R_ADDEND, target->symbolicRel, off, 1, &sym}); in postScanRelocations()
1828 sym); in postScanRelocations()
1833 if (sym.isPreemptible) in postScanRelocations()
1835 sym); in postScanRelocations()
1837 got->addConstant({R_ABS, target->tlsOffsetRel, offsetOff, 0, &sym}); in postScanRelocations()
1840 got->addEntry(sym); in postScanRelocations()
1842 sym.getGotOffset(), sym); in postScanRelocations()
1845 got->addEntry(sym); in postScanRelocations()
1847 {R_ABS, target->tlsOffsetRel, sym.getGotOffset(), 0, &sym}); in postScanRelocations()
1851 addTpOffsetGotEntry(sym); in postScanRelocations()
1866 for (Symbol *sym : symtab.getSymbols()) in postScanRelocations()
1867 fn(*sym); in postScanRelocations()
1872 for (Symbol *sym : file->getLocalSymbols()) in postScanRelocations()
1873 fn(*sym); in postScanRelocations()
2233 if (auto *d = dyn_cast<Defined>(rel.sym)) in getThunk()
2238 thunkVec = &thunkedSymbols[{rel.sym, keyAddend}]; in getThunk()
2259 if (Thunk *t = thunks.lookup(rel.sym)) { in normalizeExistingThunk()
2260 if (target->inBranchRange(rel.type, src, rel.sym->getVA(rel.addend))) in normalizeExistingThunk()
2262 rel.sym = &t->destination; in normalizeExistingThunk()
2264 if (rel.sym->isInPlt()) in normalizeExistingThunk()
2321 *rel.sym, rel.addend)) in createThunks()
2340 rel.sym = t->getThunkTargetSym(); in createThunks()
2372 if (rel.sym->type == llvm::ELF::STT_TLS && rel.expr == R_PLT_PC) { in hexagonNeedsTLSSymbol()
2381 Symbol *sym = symtab.find("__tls_get_addr"); in hexagonTLSSymbolUpdate() local
2382 if (!sym) in hexagonTLSSymbolUpdate()
2389 if (rel.sym->type == llvm::ELF::STT_TLS && rel.expr == R_PLT_PC) { in hexagonTLSSymbolUpdate()
2391 sym->allocateAux(); in hexagonTLSSymbolUpdate()
2393 *sym); in hexagonTLSSymbolUpdate()
2396 rel.sym = sym; in hexagonTLSSymbolUpdate()
2411 Symbol &sym = sec->file->getSymbol(r.getSymbol(config->isMips64EL)); in scanCrossRefs() local
2415 auto *dstOsec = sym.getOutputSection(); in scanCrossRefs()
2420 if (!sym.isSection()) in scanCrossRefs()
2421 toSymName = toString(sym); in scanCrossRefs()
2422 else if (auto *d = dyn_cast<Defined>(&sym)) in scanCrossRefs()