[lld] r246901 - [elf2] Correctly handle sections with an alignment of 0. Spec says to treat it as an alignment of 1.
Michael J. Spencer via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 4 17:25:34 PDT 2015
Author: mspencer
Date: Fri Sep 4 19:25:33 2015
New Revision: 246901
URL: http://llvm.org/viewvc/llvm-project?rev=246901&view=rev
Log:
[elf2] Correctly handle sections with an alignment of 0. Spec says to treat it as an alignment of 1.
Added:
lld/trunk/test/elf2/section-align-0.test
Modified:
lld/trunk/ELF/Chunks.h
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/Chunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Chunks.h?rev=246901&r1=246900&r2=246901&view=diff
==============================================================================
--- lld/trunk/ELF/Chunks.h (original)
+++ lld/trunk/ELF/Chunks.h Fri Sep 4 19:25:33 2015
@@ -42,7 +42,11 @@ public:
// The writer sets and uses the addresses.
uintX_t getOutputSectionOff() const { return OutputSectionOff; }
- uintX_t getAlign() { return Header->sh_addralign; }
+ uintX_t getAlign() {
+ // The ELF spec states that a value of 0 means the section has no alignment
+ // constraits.
+ return std::max<uintX_t>(Header->sh_addralign, 1);
+ }
void setOutputSectionOff(uint64_t V) { OutputSectionOff = V; }
void setOutputSection(OutputSection<ELFT> *O) { Out = O; }
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=246901&r1=246900&r2=246901&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Fri Sep 4 19:25:33 2015
@@ -63,7 +63,11 @@ public:
void setSize(uintX_t Val) { Header.sh_size = Val; }
uintX_t getFlags() { return Header.sh_flags; }
uintX_t getFileOff() { return Header.sh_offset; }
- uintX_t getAlign() { return Header.sh_addralign; }
+ uintX_t getAlign() {
+ // The ELF spec states that a value of 0 means the section has no alignment
+ // constraits.
+ return std::max<uintX_t>(Header.sh_addralign, 1);
+ }
uint32_t getType() { return Header.sh_type; }
virtual void finalize() {}
Added: lld/trunk/test/elf2/section-align-0.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/section-align-0.test?rev=246901&view=auto
==============================================================================
--- lld/trunk/test/elf2/section-align-0.test (added)
+++ lld/trunk/test/elf2/section-align-0.test Fri Sep 4 19:25:33 2015
@@ -0,0 +1,19 @@
+# RUN: yaml2obj -format elf %s -o %t
+# RUN: lld -flavor gnu2 %t -o %tout
+
+# Verify that lld can handle sections with an alignment of zero.
+
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ AddressAlign: 0
+
+Symbols:
+ Global:
+ - Name: _start
+ Section: .text
More information about the llvm-commits
mailing list