[lld] r240319 - COFF: Separate DefinedCOMDAT from DefinedRegular symbol type. NFC.
Rui Ueyama
ruiu at google.com
Mon Jun 22 12:56:01 PDT 2015
Author: ruiu
Date: Mon Jun 22 14:56:01 2015
New Revision: 240319
URL: http://llvm.org/viewvc/llvm-project?rev=240319&view=rev
Log:
COFF: Separate DefinedCOMDAT from DefinedRegular symbol type. NFC.
Before this change, you got to cast a symbol to DefinedRegular and then
call isCOMDAT() to determine if a given symbol is a COMDAT symbol.
Now you can just use isa<DefinedCOMDAT>().
As to the class definition of DefinedCOMDAT, I could remove duplicate
code from DefinedRegular and DefinedCOMDAT by introducing another base
class for them, but I chose to not do that to keep the class hierarchy
shallow. This amount of code duplication doesn't worth to define a new
class.
Modified:
lld/trunk/COFF/InputFiles.cpp
lld/trunk/COFF/Symbols.cpp
lld/trunk/COFF/Symbols.h
Modified: lld/trunk/COFF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.cpp?rev=240319&r1=240318&r2=240319&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.cpp (original)
+++ lld/trunk/COFF/InputFiles.cpp Mon Jun 22 14:56:01 2015
@@ -211,8 +211,11 @@ SymbolBody *ObjectFile::createSymbolBody
}
}
}
- if (Chunk *C = SparseChunks[Sym.getSectionNumber()])
+ if (Chunk *C = SparseChunks[Sym.getSectionNumber()]) {
+ if (C->isCOMDAT())
+ return new (Alloc) DefinedCOMDAT(COFFObj.get(), Sym, C);
return new (Alloc) DefinedRegular(COFFObj.get(), Sym, C);
+ }
return nullptr;
}
Modified: lld/trunk/COFF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Symbols.cpp?rev=240319&r1=240318&r2=240319&view=diff
==============================================================================
--- lld/trunk/COFF/Symbols.cpp (original)
+++ lld/trunk/COFF/Symbols.cpp Mon Jun 22 14:56:01 2015
@@ -26,12 +26,17 @@ namespace coff {
int DefinedRegular::compare(SymbolBody *Other) {
if (Other->kind() < kind())
return -Other->compare(this);
- auto *R = dyn_cast<DefinedRegular>(Other);
- if (!R)
- return 1;
- if (isCOMDAT() && R->isCOMDAT())
- return 1;
- return 0;
+ if (isa<DefinedRegular>(Other))
+ return 0;
+ return 1;
+}
+
+int DefinedCOMDAT::compare(SymbolBody *Other) {
+ if (Other->kind() < kind())
+ return -Other->compare(this);
+ if (isa<DefinedRegular>(Other))
+ return 0;
+ return 1;
}
int DefinedCommon::compare(SymbolBody *Other) {
@@ -39,9 +44,9 @@ int DefinedCommon::compare(SymbolBody *O
return -Other->compare(this);
if (auto *D = dyn_cast<DefinedCommon>(Other))
return getSize() > D->getSize() ? 1 : -1;
- if (isa<DefinedRegular>(Other))
- return -1;
- return 1;
+ if (isa<Lazy>(Other) || isa<Undefined>(Other))
+ return 1;
+ return -1;
}
int DefinedBitcode::compare(SymbolBody *Other) {
@@ -62,12 +67,9 @@ int DefinedBitcode::compare(SymbolBody *
// replicate the rest of the symbol resolution logic here; symbol
// resolution will be done accurately after lowering bitcode symbols
// to regular symbols in addCombinedLTOObject().
- if (auto *R = dyn_cast<DefinedRegular>(Other)) {
- if (!R->isCOMDAT() && !Replaceable)
- return 0;
+ if (isa<DefinedRegular>(Other) && Replaceable)
return -1;
- }
- if (isa<DefinedCommon>(Other))
+ if (isa<DefinedCommon>(Other) || isa<DefinedCOMDAT>(Other))
return -1;
return 0;
}
@@ -113,6 +115,12 @@ StringRef DefinedRegular::getName() {
if (Name.empty())
COFFFile->getSymbolName(Sym, Name);
return Name;
+}
+
+StringRef DefinedCOMDAT::getName() {
+ if (Name.empty())
+ COFFFile->getSymbolName(Sym, Name);
+ return Name;
}
StringRef DefinedCommon::getName() {
Modified: lld/trunk/COFF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Symbols.h?rev=240319&r1=240318&r2=240319&view=diff
==============================================================================
--- lld/trunk/COFF/Symbols.h (original)
+++ lld/trunk/COFF/Symbols.h Mon Jun 22 14:56:01 2015
@@ -50,6 +50,7 @@ public:
DefinedImportDataKind,
DefinedImportThunkKind,
DefinedCommonKind,
+ DefinedCOMDATKind,
DefinedRegularKind,
DefinedLast,
LazyKind,
@@ -128,7 +129,29 @@ public:
bool isExternal() override { return Sym.isExternal(); }
void markLive() override { Data->markLive(); }
uint64_t getFileOff() override { return Data->getFileOff() + Sym.getValue(); }
- bool isCOMDAT() const { return Data->isCOMDAT(); }
+ int compare(SymbolBody *Other) override;
+
+private:
+ StringRef Name;
+ COFFObjectFile *COFFFile;
+ COFFSymbolRef Sym;
+ Chunk *Data;
+};
+
+class DefinedCOMDAT : public Defined {
+public:
+ DefinedCOMDAT(COFFObjectFile *F, COFFSymbolRef S, Chunk *C)
+ : Defined(DefinedCOMDATKind), COFFFile(F), Sym(S), Data(C) {}
+
+ static bool classof(const SymbolBody *S) {
+ return S->kind() == DefinedCOMDATKind;
+ }
+
+ StringRef getName() override;
+ uint64_t getRVA() override { return Data->getRVA() + Sym.getValue(); }
+ bool isExternal() override { return Sym.isExternal(); }
+ void markLive() override { Data->markLive(); }
+ uint64_t getFileOff() override { return Data->getFileOff() + Sym.getValue(); }
int compare(SymbolBody *Other) override;
private:
More information about the llvm-commits
mailing list