[lld] 09401df - [ELF] Rename fetch to extract
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 26 10:58:56 PST 2021
Author: Fangrui Song
Date: 2021-11-26T10:58:50-08:00
New Revision: 09401dfcf1dbec9d55ac62596d7520ba3a10eabb
URL: https://github.com/llvm/llvm-project/commit/09401dfcf1dbec9d55ac62596d7520ba3a10eabb
DIFF: https://github.com/llvm/llvm-project/commit/09401dfcf1dbec9d55ac62596d7520ba3a10eabb.diff
LOG: [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.
Added:
Modified:
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
Removed:
################################################################################
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 8c668879b54e5..5541a397c5533 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -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;
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index 9399bb4484f03..b00204183db7d 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -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);
diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h
index fb4d46b43f35e..f3a45385af2e3 100644
--- a/lld/ELF/InputFiles.h
+++ b/lld/ELF/InputFiles.h
@@ -306,13 +306,13 @@ class LazyObjFile : public InputFile {
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 @@ class ArchiveFile : public InputFile {
// 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/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp
index a42d216e4e778..46dc77a6789c5 100644
--- a/lld/ELF/LTO.cpp
+++ b/lld/ELF/LTO.cpp
@@ -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");
diff --git a/lld/ELF/MapFile.cpp b/lld/ELF/MapFile.cpp
index 56c215d505047..325c3b3226630 100644
--- a/lld/ELF/MapFile.cpp
+++ b/lld/ELF/MapFile.cpp
@@ -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';
}
diff --git a/lld/ELF/Options.td b/lld/ELF/Options.td
index ce82eb8d27545..7de7a37b30f74 100644
--- a/lld/ELF/Options.td
+++ b/lld/ELF/Options.td
@@ -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",
diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp
index c309957ee5bac..e615fb70a40f6 100644
--- a/lld/ELF/SymbolTable.cpp
+++ b/lld/ELF/SymbolTable.cpp
@@ -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();
}
diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp
index 5f95a1b3c7acc..da3ade1b9dad2 100644
--- a/lld/ELF/Symbols.cpp
+++ b/lld/ELF/Symbols.cpp
@@ -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);
}
diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h
index 816d61563021e..cc48ef0ab3b7a 100644
--- a/lld/ELF/Symbols.h
+++ b/lld/ELF/Symbols.h
@@ -93,7 +93,7 @@ class Symbol {
// 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 @@ class Symbol {
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/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 8eb37037672d8..4078f7e016748 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -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);
diff --git a/lld/test/ELF/print-archive-stats.s b/lld/test/ELF/print-archive-stats.s
index 3f5c4820f0c6a..7f24cc671fff0 100644
--- a/lld/test/ELF/print-archive-stats.s
+++ b/lld/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
More information about the llvm-commits
mailing list