forked from OSchip/llvm-project
parent
997c31e54b
commit
e7553e4eac
|
@ -698,8 +698,7 @@ bool MipsAbiFlagsInputSection<ELFT>::classof(const InputSectionBase<ELFT> *S) {
|
|||
}
|
||||
|
||||
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;
|
||||
|
@ -707,12 +706,12 @@ CommonInputSection<ELFT>::CommonInputSection(
|
|||
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);
|
||||
|
||||
|
|
|
@ -21,11 +21,11 @@
|
|||
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;
|
||||
|
@ -287,7 +287,7 @@ template <class ELFT> class CommonInputSection : public InputSection<ELFT> {
|
|||
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;
|
||||
|
|
|
@ -20,12 +20,12 @@
|
|||
|
||||
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;
|
||||
|
|
|
@ -326,7 +326,6 @@ static int compareDefined(Symbol *S, bool WasInserted, uint8_t Binding) {
|
|||
// 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)) {
|
||||
|
@ -334,7 +333,7 @@ static int compareDefinedNonCommon(Symbol *S, bool WasInserted,
|
|||
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");
|
||||
|
@ -356,10 +355,9 @@ Symbol *SymbolTable<ELFT>::addCommon(StringRef N, uint64_t Size,
|
|||
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)
|
||||
|
@ -395,7 +393,7 @@ Symbol *SymbolTable<ELFT>::addRegular(StringRef Name, const Elf_Sym &Sym,
|
|||
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)
|
||||
|
@ -411,7 +409,7 @@ Symbol *SymbolTable<ELFT>::addRegular(StringRef Name, uint8_t Binding,
|
|||
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)
|
||||
|
@ -429,7 +427,7 @@ Symbol *SymbolTable<ELFT>::addSynthetic(StringRef N,
|
|||
/*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)
|
||||
|
@ -469,7 +467,7 @@ Symbol *SymbolTable<ELFT>::addBitcode(StringRef Name, uint8_t Binding,
|
|||
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)
|
||||
|
|
|
@ -66,7 +66,7 @@ static typename ELFT::uint getSymVA(const SymbolBody &Body,
|
|||
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)
|
||||
|
@ -175,7 +175,7 @@ template <class ELFT> typename ELFT::uint SymbolBody::getThunkVA() const {
|
|||
}
|
||||
|
||||
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;
|
||||
|
@ -208,10 +208,8 @@ DefinedSynthetic<ELFT>::DefinedSynthetic(StringRef N, uintX_t Value,
|
|||
: 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;
|
||||
|
@ -321,8 +319,3 @@ template class elf::DefinedSynthetic<ELF32LE>;
|
|||
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>;
|
||||
|
|
|
@ -158,7 +158,7 @@ public:
|
|||
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);
|
||||
|
@ -436,11 +436,10 @@ struct Symbol {
|
|||
// 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); }
|
||||
|
|
|
@ -229,11 +229,10 @@ template <class ELFT> void elf::writeResult() {
|
|||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue