[lld] r244942 - Correctly align output sections.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 13 13:24:18 PDT 2015
Author: rafael
Date: Thu Aug 13 15:24:18 2015
New Revision: 244942
URL: http://llvm.org/viewvc/llvm-project?rev=244942&view=rev
Log:
Correctly align output sections.
They don't need to be aligned to page boundaries. Only segments need that.
Modified:
lld/trunk/ELF/Writer.cpp
lld/trunk/test/elf2/basic.s
lld/trunk/test/elf2/basic32.s
lld/trunk/test/elf2/basic32be.s
lld/trunk/test/elf2/basic64be.s
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=244942&r1=244941&r2=244942&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Aug 13 15:24:18 2015
@@ -57,6 +57,7 @@ public:
uintX_t getSize() { return Header.sh_size; }
uintX_t getFlags() { return Header.sh_flags; }
uintX_t getOffset() { return Header.sh_offset; }
+ uintX_t getAlign() { return Header.sh_addralign; }
private:
StringRef Name;
@@ -213,12 +214,14 @@ template <class ELFT> void Writer<ELFT>:
compSec<ELFT::Is64Bits>);
for (OutputSection<ELFT::Is64Bits> *Sec : OutputSections) {
+ uintX_t Align = Sec->getAlign();
+ uintX_t Size = Sec->getSize();
if (Sec->getFlags() & SHF_ALLOC) {
Sec->setVA(VA);
- VA += RoundUpToAlignment(Sec->getSize(), PageSize);
+ VA += RoundUpToAlignment(Size, Align);
}
Sec->setFileOffset(FileOff);
- FileOff += RoundUpToAlignment(Sec->getSize(), 8);
+ FileOff += RoundUpToAlignment(Size, Align);
StrTabBuilder.add(Sec->getName());
}
Modified: lld/trunk/test/elf2/basic.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/basic.s?rev=244942&r1=244941&r2=244942&view=diff
==============================================================================
--- lld/trunk/test/elf2/basic.s (original)
+++ lld/trunk/test/elf2/basic.s Thu Aug 13 15:24:18 2015
@@ -74,7 +74,7 @@ _start:
# CHECK-NEXT: SHF_ALLOC (0x2)
# CHECK-NEXT: SHF_WRITE (0x1)
# CHECK-NEXT: ]
-# CHECK-NEXT: Address: 0x2000
+# CHECK-NEXT: Address: 0x1010
# CHECK-NEXT: Offset: 0x1010
# CHECK-NEXT: Size: 0
# CHECK-NEXT: Link: 0
@@ -90,7 +90,7 @@ _start:
# CHECK-NEXT: SHF_ALLOC (0x2)
# CHECK-NEXT: SHF_WRITE (0x1)
# CHECK-NEXT: ]
-# CHECK-NEXT: Address: 0x2000
+# CHECK-NEXT: Address: 0x1010
# CHECK-NEXT: Offset: 0x1010
# CHECK-NEXT: Size: 0
# CHECK-NEXT: Link: 0
Modified: lld/trunk/test/elf2/basic32.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/basic32.s?rev=244942&r1=244941&r2=244942&view=diff
==============================================================================
--- lld/trunk/test/elf2/basic32.s (original)
+++ lld/trunk/test/elf2/basic32.s Thu Aug 13 15:24:18 2015
@@ -25,7 +25,7 @@ _start:
# CHECK-NEXT: Version: 1
# CHECK-NEXT: Entry: 0x401000
# CHECK-NEXT: ProgramHeaderOffset: 0x34
-# CHECK-NEXT: SectionHeaderOffset: 0x102C
+# CHECK-NEXT: SectionHeaderOffset: 0x1028
# CHECK-NEXT: Flags [ (0x0)
# CHECK-NEXT: ]
# CHECK-NEXT: HeaderSize: 52
@@ -74,8 +74,8 @@ _start:
# CHECK-NEXT: SHF_ALLOC (0x2)
# CHECK-NEXT: SHF_WRITE (0x1)
# CHECK-NEXT: ]
-# CHECK-NEXT: Address: 0x2000
-# CHECK-NEXT: Offset: 0x1010
+# CHECK-NEXT: Address: 0x100C
+# CHECK-NEXT: Offset: 0x100C
# CHECK-NEXT: Size: 0
# CHECK-NEXT: Link: 0
# CHECK-NEXT: Info: 0
@@ -90,8 +90,8 @@ _start:
# CHECK-NEXT: SHF_ALLOC (0x2)
# CHECK-NEXT: SHF_WRITE (0x1)
# CHECK-NEXT: ]
-# CHECK-NEXT: Address: 0x2000
-# CHECK-NEXT: Offset: 0x1010
+# CHECK-NEXT: Address: 0x100C
+# CHECK-NEXT: Offset: 0x100C
# CHECK-NEXT: Size: 0
# CHECK-NEXT: Link: 0
# CHECK-NEXT: Info: 0
@@ -105,7 +105,7 @@ _start:
# CHECK-NEXT: Flags [ (0x0)
# CHECK-NEXT: ]
# CHECK-NEXT: Address: 0x0
-# CHECK-NEXT: Offset: 0x1010
+# CHECK-NEXT: Offset: 0x100C
# CHECK-NEXT: Size: 26
# CHECK-NEXT: Link: 0
# CHECK-NEXT: Info: 0
@@ -119,8 +119,8 @@ _start:
# CHECK-NEXT: Offset: 0x0
# CHECK-NEXT: VirtualAddress: 0x400000
# CHECK-NEXT: PhysicalAddress: 0x400000
-# CHECK-NEXT: FileSize: 4344
-# CHECK-NEXT: MemSize: 4344
+# CHECK-NEXT: FileSize: 4336
+# CHECK-NEXT: MemSize: 4336
# CHECK-NEXT: Flags [ (0x5)
# CHECK-NEXT: PF_R (0x4)
# CHECK-NEXT: PF_X (0x1)
Modified: lld/trunk/test/elf2/basic32be.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/basic32be.s?rev=244942&r1=244941&r2=244942&view=diff
==============================================================================
--- lld/trunk/test/elf2/basic32be.s (original)
+++ lld/trunk/test/elf2/basic32be.s Thu Aug 13 15:24:18 2015
@@ -25,7 +25,7 @@ _start:
# CHECK-NEXT: Version: 1
# CHECK-NEXT: Entry: 0x401000
# CHECK-NEXT: ProgramHeaderOffset: 0x34
-# CHECK-NEXT: SectionHeaderOffset: 0x102C
+# CHECK-NEXT: SectionHeaderOffset: 0x1028
# CHECK-NEXT: Flags [ (0x0)
# CHECK-NEXT: ]
# CHECK-NEXT: HeaderSize: 52
@@ -74,8 +74,8 @@ _start:
# CHECK-NEXT: SHF_ALLOC (0x2)
# CHECK-NEXT: SHF_WRITE (0x1)
# CHECK-NEXT: ]
-# CHECK-NEXT: Address: 0x2000
-# CHECK-NEXT: Offset: 0x1010
+# CHECK-NEXT: Address: 0x100C
+# CHECK-NEXT: Offset: 0x100C
# CHECK-NEXT: Size: 0
# CHECK-NEXT: Link: 0
# CHECK-NEXT: Info: 0
@@ -90,8 +90,8 @@ _start:
# CHECK-NEXT: SHF_ALLOC (0x2)
# CHECK-NEXT: SHF_WRITE (0x1)
# CHECK-NEXT: ]
-# CHECK-NEXT: Address: 0x2000
-# CHECK-NEXT: Offset: 0x1010
+# CHECK-NEXT: Address: 0x100C
+# CHECK-NEXT: Offset: 0x100C
# CHECK-NEXT: Size: 0
# CHECK-NEXT: Link: 0
# CHECK-NEXT: Info: 0
@@ -105,7 +105,7 @@ _start:
# CHECK-NEXT: Flags [ (0x0)
# CHECK-NEXT: ]
# CHECK-NEXT: Address: 0x0
-# CHECK-NEXT: Offset: 0x1010
+# CHECK-NEXT: Offset: 0x100C
# CHECK-NEXT: Size: 26
# CHECK-NEXT: Link: 0
# CHECK-NEXT: Info: 0
@@ -119,8 +119,8 @@ _start:
# CHECK-NEXT: Offset: 0x0
# CHECK-NEXT: VirtualAddress: 0x400000
# CHECK-NEXT: PhysicalAddress: 0x400000
-# CHECK-NEXT: FileSize: 4344
-# CHECK-NEXT: MemSize: 4344
+# CHECK-NEXT: FileSize: 4336
+# CHECK-NEXT: MemSize: 4336
# CHECK-NEXT: Flags [ (0x5)
# CHECK-NEXT: PF_R (0x4)
# CHECK-NEXT: PF_X (0x1)
Modified: lld/trunk/test/elf2/basic64be.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/basic64be.s?rev=244942&r1=244941&r2=244942&view=diff
==============================================================================
--- lld/trunk/test/elf2/basic64be.s (original)
+++ lld/trunk/test/elf2/basic64be.s Thu Aug 13 15:24:18 2015
@@ -79,8 +79,8 @@ _start:
# CHECK-NEXT: SHF_ALLOC (0x2)
# CHECK-NEXT: SHF_WRITE (0x1)
# CHECK-NEXT: ]
-# CHECK-NEXT: Address: 0x2000
-# CHECK-NEXT: Offset: 0x1010
+# CHECK-NEXT: Address: 0x100C
+# CHECK-NEXT: Offset: 0x100C
# CHECK-NEXT: Size: 0
# CHECK-NEXT: Link: 0
# CHECK-NEXT: Info: 0
@@ -95,8 +95,8 @@ _start:
# CHECK-NEXT: SHF_ALLOC (0x2)
# CHECK-NEXT: SHF_WRITE (0x1)
# CHECK-NEXT: ]
-# CHECK-NEXT: Address: 0x2000
-# CHECK-NEXT: Offset: 0x1010
+# CHECK-NEXT: Address: 0x100C
+# CHECK-NEXT: Offset: 0x100C
# CHECK-NEXT: Size: 0
# CHECK-NEXT: Link: 0
# CHECK-NEXT: Info: 0
@@ -111,8 +111,8 @@ _start:
# CHECK-NEXT: SHF_ALLOC (0x2)
# CHECK-NEXT: SHF_WRITE (0x1)
# CHECK-NEXT: ]
-# CHECK-NEXT: Address: 0x2000
-# CHECK-NEXT: Offset: 0x1010
+# CHECK-NEXT: Address: 0x100C
+# CHECK-NEXT: Offset: 0x100C
# CHECK-NEXT: Size: 24
# CHECK-NEXT: Link: 0
# CHECK-NEXT: Info: 0
@@ -126,7 +126,7 @@ _start:
# CHECK-NEXT: Flags [ (0x0)
# CHECK-NEXT: ]
# CHECK-NEXT: Address: 0x0
-# CHECK-NEXT: Offset: 0x1028
+# CHECK-NEXT: Offset: 0x1024
# CHECK-NEXT: Size: 31
# CHECK-NEXT: Link: 0
# CHECK-NEXT: Info: 0
More information about the llvm-commits
mailing list