[PATCH] D75724: [ELF] Simplify sh_addr computation and warn if sh_addr is not a multiple of sh_addralign
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 5 22:19:43 PST 2020
MaskRay created this revision.
MaskRay added reviewers: grimar, psmith, ruiu.
Herald added subscribers: llvm-commits, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
MaskRay edited the summary of this revision.
GNU ld uses the following rules to decide the VMA alignment of sh_addr.
- ADDR is unset, ALIGN is unset => max_input_align
- ADDR is unset, ALIGN is set => max(ALIGN, max_input_align)
- ADDR is set, ALIGN is unset => max_input_align
- ADDR is set, ALIGN is set => ALIGN
This patch changes/simplifies our VMA alignment of sh_addr rules to:
- ALIGN is unset => max_input_align
- ALIGN is set => max(ALIGN, max_input_align)
(For LMA alignment, we can try ignoring max_input_align when ALIGN is specified.)
When ADDR is specified, no alignment is applied when computing sh_addr.
Corollary: 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.
(Latest GNU ld will decrease sh_addralign to satisfy sh_addr%sh_addralign=0,
but it is not necessary suitable for us.)
When both ADDR 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 <https://reviews.llvm.org/D74736>.
In general, some decisions will be different from GNU ld's, but I try to
make our rule make more sense and make it hard to shoot ourselves in the
foot. Read the linked sourceware thread for my discussions with a binutils maintainer.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D75724
Files:
lld/ELF/LinkerScript.cpp
lld/ELF/LinkerScript.h
lld/ELF/Writer.cpp
lld/test/ELF/linkerscript/lma-align.test
lld/test/ELF/linkerscript/section-align2.test
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75724.248651.patch
Type: text/x-patch
Size: 8176 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200306/edb31377/attachment.bin>
More information about the llvm-commits
mailing list