[ELF] Rename fetch to extract

The canonical term is "extract" (GNU ld documentation, Solaris's `-z *extract`
options). Avoid inventing a term and match --why-extract. (ld64 prefers "load"
but the word is overloaded too much)

Mostly MFC, except for --help messages and the header row in
--print-archive-stats output.

GitOrigin-RevId: 09401dfcf1dbec9d55ac62596d7520ba3a10eabb
diff --git a/ELF/Driver.cpp b/ELF/Driver.cpp
index 8c66887..5541a39 100644
--- a/ELF/Driver.cpp
+++ b/ELF/Driver.cpp
@@ -1691,7 +1691,7 @@
 
   if (!sym->isLazy())
     return;
-  sym->fetch();
+  sym->extract();
   if (!config->whyExtract.empty())
     whyExtract.emplace_back(option, sym->file, *sym);
 }
@@ -1706,14 +1706,12 @@
     return;
   }
 
+  // Calling sym->extract() in the loop is not safe because it may add new
+  // symbols to the symbol table, invalidating the current iterator.
   std::vector<Symbol *> syms;
-  for (Symbol *sym : symtab->symbols()) {
-    // Calling Sym->fetch() from here is not safe because it may
-    // add new symbols to the symbol table, invalidating the
-    // current iterator. So we just keep a note.
+  for (Symbol *sym : symtab->symbols())
     if (pat->match(sym->getName()))
       syms.push_back(sym);
-  }
 
   for (Symbol *sym : syms)
     handleUndefined(sym, "--undefined-glob");
@@ -1731,7 +1729,7 @@
     mb = cast<LazyArchive>(sym)->getMemberBuffer();
 
   if (isBitcode(mb))
-    sym->fetch();
+    sym->extract();
 }
 
 // Handle --dependency-file=<path>. If that option is given, lld creates a
@@ -2207,7 +2205,7 @@
     symtab->insert(arg->getValue())->traced = true;
 
   // Handle -u/--undefined before input files. If both a.a and b.so define foo,
-  // -u foo a.a b.so will fetch a.a.
+  // -u foo a.a b.so will extract a.a.
   for (StringRef name : config->undefined)
     addUnusedUndefined(name)->referenced = true;
 
diff --git a/ELF/InputFiles.cpp b/ELF/InputFiles.cpp
index 9399bb4..b002041 100644
--- a/ELF/InputFiles.cpp
+++ b/ELF/InputFiles.cpp
@@ -1147,15 +1147,15 @@
     if (sec == &InputSection::discarded) {
       Undefined und{this, name, binding, stOther, type, secIdx};
       Symbol *sym = this->symbols[i];
-      // !ArchiveFile::parsed or LazyObjFile::fetched means that the file
+      // !ArchiveFile::parsed or LazyObjFile::extracted means that the file
       // containing this object has not finished processing, i.e. this symbol is
-      // a result of a lazy symbol fetch. We should demote the lazy symbol to an
-      // Undefined so that any relocations outside of the group to it will
+      // a result of a lazy symbol extract. We should demote the lazy symbol to
+      // an Undefined so that any relocations outside of the group to it will
       // trigger a discarded section error.
       if ((sym->symbolKind == Symbol::LazyArchiveKind &&
            !cast<ArchiveFile>(sym->file)->parsed) ||
           (sym->symbolKind == Symbol::LazyObjectKind &&
-           cast<LazyObjFile>(sym->file)->fetched))
+           cast<LazyObjFile>(sym->file)->extracted))
         sym->replace(und);
       else
         sym->resolve(und);
@@ -1174,7 +1174,7 @@
   }
 
   // Undefined symbols (excluding those defined relative to non-prevailing
-  // sections) can trigger recursive fetch. Process defined symbols first so
+  // sections) can trigger recursive extract. Process defined symbols first so
   // that the relative order between a defined symbol and an undefined symbol
   // does not change the symbol resolution behavior. In addition, a set of
   // interconnected symbols will all be resolved to the same file, instead of
@@ -1202,7 +1202,7 @@
 }
 
 // Returns a buffer pointing to a member file containing a given symbol.
