[ELF] Refactor how Symbol::used is set. NFC

This commit is contained in:
Fangrui Song 2022-02-05 11:09:39 -08:00
parent 6daaf5a449
commit bb4eacdb70
2 changed files with 6 additions and 11 deletions

View File

@ -248,12 +248,11 @@ protected:
isUsedInRegularObj(!file || file->kind() == InputFile::ObjKind),
exportDynamic(false), inDynamicList(false), canInline(false),
referenced(false), traced(false), hasVersionSuffix(false),
isInIplt(false), gotInIgot(false), isPreemptible(false),
used(!config->gcSections), folded(false), needsTocRestore(false),
scriptDefined(false), needsCopy(false), needsGot(false),
needsPlt(false), needsTlsDesc(false), needsTlsGd(false),
needsTlsGdToIe(false), needsTlsLd(false), needsGotDtprel(false),
needsTlsIe(false), hasDirectReloc(false) {}
isInIplt(false), gotInIgot(false), isPreemptible(false), used(false),
folded(false), needsTocRestore(false), scriptDefined(false),
needsCopy(false), needsGot(false), needsPlt(false), needsTlsDesc(false),
needsTlsGd(false), needsTlsGdToIe(false), needsTlsLd(false),
needsGotDtprel(false), needsTlsIe(false), hasDirectReloc(false) {}
public:
// True if this symbol is in the Iplt sub-section of the Plt and the Igot

View File

@ -619,12 +619,8 @@ template <class ELFT> static void markUsedLocalSymbols() {
// See MarkLive<ELFT>::resolveReloc().
if (config->gcSections)
return;
// Without --gc-sections, the field is initialized with "true".
// Drop the flag first and then rise for symbols referenced in relocations.
for (ELFFileBase *file : objectFiles) {
ObjFile<ELFT> *f = cast<ObjFile<ELFT>>(file);
for (Symbol *b : f->getLocalSymbols())
b->used = false;
for (InputSectionBase *s : f->getSections()) {
InputSection *isec = dyn_cast_or_null<InputSection>(s);
if (!isec)
@ -688,7 +684,7 @@ static bool includeInSymtab(const Symbol &b) {
return false;
return true;
}
return b.used;
return b.used || !config->gcSections;
}
// Local symbols are not in the linker's symbol table. This function scans