forked from OSchip/llvm-project
[PECOFF] Writer: Remove NULL padding at the end of each section.
If section size is not multiple of 512, the writer added NULL bytes at the end of it to make it so. That is not required by the PE/COFF spec, and the MSVC's linker does not do that too. So we don't need to do that, too. llvm-svn: 197002
This commit is contained in:
parent
2d8826a1b5
commit
0d4d40cfee
|
@ -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())
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue