Allocate LayoutInputSections using SpecificBumpPtrAllocator.
llvm-svn: 278453
This commit is contained in:
parent
bdf836db1b
commit
f34d0e0875
|
@ -89,6 +89,9 @@ template <class ELFT> static bool isDiscarded(InputSectionBase<ELFT> *S) {
|
||||||
return !S || !S->Live;
|
return !S || !S->Live;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class ELFT> LinkerScript<ELFT>::LinkerScript() {}
|
||||||
|
template <class ELFT> LinkerScript<ELFT>::~LinkerScript() {}
|
||||||
|
|
||||||
template <class ELFT>
|
template <class ELFT>
|
||||||
bool LinkerScript<ELFT>::shouldKeep(InputSectionBase<ELFT> *S) {
|
bool LinkerScript<ELFT>::shouldKeep(InputSectionBase<ELFT> *S) {
|
||||||
for (StringRef Pat : Opt.KeptSections)
|
for (StringRef Pat : Opt.KeptSections)
|
||||||
|
@ -132,8 +135,6 @@ LinkerScript<ELFT>::getInputSections(const InputSectionDescription *I) {
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
// You can define new symbols using linker scripts. For example,
|
// You can define new symbols using linker scripts. For example,
|
||||||
// ".text { abc.o(.text); foo = .; def.o(.text); }" defines symbol
|
// ".text { abc.o(.text); foo = .; def.o(.text); }" defines symbol
|
||||||
// foo just after abc.o's text section contents. This class is to
|
// foo just after abc.o's text section contents. This class is to
|
||||||
|
@ -143,9 +144,10 @@ namespace {
|
||||||
// keep symbol definitions in output sections. Because output sections
|
// keep symbol definitions in output sections. Because output sections
|
||||||
// can contain only input sections, we wrap symbol definitions
|
// can contain only input sections, we wrap symbol definitions
|
||||||
// with dummy input sections. This class serves that purpose.
|
// with dummy input sections. This class serves that purpose.
|
||||||
template <class ELFT> class LayoutInputSection : public InputSectionBase<ELFT> {
|
template <class ELFT>
|
||||||
|
class elf::LayoutInputSection : public InputSectionBase<ELFT> {
|
||||||
public:
|
public:
|
||||||
LayoutInputSection(SymbolAssignment *Cmd);
|
explicit LayoutInputSection(SymbolAssignment *Cmd);
|
||||||
static bool classof(const InputSectionBase<ELFT> *S);
|
static bool classof(const InputSectionBase<ELFT> *S);
|
||||||
SymbolAssignment *Cmd;
|
SymbolAssignment *Cmd;
|
||||||
|
|
||||||
|
@ -155,6 +157,7 @@ private:
|
||||||
|
|
||||||
// Helper class, which builds output section list, also
|
// Helper class, which builds output section list, also
|
||||||
// creating symbol sections, when needed
|
// creating symbol sections, when needed
|
||||||
|
namespace {
|
||||||
template <class ELFT> class OutputSectionBuilder {
|
template <class ELFT> class OutputSectionBuilder {
|
||||||
public:
|
public:
|
||||||
OutputSectionBuilder(OutputSectionFactory<ELFT> &F,
|
OutputSectionBuilder(OutputSectionFactory<ELFT> &F,
|
||||||
|
@ -162,9 +165,7 @@ public:
|
||||||
: Factory(F), OutputSections(Out) {}
|
: Factory(F), OutputSections(Out) {}
|
||||||
|
|
||||||
void addSection(StringRef OutputName, InputSectionBase<ELFT> *I);
|
void addSection(StringRef OutputName, InputSectionBase<ELFT> *I);
|
||||||
void addSymbol(SymbolAssignment *Cmd) {
|
void addSymbol(LayoutInputSection<ELFT> *S) { PendingSymbols.push_back(S); }
|
||||||
PendingSymbols.emplace_back(new LayoutInputSection<ELFT>(Cmd));
|
|
||||||
}
|
|
||||||
void flushSymbols();
|
void flushSymbols();
|
||||||
void flushSection();
|
void flushSection();
|
||||||
|
|
||||||
|
@ -172,14 +173,8 @@ private:
|
||||||
OutputSectionFactory<ELFT> &Factory;
|
OutputSectionFactory<ELFT> &Factory;
|
||||||
std::vector<OutputSectionBase<ELFT> *> *OutputSections;
|
std::vector<OutputSectionBase<ELFT> *> *OutputSections;
|
||||||
OutputSectionBase<ELFT> *Current = nullptr;
|
OutputSectionBase<ELFT> *Current = nullptr;
|
||||||
std::vector<std::unique_ptr<LayoutInputSection<ELFT>>> PendingSymbols;
|
std::vector<LayoutInputSection<ELFT> *> PendingSymbols;
|
||||||
static std::vector<std::unique_ptr<LayoutInputSection<ELFT>>> OwningSections;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class ELFT>
|
|
||||||
std::vector<std::unique_ptr<LayoutInputSection<ELFT>>>
|
|
||||||
OutputSectionBuilder<ELFT>::OwningSections;
|
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
template <class T> static T *zero(T *Val) {
|
template <class T> static T *zero(T *Val) {
|
||||||
|
@ -215,14 +210,12 @@ void OutputSectionBuilder<ELFT>::addSection(StringRef OutputName,
|
||||||
template <class ELFT> void OutputSectionBuilder<ELFT>::flushSymbols() {
|
template <class ELFT> void OutputSectionBuilder<ELFT>::flushSymbols() {
|
||||||
// Only regular output sections are supported.
|
// Only regular output sections are supported.
|
||||||
if (dyn_cast_or_null<OutputSection<ELFT>>(Current)) {
|
if (dyn_cast_or_null<OutputSection<ELFT>>(Current)) {
|
||||||
for (std::unique_ptr<LayoutInputSection<ELFT>> &I : PendingSymbols) {
|
for (LayoutInputSection<ELFT> *I : PendingSymbols) {
|
||||||
if (I->Cmd->Name == ".") {
|
if (I->Cmd->Name == ".") {
|
||||||
Current->addSection(I.get());
|
Current->addSection(I);
|
||||||
OwningSections.push_back(std::move(I));
|
|
||||||
} else if (shouldDefine<ELFT>(I->Cmd)) {
|
} else if (shouldDefine<ELFT>(I->Cmd)) {
|
||||||
addSynthetic<ELFT>(I->Cmd, Current);
|
addSynthetic<ELFT>(I->Cmd, Current);
|
||||||
Current->addSection(I.get());
|
Current->addSection(I);
|
||||||
OwningSections.push_back(std::move(I));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -282,7 +275,8 @@ void LinkerScript<ELFT>::createSections(
|
||||||
}
|
}
|
||||||
for (const std::unique_ptr<BaseCommand> &Base2 : Cmd->Commands) {
|
for (const std::unique_ptr<BaseCommand> &Base2 : Cmd->Commands) {
|
||||||
if (auto *Cmd2 = dyn_cast<SymbolAssignment>(Base2.get())) {
|
if (auto *Cmd2 = dyn_cast<SymbolAssignment>(Base2.get())) {
|
||||||
Builder.addSymbol(Cmd2);
|
Builder.addSymbol(new (LAlloc.Allocate())
|
||||||
|
LayoutInputSection<ELFT>(Cmd2));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto *Cmd2 = cast<InputSectionDescription>(Base2.get());
|
auto *Cmd2 = cast<InputSectionDescription>(Base2.get());
|
||||||
|
|
|
@ -25,6 +25,7 @@ template <class ELFT> class InputSectionBase;
|
||||||
template <class ELFT> class OutputSectionBase;
|
template <class ELFT> class OutputSectionBase;
|
||||||
template <class ELFT> class OutputSectionFactory;
|
template <class ELFT> class OutputSectionFactory;
|
||||||
template <class ELFT> class DefinedCommon;
|
template <class ELFT> class DefinedCommon;
|
||||||
|
template <class ELFT> class LayoutInputSection;
|
||||||
|
|
||||||
typedef std::function<uint64_t(uint64_t)> Expr;
|
typedef std::function<uint64_t(uint64_t)> Expr;
|
||||||
|
|
||||||
|
@ -138,6 +139,8 @@ template <class ELFT> class LinkerScript {
|
||||||
typedef typename ELFT::uint uintX_t;
|
typedef typename ELFT::uint uintX_t;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
LinkerScript();
|
||||||
|
~LinkerScript();
|
||||||
void createSections(OutputSectionFactory<ELFT> &Factory);
|
void createSections(OutputSectionFactory<ELFT> &Factory);
|
||||||
|
|
||||||
std::vector<PhdrEntry<ELFT>> createPhdrs();
|
std::vector<PhdrEntry<ELFT>> createPhdrs();
|
||||||
|
@ -167,6 +170,8 @@ private:
|
||||||
std::vector<size_t> getPhdrIndices(StringRef SectionName);
|
std::vector<size_t> getPhdrIndices(StringRef SectionName);
|
||||||
size_t getPhdrIndex(StringRef PhdrName);
|
size_t getPhdrIndex(StringRef PhdrName);
|
||||||
|
|
||||||
|
llvm::SpecificBumpPtrAllocator<LayoutInputSection<ELFT>> LAlloc;
|
||||||
|
|
||||||
uintX_t Dot;
|
uintX_t Dot;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue