[lld] r185205 - [PECOFF][Writer] Fix wrong section header.

Rui Ueyama ruiu at google.com
Fri Jun 28 13:10:36 PDT 2013


Author: ruiu
Date: Fri Jun 28 15:10:36 2013
New Revision: 185205

URL: http://llvm.org/viewvc/llvm-project?rev=185205&view=rev
Log:
[PECOFF][Writer] Fix wrong section header.

Modified:
    lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
    lld/trunk/test/pecoff/hello.test
    lld/trunk/test/pecoff/trivial.test

Modified: lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp?rev=185205&r1=185204&r2=185205&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp Fri Jun 28 15:10:36 2013
@@ -274,9 +274,10 @@ private:
 /// written to the raw data section.
 class SectionChunk : public Chunk {
 public:
+  /// Returns the size of the section on disk. The returned value is multiple
+  /// of disk sector, so the size may include the null padding at the end of
+  /// section.
   virtual uint64_t size() const {
-    // Round up to the nearest alignment border, so that the text segment ends
-    // at a border.
     return llvm::RoundUpToAlignment(_size, _align);
   }
 
@@ -379,9 +380,11 @@ protected:
     }
 
     // Now that we have a list of atoms that to be written in this section,
-    // and we know the size of the section.
+    // and we know the size of the section. Let's write them to the section
+    // header. VirtualSize should be the size of the actual content, and
+    // SizeOfRawData should be aligned to the section alignment.
     _sectionHeader.VirtualSize = _size;
-    _sectionHeader.SizeOfRawData = _size;
+    _sectionHeader.SizeOfRawData = size();
   }
 
 private:

Modified: lld/trunk/test/pecoff/hello.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/hello.test?rev=185205&r1=185204&r2=185205&view=diff
==============================================================================
--- lld/trunk/test/pecoff/hello.test (original)
+++ lld/trunk/test/pecoff/hello.test Fri Jun 28 15:10:36 2013
@@ -11,7 +11,7 @@ CHECK:     Number: 1
 CHECK:     Name: .text (2E 74 65 78 74 00 00 00)
 CHECK:     VirtualSize: 0x1C
 CHECK:     VirtualAddress: 0x1000
-CHECK:     RawDataSize: 28
+CHECK:     RawDataSize: 512
 CHECK:     PointerToRawData: 0x200
 CHECK:     PointerToRelocations: 0x0
 CHECK:     PointerToLineNumbers: 0x0
@@ -44,7 +44,7 @@ CHECK:     Number: 3
 CHECK:     Name: .data (2E 64 61 74 61 00 00 00)
 CHECK:     VirtualSize: 0x18
 CHECK:     VirtualAddress: 0x2000
-CHECK:     RawDataSize: 24
+CHECK:     RawDataSize: 512
 CHECK:     PointerToRawData: 0x400
 CHECK:     PointerToRelocations: 0x0
 CHECK:     PointerToLineNumbers: 0x0

Modified: lld/trunk/test/pecoff/trivial.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/trivial.test?rev=185205&r1=185204&r2=185205&view=diff
==============================================================================
--- lld/trunk/test/pecoff/trivial.test (original)
+++ lld/trunk/test/pecoff/trivial.test Fri Jun 28 15:10:36 2013
@@ -66,7 +66,7 @@ SECTIONS:     Number: 1
 SECTIONS:     Name: .text (2E 74 65 78 74 00 00 00)
 SECTIONS:     VirtualSize: 0x6
 SECTIONS:     VirtualAddress: 0x1000
-SECTIONS:     RawDataSize: 6
+SECTIONS:     RawDataSize: 512
 SECTIONS:     PointerToRawData: 0x200
 SECTIONS:     PointerToRelocations: 0x0
 SECTIONS:     PointerToLineNumbers: 0x0





More information about the llvm-commits mailing list