De-template DefinedSynthetic.

DefinedSynthetic is not created for a real ELF object, so it doesn't
have to be a template function. It has a virtual st_value, which is
either 32 bit or 64 bit, but we can simply use 64 bit.

llvm-svn: 290241
This commit is contained in:
Rui Ueyama 2016-12-21 08:40:09 +00:00
parent 3b95157090
commit 4f2f50dc64
6 changed files with 20 additions and 36 deletions

View File

@ -78,8 +78,7 @@ template <class ELFT> static void addSynthetic(SymbolAssignment *Cmd) {
// If we already know section then we can calculate symbol value immediately.
if (Sec)
cast<DefinedSynthetic<ELFT>>(Cmd->Sym)->Value =
Cmd->Expression(0) - Sec->Addr;
cast<DefinedSynthetic>(Cmd->Sym)->Value = Cmd->Expression(0) - Sec->Addr;
}
static bool isUnderSysroot(StringRef Path) {
@ -395,7 +394,7 @@ static void assignSectionSymbol(SymbolAssignment *Cmd,
if (!Cmd->Sym)
return;
if (auto *Body = dyn_cast<DefinedSynthetic<ELFT>>(Cmd->Sym)) {
if (auto *Body = dyn_cast<DefinedSynthetic>(Cmd->Sym)) {
Body->Section = Cmd->Expression.Section();
Body->Value = Cmd->Expression(Value) - Body->Section->Addr;
return;
@ -933,7 +932,7 @@ const OutputSectionBase *LinkerScript<ELFT>::getSymbolSection(StringRef S) {
if (auto *DR = dyn_cast_or_null<DefinedRegular<ELFT>>(Sym))
return DR->Section ? DR->Section->OutSec : nullptr;
if (auto *DS = dyn_cast_or_null<DefinedSynthetic<ELFT>>(Sym))
if (auto *DS = dyn_cast_or_null<DefinedSynthetic>(Sym))
return DS->Section;
return nullptr;

View File

@ -406,7 +406,7 @@ Symbol *SymbolTable<ELFT>::addSynthetic(StringRef N,
int Cmp = compareDefinedNonCommon<ELFT>(S, WasInserted, STB_GLOBAL,
/*IsAbsolute*/ false, /*Value*/ 0);
if (Cmp > 0)
replaceBody<DefinedSynthetic<ELFT>>(S, N, Value, Section);
replaceBody<DefinedSynthetic>(S, N, Value, Section);
else if (Cmp == 0)
reportDuplicate(S->body(), nullptr);
return S;

View File

@ -35,11 +35,11 @@ static typename ELFT::uint getSymVA(const SymbolBody &Body,
switch (Body.kind()) {
case SymbolBody::DefinedSyntheticKind: {
auto &D = cast<DefinedSynthetic<ELFT>>(Body);
auto &D = cast<DefinedSynthetic>(Body);
const OutputSectionBase *Sec = D.Section;
if (!Sec)
return D.Value;
if (D.Value == DefinedSynthetic<ELFT>::SectionEnd)
if (D.Value == uintX_t(-1))
return Sec->Addr + Sec->Size;
return Sec->Addr + D.Value;
}
@ -238,13 +238,6 @@ Undefined::Undefined(StringRefZ Name, bool IsLocal, uint8_t StOther,
this->File = File;
}
template <typename ELFT>
DefinedSynthetic<ELFT>::DefinedSynthetic(StringRef Name, uintX_t Value,
const OutputSectionBase *Section)
: Defined(SymbolBody::DefinedSyntheticKind, Name, /*IsLocal=*/false,
STV_HIDDEN, 0 /* Type */),
Value(Value), Section(Section) {}
DefinedCommon::DefinedCommon(StringRef Name, uint64_t Size, uint64_t Alignment,
uint8_t StOther, uint8_t Type, InputFile *File)
: Defined(SymbolBody::DefinedCommonKind, Name, /*IsLocal=*/false, StOther,
@ -365,8 +358,3 @@ template class elf::DefinedRegular<ELF32LE>;
template class elf::DefinedRegular<ELF32BE>;
template class elf::DefinedRegular<ELF64LE>;
template class elf::DefinedRegular<ELF64BE>;
template class elf::DefinedSynthetic<ELF32LE>;
template class elf::DefinedSynthetic<ELF32BE>;
template class elf::DefinedSynthetic<ELF64LE>;
template class elf::DefinedSynthetic<ELF64BE>;

View File

@ -220,21 +220,19 @@ InputSectionBase<ELFT> *DefinedRegular<ELFT>::NullInputSection;
// don't belong to any input files or sections. Thus, its constructor
// takes an output section to calculate output VA, etc.
// If Section is null, this symbol is relative to the image base.
template <class ELFT> class DefinedSynthetic : public Defined {
class DefinedSynthetic : public Defined {
public:
typedef typename ELFT::uint uintX_t;
DefinedSynthetic(StringRef N, uintX_t Value,
const OutputSectionBase *Section);
DefinedSynthetic(StringRef Name, uint64_t Value,
const OutputSectionBase *Section)
: Defined(SymbolBody::DefinedSyntheticKind, Name, /*IsLocal=*/false,
llvm::ELF::STV_HIDDEN, 0 /* Type */),
Value(Value), Section(Section) {}
static bool classof(const SymbolBody *S) {
return S->kind() == SymbolBody::DefinedSyntheticKind;
}
// Special value designates that the symbol 'points'
// to the end of the section.
static const uintX_t SectionEnd = uintX_t(-1);
uintX_t Value;
uint64_t Value;
const OutputSectionBase *Section;
};
@ -417,9 +415,9 @@ struct Symbol {
// 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, DefinedRegular<llvm::object::ELF64LE>,
DefinedSynthetic<llvm::object::ELF64LE>, Undefined,
SharedSymbol<llvm::object::ELF64LE>, LazyArchive, LazyObject> Body;
DefinedCommon, DefinedRegular<llvm::object::ELF64LE>, DefinedSynthetic,
Undefined, SharedSymbol<llvm::object::ELF64LE>, LazyArchive, LazyObject>
Body;
SymbolBody *body() { return reinterpret_cast<SymbolBody *>(Body.buffer); }
const SymbolBody *body() const { return const_cast<Symbol *>(this)->body(); }

View File

@ -1192,7 +1192,7 @@ const OutputSectionBase *
SymbolTableSection<ELFT>::getOutputSection(SymbolBody *Sym) {
switch (Sym->kind()) {
case SymbolBody::DefinedSyntheticKind:
return cast<DefinedSynthetic<ELFT>>(Sym)->Section;
return cast<DefinedSynthetic>(Sym)->Section;
case SymbolBody::DefinedRegularKind: {
auto &D = cast<DefinedRegular<ELFT>>(*Sym);
if (D.Section)

View File

@ -1089,9 +1089,9 @@ template <class ELFT> void Writer<ELFT>::addPredefinedSections() {
template <class ELFT> void Writer<ELFT>::addStartEndSymbols() {
auto Define = [&](StringRef Start, StringRef End, OutputSectionBase *OS) {
// These symbols resolve to the image base if the section does not exist.
// A special value -1 indicates end of the section.
addOptionalSynthetic<ELFT>(Start, OS, 0);
addOptionalSynthetic<ELFT>(End, OS,
OS ? DefinedSynthetic<ELFT>::SectionEnd : 0);
addOptionalSynthetic<ELFT>(End, OS, OS ? -1 : 0);
};
Define("__preinit_array_start", "__preinit_array_end",
@ -1114,8 +1114,7 @@ void Writer<ELFT>::addStartStopSymbols(OutputSectionBase *Sec) {
if (!isValidCIdentifier(S))
return;
addOptionalSynthetic<ELFT>(Saver.save("__start_" + S), Sec, 0, STV_DEFAULT);
addOptionalSynthetic<ELFT>(Saver.save("__stop_" + S), Sec,
DefinedSynthetic<ELFT>::SectionEnd, STV_DEFAULT);
addOptionalSynthetic<ELFT>(Saver.save("__stop_" + S), Sec, -1, STV_DEFAULT);
}
template <class ELFT>