diff options
author | Hans Wennborg <hans@hanshq.net> | 2019-09-06 11:20:15 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2019-09-06 11:20:15 +0000 |
commit | 4b9862f5b87d233b4b705b7284fe67711f240134 (patch) | |
tree | aa6c1848473a2c06114852f4631b8a2b62f18d7a | |
parent | 78fcb6ad74e6c86e5dd51bb517db2d13ed7f5757 (diff) |
Merging r371013:
------------------------------------------------------------------------
r371013 | ruiu | 2019-09-05 07:30:24 +0200 (Thu, 05 Sep 2019) | 13 lines
Align output segments correctly
Previously, segments were aligned according to their first section's
alignment requirements. That was not correct, but segments are also
aligned to a page boundary, and a page boundary is usually much larger
than a section alignment requirement, so no one noticed this bug before.
Now, lld has --nmagic option which sets maxPageSize to 1 to effectively
disable page alignment, which reveals the issue.
Fixes https://bugs.llvm.org/show_bug.cgi?id=43212
Differential Revision: https://reviews.llvm.org/D67152
------------------------------------------------------------------------
git-svn-id: https://llvm.org/svn/llvm-project/lld/branches/release_90@371197 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | ELF/Writer.cpp | 3 | ||||
-rw-r--r-- | test/ELF/nmagic.s | 23 |
2 files changed, 25 insertions, 1 deletions
diff --git a/ELF/Writer.cpp b/ELF/Writer.cpp index b5b81e959..10b171e8c 100644 --- a/ELF/Writer.cpp +++ b/ELF/Writer.cpp @@ -2233,7 +2233,8 @@ static uint64_t computeFileOffset(OutputSection *os, uint64_t off) { // The first section in a PT_LOAD has to have congruent offset and address // module the page size. if (os->ptLoad && os->ptLoad->firstSec == os) { - uint64_t alignment = std::max<uint64_t>(os->alignment, config->maxPageSize); + uint64_t alignment = + std::max<uint64_t>(os->ptLoad->p_align, config->maxPageSize); return alignTo(off, alignment, os->addr); } diff --git a/test/ELF/nmagic.s b/test/ELF/nmagic.s new file mode 100644 index 000000000..f2feacb1b --- /dev/null +++ b/test/ELF/nmagic.s @@ -0,0 +1,23 @@ +# REQUIRES: x86 +# Verify that .rodata is aligned to a 8 byte boundary. + +# RUN: llvm-mc -filetype=obj -triple=i386 %s -o %t.o +# RUN: ld.lld %t.o -o %t.exe -n -Ttext 0 +# RUN: llvm-readelf --section-headers %t.exe | FileCheck %s + +# CHECK: [ 0] NULL 00000000 000000 000000 00 0 0 0 +# CHECK: [ 1] .text PROGBITS 00000000 0000d4 000001 00 AX 0 0 4 +# CHECK: [ 2] .rodata PROGBITS 00000008 0000d8 000008 00 A 0 0 8 +# CHECK: [ 3] .comment PROGBITS 00000000 0000e0 000008 01 MS 0 0 1 +# CHECK: [ 4] .symtab SYMTAB 00000000 0000e8 000020 10 6 1 4 +# CHECK: [ 5] .shstrtab STRTAB 00000000 000108 000032 00 0 0 1 +# CHECK: [ 6] .strtab STRTAB 00000000 00013a 000008 00 0 0 1 + +.globl _start +.text +_start: + ret + +.rodata +.align 8 +.quad 42 |