[ELF] Simplify sh_addr computation and warn if sh_addr is not a multiple of sh_addralign
authorFangrui Song <maskray@google.com>
Tue, 3 Mar 2020 23:37:12 +0000 (15:37 -0800)
committerFangrui Song <maskray@google.com>
Wed, 11 Mar 2020 16:35:42 +0000 (09:35 -0700)
commitfbf41b52677d9e64a888be755b4fdaef89cf519e
tree3948d6efc88430495f51ec6e058f680d0657360b
parent2150a6d0d635dea12c23dc84f356deeacbc8fbc2
[ELF] Simplify sh_addr computation and warn if sh_addr is not a multiple of sh_addralign

See `docs/ELF/linker_script.rst` for the new computation for sh_addr and sh_addralign.
`ALIGN(section_align)` now means: "increase alignment to section_align"
(like yet another input section requirement).

The "start of section .foo changes from 0x11 to 0x20" warning no longer
makes sense. Change it to warn if sh_addr%sh_addralign!=0.

To decrease the alignment from the default max_input_align,
use `.output ALIGN(8) : {}` instead of `.output : ALIGN(8) {}`
See linkerscript/section-address-align.test as an example.

When both an output section address and ALIGN are set (can be seen as an
"undefined behavior" https://sourceware.org/ml/binutils/2020-03/msg00115.html),
lld may align more than GNU ld, but it makes a linker script working
with GNU ld hard to break with lld.

This patch can be considered as restoring part of the behavior before D74736.

Differential Revision: https://reviews.llvm.org/D75724
lld/ELF/LinkerScript.cpp
lld/ELF/LinkerScript.h
lld/ELF/Writer.cpp
lld/docs/ELF/linker_script.rst
lld/test/ELF/linkerscript/lma-align.test
lld/test/ELF/linkerscript/section-address-align.test [new file with mode: 0644]
lld/test/ELF/linkerscript/section-align2.test