Handle a section being more aligned than a page size.
llvm-svn: 308812
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 1853f99..558ecfb 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -1600,7 +1600,8 @@
// The first section in a PT_LOAD has to have congruent offset and address
// module the page size.
if (Sec == First)
- return alignTo(Off, Config->MaxPageSize, Sec->Addr);
+ return alignTo(Off, std::max<uint64_t>(Sec->Alignment, Config->MaxPageSize),
+ Sec->Addr);
// If two sections share the same PT_LOAD the file offset is calculated
// using this formula: Off2 = Off1 + (VA2 - VA1).
diff --git a/lld/test/ELF/linkerscript/align-section-offset.s b/lld/test/ELF/linkerscript/align-section-offset.s
new file mode 100644
index 0000000..58831f1
--- /dev/null
+++ b/lld/test/ELF/linkerscript/align-section-offset.s
@@ -0,0 +1,10 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: echo "SECTIONS { .foo : ALIGN(2M) { *(.foo) } }" > %t.script
+# RUN: ld.lld -o %t --script %t.script %t.o -shared
+# RUN: llvm-readelf -S %t | FileCheck %s
+
+# CHECK: .foo PROGBITS 0000000000200000 200000 000008 00 WA 0 0 2097152
+
+ .section .foo, "aw"
+ .quad 42