Skip to content

Commit 9e6840c

Browse files
committed
[ELF] Remove resolve => resolve{Defined,Common,Shared,Lazy,Undefined} indirection. NFC
1 parent 1eb49bb commit 9e6840c

File tree

5 files changed

+38
-44
lines changed

5 files changed

+38
-44
lines changed

lld/ELF/Driver.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,9 +2269,14 @@ static void combineVersionedSymbol(Symbol &sym,
22692269
map.try_emplace(&sym, sym2);
22702270
// If both foo@v1 and foo@@v1 are defined and non-weak, report a
22712271
// duplicate definition error.
2272-
if (sym.isDefined())
2272+
if (sym.isDefined()) {
22732273
sym2->checkDuplicate(cast<Defined>(sym));
2274-
sym2->resolve(sym);
2274+
sym2->resolve(cast<Defined>(sym));
2275+
} else if (sym.isUndefined()) {
2276+
sym2->resolve(cast<Undefined>(sym));
2277+
} else {
2278+
sym2->resolve(cast<SharedSymbol>(sym));
2279+
}
22752280
// Eliminate foo@v1 from the symbol table.
22762281
sym.symbolKind = Symbol::PlaceholderKind;
22772282
sym.isUsedInRegularObj = false;

lld/ELF/SymbolTable.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,6 @@ Symbol *SymbolTable::insert(StringRef name) {
9999
return sym;
100100
}
101101

102-
Symbol *SymbolTable::addSymbol(const Symbol &newSym) {
103-
Symbol *sym = insert(newSym.getName());
104-
sym->resolve(newSym);
105-
return sym;
106-
}
107-
108102
// This variant of addSymbol is used by BinaryFile::parse to check duplicate
109103
// symbol errors.
110104
Symbol *SymbolTable::addAndCheckDuplicate(const Defined &newSym) {

lld/ELF/SymbolTable.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ class SymbolTable {
3838

3939
Symbol *insert(StringRef name);
4040

41-
Symbol *addSymbol(const Symbol &newSym);
41+
template <typename T> Symbol *addSymbol(const T &newSym) {
42+
Symbol *sym = insert(newSym.getName());
43+
sym->resolve(newSym);
44+
return sym;
45+
}
4246
Symbol *addAndCheckDuplicate(const Defined &newSym);
4347

4448
void scanVersionScript();

lld/ELF/Symbols.cpp

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -383,31 +383,11 @@ void Symbol::mergeProperties(const Symbol &other) {
383383
}
384384
}
385385

386-
void Symbol::resolve(const Symbol &other) {
387-
mergeProperties(other);
388-
389-
switch (other.kind()) {
390-
case Symbol::UndefinedKind:
391-
resolveUndefined(cast<Undefined>(other));
392-
break;
393-
case Symbol::CommonKind:
394-
resolveCommon(cast<CommonSymbol>(other));
395-
break;
396-
case Symbol::DefinedKind:
397-
resolveDefined(cast<Defined>(other));
398-
break;
399-
case Symbol::LazyObjectKind:
400-
resolveLazy(cast<LazyObject>(other));
401-
break;
402-
case Symbol::SharedKind:
403-
resolveShared(cast<SharedSymbol>(other));
404-
break;
405-
case Symbol::PlaceholderKind:
406-
llvm_unreachable("bad symbol kind");
386+
void Symbol::resolve(const Undefined &other) {
387+
if (other.visibility() != STV_DEFAULT) {
388+
uint8_t v = visibility(), ov = other.visibility();
389+
setVisibility(v == STV_DEFAULT ? ov : std::min(v, ov));
407390
}
408-
}
409-
410-
void Symbol::resolveUndefined(const Undefined &other) {
411391
// An undefined symbol with non default visibility must be satisfied
412392
// in the same DSO.
413393
//
@@ -583,7 +563,13 @@ void Symbol::checkDuplicate(const Defined &other) const {
583563
other.value);
584564
}
585565

586-
void Symbol::resolveCommon(const CommonSymbol &other) {
566+
void Symbol::resolve(const CommonSymbol &other) {
567+
if (other.exportDynamic)
568+
exportDynamic = true;
569+
if (other.visibility() != STV_DEFAULT) {
570+
uint8_t v = visibility(), ov = other.visibility();
571+
setVisibility(v == STV_DEFAULT ? ov : std::min(v, ov));
572+
}
587573
if (isDefined() && !isWeak()) {
588574
if (config->warnCommon)
589575
warn("common " + getName() + " is overridden");
@@ -615,12 +601,18 @@ void Symbol::resolveCommon(const CommonSymbol &other) {
615601
}
616602
}
617603

618-
void Symbol::resolveDefined(const Defined &other) {
604+
void Symbol::resolve(const Defined &other) {
605+
if (other.exportDynamic)
606+
exportDynamic = true;
607+
if (other.visibility() != STV_DEFAULT) {
608+
uint8_t v = visibility(), ov = other.visibility();
609+
setVisibility(v == STV_DEFAULT ? ov : std::min(v, ov));
610+
}
619611
if (shouldReplace(other))
620612
other.overwrite(*this);
621613
}
622614

623-
void Symbol::resolveLazy(const LazyObject &other) {
615+
void Symbol::resolve(const LazyObject &other) {
624616
if (isPlaceholder()) {
625617
other.overwrite(*this);
626618
return;
@@ -659,7 +651,8 @@ void Symbol::resolveLazy(const LazyObject &other) {
659651
recordWhyExtract(oldFile, *file, *this);
660652
}
661653

662-
void Symbol::resolveShared(const SharedSymbol &other) {
654+
void Symbol::resolve(const SharedSymbol &other) {
655+
exportDynamic = true;
663656
if (isPlaceholder()) {
664657
other.overwrite(*this);
665658
return;

lld/ELF/Symbols.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,11 @@ class Symbol {
241241
// For example, if "this" is an undefined symbol and a new symbol is
242242
// a defined symbol, "this" is replaced with the new symbol.
243243
void mergeProperties(const Symbol &other);
244-
void resolve(const Symbol &other);
244+
void resolve(const Undefined &other);
245+
void resolve(const CommonSymbol &other);
246+
void resolve(const Defined &other);
247+
void resolve(const LazyObject &other);
248+
void resolve(const SharedSymbol &other);
245249

246250
// If this is a lazy symbol, extract an input file and add the symbol
247251
// in the file to the symbol table. Calling this function on
@@ -251,12 +255,6 @@ class Symbol {
251255
void checkDuplicate(const Defined &other) const;
252256

253257
private:
254-
void resolveUndefined(const Undefined &other);
255-
void resolveCommon(const CommonSymbol &other);
256-
void resolveDefined(const Defined &other);
257-
void resolveLazy(const LazyObject &other);
258-
void resolveShared(const SharedSymbol &other);
259-
260258
bool shouldReplace(const Defined &other) const;
261259

262260
protected:

0 commit comments

Comments
 (0)