-void ArchiveFile::fetch(const Archive::Symbol &sym) {
+void ArchiveFile::extract(const Archive::Symbol &sym) {
   Archive::Child c =
       CHECK(sym.getMember(), toString(this) +
                                  ": could not get the member for symbol " +
@@ -1291,7 +1291,7 @@
   }
 }
 
-bool ArchiveFile::shouldFetchForCommon(const Archive::Symbol &sym) {
+bool ArchiveFile::shouldExtractForCommon(const Archive::Symbol &sym) {
   Archive::Child c =
       CHECK(sym.getMember(), toString(this) +
                                  ": could not get the member for symbol " +
@@ -1779,10 +1779,10 @@
   }
 }
 
-void LazyObjFile::fetch() {
-  if (fetched)
+void LazyObjFile::extract() {
+  if (extracted)
     return;
-  fetched = true;
+  extracted = true;
 
   InputFile *file = createObjectFile(mb, archiveName, offsetInArchive);
   file->groupId = groupId;
@@ -1835,7 +1835,7 @@
 
     // Replace existing symbols with LazyObject symbols.
     //
-    // resolve() may trigger this->fetch() if an existing symbol is an
+    // resolve() may trigger this->extract() if an existing symbol is an
     // undefined symbol. If that happens, this LazyObjFile has served
     // its purpose, and we can exit from the loop early.
     for (Symbol *sym : this->symbols) {
@@ -1843,16 +1843,16 @@
         continue;
       sym->resolve(LazyObject{*this, sym->getName()});
 
-      // If fetched, stop iterating because this->symbols has been transferred
+      // If extracted, stop iterating because this->symbols has been transferred
       // to the instantiated ObjFile.
-      if (fetched)
+      if (extracted)
         return;
     }
     return;
   }
 }
 
-bool LazyObjFile::shouldFetchForCommon(const StringRef &name) {
+bool LazyObjFile::shouldExtractForCommon(const StringRef &name) {
   if (isBitcode(mb))
     return isBitcodeNonCommonDef(mb, name, archiveName);
 
diff --git a/ELF/InputFiles.h b/ELF/InputFiles.h
index fb4d46b..f3a4538 100644
--- a/ELF/InputFiles.h
+++ b/ELF/InputFiles.h
@@ -306,13 +306,13 @@
   static bool classof(const InputFile *f) { return f->kind() == LazyObjKind; }
 
   template <class ELFT> void parse();
-  void fetch();
+  void extract();
 
-  // Check if a non-common symbol should be fetched to override a common
+  // Check if a non-common symbol should be extracted to override a common
   // definition.
-  bool shouldFetchForCommon(const StringRef &name);
+  bool shouldExtractForCommon(const StringRef &name);
 
-  bool fetched = false;
+  bool extracted = false;
 
 private:
   uint64_t offsetInArchive;
@@ -329,14 +329,14 @@
   // returns it. If the same file was instantiated before, this
   // function does nothing (so we don't instantiate the same file
   // more than once.)
-  void fetch(const Archive::Symbol &sym);
+  void extract(const Archive::Symbol &sym);
 
-  // Check if a non-common symbol should be fetched to override a common
+  // Check if a non-common symbol should be extracted to override a common
   // definition.
-  bool shouldFetchForCommon(const Archive::Symbol &sym);
+  bool shouldExtractForCommon(const Archive::Symbol &sym);
 
   size_t getMemberCount() const;
-  size_t getFetchedMemberCount() const { return seen.size(); }
+  size_t getExtractedMemberCount() const { return seen.size(); }
 
   bool parsed = false;
 
diff --git a/ELF/LTO.cpp b/ELF/LTO.cpp
index a42d216..46dc77a 100644
--- a/ELF/LTO.cpp
+++ b/ELF/LTO.cpp
@@ -279,7 +279,7 @@
 // distributed build system that depends on that behavior.
 static void thinLTOCreateEmptyIndexFiles() {
   for (LazyObjFile *f : lazyObjFiles) {
-    if (f->fetched || !isBitcode(f->mb))
+    if (f->extracted || !isBitcode(f->mb))
       continue;
     std::string path = replaceThinLTOSuffix(getThinLTOOutputFile(f->getName()));
     std::unique_ptr<raw_fd_ostream> os = openFile(path + ".thinlto.bc");
diff --git a/ELF/MapFile.cpp b/ELF/MapFile.cpp
index 56c215d..325c3b3 100644
--- a/ELF/MapFile.cpp
+++ b/ELF/MapFile.cpp
@@ -294,8 +294,8 @@
     return;
   }
 
-  os << "members\tfetched\tarchive\n";
+  os << "members\textracted\tarchive\n";
   for (const ArchiveFile *f : archiveFiles)
-    os << f->getMemberCount() << '\t' << f->getFetchedMemberCount() << '\t'
+    os << f->getMemberCount() << '\t' << f->getExtractedMemberCount() << '\t'
        << f->getName() << '\n';
 }
diff --git a/ELF/Options.td b/ELF/Options.td
index ce82eb8..7de7a37 100644
--- a/ELF/Options.td
+++ b/ELF/Options.td
@@ -338,7 +338,7 @@
 
 def print_archive_stats: J<"print-archive-stats=">,
   HelpText<"Write archive usage statistics to the specified file. "
-           "Print the numbers of members and fetched members for each archive">;
+           "Print the numbers of members and extracted members for each archive">;
 
 defm print_symbol_order: Eq<"print-symbol-order",
   "Print a symbol order specified by --call-graph-ordering-file into the specified file">;
@@ -468,8 +468,8 @@
 defm version_script: Eq<"version-script", "Read a version script">;
 
 defm warn_backrefs: BB<"warn-backrefs",
-    "Warn about backward symbol references to fetch archive members",
-    "Do not warn about backward symbol references to fetch archive members (default)">;
+    "Warn about backward symbol references to extract archive members",
+    "Do not warn about backward symbol references to extract archive members (default)">;
 
 defm warn_backrefs_exclude
     : EEq<"warn-backrefs-exclude",
diff --git a/ELF/SymbolTable.cpp b/ELF/SymbolTable.cpp
index c309957..e615fb7 100644
--- a/ELF/SymbolTable.cpp
+++ b/ELF/SymbolTable.cpp
@@ -113,7 +113,7 @@
 
 // A version script/dynamic list is only meaningful for a Defined symbol.
 // A CommonSymbol will be converted to a Defined in replaceCommonSymbols().
-// A lazy symbol may be made Defined if an LTO libcall fetches it.
+// A lazy symbol may be made Defined if an LTO libcall extracts it.
 static bool canBeVersioned(const Symbol &sym) {
   return sym.isDefined() || sym.isCommon() || sym.isLazy();
 }
diff --git a/ELF/Symbols.cpp b/ELF/Symbols.cpp
index 5f95a1b..da3ade1 100644
--- a/ELF/Symbols.cpp
+++ b/ELF/Symbols.cpp
@@ -256,18 +256,18 @@
           verstr);
 }
 
-void Symbol::fetch() const {
+void Symbol::extract() const {
   if (auto *sym = dyn_cast<LazyArchive>(this)) {
-    cast<ArchiveFile>(sym->file)->fetch(sym->sym);
+    cast<ArchiveFile>(sym->file)->extract(sym->sym);
     return;
   }
 
   if (auto *sym = dyn_cast<LazyObject>(this)) {
-    dyn_cast<LazyObjFile>(sym->file)->fetch();
+    dyn_cast<LazyObjFile>(sym->file)->extract();
     return;
   }
 
-  llvm_unreachable("Symbol::fetch() is called on a non-lazy symbol");
+  llvm_unreachable("Symbol::extract() is called on a non-lazy symbol");
 }
 
 MemoryBufferRef LazyArchive::getMemberBuffer() {
@@ -478,8 +478,8 @@
     printTraceSymbol(&other);
 
   if (isLazy()) {
-    // An undefined weak will not fetch archive members. See comment on Lazy in
-    // Symbols.h for the details.
+    // An undefined weak will not extract archive members. See comment on Lazy
+    // in Symbols.h for the details.
     if (other.binding == STB_WEAK) {
       binding = STB_WEAK;
       type = other.type;
@@ -489,9 +489,9 @@
     // Do extra check for --warn-backrefs.
     //
     // --warn-backrefs is an option to prevent an undefined reference from
-    // fetching an archive member written earlier in the command line. It can be
-    // used to keep compatibility with GNU linkers to some degree.
-    // I'll explain the feature and why you may find it useful in this comment.
+    // extracting an archive member written earlier in the command line. It can
+    // be used to keep compatibility with GNU linkers to some degree. I'll
+    // explain the feature and why you may find it useful in this comment.
     //
     // lld's symbol resolution semantics is more relaxed than traditional Unix
     // linkers. For example,
@@ -538,7 +538,7 @@
     // group assignment rule simulates the traditional linker's semantics.
     bool backref = config->warnBackrefs && other.file &&
                    file->groupId < other.file->groupId;
-    fetch();
+    extract();
 
     if (!config->whyExtract.empty())
       recordWhyExtract(other.file, *file, *this);
@@ -712,23 +712,23 @@
 static void replaceCommon(Symbol &oldSym, const LazyT &newSym) {
   backwardReferences.erase(&oldSym);
   oldSym.replace(newSym);
-  newSym.fetch();
+  newSym.extract();
 }
 
 template <class LazyT> void Symbol::resolveLazy(const LazyT &other) {
   // For common objects, we want to look for global or weak definitions that
-  // should be fetched as the canonical definition instead.
+  // should be extracted as the canonical definition instead.
   if (isCommon() && elf::config->fortranCommon) {
     if (auto *laSym = dyn_cast<LazyArchive>(&other)) {
       ArchiveFile *archive = cast<ArchiveFile>(laSym->file);
       const Archive::Symbol &archiveSym = laSym->sym;
-      if (archive->shouldFetchForCommon(archiveSym)) {
+      if (archive->shouldExtractForCommon(archiveSym)) {
         replaceCommon(*this, other);
         return;
       }
     } else if (auto *loSym = dyn_cast<LazyObject>(&other)) {
       LazyObjFile *obj = cast<LazyObjFile>(loSym->file);
-      if (obj->shouldFetchForCommon(loSym->getName())) {
+      if (obj->shouldExtractForCommon(loSym->getName())) {
         replaceCommon(*this, other);
         return;
       }
@@ -742,7 +742,7 @@
     return;
   }
 
-  // An undefined weak will not fetch archive members. See comment on Lazy in
+  // An undefined weak will not extract archive members. See comment on Lazy in
   // Symbols.h for the details.
   if (isWeak()) {
     uint8_t ty = type;
@@ -753,7 +753,7 @@
   }
 
   const InputFile *oldFile = file;
-  other.fetch();
+  other.extract();
   if (!config->whyExtract.empty())
     recordWhyExtract(oldFile, *file, *this);
 }
diff --git a/ELF/Symbols.h b/ELF/Symbols.h
index 816d615..cc48ef0 100644
--- a/ELF/Symbols.h
+++ b/ELF/Symbols.h
@@ -93,7 +93,7 @@
   // Symbol binding. This is not overwritten by replace() to track
   // changes during resolution. In particular:
   //  - An undefined weak is still weak when it resolves to a shared library.
-  //  - An undefined weak will not fetch archive members, but we have to
+  //  - An undefined weak will not extract archive members, but we have to
   //    remember it is weak.
   uint8_t binding;
 
@@ -216,10 +216,10 @@
   void mergeProperties(const Symbol &other);
   void resolve(const Symbol &other);
 
-  // If this is a lazy symbol, fetch an input file and add the symbol
+  // If this is a lazy symbol, extract an input file and add the symbol
   // in the file to the symbol table. Calling this function on
   // non-lazy object causes a runtime error.
-  void fetch() const;
+  void extract() const;
 
   static bool isExportDynamic(Kind k, uint8_t visibility) {
     if (k == SharedKind)
diff --git a/ELF/SyntheticSections.cpp b/ELF/SyntheticSections.cpp
index 8eb3703..4078f7e 100644
--- a/ELF/SyntheticSections.cpp
+++ b/ELF/SyntheticSections.cpp
@@ -3116,7 +3116,7 @@
 void VersionTableSection::writeTo(uint8_t *buf) {
   buf += 2;
   for (const SymbolTableEntry &s : getPartition().dynSymTab->getSymbols()) {
-    // For an unfetched lazy symbol (undefined weak), it must have been
+    // For an unextracted lazy symbol (undefined weak), it must have been
     // converted to Undefined and have VER_NDX_GLOBAL version here.
     assert(!s.sym->isLazy());
     write16(buf, s.sym->versionId);
diff --git a/test/ELF/print-archive-stats.s b/test/ELF/print-archive-stats.s
index 3f5c482..7f24cc6 100644
--- a/test/ELF/print-archive-stats.s
+++ b/test/ELF/print-archive-stats.s
@@ -12,7 +12,7 @@
 # RUN: FileCheck --input-file=%t.txt -DT=%t %s --match-full-lines --strict-whitespace
 
 ## Fetches 0 member from %tweak.a and 2 members from %t1.a
-#      CHECK:members	fetched	archive
+#      CHECK:members	extracted	archive
 # CHECK-NEXT:1	0	[[T]]weak.a
 # CHECK-NEXT:3	2	[[T]]1.a
 
@@ -22,7 +22,7 @@
 ## The second %t1.a has 0 fetched member.
 # RUN: ld.lld %t.o %tweak.a %t1.a %t1.a --print-archive-stats=- -o /dev/null | \
 # RUN:   FileCheck --check-prefix=CHECK2 %s
-# CHECK2:      members	fetched	archive
+# CHECK2:      members	extracted	archive
 # CHECK2-NEXT: 1	0	{{.*}}weak.a
 # CHECK2-NEXT: 3	2	{{.*}}1.a
 # CHECK2-NEXT: 3	0	{{.*}}1.a