[PATCH] D61688: [LLD][ELF] Full support for -n (--nmagic) and -N (--omagic) via -zcommon-page-size

Peter Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 8 08:51:21 PDT 2019


peter.smith created this revision.
peter.smith added reviewers: ruiu, grimar, MaskRay.
Herald added subscribers: fedor.sergeev, arichardson, emaste, jyknight.
Herald added a reviewer: espindola.

This is an alternative implementation of -n and -N to D61201 <https://reviews.llvm.org/D61201> as this was suggested as a review comment. Instead of skipping page alignment when -n (--nmagic) and -N (--omagic) are used but leaving the values of the Config->MaxPageSize and Target->PageSize unchanged, we instead:

- Use Config->CommonPageSize to store the appropriate Target->PageSize value
- When -n or -N is used we set the Config->MaxPageSize and Config->PageSize to 1 so all page-alignment does nothing.
- We still have to account for -n and -N meaning -Bstatic.
- We still have to not allocate headers unless explicitly stated in the linker script.

As we now have a modifiable Config->CommonPageSize it becomes trivial to support the -zcommon-page-size command line option so I've done that and added a test case for it. This could be split into a different patch if it makes sense. I've also added a test to show the effect of increasing -zcommon-page-size. Other test cases have been taken from D61201 <https://reviews.llvm.org/D61201>

This approach has the advantage that none of the page alignment statements have to be changed, and any future ones we add won't need guarding. It has the disadvantage that the CONSTANT(MAXPAGESIZE) and CONSTANT(COMMONPAGESIZE) linker script commands will be affected when -n or -N is used. There is at least one linkerscript in Tianocore edk2 that (ab)uses -n -z common-page-size=0x20 to use CONSTANT(COMMONPAGESIZE) as if it were a preprocessor macro set with -D in the compiler. The usual approach to this is to pre-process the linkerscript.


https://reviews.llvm.org/D61688

Files:
  ELF/Arch/SPARCV9.cpp
  ELF/Config.h
  ELF/Driver.cpp
  ELF/LinkerScript.cpp
  ELF/Options.td
  ELF/ScriptParser.cpp
  ELF/Target.h
  ELF/Writer.cpp
  docs/ld.lld.1
  test/ELF/common-page.s
  test/ELF/linkerscript/nmagic-alignment.test
  test/ELF/magic-page-combo-warn.s
  test/ELF/relro-omagic.s
  test/ELF/segments.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61688.198669.patch
Type: text/x-patch
Size: 28124 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190508/83e20f40/attachment.bin>


More information about the llvm-commits mailing list