aboutsummaryrefslogtreecommitdiffstats
path: root/ELF
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-06-03 15:21:18 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-06-03 15:21:18 +0000
commitb9a1baec33e911ca24f51abf882d454e62047ea6 (patch)
treed426cb84117bdb3ec63a7bef741444456d30e414 /ELF
parent80350c116f86dbb87e055a630b1b2be0c66b244b (diff)
downloadsrc-b9a1baec33e911ca24f51abf882d454e62047ea6.tar.gz
src-b9a1baec33e911ca24f51abf882d454e62047ea6.zip
Vendor import of lld trunk r304659:vendor/lld/lld-trunk-r304659
Notes
Notes: svn path=/vendor/lld/dist/; revision=319531 svn path=/vendor/lld/lld-trunk-r304659/; revision=319532; tag=vendor/lld/lld-trunk-r304659
Diffstat (limited to 'ELF')
-rw-r--r--ELF/LinkerScript.cpp7
-rw-r--r--ELF/OutputSections.cpp1
-rw-r--r--ELF/OutputSections.h4
-rw-r--r--ELF/Writer.cpp32
4 files changed, 23 insertions, 21 deletions
diff --git a/ELF/LinkerScript.cpp b/ELF/LinkerScript.cpp
index 75df2cd4bd5c..1ced3e8e8d71 100644
--- a/ELF/LinkerScript.cpp
+++ b/ELF/LinkerScript.cpp
@@ -463,12 +463,7 @@ void LinkerScript::fabricateDefaultCommands() {
// Prefer user supplied address over additional alignment constraint
auto I = Config->SectionStartMap.find(Sec->Name);
if (I != Config->SectionStartMap.end())
- Commands.push_back(
- make<SymbolAssignment>(".", [=] { return I->second; }, ""));
- else if (Sec->PageAlign)
- OSCmd->AddrExpr = [=] {
- return alignTo(Script->getDot(), Config->MaxPageSize);
- };
+ OSCmd->AddrExpr = [=] { return I->second; };
Commands.push_back(OSCmd);
if (Sec->Sections.size()) {
diff --git a/ELF/OutputSections.cpp b/ELF/OutputSections.cpp
index 4f8906a32081..8357d6b03bb1 100644
--- a/ELF/OutputSections.cpp
+++ b/ELF/OutputSections.cpp
@@ -128,6 +128,7 @@ template <class ELFT> void OutputSection::finalize() {
// the section to which the relocation applies.
InputSectionBase *S = First->getRelocatedSection();
Info = S->getOutputSection()->SectionIndex;
+ Flags |= SHF_INFO_LINK;
}
static uint64_t updateOffset(uint64_t Off, InputSection *S) {
diff --git a/ELF/OutputSections.h b/ELF/OutputSections.h
index 326348cd5a20..0f2fe68ca708 100644
--- a/ELF/OutputSections.h
+++ b/ELF/OutputSections.h
@@ -59,10 +59,6 @@ public:
Alignment = Val;
}
- // If true, this section will be page aligned on disk.
- // Typically the first section of each PT_LOAD segment has this flag.
- bool PageAlign = false;
-
// Pointer to the first section in PT_LOAD segment, which this section
// also resides in. This field is used to correctly compute file offset
// of a section. When two sections share the same load segment, difference
diff --git a/ELF/Writer.cpp b/ELF/Writer.cpp
index 258d5e26ef7f..f68e07fc69d7 100644
--- a/ELF/Writer.cpp
+++ b/ELF/Writer.cpp
@@ -257,19 +257,20 @@ template <class ELFT> void Writer<ELFT>::run() {
if (ErrorCount)
return;
- if (!Script->Opt.HasSections) {
- if (!Config->Relocatable)
- fixSectionAlignments();
+ if (!Script->Opt.HasSections)
Script->fabricateDefaultCommands();
- } else {
+ else
Script->synchronize();
- }
for (BaseCommand *Base : Script->Opt.Commands)
if (auto *Cmd = dyn_cast<OutputSectionCommand>(Base))
OutputSectionCommands.push_back(Cmd);
clearOutputSections();
+
+ if (!Script->Opt.HasSections &&!Config->Relocatable)
+ fixSectionAlignments();
+
// If -compressed-debug-sections is specified, we need to compress
// .debug_* sections. Do it right now because it changes the size of
// output sections.
@@ -1504,24 +1505,33 @@ void Writer<ELFT>::addPtArmExid(std::vector<PhdrEntry> &Phdrs) {
// first section after PT_GNU_RELRO have to be page aligned so that the dynamic
// linker can set the permissions.
template <class ELFT> void Writer<ELFT>::fixSectionAlignments() {
+ auto PageAlign = [](OutputSection *Sec) {
+ OutputSectionCommand *Cmd = Script->getCmd(Sec);
+ if (Cmd && !Cmd->AddrExpr)
+ Cmd->AddrExpr = [=] {
+ return alignTo(Script->getDot(), Config->MaxPageSize);
+ };
+ };
+
for (const PhdrEntry &P : Phdrs)
if (P.p_type == PT_LOAD && P.First)
- P.First->PageAlign = true;
+ PageAlign(P.First);
for (const PhdrEntry &P : Phdrs) {
if (P.p_type != PT_GNU_RELRO)
continue;
if (P.First)
- P.First->PageAlign = true;
+ PageAlign(P.First);
// Find the first section after PT_GNU_RELRO. If it is in a PT_LOAD we
// have to align it to a page.
- auto End = OutputSections.end();
- auto I = std::find(OutputSections.begin(), End, P.Last);
+ auto End = OutputSectionCommands.end();
+ auto I =
+ std::find(OutputSectionCommands.begin(), End, Script->getCmd(P.Last));
if (I == End || (I + 1) == End)
continue;
- OutputSection *Sec = *(I + 1);
+ OutputSection *Sec = (*(I + 1))->Sec;
if (needsPtLoad(Sec))
- Sec->PageAlign = true;
+ PageAlign(Sec);
}
}