[lld] r247599 - Correctly align sections.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 14 12:00:35 PDT 2015
Author: rafael
Date: Mon Sep 14 14:00:35 2015
New Revision: 247599
URL: http://llvm.org/viewvc/llvm-project?rev=247599&view=rev
Log:
Correctly align sections.
We have to align the start, not the end.
This should fix crashes on systems where memcpy enforces the expected
alignment.
Modified:
lld/trunk/ELF/Writer.cpp
lld/trunk/test/elf2/shared.s
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=247599&r1=247598&r2=247599&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Mon Sep 14 14:00:35 2015
@@ -704,12 +704,14 @@ template <class ELFT> void Writer<ELFT>:
uintX_t Align = Sec->getAlign();
uintX_t Size = Sec->getSize();
if (Sec->getFlags() & SHF_ALLOC) {
+ VA = RoundUpToAlignment(VA, Align);
Sec->setVA(VA);
- VA += RoundUpToAlignment(Size, Align);
+ VA += Size;
}
+ FileOff = RoundUpToAlignment(FileOff, Align);
Sec->setFileOffset(FileOff);
if (Sec->getType() != SHT_NOBITS)
- FileOff += RoundUpToAlignment(Size, Align);
+ FileOff += Size;
}
// Add a PHDR for the dynamic table.
Modified: lld/trunk/test/elf2/shared.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/shared.s?rev=247599&r1=247598&r2=247599&view=diff
==============================================================================
--- lld/trunk/test/elf2/shared.s (original)
+++ lld/trunk/test/elf2/shared.s Mon Sep 14 14:00:35 2015
@@ -1,10 +1,23 @@
// RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %s -o %t.o
// RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %p/Inputs/shared.s -o %t2.o
// RUN: lld -flavor gnu2 -shared %t2.o -o %t2.so
+// RUN: llvm-readobj -s %t2.so | FileCheck --check-prefix=SO %s
// RUN: lld -flavor gnu2 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -rpath foo -rpath bar %t.o %t2.so -o %t
// RUN: llvm-readobj --program-headers --dynamic-table -t -s -dyn-symbols -section-data %t | FileCheck %s
// REQUIRES: x86
+// Make sure .symtab is properly aligned.
+// SO: Name: .symtab
+// SO-NEXT: Type: SHT_SYMTAB
+// SO-NEXT: Flags [
+// SO-NEXT: ]
+// SO-NEXT: Address:
+// SO-NEXT: Offset: 0x300C
+// SO-NEXT: Size:
+// SO-NEXT: Link:
+// SO-NEXT: Info:
+// SO-NEXT: AddressAlignment: 4
+
// CHECK: Name: .interp
// CHECK-NEXT: Type: SHT_PROGBITS
// CHECK-NEXT: Flags [
More information about the llvm-commits
mailing list