diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2017-05-08 17:13:44 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2017-05-08 17:13:44 +0000 |
| commit | fbe69f787ace06f44b6cb1bd3cd45ac703a16a05 (patch) | |
| tree | 71baf2dfe04008283f87b4c0ae75a2268033cd62 /ELF/OutputSections.cpp | |
| parent | d803cda42997f42649910309ac18170d2d6f2214 (diff) | |
Notes
Diffstat (limited to 'ELF/OutputSections.cpp')
| -rw-r--r-- | ELF/OutputSections.cpp | 24 |
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) { |
