[llvm] r228879 - MC, COFF: Align section contents to a four byte boundary

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 22 20:23:46 PDT 2018


https://reviews.llvm.org/D51149

On Wed, Aug 22, 2018 at 8:08 PM Peter Collingbourne <peter at pcc.me.uk> wrote:

> I think we should switch back to not aligning them. I measured the median
> run time of 100 links of Chromium's base_unittests on Linux with lld-link
> and on Windows with link.exe with both aligned and unaligned sections. On
> Linux I didn't see a measurable performance difference, and on Windows the
> link was slightly faster with unaligned sections (presumably because on
> Windows the bottleneck is I/O). Also, the sections created by cl.exe are
> unaligned.
>
> Peter
>
> On Wed, Aug 22, 2018 at 5:59 PM David Majnemer <david.majnemer at gmail.com>
> wrote:
>
>> Microsoft's documentation says (
>> https://docs.microsoft.com/en-us/windows/desktop/debug/pe-format#section-table-section-headers
>> ):
>> "For object files, the value should be aligned on a 4-byte boundary for
>> best performance."
>>
>> It should be legal to relax this IIRC.
>>
>> On Wed, Aug 22, 2018 at 5:37 PM Peter Collingbourne <peter at pcc.me.uk>
>> wrote:
>>
>>> Hi David,
>>>
>>> Do you remember why you made this change?
>>>
>>> Peter
>>>
>>> > Author: majnemer
>>> > Date: Wed Feb 11 16:22:30 2015
>>> > New Revision: 228879
>>> >
>>> > URL: http://llvm.org/viewvc/llvm-project?rev=228879&view=rev
>>> > Log:
>>> > MC, COFF: Align section contents to a four byte boundary
>>> >
>>> > Modified:
>>> >     llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
>>> >     llvm/trunk/test/MC/COFF/directive-section-characteristics.ll
>>> >
>>> > Modified: llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
>>> > URL:
>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp?rev=228879&r1=228878&r2=228879&view=diff
>>> >
>>> ==============================================================================
>>> > --- llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp (original)
>>> > +++ llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp Wed Feb 11 16:22:30 2015
>>> > @@ -939,7 +939,8 @@ void WinCOFFObjectWriter::WriteObject(MC
>>> >      Sec->Header.SizeOfRawData =
>>> Layout.getSectionAddressSize(&Section);
>>> >
>>> >      if (IsPhysicalSection(Sec)) {
>>> > -      Sec->Header.PointerToRawData = offset;
>>> > +      // Align the section data to a four byte boundary.
>>> > +      Sec->Header.PointerToRawData = RoundUpToAlignment(offset, 4);
>>> >
>>> >        offset += Sec->Header.SizeOfRawData;
>>> >      }
>>> > @@ -1009,9 +1010,15 @@ void WinCOFFObjectWriter::WriteObject(MC
>>> >          continue;
>>> >
>>> >        if ((*i)->Header.PointerToRawData != 0) {
>>> > -        assert(OS.tell() == (*i)->Header.PointerToRawData &&
>>> > +        assert(OS.tell() <= (*i)->Header.PointerToRawData &&
>>> >                 "Section::PointerToRawData is insane!");
>>> >
>>> > +        unsigned SectionDataPadding = (*i)->Header.PointerToRawData -
>>> OS.tell();
>>> > +        assert(SectionDataPadding < 4 &&
>>> > +               "Should only need at most three bytes of padding!");
>>> > +
>>> > +        WriteZeros(SectionDataPadding);
>>> > +
>>> >          Asm.writeSectionData(j, Layout);
>>> >        }
>>> >
>>> >
>>> > Modified: llvm/trunk/test/MC/COFF/directive-section-characteristics.ll
>>> > URL:
>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/COFF/directive-section-characteristics.ll?rev=228879&r1=228878&r2=228879&view=diff
>>> >
>>> ==============================================================================
>>> > --- llvm/trunk/test/MC/COFF/directive-section-characteristics.ll
>>> (original)
>>> > +++ llvm/trunk/test/MC/COFF/directive-section-characteristics.ll Wed
>>> Feb 11 16:22:30 2015
>>> > @@ -7,7 +7,13 @@ entry:
>>> >  }
>>> >
>>> >  ; CHECK: Section {
>>> > +; CHECK:   Name: .text
>>> > +; CHECK:   PointerToRawData: 0xB4
>>> > +; CHECK: }
>>> > +
>>> > +; CHECK: Section {
>>> >  ; CHECK:   Name: .drectve
>>> > +; CHECK:   PointerToRawData: 0xB8
>>> >  ; CHECK:   Characteristics [
>>> >  ; CHECK:     IMAGE_SCN_ALIGN_1BYTES
>>> >  ; CHECK:     IMAGE_SCN_LNK_INFO
>>>
>>> --
>>> --
>>> Peter
>>>
>>
>
> --
> --
> Peter
>


-- 
-- 
Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180822/aab1ede8/attachment.html>


More information about the llvm-commits mailing list