Skip to content

Commit de934bf

Browse files
committed
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 ------------------------------------------------------------------------ llvm-svn: 371197
1 parent 501ad1d commit de934bf

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lld/ELF/Writer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2233,7 +2233,8 @@ static uint64_t computeFileOffset(OutputSection *os, uint64_t off) {
22332233
// The first section in a PT_LOAD has to have congruent offset and address
22342234
// module the page size.
22352235
if (os->ptLoad && os->ptLoad->firstSec == os) {
2236-
uint64_t alignment = std::max<uint64_t>(os->alignment, config->maxPageSize);
2236+
uint64_t alignment =
2237+
std::max<uint64_t>(os->ptLoad->p_align, config->maxPageSize);
22372238
return alignTo(off, alignment, os->addr);
22382239
}
22392240

lld/test/ELF/nmagic.s

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# REQUIRES: x86
2+
# Verify that .rodata is aligned to a 8 byte boundary.
3+
4+
# RUN: llvm-mc -filetype=obj -triple=i386 %s -o %t.o
5+
# RUN: ld.lld %t.o -o %t.exe -n -Ttext 0
6+
# RUN: llvm-readelf --section-headers %t.exe | FileCheck %s
7+
8+
# CHECK: [ 0] NULL 00000000 000000 000000 00 0 0 0
9+
# CHECK: [ 1] .text PROGBITS 00000000 0000d4 000001 00 AX 0 0 4
10+
# CHECK: [ 2] .rodata PROGBITS 00000008 0000d8 000008 00 A 0 0 8
11+
# CHECK: [ 3] .comment PROGBITS 00000000 0000e0 000008 01 MS 0 0 1
12+
# CHECK: [ 4] .symtab SYMTAB 00000000 0000e8 000020 10 6 1 4
13+
# CHECK: [ 5] .shstrtab STRTAB 00000000 000108 000032 00 0 0 1
14+
# CHECK: [ 6] .strtab STRTAB 00000000 00013a 000008 00 0 0 1
15+
16+
.globl _start
17+
.text
18+
_start:
19+
ret
20+
21+
.rodata
22+
.align 8
23+
.quad 42

0 commit comments

Comments
 (0)