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

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 22 17:59:08 PDT 2018


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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180822/204ef0a6/attachment.html>


More information about the llvm-commits mailing list