aboutsummaryrefslogtreecommitdiffstats
path: root/ELF/OutputSections.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-05-08 17:13:44 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-05-08 17:13:44 +0000
commitfbe69f787ace06f44b6cb1bd3cd45ac703a16a05 (patch)
tree71baf2dfe04008283f87b4c0ae75a2268033cd62 /ELF/OutputSections.cpp
parentd803cda42997f42649910309ac18170d2d6f2214 (diff)
downloadsrc-fbe69f787ace06f44b6cb1bd3cd45ac703a16a05.tar.gz
src-fbe69f787ace06f44b6cb1bd3cd45ac703a16a05.zip
Vendor import of lld trunk r302418:vendor/lld/lld-trunk-r302418
Notes
Notes: svn path=/vendor/lld/dist/; revision=317957 svn path=/vendor/lld/lld-trunk-r302418/; revision=317958; tag=vendor/lld/lld-trunk-r302418
Diffstat (limited to 'ELF/OutputSections.cpp')
-rw-r--r--ELF/OutputSections.cpp24
1 files changed, 17 insertions, 7 deletions
diff --git a/ELF/OutputSections.cpp b/ELF/OutputSections.cpp
index 839f68f2da55..cb9c57657af3 100644
--- a/ELF/OutputSections.cpp
+++ b/ELF/OutputSections.cpp
@@ -68,7 +68,8 @@ void OutputSection::writeHeaderTo(typename ELFT::Shdr *Shdr) {
OutputSection::OutputSection(StringRef Name, uint32_t Type, uint64_t Flags)
: SectionBase(Output, Name, Flags, /*Entsize*/ 0, /*Alignment*/ 1, Type,
/*Info*/ 0,
- /*Link*/ 0) {}
+ /*Link*/ 0),
+ SectionIndex(INT_MAX) {}
static bool compareByFilePosition(InputSection *A, InputSection *B) {
// Synthetic doesn't have link order dependecy, stable_sort will keep it last
@@ -139,12 +140,24 @@ template <class ELFT> void OutputSection::finalize() {
this->Info = S->OutSec->SectionIndex;
}
+static uint64_t updateOffset(uint64_t Off, InputSection *S) {
+ Off = alignTo(Off, S->Alignment);
+ S->OutSecOff = Off;
+ return Off + S->getSize();
+}
+
void OutputSection::addSection(InputSection *S) {
assert(S->Live);
Sections.push_back(S);
S->OutSec = this;
this->updateAlignment(S->Alignment);
+ // The actual offsets will be computed by assignAddresses. For now, use
+ // crude approximation so that it is at least easy for other code to know the
+ // section order. It is also used to calculate the output section size early
+ // for compressed debug sections.
+ this->Size = updateOffset(Size, S);
+
// If this section contains a table of fixed-size entries, sh_entsize
// holds the element size. Consequently, if this contains two or more
// input sections, all of them must have the same sh_entsize. However,
@@ -159,11 +172,8 @@ void OutputSection::addSection(InputSection *S) {
// and scan relocations to setup sections' offsets.
void OutputSection::assignOffsets() {
uint64_t Off = 0;
- for (InputSection *S : Sections) {
- Off = alignTo(Off, S->Alignment);
- S->OutSecOff = Off;
- Off += S->getSize();
- }
+ for (InputSection *S : Sections)
+ Off = updateOffset(Off, S);
this->Size = Off;
}
@@ -305,7 +315,7 @@ template <class ELFT> void OutputSection::writeTo(uint8_t *Buf) {
// Linker scripts may have BYTE()-family commands with which you
// can write arbitrary bytes to the output. Process them if any.
- Script->writeDataBytes(Name, Buf);
+ Script->writeDataBytes(this, Buf);
}
static uint64_t getOutFlags(InputSectionBase *S) {