[lld] r276141 - Simplify output section ownership.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 20 10:19:03 PDT 2016
Author: ruiu
Date: Wed Jul 20 12:19:03 2016
New Revision: 276141
URL: http://llvm.org/viewvc/llvm-project?rev=276141&view=rev
Log:
Simplify output section ownership.
This patch simplifies output section management by making
Factory class have ownership of sections that creates.
Differential Revision: https://reviews.llvm.org/D22575
Modified:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/ELF/LinkerScript.h
lld/trunk/ELF/OutputSections.cpp
lld/trunk/ELF/OutputSections.h
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=276141&r1=276140&r2=276141&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Wed Jul 20 12:19:03 2016
@@ -208,9 +208,10 @@ bool LinkerScript<ELFT>::shouldKeep(Inpu
}
template <class ELFT>
-std::vector<std::unique_ptr<OutputSectionBase<ELFT>>>
+std::vector<OutputSectionBase<ELFT> *>
LinkerScript<ELFT>::createSections(OutputSectionFactory<ELFT> &Factory) {
- std::vector<std::unique_ptr<OutputSectionBase<ELFT>>> Result;
+ std::vector<OutputSectionBase<ELFT> *> Result;
+
// Add input section to output section. If there is no output section yet,
// then create it and add to output section list.
auto AddInputSec = [&](InputSectionBase<ELFT> *C, StringRef Name) {
@@ -218,7 +219,7 @@ LinkerScript<ELFT>::createSections(Outpu
bool IsNew;
std::tie(Sec, IsNew) = Factory.create(C, Name);
if (IsNew)
- Result.emplace_back(Sec);
+ Result.push_back(Sec);
Sec->addSection(C);
};
Modified: lld/trunk/ELF/LinkerScript.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.h?rev=276141&r1=276140&r2=276141&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.h (original)
+++ lld/trunk/ELF/LinkerScript.h Wed Jul 20 12:19:03 2016
@@ -92,12 +92,13 @@ template <class ELFT> class LinkerScript
public:
typedef PhdrEntry<ELFT> Phdr;
+ std::vector<OutputSectionBase<ELFT> *>
+ createSections(OutputSectionFactory<ELFT> &Factory);
+
StringRef getOutputSection(InputSectionBase<ELFT> *S);
ArrayRef<uint8_t> getFiller(StringRef Name);
bool isDiscarded(InputSectionBase<ELFT> *S);
bool shouldKeep(InputSectionBase<ELFT> *S);
- std::vector<std::unique_ptr<OutputSectionBase<ELFT>>>
- createSections(OutputSectionFactory<ELFT> &Factory);
void assignAddresses(ArrayRef<OutputSectionBase<ELFT> *> S);
int compareSections(StringRef A, StringRef B);
void addScriptedSymbols();
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=276141&r1=276140&r2=276141&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Wed Jul 20 12:19:03 2016
@@ -1770,6 +1770,7 @@ OutputSectionFactory<ELFT>::create(Input
Sec = new MipsOptionsOutputSection<ELFT>();
break;
}
+ OwningSections.emplace_back(Sec);
return {Sec, true};
}
Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=276141&r1=276140&r2=276141&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Wed Jul 20 12:19:03 2016
@@ -685,6 +685,7 @@ private:
Key createKey(InputSectionBase<ELFT> *C, StringRef OutsecName);
llvm::SmallDenseMap<Key, OutputSectionBase<ELFT> *> Map;
+ std::vector<std::unique_ptr<OutputSectionBase<ELFT>>> OwningSections;
};
template <class ELFT> BuildIdSection<ELFT> *Out<ELFT>::BuildId;
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=276141&r1=276140&r2=276141&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed Jul 20 12:19:03 2016
@@ -48,7 +48,7 @@ private:
void copyLocalSymbols();
void addReservedSymbols();
- std::vector<std::unique_ptr<OutputSectionBase<ELFT>>> createSections();
+ std::vector<OutputSectionBase<ELFT> *> createSections();
void finalizeSections();
void addPredefinedSections();
bool needsGot();
@@ -218,13 +218,9 @@ template <class ELFT> void Writer<ELFT>:
copyLocalSymbols();
addReservedSymbols();
- std::vector<std::unique_ptr<OutputSectionBase<ELFT>>> Sections =
- ScriptConfig->DoLayout ? Script<ELFT>::X->createSections(Factory)
- : createSections();
-
- for (std::unique_ptr<OutputSectionBase<ELFT>> &S : Sections)
- OutputSections.push_back(S.get());
-
+ OutputSections = ScriptConfig->DoLayout
+ ? Script<ELFT>::X->createSections(Factory)
+ : createSections();
finalizeSections();
if (HasError)
return;
@@ -637,9 +633,8 @@ template <class ELFT> static void sortCt
}
template <class ELFT>
-std::vector<std::unique_ptr<OutputSectionBase<ELFT>>>
-Writer<ELFT>::createSections() {
- std::vector<std::unique_ptr<OutputSectionBase<ELFT>>> Result;
+std::vector<OutputSectionBase<ELFT> *> Writer<ELFT>::createSections() {
+ std::vector<OutputSectionBase<ELFT> *> Result;
for (const std::unique_ptr<elf::ObjectFile<ELFT>> &F :
Symtab.getObjectFiles()) {
@@ -652,8 +647,7 @@ Writer<ELFT>::createSections() {
bool IsNew;
std::tie(Sec, IsNew) = Factory.create(C, getOutputSectionName(C));
if (IsNew)
- Result.emplace_back(Sec);
-
+ Result.push_back(Sec);
Sec->addSection(C);
}
}
More information about the llvm-commits
mailing list