[llvm] r340514 - MC: Don't align COFF section contents.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 22 22:39:36 PDT 2018


Author: pcc
Date: Wed Aug 22 22:39:36 2018
New Revision: 340514

URL: http://llvm.org/viewvc/llvm-project?rev=340514&view=rev
Log:
MC: Don't align COFF section contents.

Aligning section contents is not required, but only
recommended, by the specification. 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."

However, according to my measurements, aligning section contents has
a neutral to negative effect on performance.

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, so we should expect
tools to broadly accept unaligned sections.

Differential Revision: https://reviews.llvm.org/D51149

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=340514&r1=340513&r2=340514&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp Wed Aug 22 22:39:36 2018
@@ -620,14 +620,9 @@ void WinCOFFObjectWriter::writeSection(M
 
   // Write the section contents.
   if (Sec.Header.PointerToRawData != 0) {
-    assert(W.OS.tell() <= Sec.Header.PointerToRawData &&
+    assert(W.OS.tell() == Sec.Header.PointerToRawData &&
            "Section::PointerToRawData is insane!");
 
-    unsigned PaddingSize = Sec.Header.PointerToRawData - W.OS.tell();
-    assert(PaddingSize < 4 &&
-           "Should only need at most three bytes of padding!");
-    W.OS.write_zeros(PaddingSize);
-
     uint32_t CRC = writeSectionContents(Asm, Layout, MCSec);
 
     // Update the section definition auxiliary symbol to record the CRC.
@@ -912,10 +907,7 @@ void WinCOFFObjectWriter::assignFileOffs
     Sec->Header.SizeOfRawData = Layout.getSectionAddressSize(&Section);
 
     if (IsPhysicalSection(Sec)) {
-      // Align the section data to a four byte boundary.
-      Offset = alignTo(Offset, 4);
       Sec->Header.PointerToRawData = Offset;
-
       Offset += Sec->Header.SizeOfRawData;
     }
 

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=340514&r1=340513&r2=340514&view=diff
==============================================================================
--- llvm/trunk/test/MC/COFF/directive-section-characteristics.ll (original)
+++ llvm/trunk/test/MC/COFF/directive-section-characteristics.ll Wed Aug 22 22:39:36 2018
@@ -13,7 +13,7 @@ entry:
 
 ; CHECK: Section {
 ; CHECK:   Name: .drectve
-; CHECK:   PointerToRawData: 0xB8
+; CHECK:   PointerToRawData: 0xB5
 ; CHECK:   Characteristics [
 ; CHECK:     IMAGE_SCN_ALIGN_1BYTES
 ; CHECK:     IMAGE_SCN_LNK_INFO




More information about the llvm-commits mailing list