[lld] r201740 - [ELF] Fix alignment for dynamic relocation sections.
Shankar Easwaran
shankare at codeaurora.org
Wed Feb 19 15:46:08 PST 2014
Author: shankare
Date: Wed Feb 19 17:46:08 2014
New Revision: 201740
URL: http://llvm.org/viewvc/llvm-project?rev=201740&view=rev
Log:
[ELF] Fix alignment for dynamic relocation sections.
The sections .rela/.rel.(*) have a alignment of 2 in the final image created by
the linker. This needs to be properly set to the right alignment depending on
the architecture(32/64bits).
Added:
lld/trunk/test/elf/Hexagon/dynlib-rela.test
Modified:
lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h
lld/trunk/test/elf/Mips/exe-dynamic.test
Modified: lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h?rev=201740&r1=201739&r2=201740&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/SectionChunks.h Wed Feb 19 17:46:08 2014
@@ -913,13 +913,16 @@ public:
: Section<ELFT>(context, str), _symbolTable(nullptr) {
this->setOrder(order);
this->_flags = SHF_ALLOC;
+ // Set the alignment properly depending on the target architecture
+ if (context.is64Bits())
+ this->_align2 = 8;
+ else
+ this->_align2 = 4;
if (context.isRelaOutputFormat()) {
this->_entSize = sizeof(Elf_Rela);
- this->_align2 = llvm::alignOf<Elf_Rela>();
this->_type = SHT_RELA;
} else {
this->_entSize = sizeof(Elf_Rel);
- this->_align2 = llvm::alignOf<Elf_Rel>();
this->_type = SHT_REL;
}
}
Added: lld/trunk/test/elf/Hexagon/dynlib-rela.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Hexagon/dynlib-rela.test?rev=201740&view=auto
==============================================================================
--- lld/trunk/test/elf/Hexagon/dynlib-rela.test (added)
+++ lld/trunk/test/elf/Hexagon/dynlib-rela.test Wed Feb 19 17:46:08 2014
@@ -0,0 +1,9 @@
+# Tests that the relocation sections have the right alignment.
+RUN: lld -flavor gnu -target hexagon %p/Inputs/use-shared.hexagon -shared -o %t1
+RUN: llvm-readobj -sections %t1 > %t2
+RUN: FileCheck -check-prefix=SECTIONS %s < %t2
+
+SECTIONS: Section {
+SECTIONS: Name: .rela.plt (23)
+SECTIONS: AddressAlignment: 4
+SECTIONS: }
Modified: lld/trunk/test/elf/Mips/exe-dynamic.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/exe-dynamic.test?rev=201740&r1=201739&r2=201740&view=diff
==============================================================================
--- lld/trunk/test/elf/Mips/exe-dynamic.test (original)
+++ lld/trunk/test/elf/Mips/exe-dynamic.test Wed Feb 19 17:46:08 2014
@@ -26,7 +26,7 @@
# CHECK-NEXT: 0x00000002 PLTRELSZ 8 (bytes)
# CHECK-NEXT: 0x70000032 MIPS_PLTGOT 0x402000
# CHECK-NEXT: 0x00000014 PLTREL REL
-# CHECK-NEXT: 0x00000017 JMPREL 0x400162
+# CHECK-NEXT: 0x00000017 JMPREL 0x400164
# CHECK-NEXT: 0x70000001 MIPS_RLD_VERSION 1
# CHECK-NEXT: 0x70000005 MIPS_FLAGS 0x2
# CHECK-NEXT: 0x70000006 MIPS_BASE_ADDRESS 0x400000
More information about the llvm-commits
mailing list