}
template <class ELFT>
-CommonInputSection<ELFT>::CommonInputSection(
- std::vector<DefinedCommon<ELFT> *> Syms)
+CommonInputSection<ELFT>::CommonInputSection(std::vector<DefinedCommon *> Syms)
: InputSection<ELFT>(nullptr, &Hdr) {
Hdr.sh_size = 0;
Hdr.sh_type = SHT_NOBITS;
this->Live = true;
// Sort the common symbols by alignment as an heuristic to pack them better.
- std::stable_sort(Syms.begin(), Syms.end(), [](const DefinedCommon<ELFT> *A,
- const DefinedCommon<ELFT> *B) {
- return A->Alignment > B->Alignment;
- });
+ std::stable_sort(Syms.begin(), Syms.end(),
+ [](const DefinedCommon *A, const DefinedCommon *B) {
+ return A->Alignment > B->Alignment;
+ });
- for (DefinedCommon<ELFT> *Sym : Syms) {
+ for (DefinedCommon *Sym : Syms) {
this->Alignment = std::max<uintX_t>(this->Alignment, Sym->Alignment);
Hdr.sh_size = alignTo(Hdr.sh_size, Sym->Alignment);
namespace lld {
namespace elf {
+class DefinedCommon;
class SymbolBody;
template <class ELFT> class ICF;
template <class ELFT> class DefinedRegular;
-template <class ELFT> class DefinedCommon;
template <class ELFT> class ObjectFile;
template <class ELFT> class OutputSection;
template <class ELFT> class OutputSectionBase;
typedef typename ELFT::uint uintX_t;
public:
- CommonInputSection(std::vector<DefinedCommon<ELFT> *> Syms);
+ CommonInputSection(std::vector<DefinedCommon *> Syms);
// The singleton instance of this class.
static CommonInputSection<ELFT> *X;
namespace lld {
namespace elf {
+class DefinedCommon;
class ScriptParser;
class SymbolBody;
template <class ELFT> class InputSectionBase;
template <class ELFT> class OutputSectionBase;
template <class ELFT> class OutputSectionFactory;
-template <class ELFT> class DefinedCommon;
template <class ELFT> class LayoutInputSection;
typedef std::function<uint64_t(uint64_t)> Expr;
// We have a new non-common defined symbol with the specified binding. Return 1
// if the new symbol should win, -1 if the new symbol should lose, or 0 if there
// is a conflict. If the new symbol wins, also update the binding.
-template <class ELFT>
static int compareDefinedNonCommon(Symbol *S, bool WasInserted,
uint8_t Binding) {
if (int Cmp = compareDefined(S, WasInserted, Binding)) {
S->Binding = Binding;
return Cmp;
}
- if (isa<DefinedCommon<ELFT>>(S->body())) {
+ if (isa<DefinedCommon>(S->body())) {
// Non-common symbols take precedence over common symbols.
if (Config->WarnCommon)
warning("common " + S->body()->getName() + " is overridden");
int Cmp = compareDefined(S, WasInserted, Binding);
if (Cmp > 0) {
S->Binding = Binding;
- replaceBody<DefinedCommon<ELFT>>(S, N, Size, Alignment, StOther, Type,
- File);
+ replaceBody<DefinedCommon>(S, N, Size, Alignment, StOther, Type, File);
} else if (Cmp == 0) {
- auto *C = dyn_cast<DefinedCommon<ELFT>>(S->body());
+ auto *C = dyn_cast<DefinedCommon>(S->body());
if (!C) {
// Non-common symbols take precedence over common symbols.
if (Config->WarnCommon)
Name, Sym.getType(), Sym.getVisibility(),
/*CanOmitFromDynSym*/ false, /*HasUnnamedAddr*/ false,
/*IsUsedInRegularObj*/ true, Section ? Section->getFile() : nullptr);
- int Cmp = compareDefinedNonCommon<ELFT>(S, WasInserted, Sym.getBinding());
+ int Cmp = compareDefinedNonCommon(S, WasInserted, Sym.getBinding());
if (Cmp > 0)
replaceBody<DefinedRegular<ELFT>>(S, Name, Sym, Section);
else if (Cmp == 0)
std::tie(S, WasInserted) =
insert(Name, STT_NOTYPE, StOther & 3, /*CanOmitFromDynSym*/ false,
/*HasUnnamedAddr*/ false, /*IsUsedInRegularObj*/ true, nullptr);
- int Cmp = compareDefinedNonCommon<ELFT>(S, WasInserted, Binding);
+ int Cmp = compareDefinedNonCommon(S, WasInserted, Binding);
if (Cmp > 0)
replaceBody<DefinedRegular<ELFT>>(S, Name, StOther);
else if (Cmp == 0)
/*CanOmitFromDynSym*/ false,
/*HasUnnamedAddr*/ false,
/*IsUsedInRegularObj*/ true, nullptr);
- int Cmp = compareDefinedNonCommon<ELFT>(S, WasInserted, STB_GLOBAL);
+ int Cmp = compareDefinedNonCommon(S, WasInserted, STB_GLOBAL);
if (Cmp > 0)
replaceBody<DefinedSynthetic<ELFT>>(S, N, Value, Section);
else if (Cmp == 0)
std::tie(S, WasInserted) =
insert(Name, Type, StOther & 3, CanOmitFromDynSym, HasUnnamedAddr,
/*IsUsedInRegularObj*/ false, F);
- int Cmp = compareDefinedNonCommon<ELFT>(S, WasInserted, Binding);
+ int Cmp = compareDefinedNonCommon(S, WasInserted, Binding);
if (Cmp > 0)
replaceBody<DefinedRegular<ELFT>>(S, Name, StOther, Type, F);
else if (Cmp == 0)
case SymbolBody::DefinedCommonKind:
return CommonInputSection<ELFT>::X->OutSec->getVA() +
CommonInputSection<ELFT>::X->OutSecOff +
- cast<DefinedCommon<ELFT>>(Body).Offset;
+ cast<DefinedCommon>(Body).Offset;
case SymbolBody::SharedKind: {
auto &SS = cast<SharedSymbol<ELFT>>(Body);
if (!SS.NeedsCopyOrPltAddr)
}
template <class ELFT> typename ELFT::uint SymbolBody::getSize() const {
- if (const auto *C = dyn_cast<DefinedCommon<ELFT>>(this))
+ if (const auto *C = dyn_cast<DefinedCommon>(this))
return C->Size;
if (const auto *DR = dyn_cast<DefinedRegular<ELFT>>(this))
return DR->Size;
: Defined(SymbolBody::DefinedSyntheticKind, N, STV_HIDDEN, 0 /* Type */),
Value(Value), Section(Section) {}
-template <class ELFT>
-DefinedCommon<ELFT>::DefinedCommon(StringRef N, uint64_t Size,
- uint64_t Alignment, uint8_t StOther,
- uint8_t Type, InputFile *File)
+DefinedCommon::DefinedCommon(StringRef N, uint64_t Size, uint64_t Alignment,
+ uint8_t StOther, uint8_t Type, InputFile *File)
: Defined(SymbolBody::DefinedCommonKind, N, StOther, Type),
Alignment(Alignment), Size(Size) {
this->File = File;
template class elf::DefinedSynthetic<ELF32BE>;
template class elf::DefinedSynthetic<ELF64LE>;
template class elf::DefinedSynthetic<ELF64BE>;
-
-template class elf::DefinedCommon<ELF32LE>;
-template class elf::DefinedCommon<ELF32BE>;
-template class elf::DefinedCommon<ELF64LE>;
-template class elf::DefinedCommon<ELF64BE>;
static bool classof(const SymbolBody *S) { return S->isDefined(); }
};
-template <class ELFT> class DefinedCommon : public Defined {
+class DefinedCommon : public Defined {
public:
DefinedCommon(StringRef N, uint64_t Size, uint64_t Alignment, uint8_t StOther,
uint8_t Type, InputFile *File);
// large and aligned enough to store any derived class of SymbolBody. We
// assume that the size and alignment of ELF64LE symbols is sufficient for any
// ELFT, and we verify this with the static_asserts in replaceBody.
- llvm::AlignedCharArrayUnion<DefinedCommon<llvm::object::ELF64LE>,
- DefinedRegular<llvm::object::ELF64LE>,
- DefinedSynthetic<llvm::object::ELF64LE>,
- Undefined, SharedSymbol<llvm::object::ELF64LE>,
- LazyArchive, LazyObject>
+ llvm::AlignedCharArrayUnion<
+ DefinedCommon, DefinedRegular<llvm::object::ELF64LE>,
+ DefinedSynthetic<llvm::object::ELF64LE>, Undefined,
+ SharedSymbol<llvm::object::ELF64LE>, LazyArchive, LazyObject>
Body;
SymbolBody *body() { return reinterpret_cast<SymbolBody *>(Body.buffer); }
Out<ELFT>::Pool.clear();
}
-template <class ELFT>
-static std::vector<DefinedCommon<ELFT> *> getCommonSymbols() {
- std::vector<DefinedCommon<ELFT> *> V;
+template <class ELFT> static std::vector<DefinedCommon *> getCommonSymbols() {
+ std::vector<DefinedCommon *> V;
for (Symbol *S : Symtab<ELFT>::X->getSymbols())
- if (auto *B = dyn_cast<DefinedCommon<ELFT>>(S->body()))
+ if (auto *B = dyn_cast<DefinedCommon>(S->body()))
V.push_back(B);
return V;
}