brintos

brintos / llvm-project-archived public Read only

0
0
Text · 25.0 KiB · a7db5a3 Raw
694 lines · cpp
1//===- SymbolTable.cpp ----------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "SymbolTable.h"10#include "ConcatOutputSection.h"11#include "Config.h"12#include "InputFiles.h"13#include "InputSection.h"14#include "Symbols.h"15#include "SyntheticSections.h"16#include "lld/Common/ErrorHandler.h"17#include "lld/Common/Memory.h"18#include "llvm/Demangle/Demangle.h"19 20using namespace llvm;21using namespace lld;22using namespace lld::macho;23 24Symbol *SymbolTable::find(CachedHashStringRef cachedName) {25  auto it = symMap.find(cachedName);26  if (it == symMap.end())27    return nullptr;28  return symVector[it->second];29}30 31std::pair<Symbol *, bool> SymbolTable::insert(StringRef name,32                                              const InputFile *file) {33  auto p = symMap.insert({CachedHashStringRef(name), (int)symVector.size()});34 35  Symbol *sym;36  if (!p.second) {37    // Name already present in the symbol table.38    sym = symVector[p.first->second];39  } else {40    // Name is a new symbol.41    sym = reinterpret_cast<Symbol *>(make<SymbolUnion>());42    symVector.push_back(sym);43  }44 45  sym->isUsedInRegularObj |= !file || isa<ObjFile>(file);46  return {sym, p.second};47}48 49namespace {50struct DuplicateSymbolDiag {51  // Pair containing source location and source file52  const std::pair<std::string, std::string> src1;53  const std::pair<std::string, std::string> src2;54  const Symbol *sym;55 56  DuplicateSymbolDiag(const std::pair<std::string, std::string> src1,57                      const std::pair<std::string, std::string> src2,58                      const Symbol *sym)59      : src1(src1), src2(src2), sym(sym) {}60};61SmallVector<DuplicateSymbolDiag> dupSymDiags;62} // namespace63 64// Move local symbols at \p fromOff in \p fromIsec into \p toIsec, unless that65// symbol is \p skip, in which case we just remove it.66static void transplantSymbolsAtOffset(InputSection *fromIsec,67                                      InputSection *toIsec, Defined *skip,68                                      uint64_t fromOff, uint64_t toOff) {69  // Ensure the symbols will still be in address order after our insertions.70  auto symSucceedsOff = [](uint64_t off, const Symbol *s) {71    return cast<Defined>(s)->value > off;72  };73  assert(std::is_partitioned(toIsec->symbols.begin(), toIsec->symbols.end(),74                             [symSucceedsOff, toOff](const Symbol *s) {75                               return !symSucceedsOff(toOff, s);76                             }) &&77         "Symbols in toIsec must be partitioned by toOff.");78  auto insertIt = llvm::upper_bound(toIsec->symbols, toOff, symSucceedsOff);79  llvm::erase_if(fromIsec->symbols, [&](Symbol *s) {80    auto *d = cast<Defined>(s);81    if (d == skip)82      return true;83    if (d->value != fromOff || d->isExternal())84      return false;85 86    // This repeated insertion will be quadratic unless insertIt is the end87    // iterator. However, that is typically the case for files that have88    // .subsections_via_symbols set.89    insertIt = toIsec->symbols.insert(insertIt, d);90    d->originalIsec = toIsec;91    d->value = toOff;92    // We don't want to have more than one unwindEntry at a given address, so93    // drop the redundant ones. We can safely drop the unwindEntries of the94    // symbols in fromIsec since we will be adding another unwindEntry as we95    // finish parsing toIsec's file. (We can assume that toIsec has its own96    // unwindEntry because of the ODR.)97    d->originalUnwindEntry = nullptr;98    return true;99  });100}101 102Defined *SymbolTable::addDefined(StringRef name, InputFile *file,103                                 InputSection *isec, uint64_t value,104                                 uint64_t size, bool isWeakDef,105                                 bool isPrivateExtern,106                                 bool isReferencedDynamically, bool noDeadStrip,107                                 bool isWeakDefCanBeHidden) {108  bool overridesWeakDef = false;109  auto [s, wasInserted] = insert(name, file);110 111  assert(!file || !isa<BitcodeFile>(file) || !isec);112 113  if (!wasInserted) {114    if (auto *defined = dyn_cast<Defined>(s)) {115      if (isWeakDef) {116        // See further comment in createDefined() in InputFiles.cpp117        if (defined->isWeakDef()) {118          defined->privateExtern &= isPrivateExtern;119          defined->weakDefCanBeHidden &= isWeakDefCanBeHidden;120          defined->referencedDynamically |= isReferencedDynamically;121          defined->noDeadStrip |= noDeadStrip;122        }123        if (auto concatIsec = dyn_cast_or_null<ConcatInputSection>(isec)) {124          concatIsec->wasCoalesced = true;125          // Any local symbols that alias the coalesced symbol should be moved126          // into the prevailing section. Note that we have sorted the symbols127          // in ObjFile::parseSymbols() such that extern weak symbols appear128          // last, so we don't need to worry about subsequent symbols being129          // added to an already-coalesced section.130          if (defined->isec())131            transplantSymbolsAtOffset(concatIsec, defined->isec(),132                                      /*skip=*/nullptr, value, defined->value);133        }134        return defined;135      }136 137      if (defined->isWeakDef()) {138        if (auto concatIsec =139                dyn_cast_or_null<ConcatInputSection>(defined->isec())) {140          concatIsec->wasCoalesced = true;141          if (isec)142            transplantSymbolsAtOffset(concatIsec, isec, defined, defined->value,143                                      value);144        }145      } else {146        std::string srcLoc1 = defined->getSourceLocation();147        std::string srcLoc2 = isec ? isec->getSourceLocation(value) : "";148        std::string srcFile1 = toString(defined->getFile());149        std::string srcFile2 = toString(file);150 151        dupSymDiags.push_back({make_pair(srcLoc1, srcFile1),152                               make_pair(srcLoc2, srcFile2), defined});153      }154 155    } else if (auto *dysym = dyn_cast<DylibSymbol>(s)) {156      overridesWeakDef = !isWeakDef && dysym->isWeakDef();157      dysym->unreference();158    } else if (auto *undef = dyn_cast<Undefined>(s)) {159      if (undef->wasBitcodeSymbol) {160        auto objFile = dyn_cast<ObjFile>(file);161        if (!objFile) {162          // The file must be a native object file, as opposed to potentially163          // being another bitcode file. A situation arises when some symbols164          // are defined thru `module asm` and thus they are not present in the165          // bitcode's symbol table. Consider bitcode modules `A`, `B`, and `C`.166          // LTO compiles only `A` and `C`, since there's no explicit symbol167          // reference to `B` other than a symbol from `A` via `module asm`.168          // After LTO is finished, the missing symbol now appears in the169          // resulting object file for `A`, which  prematurely resolves another170          // prevailing symbol with `B` that hasn't been compiled, instead of171          // the resulting object for `C`. Consequently, an incorrect172          // relocation is generated for the prevailing symbol.173          assert(isa<BitcodeFile>(file) && "Bitcode file is expected.");174          std::string message =175              "The pending prevailing symbol(" + name.str() +176              ") in the bitcode file(" + toString(undef->getFile()) +177              ") is overridden by a non-native object (from bitcode): " +178              toString(file);179          error(message);180        } else if (!objFile->builtFromBitcode) {181          // Ideally, this should be an object file compiled from a bitcode182          // file. However, this might not hold true if a LC linker option is183          // used. In case LTO internalizes a prevailing hidden weak symbol,184          // there's a situation where an unresolved prevailing symbol might be185          // linked with the corresponding one from a native library, which is186          // loaded later after LTO. Although this could potentially result in187          // an ODR violation, we choose to permit this scenario as a warning.188          std::string message = "The pending prevailing symbol(" + name.str() +189                                ") in the bitcode file(" +190                                toString(undef->getFile()) +191                                ") is overridden by a post-processed native "192                                "object (from native archive): " +193                                toString(file);194          warn(message);195        } else {196          // Preserve the original bitcode file name (instead of using the197          // object file name).198          file = undef->getFile();199        }200      }201    }202    // Defined symbols take priority over other types of symbols, so in case203    // of a name conflict, we fall through to the replaceSymbol() call below.204  }205 206  // With -flat_namespace, all extern symbols in dylibs are interposable.207  bool interposable = ((config->namespaceKind == NamespaceKind::flat &&208                        config->outputType != MachO::MH_EXECUTE) ||209                       config->interposable) &&210                      !isPrivateExtern;211  Defined *defined = replaceSymbol<Defined>(212      s, name, file, isec, value, size, isWeakDef, /*isExternal=*/true,213      isPrivateExtern, /*includeInSymtab=*/true, isReferencedDynamically,214      noDeadStrip, overridesWeakDef, isWeakDefCanBeHidden, interposable);215  return defined;216}217 218Defined *SymbolTable::aliasDefined(Defined *src, StringRef target,219                                   InputFile *newFile, bool makePrivateExtern) {220  bool isPrivateExtern = makePrivateExtern || src->privateExtern;221  return addDefined(target, newFile, src->isec(), src->value, src->size,222                    src->isWeakDef(), isPrivateExtern,223                    src->referencedDynamically, src->noDeadStrip,224                    src->weakDefCanBeHidden);225}226 227Symbol *SymbolTable::addUndefined(StringRef name, InputFile *file,228                                  bool isWeakRef) {229  auto [s, wasInserted] = insert(name, file);230 231  RefState refState = isWeakRef ? RefState::Weak : RefState::Strong;232 233  if (wasInserted)234    replaceSymbol<Undefined>(s, name, file, refState,235                             /*wasBitcodeSymbol=*/false);236  else if (auto *lazy = dyn_cast<LazyArchive>(s))237    lazy->fetchArchiveMember();238  else if (isa<LazyObject>(s))239    extract(*s->getFile(), s->getName());240  else if (auto *dynsym = dyn_cast<DylibSymbol>(s))241    dynsym->reference(refState);242  else if (auto *undefined = dyn_cast<Undefined>(s))243    undefined->refState = std::max(undefined->refState, refState);244  return s;245}246 247Symbol *SymbolTable::addCommon(StringRef name, InputFile *file, uint64_t size,248                               uint32_t align, bool isPrivateExtern) {249  auto [s, wasInserted] = insert(name, file);250 251  if (!wasInserted) {252    if (auto *common = dyn_cast<CommonSymbol>(s)) {253      if (size < common->size)254        return s;255    } else if (isa<Defined>(s)) {256      return s;257    }258    // Common symbols take priority over all non-Defined symbols, so in case of259    // a name conflict, we fall through to the replaceSymbol() call below.260  }261 262  replaceSymbol<CommonSymbol>(s, name, file, size, align, isPrivateExtern);263  return s;264}265 266Symbol *SymbolTable::addDylib(StringRef name, DylibFile *file, bool isWeakDef,267                              bool isTlv) {268  auto [s, wasInserted] = insert(name, file);269 270  RefState refState = RefState::Unreferenced;271  if (!wasInserted) {272    if (auto *defined = dyn_cast<Defined>(s)) {273      if (isWeakDef && !defined->isWeakDef())274        defined->overridesWeakDef = true;275    } else if (auto *undefined = dyn_cast<Undefined>(s)) {276      refState = undefined->refState;277    } else if (auto *dysym = dyn_cast<DylibSymbol>(s)) {278      refState = dysym->getRefState();279    }280  }281 282  bool isDynamicLookup = file == nullptr;283  if (wasInserted || isa<Undefined>(s) ||284      (isa<DylibSymbol>(s) &&285       ((!isWeakDef && s->isWeakDef()) ||286        (!isDynamicLookup && cast<DylibSymbol>(s)->isDynamicLookup())))) {287    if (auto *dynsym = dyn_cast<DylibSymbol>(s))288      dynsym->unreference();289    replaceSymbol<DylibSymbol>(s, file, name, isWeakDef, refState, isTlv);290  }291 292  return s;293}294 295Symbol *SymbolTable::addDynamicLookup(StringRef name) {296  return addDylib(name, /*file=*/nullptr, /*isWeakDef=*/false, /*isTlv=*/false);297}298 299Symbol *SymbolTable::addLazyArchive(StringRef name, ArchiveFile *file,300                                    const object::Archive::Symbol &sym) {301  auto [s, wasInserted] = insert(name, file);302 303  if (wasInserted) {304    replaceSymbol<LazyArchive>(s, file, sym);305  } else if (isa<Undefined>(s)) {306    file->fetch(sym);307  } else if (auto *dysym = dyn_cast<DylibSymbol>(s)) {308    if (dysym->isWeakDef()) {309      if (dysym->getRefState() != RefState::Unreferenced)310        file->fetch(sym);311      else312        replaceSymbol<LazyArchive>(s, file, sym);313    }314  }315  return s;316}317 318Symbol *SymbolTable::addLazyObject(StringRef name, InputFile &file) {319  auto [s, wasInserted] = insert(name, &file);320 321  if (wasInserted) {322    replaceSymbol<LazyObject>(s, file, name);323  } else if (isa<Undefined>(s)) {324    extract(file, name);325  } else if (auto *dysym = dyn_cast<DylibSymbol>(s)) {326    if (dysym->isWeakDef()) {327      if (dysym->getRefState() != RefState::Unreferenced)328        extract(file, name);329      else330        replaceSymbol<LazyObject>(s, file, name);331    }332  }333  return s;334}335 336Defined *SymbolTable::addSynthetic(StringRef name, InputSection *isec,337                                   uint64_t value, bool isPrivateExtern,338                                   bool includeInSymtab,339                                   bool referencedDynamically) {340  assert(!isec || !isec->getFile()); // See makeSyntheticInputSection().341  Defined *s = addDefined(name, /*file=*/nullptr, isec, value, /*size=*/0,342                          /*isWeakDef=*/false, isPrivateExtern,343                          referencedDynamically, /*noDeadStrip=*/false,344                          /*isWeakDefCanBeHidden=*/false);345  s->includeInSymtab = includeInSymtab;346  return s;347}348 349enum class Boundary {350  Start,351  End,352};353 354static Defined *createBoundarySymbol(const Undefined &sym) {355  return symtab->addSynthetic(356      sym.getName(), /*isec=*/nullptr, /*value=*/-1, /*isPrivateExtern=*/true,357      /*includeInSymtab=*/false, /*referencedDynamically=*/false);358}359 360static void handleSectionBoundarySymbol(const Undefined &sym, StringRef segSect,361                                        Boundary which) {362  auto [segName, sectName] = segSect.split('$');363 364  // Attach the symbol to any InputSection that will end up in the right365  // OutputSection -- it doesn't matter which one we pick.366  // Don't bother looking through inputSections for a matching367  // ConcatInputSection -- we need to create ConcatInputSection for368  // non-existing sections anyways, and that codepath works even if we should369  // already have a ConcatInputSection with the right name.370 371  OutputSection *osec = nullptr;372  // This looks for __TEXT,__cstring etc.373  for (SyntheticSection *ssec : syntheticSections)374    if (ssec->segname == segName && ssec->name == sectName) {375      osec = ssec->isec->parent;376      break;377    }378 379  if (!osec) {380    ConcatInputSection *isec = makeSyntheticInputSection(segName, sectName);381 382    // This runs after markLive() and is only called for Undefineds that are383    // live. Marking the isec live ensures an OutputSection is created that the384    // start/end symbol can refer to.385    assert(sym.isLive());386    assert(isec->live);387 388    // This runs after gatherInputSections(), so need to explicitly set parent389    // and add to inputSections.390    osec = isec->parent = ConcatOutputSection::getOrCreateForInput(isec);391    inputSections.push_back(isec);392  }393 394  if (which == Boundary::Start)395    osec->sectionStartSymbols.push_back(createBoundarySymbol(sym));396  else397    osec->sectionEndSymbols.push_back(createBoundarySymbol(sym));398}399 400static void handleSegmentBoundarySymbol(const Undefined &sym, StringRef segName,401                                        Boundary which) {402  OutputSegment *seg = getOrCreateOutputSegment(segName);403  if (which == Boundary::Start)404    seg->segmentStartSymbols.push_back(createBoundarySymbol(sym));405  else406    seg->segmentEndSymbols.push_back(createBoundarySymbol(sym));407}408 409// Try to find a definition for an undefined symbol.410// Returns true if a definition was found and no diagnostics are needed.411static bool recoverFromUndefinedSymbol(const Undefined &sym) {412  // Handle start/end symbols.413  StringRef name = sym.getName();414  if (name.consume_front("section$start$")) {415    handleSectionBoundarySymbol(sym, name, Boundary::Start);416    return true;417  }418  if (name.consume_front("section$end$")) {419    handleSectionBoundarySymbol(sym, name, Boundary::End);420    return true;421  }422  if (name.consume_front("segment$start$")) {423    handleSegmentBoundarySymbol(sym, name, Boundary::Start);424    return true;425  }426  if (name.consume_front("segment$end$")) {427    handleSegmentBoundarySymbol(sym, name, Boundary::End);428    return true;429  }430 431  // Leave dtrace symbols, since we will handle them when we do the relocation432  if (name.starts_with("___dtrace_"))433    return true;434 435  // Handle -U.436  if (config->explicitDynamicLookups.count(sym.getName())) {437    symtab->addDynamicLookup(sym.getName());438    return true;439  }440 441  // Handle -undefined.442  if (config->undefinedSymbolTreatment ==443          UndefinedSymbolTreatment::dynamic_lookup ||444      config->undefinedSymbolTreatment == UndefinedSymbolTreatment::suppress) {445    symtab->addDynamicLookup(sym.getName());446    return true;447  }448 449  // We do not return true here, as we still need to print diagnostics.450  if (config->undefinedSymbolTreatment == UndefinedSymbolTreatment::warning)451    symtab->addDynamicLookup(sym.getName());452 453  return false;454}455 456namespace {457struct UndefinedDiag {458  struct SectionAndOffset {459    const InputSection *isec;460    uint64_t offset;461  };462 463  std::vector<SectionAndOffset> codeReferences;464  std::vector<std::string> otherReferences;465};466 467MapVector<const Undefined *, UndefinedDiag> undefs;468} // namespace469 470void macho::reportPendingDuplicateSymbols() {471  for (const auto &duplicate : dupSymDiags) {472    if (!config->deadStripDuplicates || duplicate.sym->isLive()) {473      std::string message =474          "duplicate symbol: " + toString(*duplicate.sym) + "\n>>> defined in ";475      if (!duplicate.src1.first.empty())476        message += duplicate.src1.first + "\n>>>            ";477      message += duplicate.src1.second + "\n>>> defined in ";478      if (!duplicate.src2.first.empty())479        message += duplicate.src2.first + "\n>>>            ";480      error(message + duplicate.src2.second);481    }482  }483}484 485// Check whether the definition name def is a mangled function name that matches486// the reference name ref.487static bool canSuggestExternCForCXX(StringRef ref, StringRef def) {488  llvm::ItaniumPartialDemangler d;489  std::string name = def.str();490  if (d.partialDemangle(name.c_str()))491    return false;492  char *buf = d.getFunctionName(nullptr, nullptr);493  if (!buf)494    return false;495  bool ret = ref == buf;496  free(buf);497  return ret;498}499 500// Suggest an alternative spelling of an "undefined symbol" diagnostic. Returns501// the suggested symbol, which is either in the symbol table, or in the same502// file of sym.503static const Symbol *getAlternativeSpelling(const Undefined &sym,504                                            std::string &preHint,505                                            std::string &postHint) {506  DenseMap<StringRef, const Symbol *> map;507  if (sym.getFile() && sym.getFile()->kind() == InputFile::ObjKind) {508    // Build a map of local defined symbols.509    for (const Symbol *s : sym.getFile()->symbols)510      if (auto *defined = dyn_cast_or_null<Defined>(s))511        if (!defined->isExternal())512          map.try_emplace(s->getName(), s);513  }514 515  auto suggest = [&](StringRef newName) -> const Symbol * {516    // If defined locally.517    if (const Symbol *s = map.lookup(newName))518      return s;519 520    // If in the symbol table and not undefined.521    if (const Symbol *s = symtab->find(newName))522      if (!isa<Undefined>(s))523        return s;524 525    return nullptr;526  };527 528  // This loop enumerates all strings of Levenshtein distance 1 as typo529  // correction candidates and suggests the one that exists as a non-undefined530  // symbol.531  StringRef name = sym.getName();532  for (size_t i = 0, e = name.size(); i != e + 1; ++i) {533    // Insert a character before name[i].534    std::string newName = (name.substr(0, i) + "0" + name.substr(i)).str();535    for (char c = '0'; c <= 'z'; ++c) {536      newName[i] = c;537      if (const Symbol *s = suggest(newName))538        return s;539    }540    if (i == e)541      break;542 543    // Substitute name[i].544    newName = std::string(name);545    for (char c = '0'; c <= 'z'; ++c) {546      newName[i] = c;547      if (const Symbol *s = suggest(newName))548        return s;549    }550 551    // Transpose name[i] and name[i+1]. This is of edit distance 2 but it is552    // common.553    if (i + 1 < e) {554      newName[i] = name[i + 1];555      newName[i + 1] = name[i];556      if (const Symbol *s = suggest(newName))557        return s;558    }559 560    // Delete name[i].561    newName = (name.substr(0, i) + name.substr(i + 1)).str();562    if (const Symbol *s = suggest(newName))563      return s;564  }565 566  // Case mismatch, e.g. Foo vs FOO.567  for (auto &it : map)568    if (name.equals_insensitive(it.first))569      return it.second;570  for (Symbol *sym : symtab->getSymbols())571    if (!isa<Undefined>(sym) && name.equals_insensitive(sym->getName()))572      return sym;573 574  // The reference may be a mangled name while the definition is not. Suggest a575  // missing extern "C".576  if (name.starts_with("__Z")) {577    std::string buf = name.str();578    llvm::ItaniumPartialDemangler d;579    if (!d.partialDemangle(buf.c_str()))580      if (char *buf = d.getFunctionName(nullptr, nullptr)) {581        const Symbol *s = suggest((Twine("_") + buf).str());582        free(buf);583        if (s) {584          preHint = ": extern \"C\" ";585          return s;586        }587      }588  } else {589    StringRef nameWithoutUnderscore = name;590    nameWithoutUnderscore.consume_front("_");591    const Symbol *s = nullptr;592    for (auto &it : map)593      if (canSuggestExternCForCXX(nameWithoutUnderscore, it.first)) {594        s = it.second;595        break;596      }597    if (!s)598      for (Symbol *sym : symtab->getSymbols())599        if (canSuggestExternCForCXX(nameWithoutUnderscore, sym->getName())) {600          s = sym;601          break;602        }603    if (s) {604      preHint = " to declare ";605      postHint = " as extern \"C\"?";606      return s;607    }608  }609 610  return nullptr;611}612 613static void reportUndefinedSymbol(const Undefined &sym,614                                  const UndefinedDiag &locations,615                                  bool correctSpelling) {616  std::string message = "undefined symbol";617  if (config->archMultiple)618    message += (" for arch " + getArchitectureName(config->arch())).str();619  message += ": " + toString(sym);620 621  const size_t maxUndefinedReferences = 3;622  size_t i = 0;623  for (const std::string &loc : locations.otherReferences) {624    if (i >= maxUndefinedReferences)625      break;626    message += "\n>>> referenced by " + loc;627    ++i;628  }629 630  for (const UndefinedDiag::SectionAndOffset &loc : locations.codeReferences) {631    if (i >= maxUndefinedReferences)632      break;633    message += "\n>>> referenced by ";634    std::string src = loc.isec->getSourceLocation(loc.offset);635    if (!src.empty())636      message += src + "\n>>>               ";637    message += loc.isec->getLocation(loc.offset);638    ++i;639  }640 641  size_t totalReferences =642      locations.otherReferences.size() + locations.codeReferences.size();643  if (totalReferences > i)644    message +=645        ("\n>>> referenced " + Twine(totalReferences - i) + " more times")646            .str();647 648  if (correctSpelling) {649    std::string preHint = ": ", postHint;650    if (const Symbol *corrected =651            getAlternativeSpelling(sym, preHint, postHint)) {652      message +=653          "\n>>> did you mean" + preHint + toString(*corrected) + postHint;654      if (corrected->getFile())655        message += "\n>>> defined in: " + toString(corrected->getFile());656    }657  }658 659  if (config->undefinedSymbolTreatment == UndefinedSymbolTreatment::error)660    error(message);661  else if (config->undefinedSymbolTreatment ==662           UndefinedSymbolTreatment::warning)663    warn(message);664  else665    assert(false && "diagnostics make sense for -undefined error|warning only");666}667 668void macho::reportPendingUndefinedSymbols() {669  // Enable spell corrector for the first 2 diagnostics.670  for (const auto &[i, undef] : llvm::enumerate(undefs))671    reportUndefinedSymbol(*undef.first, undef.second, i < 2);672 673  // This function is called multiple times during execution. Clear the printed674  // diagnostics to avoid printing the same things again the next time.675  undefs.clear();676}677 678void macho::treatUndefinedSymbol(const Undefined &sym, StringRef source) {679  if (recoverFromUndefinedSymbol(sym))680    return;681 682  undefs[&sym].otherReferences.push_back(source.str());683}684 685void macho::treatUndefinedSymbol(const Undefined &sym, const InputSection *isec,686                                 uint64_t offset) {687  if (recoverFromUndefinedSymbol(sym))688    return;689 690  undefs[&sym].codeReferences.push_back({isec, offset});691}692 693std::unique_ptr<SymbolTable> macho::symtab;694