Skip to content

Commit f1f0084

Browse files
committedOct 31, 2017
Merge SymbolBody and Symbol into one class, SymbolBody.
SymbolBody and Symbol were separated classes due to a historical reason. Symbol used to be a pointer to a SymbolBody, and the relationship between Symbol and SymbolBody was n:1. r2681780 changed that. Since that patch, SymbolBody and Symbol are allocated next to each other to improve memory locality, and they have 1:1 relationship now. So, the separation of Symbol and SymbolBody no longer makes sense. This patch merges them into one class. In order to avoid updating too many places, I chose SymbolBody as a unified name. I'll rename it Symbol in a follow-up patch. Differential Revision: https://reviews.llvm.org/D39406 llvm-svn: 317006
1 parent f3c33ca commit f1f0084

14 files changed

+332
-358
lines changed
 

‎lld/ELF/Config.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ namespace lld {
2424
namespace elf {
2525

2626
class InputFile;
27-
struct Symbol;
2827

2928
enum ELFKind {
3029
ELFNoneKind,

‎lld/ELF/Driver.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -997,13 +997,12 @@ static void excludeLibs(opt::InputArgList &Args, ArrayRef<InputFile *> Files) {
997997
DenseSet<StringRef> Libs = getExcludeLibs(Args);
998998
bool All = Libs.count("ALL");
999999

1000-
for (InputFile *File : Files) {
1000+
for (InputFile *File : Files)
10011001
if (Optional<StringRef> Archive = getArchiveName(File))
10021002
if (All || Libs.count(path::filename(*Archive)))
1003-
for (SymbolBody *SymBody : File->getSymbols())
1004-
if (!SymBody->isLocal())
1005-
SymBody->symbol()->VersionId = VER_NDX_LOCAL;
1006-
}
1003+
for (SymbolBody *Sym : File->getSymbols())
1004+
if (!Sym->isLocal())
1005+
Sym->VersionId = VER_NDX_LOCAL;
10071006
}
10081007

10091008
// Do actual linking. Note that when this function is called,

‎lld/ELF/InputFiles.cpp

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -551,16 +551,14 @@ SymbolBody *ObjFile<ELFT>::createSymbolBody(const Elf_Sym *Sym) {
551551

552552
switch (Sym->st_shndx) {
553553
case SHN_UNDEF:
554-
return Symtab
555-
->addUndefined<ELFT>(Name, /*IsLocal=*/false, Binding, StOther, Type,
556-
/*CanOmitFromDynSym=*/false, this)
557-
->body();
554+
return Symtab->addUndefined<ELFT>(Name, /*IsLocal=*/false, Binding, StOther,
555+
Type,
556+
/*CanOmitFromDynSym=*/false, this);
558557
case SHN_COMMON:
559558
if (Value == 0 || Value >= UINT32_MAX)
560559
fatal(toString(this) + ": common symbol '" + Name +
561560
"' has invalid alignment: " + Twine(Value));
562-
return Symtab->addCommon(Name, Size, Value, Binding, StOther, Type, this)
563-
->body();
561+
return Symtab->addCommon(Name, Size, Value, Binding, StOther, Type, this);
564562
}
565563

566564
switch (Binding) {
@@ -570,13 +568,11 @@ SymbolBody *ObjFile<ELFT>::createSymbolBody(const Elf_Sym *Sym) {
570568
case STB_WEAK:
571569
case STB_GNU_UNIQUE:
572570
if (Sec == &InputSection::Discarded)
573-
return Symtab
574-
->addUndefined<ELFT>(Name, /*IsLocal=*/false, Binding, StOther, Type,
575-
/*CanOmitFromDynSym=*/false, this)
576-
->body();
577-
return Symtab
578-
->addRegular<ELFT>(Name, StOther, Type, Value, Size, Binding, Sec, this)
579-
->body();
571+
return Symtab->addUndefined<ELFT>(Name, /*IsLocal=*/false, Binding,
572+
StOther, Type,
573+
/*CanOmitFromDynSym=*/false, this);
574+
return Symtab->addRegular<ELFT>(Name, StOther, Type, Value, Size, Binding,
575+
Sec, this);
580576
}
581577
}
582578

@@ -587,8 +583,7 @@ ArchiveFile::ArchiveFile(std::unique_ptr<Archive> &&File)
587583
template <class ELFT> void ArchiveFile::parse() {
588584
Symbols.reserve(File->getNumberOfSymbols());
589585
for (const Archive::Symbol &Sym : File->symbols())
590-
Symbols.push_back(
591-
Symtab->addLazyArchive<ELFT>(Sym.getName(), this, Sym)->body());
586+
Symbols.push_back(Symtab->addLazyArchive<ELFT>(Sym.getName(), this, Sym));
592587
}
593588

594589
// Returns a buffer pointing to a member file containing a given symbol.
@@ -848,9 +843,9 @@ static uint8_t mapVisibility(GlobalValue::VisibilityTypes GvVisibility) {
848843
}
849844

850845
template <class ELFT>
851-
static Symbol *createBitcodeSymbol(const std::vector<bool> &KeptComdats,
852-
const lto::InputFile::Symbol &ObjSym,
853-
BitcodeFile *F) {
846+
static SymbolBody *createBitcodeSymbol(const std::vector<bool> &KeptComdats,
847+
const lto::InputFile::Symbol &ObjSym,
848+
BitcodeFile *F) {
854849
StringRef NameRef = Saver.save(ObjSym.getName());
855850
uint32_t Binding = ObjSym.isWeak() ? STB_WEAK : STB_GLOBAL;
856851

@@ -883,8 +878,7 @@ void BitcodeFile::parse(DenseSet<CachedHashStringRef> &ComdatGroups) {
883878
KeptComdats.push_back(ComdatGroups.insert(CachedHashStringRef(S)).second);
884879

885880
for (const lto::InputFile::Symbol &ObjSym : Obj->symbols())
886-
Symbols.push_back(
887-
createBitcodeSymbol<ELFT>(KeptComdats, ObjSym, this)->body());
881+
Symbols.push_back(createBitcodeSymbol<ELFT>(KeptComdats, ObjSym, this));
888882
}
889883

890884
static ELFKind getELFKind(MemoryBufferRef MB) {

‎lld/ELF/LTO.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ static std::unique_ptr<lto::LTO> createLTO() {
108108
}
109109

110110
BitcodeCompiler::BitcodeCompiler() : LTOObj(createLTO()) {
111-
for (Symbol *Sym : Symtab->getSymbols()) {
112-
StringRef Name = Sym->body()->getName();
111+
for (SymbolBody *Sym : Symtab->getSymbols()) {
112+
StringRef Name = Sym->getName();
113113
for (StringRef Prefix : {"__start_", "__stop_"})
114114
if (Name.startswith(Prefix))
115115
UsedStartStop.insert(Name.substr(Prefix.size()));
@@ -118,9 +118,9 @@ BitcodeCompiler::BitcodeCompiler() : LTOObj(createLTO()) {
118118

119119
BitcodeCompiler::~BitcodeCompiler() = default;
120120

121-
static void undefine(Symbol *S) {
122-
replaceBody<Undefined>(S, nullptr, S->body()->getName(), /*IsLocal=*/false,
123-
STV_DEFAULT, S->body()->Type);
121+
static void undefine(SymbolBody *S) {
122+
replaceBody<Undefined>(S, nullptr, S->getName(), /*IsLocal=*/false,
123+
STV_DEFAULT, S->Type);
124124
}
125125

126126
void BitcodeCompiler::add(BitcodeFile &F) {
@@ -136,8 +136,7 @@ void BitcodeCompiler::add(BitcodeFile &F) {
136136

137137
// Provide a resolution to the LTO API for each symbol.
138138
for (const lto::InputFile::Symbol &ObjSym : Obj.symbols()) {
139-
SymbolBody *B = Syms[SymNum];
140-
Symbol *Sym = B->symbol();
139+
SymbolBody *Sym = Syms[SymNum];
141140
lto::SymbolResolution &R = Resols[SymNum];
142141
++SymNum;
143142

@@ -146,7 +145,7 @@ void BitcodeCompiler::add(BitcodeFile &F) {
146145
// flags an undefined in IR with a definition in ASM as prevailing.
147146
// Once IRObjectFile is fixed to report only one symbol this hack can
148147
// be removed.
149-
R.Prevailing = !ObjSym.isUndefined() && B->getFile() == &F;
148+
R.Prevailing = !ObjSym.isUndefined() && Sym->getFile() == &F;
150149

151150
// We ask LTO to preserve following global symbols:
152151
// 1) All symbols when doing relocatable link, so that them can be used
@@ -165,7 +164,7 @@ void BitcodeCompiler::add(BitcodeFile &F) {
165164
// still not final:
166165
// 1) Aliased (with --defsym) or wrapped (with --wrap) symbols.
167166
// 2) Symbols redefined in linker script.
168-
R.LinkerRedefined = !Sym->CanInline || ScriptSymbols.count(B->getName());
167+
R.LinkerRedefined = !Sym->CanInline || ScriptSymbols.count(Sym->getName());
169168
}
170169
checkError(LTOObj->add(std::move(F.Obj), Resols));
171170
}

‎lld/ELF/LinkerScript.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ void LinkerScript::addSymbol(SymbolAssignment *Cmd) {
127127
return;
128128

129129
// Define a symbol.
130-
Symbol *Sym;
130+
SymbolBody *Sym;
131131
uint8_t Visibility = Cmd->Hidden ? STV_HIDDEN : STV_DEFAULT;
132132
std::tie(Sym, std::ignore) = Symtab->insert(Cmd->Name, /*Type*/ 0, Visibility,
133133
/*CanOmitFromDynSym*/ false,
@@ -151,7 +151,7 @@ void LinkerScript::addSymbol(SymbolAssignment *Cmd) {
151151

152152
replaceBody<DefinedRegular>(Sym, nullptr, Cmd->Name, /*IsLocal=*/false,
153153
Visibility, STT_NOTYPE, SymValue, 0, Sec);
154-
Cmd->Sym = cast<DefinedRegular>(Sym->body());
154+
Cmd->Sym = cast<DefinedRegular>(Sym);
155155
}
156156

157157
// This function is called from assignAddresses, while we are

‎lld/ELF/MarkLive.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ template <class ELFT> static void doGcSections() {
228228

229229
// Preserve externally-visible symbols if the symbols defined by this
230230
// file can interrupt other ELF file's symbols at runtime.
231-
for (Symbol *S : Symtab->getSymbols())
231+
for (SymbolBody *S : Symtab->getSymbols())
232232
if (S->includeInDynsym())
233-
MarkSymbol(S->body());
233+
MarkSymbol(S);
234234

235235
// Preserve special sections and those which are specified in linker
236236
// script KEEP command.

‎lld/ELF/Relocations.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ template <class ELFT> static void addCopyRelSymbol(SharedSymbol *SS) {
544544
for (SharedSymbol *Sym : getSymbolsAt<ELFT>(SS)) {
545545
Sym->CopyRelSec = Sec;
546546
Sym->IsPreemptible = false;
547-
Sym->symbol()->IsUsedInRegularObj = true;
547+
Sym->IsUsedInRegularObj = true;
548548
}
549549

550550
In<ELFT>::RelaDyn->addReloc({Target->CopyRel, Sec, 0, false, SS, 0});
@@ -717,11 +717,11 @@ static bool maybeReportUndefined(SymbolBody &Sym, InputSectionBase &Sec,
717717
if (Config->UnresolvedSymbols == UnresolvedPolicy::IgnoreAll)
718718
return false;
719719

720-
if (Sym.isLocal() || !Sym.isUndefined() || Sym.symbol()->isWeak())
720+
if (Sym.isLocal() || !Sym.isUndefined() || Sym.isWeak())
721721
return false;
722722

723-
bool CanBeExternal = Sym.symbol()->computeBinding() != STB_LOCAL &&
724-
Sym.getVisibility() == STV_DEFAULT;
723+
bool CanBeExternal =
724+
Sym.computeBinding() != STB_LOCAL && Sym.getVisibility() == STV_DEFAULT;
725725
if (Config->UnresolvedSymbols == UnresolvedPolicy::Ignore && CanBeExternal)
726726
return false;
727727

0 commit comments

Comments
 (0)
Please sign in to comment.