[lld] r244904 - Store the offset in the output section, no in the file.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 13 19:18:33 PDT 2015
Can you make the same change for COFF so that the two are not going to
unnecessarily diverge?
On Fri, Aug 14, 2015 at 12:54 AM, Rafael Espindola via llvm-commits <
llvm-commits at lists.llvm.org> wrote:
> Author: rafael
> Date: Thu Aug 13 10:54:36 2015
> New Revision: 244904
>
> URL: http://llvm.org/viewvc/llvm-project?rev=244904&view=rev
> Log:
> Store the offset in the output section, no in the file.
>
> That is the value that is stable as the we layout the output sections.
>
> Modified:
> lld/trunk/ELF/Chunks.cpp
> lld/trunk/ELF/Chunks.h
> lld/trunk/ELF/Writer.cpp
>
> Modified: lld/trunk/ELF/Chunks.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Chunks.cpp?rev=244904&r1=244903&r2=244904&view=diff
>
> ==============================================================================
> --- lld/trunk/ELF/Chunks.cpp (original)
> +++ lld/trunk/ELF/Chunks.cpp Thu Aug 13 10:54:36 2015
> @@ -33,7 +33,7 @@ template <class ELFT> void SectionChunk<
> return;
> // Copy section contents from source object file to output file.
> ArrayRef<uint8_t> Data = *Obj->getSectionContents(Header);
> - memcpy(Buf + FileOff, Data.data(), Data.size());
> + memcpy(Buf + OutputSectionOff, Data.data(), Data.size());
>
> // FIXME: Relocations
> }
>
> Modified: lld/trunk/ELF/Chunks.h
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Chunks.h?rev=244904&r1=244903&r2=244904&view=diff
>
> ==============================================================================
> --- lld/trunk/ELF/Chunks.h (original)
> +++ lld/trunk/ELF/Chunks.h Thu Aug 13 10:54:36 2015
> @@ -37,17 +37,18 @@ public:
> virtual void writeTo(uint8_t *Buf) = 0;
>
> // The writer sets and uses the addresses.
> - uint64_t getFileOff() { return FileOff; }
> + uint64_t getOutputSectionOff() { return OutputSectionOff; }
> uint32_t getAlign() { return Align; }
> - void setFileOff(uint64_t V) { FileOff = V; }
> + void setOutputSectionOff(uint64_t V) { OutputSectionOff = V; }
>
> // Returns the section name if this is a section chunk.
> // It is illegal to call this function on non-section chunks.
> virtual StringRef getSectionName() const = 0;
>
> protected:
> - // The offset from beginning of the output file. The writer sets a
> value.
> - uint64_t FileOff = 0;
> + // The offset from beginning of the output sections this chunk was
> assigned
> + // to. The writer sets a value.
> + uint64_t OutputSectionOff = 0;
>
> // The alignment of this chunk. The writer uses the value.
> uint32_t Align = 1;
>
> Modified: lld/trunk/ELF/Writer.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=244904&r1=244903&r2=244904&view=diff
>
> ==============================================================================
> --- lld/trunk/ELF/Writer.cpp (original)
> +++ lld/trunk/ELF/Writer.cpp Thu Aug 13 10:54:36 2015
> @@ -50,8 +50,8 @@ public:
>
> // Returns the size of the section in the output file.
> uintX_t getSize() { return Header.sh_size; }
> -
> uintX_t getFlags() { return Header.sh_flags; }
> + uintX_t getOffset() { return Header.sh_offset; }
>
> private:
> StringRef Name;
> @@ -122,8 +122,6 @@ template <class ELFT> void OutputSection
> if (Header.sh_size == 0)
> return;
> Header.sh_offset = Off;
> - for (Chunk *C : Chunks)
> - C->setFileOff(C->getFileOff() + Off);
> }
>
> template <class ELFT>
> @@ -131,7 +129,7 @@ void OutputSection<ELFT>::addSectionChun
> Chunks.push_back(C);
> uintX_t Off = Header.sh_size;
> Off = RoundUpToAlignment(Off, C->getAlign());
> - C->setFileOff(Off);
> + C->setOutputSectionOff(Off);
> Off += C->getSize();
> Header.sh_size = Off;
> Header.sh_type = C->getSectionHdr()->sh_type;
> @@ -275,8 +273,9 @@ template <class ELFT> void Writer<ELFT>:
> template <class ELFT> void Writer<ELFT>::writeSections() {
> uint8_t *Buf = Buffer->getBufferStart();
> for (OutputSection<ELFT> *Sec : OutputSections) {
> + uint8_t *SecBuf = Buf + Sec->getOffset();
> for (Chunk *C : Sec->getChunks())
> - C->writeTo(Buf);
> + C->writeTo(SecBuf);
> }
>
> // String table.
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150814/455d86a8/attachment.html>
More information about the llvm-commits
mailing list