diff --git a/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp b/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp index 625310b0481d..73fc7fcd7ab9 100644 --- a/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp +++ b/lld/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp @@ -71,12 +71,12 @@ public: kindDataDirectory }; - explicit Chunk(Kind kind) : _kind(kind), _size(0), _align(1) {} + explicit Chunk(Kind kind) : _kind(kind), _size(0) {} virtual ~Chunk() {}; virtual void write(uint8_t *buffer) = 0; virtual uint64_t size() const { return _size; } + virtual uint64_t align() const { return 1; } - uint64_t align() const { return _align; } uint64_t fileOffset() const { return _fileOffset; } void setFileOffset(uint64_t fileOffset) { _fileOffset = fileOffset; } Kind getKind() const { return _kind; } @@ -85,7 +85,6 @@ protected: Kind _kind; uint64_t _size; uint64_t _fileOffset; - uint64_t _align; }; /// A HeaderChunk is an abstract class to represent a file header for @@ -249,12 +248,7 @@ private: /// written to the raw data section. class SectionChunk : public AtomChunk { 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 { - return llvm::RoundUpToAlignment(_size, _align); - } + virtual uint64_t align() const { return SECTOR_SIZE; } virtual uint64_t rawSize() const { return _size; } @@ -596,10 +590,7 @@ void SectionChunk::appendAtom(const DefinedAtom *atom) { SectionChunk::SectionChunk(StringRef sectionName, uint32_t characteristics) : AtomChunk(kindSection), _sectionName(sectionName), - _characteristics(characteristics) { - // The section should be aligned to disk sector. - _align = SECTOR_SIZE; -} + _characteristics(characteristics) {} void GenericSectionChunk::write(uint8_t *buffer) { if (_atomLayouts.empty()) diff --git a/lld/test/pecoff/base-reloc.test b/lld/test/pecoff/base-reloc.test index 67c1de67aa97..48a4dc02d400 100644 --- a/lld/test/pecoff/base-reloc.test +++ b/lld/test/pecoff/base-reloc.test @@ -15,7 +15,7 @@ # objdump does. BASEREL-SECTION: Contents of section .reloc: -BASEREL-SECTION-NEXT: 3000 00200000 0c000000 07300c30 00000000 +BASEREL-SECTION-NEXT: 3000 00200000 0c000000 07300c30 NOBASEREL-SECTION-NOT: Contents of section .reloc: @@ -36,7 +36,7 @@ BASEREL-HEADER: BaseRelocationTableSize: 0xC BASEREL-HEADER: Name: .reloc (2E 72 65 6C 6F 63 00 00) BASEREL-HEADER-NEXT: VirtualSize: 0xC BASEREL-HEADER-NEXT: VirtualAddress: 0x3000 -BASEREL-HEADER-NEXT: RawDataSize: 512 +BASEREL-HEADER-NEXT: RawDataSize: 12 BASEREL-HEADER-NEXT: PointerToRawData: 0x600 BASEREL-HEADER-NEXT: PointerToRelocations: 0x0 BASEREL-HEADER-NEXT: PointerToLineNumbers: 0x0 diff --git a/lld/test/pecoff/bss-section.test b/lld/test/pecoff/bss-section.test index 24240cfd937c..32c363ea11c0 100644 --- a/lld/test/pecoff/bss-section.test +++ b/lld/test/pecoff/bss-section.test @@ -6,7 +6,7 @@ CHECK: Number: 1 CHECK-NEXT: Name: .bss CHECK-NEXT: VirtualSize: 0x0 CHECK-NEXT: VirtualAddress: 0x1000 -CHECK-NEXT: RawDataSize: 1024 +CHECK-NEXT: RawDataSize: 800 CHECK-NEXT: PointerToRawData: 0x0 CHECK-NEXT: PointerToRelocations: 0x0 CHECK-NEXT: PointerToLineNumbers: 0x0 diff --git a/lld/test/pecoff/common-symbol.test b/lld/test/pecoff/common-symbol.test index b7620e337444..4ffe648cb7af 100644 --- a/lld/test/pecoff/common-symbol.test +++ b/lld/test/pecoff/common-symbol.test @@ -8,7 +8,7 @@ CHECK: Number: 1 CHECK-NEXT: Name: .bss (2E 62 73 73 00 00 00 00) CHECK-NEXT: VirtualSize: 0x0 CHECK-NEXT: VirtualAddress: 0x1000 -CHECK-NEXT: RawDataSize: 512 +CHECK-NEXT: RawDataSize: 8 CHECK-NEXT: PointerToRawData: 0x0 CHECK-NEXT: PointerToRelocations: 0x0 CHECK-NEXT: PointerToLineNumbers: 0x0 diff --git a/lld/test/pecoff/hello.test b/lld/test/pecoff/hello.test index eb0df98badc2..eee69ab70971 100644 --- a/lld/test/pecoff/hello.test +++ b/lld/test/pecoff/hello.test @@ -4,7 +4,7 @@ # RUN: llvm-readobj -file-headers %t1 | FileCheck -check-prefix=FILE %s FILE: ImageOptionalHeader { -FILE: SizeOfInitializedData: 1024 +FILE: SizeOfInitializedData: 30 FILE: SizeOfHeaders: 512 FILE: } @@ -20,7 +20,7 @@ SECTIONS-NEXT: Number: 1 SECTIONS-NEXT: Name: .data SECTIONS-NEXT: VirtualSize: 0x12 SECTIONS-NEXT: VirtualAddress: 0x1000 -SECTIONS-NEXT: RawDataSize: 512 +SECTIONS-NEXT: RawDataSize: 18 SECTIONS-NEXT: PointerToRawData: 0x200 SECTIONS-NEXT: PointerToRelocations: 0x0 SECTIONS-NEXT: PointerToLineNumbers: 0x0 @@ -37,7 +37,7 @@ SECTIONS-NEXT: Number: 2 SECTIONS-NEXT: Name: .text (2E 74 65 78 74 00 00 00) SECTIONS-NEXT: VirtualSize: 0x1C SECTIONS-NEXT: VirtualAddress: 0x2000 -SECTIONS-NEXT: RawDataSize: 512 +SECTIONS-NEXT: RawDataSize: 28 SECTIONS-NEXT: PointerToRawData: 0x400 SECTIONS-NEXT: PointerToRelocations: 0x0 SECTIONS-NEXT: PointerToLineNumbers: 0x0 diff --git a/lld/test/pecoff/nonstandard-sections.test b/lld/test/pecoff/nonstandard-sections.test index 2ca181629230..27c5fb38ba61 100644 --- a/lld/test/pecoff/nonstandard-sections.test +++ b/lld/test/pecoff/nonstandard-sections.test @@ -10,7 +10,7 @@ CHECK-NEXT: Number: 1 CHECK-NEXT: Name: .bar (2E 62 61 72 00 00 00 00) CHECK-NEXT: VirtualSize: 0x4 CHECK-NEXT: VirtualAddress: 0x1000 -CHECK-NEXT: RawDataSize: 512 +CHECK-NEXT: RawDataSize: 4 CHECK-NEXT: PointerToRawData: 0x400 CHECK-NEXT: PointerToRelocations: 0x0 CHECK-NEXT: PointerToLineNumbers: 0x0 @@ -26,7 +26,7 @@ CHECK-NEXT: Number: 2 CHECK-NEXT: Name: .data (2E 64 61 74 61 00 00 00) CHECK-NEXT: VirtualSize: 0x4 CHECK-NEXT: VirtualAddress: 0x2000 -CHECK-NEXT: RawDataSize: 512 +CHECK-NEXT: RawDataSize: 4 CHECK-NEXT: PointerToRawData: 0x600 CHECK-NEXT: PointerToRelocations: 0x0 CHECK-NEXT: PointerToLineNumbers: 0x0 @@ -43,7 +43,7 @@ CHECK-NEXT: Number: 3 CHECK-NEXT: Name: .foo (2E 66 6F 6F 00 00 00 00) CHECK-NEXT: VirtualSize: 0x4 CHECK-NEXT: VirtualAddress: 0x3000 -CHECK-NEXT: RawDataSize: 512 +CHECK-NEXT: RawDataSize: 4 CHECK-NEXT: PointerToRawData: 0x800 CHECK-NEXT: PointerToRelocations: 0x0 CHECK-NEXT: PointerToLineNumbers: 0x0 @@ -60,7 +60,7 @@ CHECK-NEXT: Number: 4 CHECK-NEXT: Name: .text (2E 74 65 78 74 00 00 00) CHECK-NEXT: VirtualSize: 0x4 CHECK-NEXT: VirtualAddress: 0x4000 -CHECK-NEXT: RawDataSize: 512 +CHECK-NEXT: RawDataSize: 4 CHECK-NEXT: PointerToRawData: 0xA00 CHECK-NEXT: PointerToRelocations: 0x0 CHECK-NEXT: PointerToLineNumbers: 0x0 diff --git a/lld/test/pecoff/section-renaming.test b/lld/test/pecoff/section-renaming.test index d4fc154693af..6b84a0d9fea7 100644 --- a/lld/test/pecoff/section-renaming.test +++ b/lld/test/pecoff/section-renaming.test @@ -12,7 +12,7 @@ CHECK-NEXT: Number: 1 CHECK-NEXT: Name: .data (2E 64 61 74 61 00 00 00) CHECK-NEXT: VirtualSize: 0x4 CHECK-NEXT: VirtualAddress: 0x1000 -CHECK-NEXT: RawDataSize: 512 +CHECK-NEXT: RawDataSize: 4 CHECK-NEXT: PointerToRawData: 0x200 CHECK-NEXT: PointerToRelocations: 0x0 CHECK-NEXT: PointerToLineNumbers: 0x0 @@ -29,7 +29,7 @@ CHECK-NEXT: Number: 2 CHECK-NEXT: Name: .hoge (2E 68 6F 67 65 00 00 00) CHECK-NEXT: VirtualSize: 0x4 CHECK-NEXT: VirtualAddress: 0x2000 -CHECK-NEXT: RawDataSize: 512 +CHECK-NEXT: RawDataSize: 4 CHECK-NEXT: PointerToRawData: 0x400 CHECK-NEXT: PointerToRelocations: 0x0 CHECK-NEXT: PointerToLineNumbers: 0x0 @@ -46,7 +46,7 @@ CHECK-NEXT: Number: 3 CHECK-NEXT: Name: .text (2E 74 65 78 74 00 00 00) CHECK-NEXT: VirtualSize: 0x8 CHECK-NEXT: VirtualAddress: 0x3000 -CHECK-NEXT: RawDataSize: 512 +CHECK-NEXT: RawDataSize: 8 CHECK-NEXT: PointerToRawData: 0x600 CHECK-NEXT: PointerToRelocations: 0x0 CHECK-NEXT: PointerToLineNumbers: 0x0 diff --git a/lld/test/pecoff/trivial.test b/lld/test/pecoff/trivial.test index 723ba3e620e6..7f0f7bde9215 100644 --- a/lld/test/pecoff/trivial.test +++ b/lld/test/pecoff/trivial.test @@ -30,7 +30,7 @@ FILE-NEXT: } FILE-NEXT: ImageOptionalHeader { FILE-NEXT: MajorLinkerVersion: 0 FILE-NEXT: MinorLinkerVersion: 0 -FILE-NEXT: SizeOfCode: 512 +FILE-NEXT: SizeOfCode: 6 FILE-NEXT: SizeOfInitializedData: 0 FILE-NEXT: SizeOfUninitializedData: 0 FILE-NEXT: AddressOfEntryPoint: 0x1000 @@ -86,7 +86,7 @@ SECTIONS-NEXT: Number: 2 SECTIONS-NEXT: Name: .text (2E 74 65 78 74 00 00 00) SECTIONS-NEXT: VirtualSize: 0x6 SECTIONS-NEXT: VirtualAddress: 0x1000 -SECTIONS-NEXT: RawDataSize: 512 +SECTIONS-NEXT: RawDataSize: 6 SECTIONS-NEXT: PointerToRawData: 0x200 SECTIONS-NEXT: PointerToRelocations: 0x0 SECTIONS-NEXT: PointerToLineNumbers: 0x0