[PATCH] [lld] [LinkerScript] Implement semantics for simple sections mappings

Rafael Auler rafaelauler at gmail.com
Sun Mar 8 18:49:36 PDT 2015


Hi shankar.easwaran, ruiu,

This patch should work on top of D8156 because it needs linker script
expression evaluation.

This patch implements the behaviour of the SECTIONS linker script directive,
used to define a custom mapping between input and output sections. Not all
sections constructs are currently supported, but only the ones that do not
use special sort orders. I added two LIT test as practical examples of which
sections directives are currently supported.

In terms of high-level changes, I created a new class "script::Sema" that owns
all linker script ASTs and the logic for linker script semantics as well.
ELFLinkingContext owns a single copy of Sema, which will be used throughout
the object file reading process (to assign rule ids to atoms) and writing
process (to layout sections as proposed by the linker script).

Other high-level change is that the writer no longer uses a "const" copy of
the linking context. This happens because linker script expressions must be
calculated *while* calculating final virtual addresses, which is a very late
step in object file writing. While calculating these expressions, we need to
update the linker script symbol table (inside the semantics object), and, thus,
we are "modifying our context" as we prepare to write the file.

The difference D7915 is that I implemented several suggestions from Rui and
Shankar:

  *  there is no exposed "id". Clients always ask how to order a section,
     and whether we use "ids" to sort or not is internal to the Sema class
     implementation. (suggestion from Rui)

  *  improved the input sections ordering and addressed the test case
     mentioned by Shankar (second LIT test case in this patch) (suggestion from Shankar)

  *  refactored the code in DefaultLayout to live in ScriptLayout (suggestion from Shankar)

I also took the opportunity to improve the code and implement simple
SORT directives and wildcard matching.

http://reviews.llvm.org/D8157

Files:
  include/lld/ReaderWriter/ELFLinkingContext.h
  include/lld/ReaderWriter/LinkerScript.h
  lib/Driver/GnuLdDriver.cpp
  lib/ReaderWriter/ELF/Chunk.h
  lib/ReaderWriter/ELF/DefaultLayout.h
  lib/ReaderWriter/ELF/ELFLinkingContext.cpp
  lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h
  lib/ReaderWriter/ELF/Mips/MipsTargetHandler.h
  lib/ReaderWriter/ELF/SectionChunks.h
  lib/ReaderWriter/ELF/SegmentChunks.h
  lib/ReaderWriter/ELF/TargetLayout.h
  lib/ReaderWriter/LinkerScript.cpp
  test/elf/linkerscript/Inputs/prog1.o.yaml
  test/elf/linkerscript/Inputs/prog2.o.yaml
  test/elf/linkerscript/Inputs/prog3.o.yaml
  test/elf/linkerscript/sections-order.test
  test/elf/linkerscript/sections-with-wildcards.test
  unittests/DriverTests/GnuLdDriverTest.cpp

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8157.21466.patch
Type: text/x-patch
Size: 64267 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150309/2b046816/attachment.bin>


More information about the llvm-commits mailing list