[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
Sun Mar 8 09:35:32 PDT 2020


MaskRay added a comment.

In D75724#1911650 <https://reviews.llvm.org/D75724#1911650>, @psmith wrote:

> If the ld.bfd developers consider both [address] and [ALIGN(section_align)] as undefined behaviour then I'm happy that we can simplify and the above change does implement that. Would like to hear what some of the other reviewers think as well.
>
> For the documentation may I suggest we add something like this to ld.lld.1
>
>   Linker Script implementation notes and policy.
>  
>   LLD implements a large subset of the GNU ld linker script notation. The LLD
>   implementation policy is to implement linker script features as they are
>   documented in the ld manual https://sourceware.org/binutils/docs/ld/Scripts.html
>   We consider it a bug if the lld implementation does not agree with the manual
>   and it is not mentioned in the exceptions below.
>  
>   The ld manual is not a complete specification, and is not sufficient to build
>   an implementation. In particular some features are only defined by the
>   implementation and have changed over time.
>  
>   The lld implementation policy for properties of linker scripts that are not
>   defined by the documentation is to follow the GNU ld implementation wherever
>   possible. We reserve the right to make different implementation choices where
>   it is appropriate for LLD. Intentional deviations will be documented here:
>  
>   Linker Script deviations
>  
>   Status: This is under construction and is not complete.
>  
>   Output Section ALIGN
>  
>   When an OutputSection S has both [address] and [ALIGN(section_align)]
>   LLD will set the alignment of S to the maximum of [ALIGN(section_align)] and
>   the maximum alignment of the input sections in S. GNU ld will always use
>   [ALIGN(section_align)].
>  
>   When an OutputSection S has [address] LLD will warn if this not 0 modulo
>   OutputSection alignment. The ELF file will set sh_addr to [address] and
>   sh_addralign to OutputSection alignment even if this would produce a
>   non-compliant ELF file. GNU ld from Binutils 2.35 onwards will reduce
>   sh_addralign so that sh_addr = 0 (modulo sh_addralign).
>
>
> We could add to this as we make more decisions, I've kept to just those made in this review here. We could also add a known limitations for the areas where we haven't implemented corner cases.


Thanks for the documentation! I think the paragraphs may be too long for `docs/ld.lld.1`. May I suggest you create a patch to add `Linker Script implementation notes and policy` to `docs/ELF/linker_script.rst`? I can add `Output Section ALIGN` in this patch. I don't want to take credit for the important policy part.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75724/new/

https://reviews.llvm.org/D75724





More information about the llvm-commits mailing list