forked from OSchip/llvm-project
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:
parent
3b95157090
commit
4f2f50dc64
|
@ -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 we already know section then we can calculate symbol value immediately.
|
||||||
if (Sec)
|
if (Sec)
|
||||||
cast<DefinedSynthetic<ELFT>>(Cmd->Sym)->Value =
|
cast<DefinedSynthetic>(Cmd->Sym)->Value = Cmd->Expression(0) - Sec->Addr;
|
||||||
Cmd->Expression(0) - Sec->Addr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isUnderSysroot(StringRef Path) {
|
static bool isUnderSysroot(StringRef Path) {
|
||||||
|
@ -395,7 +394,7 @@ static void assignSectionSymbol(SymbolAssignment *Cmd,
|
||||||
if (!Cmd->Sym)
|
if (!Cmd->Sym)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (auto *Body = dyn_cast<DefinedSynthetic<ELFT>>(Cmd->Sym)) {
|
if (auto *Body = dyn_cast<DefinedSynthetic>(Cmd->Sym)) {
|
||||||
Body->Section = Cmd->Expression.Section();
|
Body->Section = Cmd->Expression.Section();
|
||||||
Body->Value = Cmd->Expression(Value) - Body->Section->Addr;
|
Body->Value = Cmd->Expression(Value) - Body->Section->Addr;
|
||||||
return;
|
return;
|
||||||
|
@ -933,7 +932,7 @@ const OutputSectionBase *LinkerScript<ELFT>::getSymbolSection(StringRef S) {
|
||||||
|
|
||||||
if (auto *DR = dyn_cast_or_null<DefinedRegular<ELFT>>(Sym))
|
if (auto *DR = dyn_cast_or_null<DefinedRegular<ELFT>>(Sym))
|
||||||
return DR->Section ? DR->Section->OutSec : nullptr;
|
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 DS->Section;
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -406,7 +406,7 @@ Symbol *SymbolTable<ELFT>::addSynthetic(StringRef N,
|
||||||
int Cmp = compareDefinedNonCommon<ELFT>(S, WasInserted, STB_GLOBAL,
|
int Cmp = compareDefinedNonCommon<ELFT>(S, WasInserted, STB_GLOBAL,
|
||||||
/*IsAbsolute*/ false, /*Value*/ 0);
|
/*IsAbsolute*/ false, /*Value*/ 0);
|
||||||
if (Cmp > 0)
|
if (Cmp > 0)
|
||||||
replaceBody<DefinedSynthetic<ELFT>>(S, N, Value, Section);
|
replaceBody<DefinedSynthetic>(S, N, Value, Section);
|
||||||
else if (Cmp == 0)
|
else if (Cmp == 0)
|
||||||
reportDuplicate(S->body(), nullptr);
|
reportDuplicate(S->body(), nullptr);
|
||||||
return S;
|
return S;
|
||||||
|
|
|
@ -35,11 +35,11 @@ static typename ELFT::uint getSymVA(const SymbolBody &Body,
|
||||||
|
|
||||||
switch (Body.kind()) {
|
switch (Body.kind()) {
|
||||||
case SymbolBody::DefinedSyntheticKind: {
|
case SymbolBody::DefinedSyntheticKind: {
|
||||||
auto &D = cast<DefinedSynthetic<ELFT>>(Body);
|
auto &D = cast<DefinedSynthetic>(Body);
|
||||||
const OutputSectionBase *Sec = D.Section;
|
const OutputSectionBase *Sec = D.Section;
|
||||||
if (!Sec)
|
if (!Sec)
|
||||||
return D.Value;
|
return D.Value;
|
||||||
if (D.Value == DefinedSynthetic<ELFT>::SectionEnd)
|
if (D.Value == uintX_t(-1))
|
||||||
return Sec->Addr + Sec->Size;
|
return Sec->Addr + Sec->Size;
|
||||||
return Sec->Addr + D.Value;
|
return Sec->Addr + D.Value;
|
||||||
}
|
}
|
||||||
|
@ -238,13 +238,6 @@ Undefined::Undefined(StringRefZ Name, bool IsLocal, uint8_t StOther,
|
||||||
this->File = File;
|
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,
|
DefinedCommon::DefinedCommon(StringRef Name, uint64_t Size, uint64_t Alignment,
|
||||||
uint8_t StOther, uint8_t Type, InputFile *File)
|
uint8_t StOther, uint8_t Type, InputFile *File)
|
||||||
: Defined(SymbolBody::DefinedCommonKind, Name, /*IsLocal=*/false, StOther,
|
: 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<ELF32BE>;
|
||||||
template class elf::DefinedRegular<ELF64LE>;
|
template class elf::DefinedRegular<ELF64LE>;
|
||||||
template class elf::DefinedRegular<ELF64BE>;
|
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>;
|
|
||||||
|
|
|
@ -220,21 +220,19 @@ InputSectionBase<ELFT> *DefinedRegular<ELFT>::NullInputSection;
|
||||||
// don't belong to any input files or sections. Thus, its constructor
|
// don't belong to any input files or sections. Thus, its constructor
|
||||||
// takes an output section to calculate output VA, etc.
|
// takes an output section to calculate output VA, etc.
|
||||||
// If Section is null, this symbol is relative to the image base.
|
// If Section is null, this symbol is relative to the image base.
|
||||||
template <class ELFT> class DefinedSynthetic : public Defined {
|
class DefinedSynthetic : public Defined {
|
||||||
public:
|
public:
|
||||||
typedef typename ELFT::uint uintX_t;
|
DefinedSynthetic(StringRef Name, uint64_t Value,
|
||||||
DefinedSynthetic(StringRef N, uintX_t Value,
|
const OutputSectionBase *Section)
|
||||||
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) {
|
static bool classof(const SymbolBody *S) {
|
||||||
return S->kind() == SymbolBody::DefinedSyntheticKind;
|
return S->kind() == SymbolBody::DefinedSyntheticKind;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special value designates that the symbol 'points'
|
uint64_t Value;
|
||||||
// to the end of the section.
|
|
||||||
static const uintX_t SectionEnd = uintX_t(-1);
|
|
||||||
|
|
||||||
uintX_t Value;
|
|
||||||
const OutputSectionBase *Section;
|
const OutputSectionBase *Section;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -417,9 +415,9 @@ struct Symbol {
|
||||||
// assume that the size and alignment of ELF64LE symbols is sufficient for any
|
// assume that the size and alignment of ELF64LE symbols is sufficient for any
|
||||||
// ELFT, and we verify this with the static_asserts in replaceBody.
|
// ELFT, and we verify this with the static_asserts in replaceBody.
|
||||||
llvm::AlignedCharArrayUnion<
|
llvm::AlignedCharArrayUnion<
|
||||||
DefinedCommon, DefinedRegular<llvm::object::ELF64LE>,
|
DefinedCommon, DefinedRegular<llvm::object::ELF64LE>, DefinedSynthetic,
|
||||||
DefinedSynthetic<llvm::object::ELF64LE>, Undefined,
|
Undefined, SharedSymbol<llvm::object::ELF64LE>, LazyArchive, LazyObject>
|
||||||
SharedSymbol<llvm::object::ELF64LE>, LazyArchive, LazyObject> Body;
|
Body;
|
||||||
|
|
||||||
SymbolBody *body() { return reinterpret_cast<SymbolBody *>(Body.buffer); }
|
SymbolBody *body() { return reinterpret_cast<SymbolBody *>(Body.buffer); }
|
||||||
const SymbolBody *body() const { return const_cast<Symbol *>(this)->body(); }
|
const SymbolBody *body() const { return const_cast<Symbol *>(this)->body(); }
|
||||||
|
|
|
@ -1192,7 +1192,7 @@ const OutputSectionBase *
|
||||||
SymbolTableSection<ELFT>::getOutputSection(SymbolBody *Sym) {
|
SymbolTableSection<ELFT>::getOutputSection(SymbolBody *Sym) {
|
||||||
switch (Sym->kind()) {
|
switch (Sym->kind()) {
|
||||||
case SymbolBody::DefinedSyntheticKind:
|
case SymbolBody::DefinedSyntheticKind:
|
||||||
return cast<DefinedSynthetic<ELFT>>(Sym)->Section;
|
return cast<DefinedSynthetic>(Sym)->Section;
|
||||||
case SymbolBody::DefinedRegularKind: {
|
case SymbolBody::DefinedRegularKind: {
|
||||||
auto &D = cast<DefinedRegular<ELFT>>(*Sym);
|
auto &D = cast<DefinedRegular<ELFT>>(*Sym);
|
||||||
if (D.Section)
|
if (D.Section)
|
||||||
|
|
|
@ -1089,9 +1089,9 @@ template <class ELFT> void Writer<ELFT>::addPredefinedSections() {
|
||||||
template <class ELFT> void Writer<ELFT>::addStartEndSymbols() {
|
template <class ELFT> void Writer<ELFT>::addStartEndSymbols() {
|
||||||
auto Define = [&](StringRef Start, StringRef End, OutputSectionBase *OS) {
|
auto Define = [&](StringRef Start, StringRef End, OutputSectionBase *OS) {
|
||||||
// These symbols resolve to the image base if the section does not exist.
|
// 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>(Start, OS, 0);
|
||||||
addOptionalSynthetic<ELFT>(End, OS,
|
addOptionalSynthetic<ELFT>(End, OS, OS ? -1 : 0);
|
||||||
OS ? DefinedSynthetic<ELFT>::SectionEnd : 0);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Define("__preinit_array_start", "__preinit_array_end",
|
Define("__preinit_array_start", "__preinit_array_end",
|
||||||
|
@ -1114,8 +1114,7 @@ void Writer<ELFT>::addStartStopSymbols(OutputSectionBase *Sec) {
|
||||||
if (!isValidCIdentifier(S))
|
if (!isValidCIdentifier(S))
|
||||||
return;
|
return;
|
||||||
addOptionalSynthetic<ELFT>(Saver.save("__start_" + S), Sec, 0, STV_DEFAULT);
|
addOptionalSynthetic<ELFT>(Saver.save("__start_" + S), Sec, 0, STV_DEFAULT);
|
||||||
addOptionalSynthetic<ELFT>(Saver.save("__stop_" + S), Sec,
|
addOptionalSynthetic<ELFT>(Saver.save("__stop_" + S), Sec, -1, STV_DEFAULT);
|
||||||
DefinedSynthetic<ELFT>::SectionEnd, STV_DEFAULT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
|
|
Loading…
Reference in New Issue