Skip to content

Commit 09401df

Browse files
committed
[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.
1 parent fcee33b commit 09401df

File tree

11 files changed

+57
-59
lines changed

11 files changed

+57
-59
lines changed

lld/ELF/Driver.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,7 +1691,7 @@ static void handleUndefined(Symbol *sym, const char *option) {
16911691

16921692
if (!sym->isLazy())
16931693
return;
1694-
sym->fetch();
1694+
sym->extract();
16951695
if (!config->whyExtract.empty())
16961696
whyExtract.emplace_back(option, sym->file, *sym);
16971697
}
@@ -1706,14 +1706,12 @@ static void handleUndefinedGlob(StringRef arg) {
17061706
return;
17071707
}
17081708

1709+
// Calling sym->extract() in the loop is not safe because it may add new
1710+
// symbols to the symbol table, invalidating the current iterator.
17091711
std::vector<Symbol *> syms;
1710-
for (Symbol *sym : symtab->symbols()) {
1711-
// Calling Sym->fetch() from here is not safe because it may
1712-
// add new symbols to the symbol table, invalidating the
1713-
// current iterator. So we just keep a note.
1712+
for (Symbol *sym : symtab->symbols())
17141713
if (pat->match(sym->getName()))
17151714
syms.push_back(sym);
1716-
}
17171715

17181716
for (Symbol *sym : syms)
17191717
handleUndefined(sym, "--undefined-glob");
@@ -1731,7 +1729,7 @@ static void handleLibcall(StringRef name) {
17311729
mb = cast<LazyArchive>(sym)->getMemberBuffer();
17321730

17331731
if (isBitcode(mb))
1734-
sym->fetch();
1732+
sym->extract();
17351733
}
17361734

17371735
// 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) {
22072205
symtab->insert(arg->getValue())->traced = true;
22082206

22092207
// Handle -u/--undefined before input files. If both a.a and b.so define foo,
2210-
// -u foo a.a b.so will fetch a.a.
2208+
// -u foo a.a b.so will extract a.a.
22112209
for (StringRef name : config->undefined)
22122210
addUnusedUndefined(name)->referenced = true;
22132211

lld/ELF/InputFiles.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,15 +1147,15 @@ template <class ELFT> void ObjFile<ELFT>::initializeSymbols() {
11471147
if (sec == &InputSection::discarded) {
11481148
Undefined und{this, name, binding, stOther, type, secIdx};
11491149
Symbol *sym = this->symbols[i];
1150-
// !ArchiveFile::parsed or LazyObjFile::fetched means that the file
1150+
// !ArchiveFile::parsed or LazyObjFile::extracted means that the file
11511151
// containing this object has not finished processing, i.e. this symbol is
1152-
// a result of a lazy symbol fetch. We should demote the lazy symbol to an
1153-
// Undefined so that any relocations outside of the group to it will
1152+
// a result of a lazy symbol extract. We should demote the lazy symbol to
1153+
// an Undefined so that any relocations outside of the group to it will
11541154
// trigger a discarded section error.
11551155
if ((sym->symbolKind == Symbol::LazyArchiveKind &&
11561156
!cast<ArchiveFile>(sym->file)->parsed) ||
11571157
(sym->symbolKind == Symbol::LazyObjectKind &&
1158-
cast<LazyObjFile>(sym->file)->fetched))
1158+
cast<LazyObjFile>(sym->file)->extracted))
11591159
sym->replace(und);
11601160
else
11611161
sym->resolve(und);
@@ -1174,7 +1174,7 @@ template <class ELFT> void ObjFile<ELFT>::initializeSymbols() {
11741174
}
11751175

11761176
// Undefined symbols (excluding those defined relative to non-prevailing
1177-
// sections) can trigger recursive fetch. Process defined symbols first so
1177+
// sections) can trigger recursive extract. Process defined symbols first so
11781178
// that the relative order between a defined symbol and an undefined symbol
11791179
// does not change the symbol resolution behavior. In addition, a set of
11801180
// interconnected symbols will all be resolved to the same file, instead of
@@ -1202,7 +1202,7 @@ void ArchiveFile::parse() {
12021202
}
12031203

12041204
// Returns a buffer pointing to a member file containing a given symbol.
1205-
void ArchiveFile::fetch(const Archive::Symbol &sym) {
1205+
void ArchiveFile::extract(const Archive::Symbol &sym) {
12061206
Archive::Child c =
12071207
CHECK(sym.getMember(), toString(this) +
12081208
": could not get the member for symbol " +
@@ -1291,7 +1291,7 @@ static bool isNonCommonDef(MemoryBufferRef mb, StringRef symName,
12911291
}
12921292
}
12931293

1294-
bool ArchiveFile::shouldFetchForCommon(const Archive::Symbol &sym) {
1294+
bool ArchiveFile::shouldExtractForCommon(const Archive::Symbol &sym) {
12951295
Archive::Child c =
12961296
CHECK(sym.getMember(), toString(this) +
12971297
": could not get the member for symbol " +
@@ -1779,10 +1779,10 @@ InputFile *elf::createObjectFile(MemoryBufferRef mb, StringRef archiveName,
17791779
}
17801780
}
17811781

1782-
void LazyObjFile::fetch() {
1783-
if (fetched)
1782+
void LazyObjFile::extract() {
1783+
if (extracted)
17841784
return;
1785-
fetched = true;
1785+
extracted = true;
17861786

17871787
InputFile *file = createObjectFile(mb, archiveName, offsetInArchive);
17881788
file->groupId = groupId;
@@ -1835,24 +1835,24 @@ template <class ELFT> void LazyObjFile::parse() {
18351835

18361836
// Replace existing symbols with LazyObject symbols.
18371837
//
1838-
// resolve() may trigger this->fetch() if an existing symbol is an
1838+
// resolve() may trigger this->extract() if an existing symbol is an
18391839
// undefined symbol. If that happens, this LazyObjFile has served
18401840
// its purpose, and we can exit from the loop early.
18411841
for (Symbol *sym : this->symbols) {
18421842
if (!sym)
18431843
continue;
18441844
sym->resolve(LazyObject{*this, sym->getName()});
18451845

1846-
// If fetched, stop iterating because this->symbols has been transferred
1846+
// If extracted, stop iterating because this->symbols has been transferred
18471847
// to the instantiated ObjFile.
1848-
if (fetched)
1848+
if (extracted)
18491849
return;
18501850
}
18511851
return;
18521852
}
18531853
}
18541854

1855-
bool LazyObjFile::shouldFetchForCommon(const StringRef &name) {
1855+
bool LazyObjFile::shouldExtractForCommon(const StringRef &name) {
18561856
if (isBitcode(mb))
18571857
return isBitcodeNonCommonDef(mb, name, archiveName);
18581858

lld/ELF/InputFiles.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -306,13 +306,13 @@ class LazyObjFile : public InputFile {
306306
static bool classof(const InputFile *f) { return f->kind() == LazyObjKind; }
307307

308308
template <class ELFT> void parse();
309-
void fetch();
309+
void extract();
310310

311-
// Check if a non-common symbol should be fetched to override a common
311+
// Check if a non-common symbol should be extracted to override a common
312312
// definition.
313-
bool shouldFetchForCommon(const StringRef &name);
313+
bool shouldExtractForCommon(const StringRef &name);
314314

315-
bool fetched = false;
315+
bool extracted = false;
316316

317317
private:
318318
uint64_t offsetInArchive;
@@ -329,14 +329,14 @@ class ArchiveFile : public InputFile {
329329
// returns it. If the same file was instantiated before, this
330330
// function does nothing (so we don't instantiate the same file
331331
// more than once.)
332-
void fetch(const Archive::Symbol &sym);
332+
void extract(const Archive::Symbol &sym);
333333

334-
// Check if a non-common symbol should be fetched to override a common
334+
// Check if a non-common symbol should be extracted to override a common
335335
// definition.
336-
bool shouldFetchForCommon(const Archive::Symbol &sym);
336+
bool shouldExtractForCommon(const Archive::Symbol &sym);
337337

338338
size_t getMemberCount() const;
339-
size_t getFetchedMemberCount() const { return seen.size(); }
339+
size_t getExtractedMemberCount() const { return seen.size(); }
340340

341341
bool parsed = false;
342342

lld/ELF/LTO.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ void BitcodeCompiler::add(BitcodeFile &f) {
279279
// distributed build system that depends on that behavior.
280280
static void thinLTOCreateEmptyIndexFiles() {
281281
for (LazyObjFile *f : lazyObjFiles) {
282-
if (f->fetched || !isBitcode(f->mb))
282+
if (f->extracted || !isBitcode(f->mb))
283283
continue;
284284
std::string path = replaceThinLTOSuffix(getThinLTOOutputFile(f->getName()));
285285
std::unique_ptr<raw_fd_ostream> os = openFile(path + ".thinlto.bc");

lld/ELF/MapFile.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@ void elf::writeArchiveStats() {
294294
return;
295295
}
296296

297-
os << "members\tfetched\tarchive\n";
297+
os << "members\textracted\tarchive\n";
298298
for (const ArchiveFile *f : archiveFiles)
299-
os << f->getMemberCount() << '\t' << f->getFetchedMemberCount() << '\t'
299+
os << f->getMemberCount() << '\t' << f->getExtractedMemberCount() << '\t'
300300
<< f->getName() << '\n';
301301
}

lld/ELF/Options.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ defm print_icf_sections: B<"print-icf-sections",
338338

339339
def print_archive_stats: J<"print-archive-stats=">,
340340
HelpText<"Write archive usage statistics to the specified file. "
341-
"Print the numbers of members and fetched members for each archive">;
341+
"Print the numbers of members and extracted members for each archive">;
342342

343343
defm print_symbol_order: Eq<"print-symbol-order",
344344
"Print a symbol order specified by --call-graph-ordering-file into the specified file">;
@@ -468,8 +468,8 @@ def power10_stubs_eq:
468468
defm version_script: Eq<"version-script", "Read a version script">;
469469

470470
defm warn_backrefs: BB<"warn-backrefs",
471-
"Warn about backward symbol references to fetch archive members",
472-
"Do not warn about backward symbol references to fetch archive members (default)">;
471+
"Warn about backward symbol references to extract archive members",
472+
"Do not warn about backward symbol references to extract archive members (default)">;
473473

474474
defm warn_backrefs_exclude
475475
: EEq<"warn-backrefs-exclude",

lld/ELF/SymbolTable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ Symbol *SymbolTable::find(StringRef name) {
113113

114114
// A version script/dynamic list is only meaningful for a Defined symbol.
115115
// A CommonSymbol will be converted to a Defined in replaceCommonSymbols().
116-
// A lazy symbol may be made Defined if an LTO libcall fetches it.
116+
// A lazy symbol may be made Defined if an LTO libcall extracts it.
117117
static bool canBeVersioned(const Symbol &sym) {
118118
return sym.isDefined() || sym.isCommon() || sym.isLazy();
119119
}

lld/ELF/Symbols.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -256,18 +256,18 @@ void Symbol::parseSymbolVersion() {
256256
verstr);
257257
}
258258

259-
void Symbol::fetch() const {
259+
void Symbol::extract() const {
260260
if (auto *sym = dyn_cast<LazyArchive>(this)) {
261-
cast<ArchiveFile>(sym->file)->fetch(sym->sym);
261+
cast<ArchiveFile>(sym->file)->extract(sym->sym);
262262
return;
263263
}
264264

265265
if (auto *sym = dyn_cast<LazyObject>(this)) {
266-
dyn_cast<LazyObjFile>(sym->file)->fetch();
266+
dyn_cast<LazyObjFile>(sym->file)->extract();
267267
return;
268268
}
269269

270-
llvm_unreachable("Symbol::fetch() is called on a non-lazy symbol");
270+
llvm_unreachable("Symbol::extract() is called on a non-lazy symbol");
271271
}
272272

273273
MemoryBufferRef LazyArchive::getMemberBuffer() {
@@ -478,8 +478,8 @@ void Symbol::resolveUndefined(const Undefined &other) {
478478
printTraceSymbol(&other);
479479

480480
if (isLazy()) {
481-
// An undefined weak will not fetch archive members. See comment on Lazy in
482-
// Symbols.h for the details.
481+
// An undefined weak will not extract archive members. See comment on Lazy
482+
// in Symbols.h for the details.
483483
if (other.binding == STB_WEAK) {
484484
binding = STB_WEAK;
485485
type = other.type;
@@ -489,9 +489,9 @@ void Symbol::resolveUndefined(const Undefined &other) {
489489
// Do extra check for --warn-backrefs.
490490
//
491491
// --warn-backrefs is an option to prevent an undefined reference from
492-
// fetching an archive member written earlier in the command line. It can be
493-
// used to keep compatibility with GNU linkers to some degree.
494-
// I'll explain the feature and why you may find it useful in this comment.
492+
// extracting an archive member written earlier in the command line. It can
493+
// be used to keep compatibility with GNU linkers to some degree. I'll
494+
// explain the feature and why you may find it useful in this comment.
495495
//
496496
// lld's symbol resolution semantics is more relaxed than traditional Unix
497497
// linkers. For example,
@@ -538,7 +538,7 @@ void Symbol::resolveUndefined(const Undefined &other) {
538538
// group assignment rule simulates the traditional linker's semantics.
539539
bool backref = config->warnBackrefs && other.file &&
540540
file->groupId < other.file->groupId;
541-
fetch();
541+
extract();
542542

543543
if (!config->whyExtract.empty())
544544
recordWhyExtract(other.file, *file, *this);
@@ -712,23 +712,23 @@ template <class LazyT>
712712
static void replaceCommon(Symbol &oldSym, const LazyT &newSym) {
713713
backwardReferences.erase(&oldSym);
714714
oldSym.replace(newSym);
715-
newSym.fetch();
715+
newSym.extract();
716716
}
717717

718718
template <class LazyT> void Symbol::resolveLazy(const LazyT &other) {
719719
// For common objects, we want to look for global or weak definitions that
720-
// should be fetched as the canonical definition instead.
720+
// should be extracted as the canonical definition instead.
721721
if (isCommon() && elf::config->fortranCommon) {
722722
if (auto *laSym = dyn_cast<LazyArchive>(&other)) {
723723
ArchiveFile *archive = cast<ArchiveFile>(laSym->file);
724724
const Archive::Symbol &archiveSym = laSym->sym;
725-
if (archive->shouldFetchForCommon(archiveSym)) {
725+
if (archive->shouldExtractForCommon(archiveSym)) {
726726
replaceCommon(*this, other);
727727
return;
728728
}
729729
} else if (auto *loSym = dyn_cast<LazyObject>(&other)) {
730730
LazyObjFile *obj = cast<LazyObjFile>(loSym->file);
731-
if (obj->shouldFetchForCommon(loSym->getName())) {
731+
if (obj->shouldExtractForCommon(loSym->getName())) {
732732
replaceCommon(*this, other);
733733
return;
734734
}
@@ -742,7 +742,7 @@ template <class LazyT> void Symbol::resolveLazy(const LazyT &other) {
742742
return;
743743
}
744744

745-
// An undefined weak will not fetch archive members. See comment on Lazy in
745+
// An undefined weak will not extract archive members. See comment on Lazy in
746746
// Symbols.h for the details.
747747
if (isWeak()) {
748748
uint8_t ty = type;
@@ -753,7 +753,7 @@ template <class LazyT> void Symbol::resolveLazy(const LazyT &other) {
753753
}
754754

755755
const InputFile *oldFile = file;
756-
other.fetch();
756+
other.extract();
757757
if (!config->whyExtract.empty())
758758
recordWhyExtract(oldFile, *file, *this);
759759
}

lld/ELF/Symbols.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class Symbol {
9393
// Symbol binding. This is not overwritten by replace() to track
9494
// changes during resolution. In particular:
9595
// - An undefined weak is still weak when it resolves to a shared library.
96-
// - An undefined weak will not fetch archive members, but we have to
96+
// - An undefined weak will not extract archive members, but we have to
9797
// remember it is weak.
9898
uint8_t binding;
9999

@@ -216,10 +216,10 @@ class Symbol {
216216
void mergeProperties(const Symbol &other);
217217
void resolve(const Symbol &other);
218218

219-
// If this is a lazy symbol, fetch an input file and add the symbol
219+
// If this is a lazy symbol, extract an input file and add the symbol
220220
// in the file to the symbol table. Calling this function on
221221
// non-lazy object causes a runtime error.
222-
void fetch() const;
222+
void extract() const;
223223

224224
static bool isExportDynamic(Kind k, uint8_t visibility) {
225225
if (k == SharedKind)

lld/ELF/SyntheticSections.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3116,7 +3116,7 @@ size_t VersionTableSection::getSize() const {
31163116
void VersionTableSection::writeTo(uint8_t *buf) {
31173117
buf += 2;
31183118
for (const SymbolTableEntry &s : getPartition().dynSymTab->getSymbols()) {
3119-
// For an unfetched lazy symbol (undefined weak), it must have been
3119+
// For an unextracted lazy symbol (undefined weak), it must have been
31203120
// converted to Undefined and have VER_NDX_GLOBAL version here.
31213121
assert(!s.sym->isLazy());
31223122
write16(buf, s.sym->versionId);

lld/test/ELF/print-archive-stats.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# RUN: FileCheck --input-file=%t.txt -DT=%t %s --match-full-lines --strict-whitespace
1313

1414
## Fetches 0 member from %tweak.a and 2 members from %t1.a
15-
# CHECK:members fetched archive
15+
# CHECK:members extracted archive
1616
# CHECK-NEXT:1 0 [[T]]weak.a
1717
# CHECK-NEXT:3 2 [[T]]1.a
1818

@@ -22,7 +22,7 @@
2222
## The second %t1.a has 0 fetched member.
2323
# RUN: ld.lld %t.o %tweak.a %t1.a %t1.a --print-archive-stats=- -o /dev/null | \
2424
# RUN: FileCheck --check-prefix=CHECK2 %s
25-
# CHECK2: members fetched archive
25+
# CHECK2: members extracted archive
2626
# CHECK2-NEXT: 1 0 {{.*}}weak.a
2727
# CHECK2-NEXT: 3 2 {{.*}}1.a
2828
# CHECK2-NEXT: 3 0 {{.*}}1.a

0 commit comments

Comments
 (0)