[ELF] Ignore the maximum of input section alignments for two cases
authorFangrui Song <maskray@google.com>
Mon, 17 Feb 2020 18:21:31 +0000 (10:21 -0800)
committerFangrui Song <maskray@google.com>
Fri, 21 Feb 2020 16:12:00 +0000 (08:12 -0800)
commit6ed8e2014330b6a48d238cdc4357e788cdd6d445
tree36df97d83f724126560e2c835569d7cc71280bb4
parent89dc8fe6222041319e073ceb8ee0cb38d045ea16
[ELF] Ignore the maximum of input section alignments for two cases

Follow-up for D74286.

Notations:

* alignExpr: the computed ALIGN value
* max_input_align: the maximum of input section alignments

This patch changes the following two cases to match GNU ld:

* When ALIGN is present, GNU ld sets output sh_addr to alignExpr, while lld use max(alignExpr, max_input_align)
* When addrExpr is specified but alignExpr is not, GNU ld sets output sh_addr to addrExpr, while lld uses `advance(0, max_input_align)`

Note, sh_addralign is still set to max(alignExpr, max_input_align).

lma-align.test is enhanced a bit to check we don't overalign sh_addr.

fixSectionAlignments() sets addrExpr but not alignExpr for the `!hasSectionsCommand` case.
This patch sets alignExpr as well so that max_input_align will be respected.

Reviewed By: grimar

Differential Revision: https://reviews.llvm.org/D74736
lld/ELF/LinkerScript.cpp
lld/ELF/Writer.cpp
lld/test/ELF/linkerscript/lma-align.test
lld/test/ELF/linkerscript/outsections-addr.s
lld/test/ELF/linkerscript/section-align2.test [new file with mode: 0644]