[ELF] Rename fetch to extract
authorFangrui Song <i@maskray.me>
Fri, 26 Nov 2021 18:58:50 +0000 (10:58 -0800)
committerFangrui Song <i@maskray.me>
Fri, 26 Nov 2021 18:58:50 +0000 (10:58 -0800)
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.

lld/ELF/Driver.cpp
lld/ELF/InputFiles.cpp
lld/ELF/InputFiles.h
lld/ELF/LTO.cpp
lld/ELF/MapFile.cpp
lld/ELF/Options.td
lld/ELF/SymbolTable.cpp
lld/ELF/Symbols.cpp
lld/ELF/Symbols.h
lld/ELF/SyntheticSections.cpp
lld/test/ELF/print-archive-stats.s

index 8c668879b54e5d0cba5e1273ff626fac92efd156..5541a397c55337b022acfd98663a1b684d7c6756 100644 (file)
@@ -1691,7 +1691,7 @@ static void handleUndefined(Symbol *sym, const char *option) {
 
   if (!sym->isLazy())
     return;
-  sym->fetch();
+  sym->extract();
   if (!config->whyExtract.empty())
     whyExtract.emplace_back(option, sym->file, *sym);
 }
@@ -1706,14 +1706,12 @@ static void handleUndefinedGlob(StringRef arg) {
     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 @@ static void handleLibcall(StringRef name) {
     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 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
     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;
 
index 9399bb4484f03032f39136fc39cf9a1486a6dff2..b00204183db7db3692af7d5c90f62a44d5ddf983 100644 (file)
@@ -1147,15 +1147,15 @@ template <class ELFT> void ObjFile<ELFT>::initializeSymbols() {
     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 @@ template <class ELFT> void ObjFile<ELFT>::initializeSymbols() {
   }
 
   // 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 @@ void ArchiveFile::parse() {
 }
 
 // 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 @@ static bool isNonCommonDef(MemoryBufferRef mb, StringRef symName,
   }
 }
 
-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 @@ InputFile *elf::createObjectFile(MemoryBufferRef mb, StringRef archiveName,
   }
 }
 
-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 @@ template <class ELFT> void LazyObjFile::parse() {
 
     // 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 @@ template <class ELFT> void LazyObjFile::parse() {
         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);
 
index fb4d46b43f35e3a0093da17335c53f7a83f7bddc..f3a45385af2e3a0a33575e9aac173e6284fc3bcb 100644 (file)
@@ -306,13 +306,13 @@ public:
   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 @@ public:
   // 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;
 
index a42d216e4e778609bebc5e8780b9af800077d232..46dc77a6789c571426a77368cbb2e099a7478932 100644 (file)
@@ -279,7 +279,7 @@ void BitcodeCompiler::add(BitcodeFile &f) {
 // 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");
index 56c215d505047610a4f4960f06283cce05287c25..325c3b3226630cafb57a4c6413616eb971711e62 100644 (file)
@@ -294,8 +294,8 @@ void elf::writeArchiveStats() {
     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';
 }
index ce82eb8d275450c8da19e37867f11cc59b594457..7de7a37b30f74536ef0da6e810b9387fca3b825f 100644 (file)
@@ -338,7 +338,7 @@ defm print_icf_sections: B<"print-icf-sections",
 
 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 @@ def power10_stubs_eq:
 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",
index c309957ee5bacfc2c612acbdb5dc38c93acc3ddf..e615fb70a40f60856059fae1bf27f71ac3fb2a76 100644 (file)
@@ -113,7 +113,7 @@ Symbol *SymbolTable::find(StringRef name) {
 
 // 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();
 }
index 5f95a1b3c7acc8166efa7c6868083fd6a842f51a..da3ade1b9dad233e42aeef313c17dc99931631a7 100644 (file)
@@ -256,18 +256,18 @@ void Symbol::parseSymbolVersion() {
           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 @@ void Symbol::resolveUndefined(const Undefined &other) {
     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 @@ void Symbol::resolveUndefined(const Undefined &other) {
     // 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 @@ void Symbol::resolveUndefined(const Undefined &other) {
     // 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 @@ template <class LazyT>
 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 @@ template <class LazyT> void Symbol::resolveLazy(const LazyT &other) {
     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 @@ template <class LazyT> void Symbol::resolveLazy(const LazyT &other) {
   }
 
   const InputFile *oldFile = file;
-  other.fetch();
+  other.extract();
   if (!config->whyExtract.empty())
     recordWhyExtract(oldFile, *file, *this);
 }
index 816d61563021ebe9e85a9c498e54bafb6b7a0201..cc48ef0ab3b7ac67d2874cf20197bdf4e7f58e9c 100644 (file)
@@ -93,7 +93,7 @@ public:
   // 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 @@ public:
   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)
index 8eb37037672d87bd484a45e44bfdc23d290eae10..4078f7e0167489608e2d6c6f557bbdc2fbd7cf24 100644 (file)
@@ -3116,7 +3116,7 @@ size_t VersionTableSection::getSize() const {
 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);
index 3f5c4820f0c6ad3f98f86717829d2357aeaa3ea0..7f24cc671fff0d7c94c14bef220d20829afb7ac1 100644 (file)
@@ -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