diff options
| -rw-r--r-- | lld/ELF/Chunks.h | 6 | ||||
| -rw-r--r-- | lld/ELF/Writer.cpp | 6 | ||||
| -rw-r--r-- | lld/test/elf2/section-align-0.test | 19 |
3 files changed, 29 insertions, 2 deletions
diff --git a/lld/ELF/Chunks.h b/lld/ELF/Chunks.h index 1cb97210456..e331bcb7097 100644 --- a/lld/ELF/Chunks.h +++ b/lld/ELF/Chunks.h @@ -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; } diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 06042f1331a..0dc4f60ad17 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -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() {} diff --git a/lld/test/elf2/section-align-0.test b/lld/test/elf2/section-align-0.test new file mode 100644 index 00000000000..4e5547400d1 --- /dev/null +++ b/lld/test/elf2/section-align-0.test @@ -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 |

