[PATCH] D19976: [ELF] - Prototype of possible linkerscript redesign.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Thu May 5 07:53:36 PDT 2016


grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.

After some investigation below is my vision of this feature.
This patch is in draft state now, it needs testing and polishing and probably have problems,
it is here to describe and discuss the idea.

Patch performs few passes now.  After applying ScriptConfiguration class becomes almost redundant.
Also  intermediate representation of LS commands is gone.

Details:
1) First problem is that we need to know
which sections are preserved using KEEP() on GC stage which is performed much earlier than actual creation
of sections. That means that some early pass should be done to mark them live.

2) Creating of sections should be performed on linkerscript side. That is needed
to properly create them in case of descriptions like next:
SECTIONS
{
 .foo : 
 { 
   *(.foo1)
   . = . + 0x100
   *(.foo2) 
 }
} 
So we want to know how to align/combine input sections into output one and the best way is let linkerscript to
do that on his side. We don't have to create some intermediate representation for this, we can process linkerscript commands directly.

If location counter (.) is used inside a section description, it refers to the byte offset from the start of that section, not an absolute address. 
We can use that knowledge to implement PROVIDE() on this step. We know offset of symbols from start of output section and that should be enough.

Sorting of output sections can be performed right during creation. Because creation should be in the same order
as sections are listed in script, since we do not use any heuristic like other linkers do to process orphans.
So it is not actually sorting - we just create them in specified order.

So after this step we will have created and configured output sections, and the only thing we might want to do after that is to assign address to them.

3) Last step is assign addresses. On this step we are not interested on anything except commands outside sections declarations.
So we can just ignore all parts that we are not interested in, assuming output sections is a pre-created black box. That is close
to how we already do that without linker script now.

So we can skip declaration internals and parse them as:
SECTIONS
{
 . = 0x100 // Process
 .foo ... // Assign address and skip decl
 . = ALIGN(16); // Process
 .bar ... // Assign address and skip decl
 <any other command> //Process
} 

Conclusion: so logically that patch performs 2 main steps: create all sections, process output section declarations and commands inside, and second is
assign addresses and process all other commands outside section declarations.

http://reviews.llvm.org/D19976

Files:
  ELF/LinkerScript.cpp
  ELF/LinkerScript.h
  ELF/MarkLive.cpp
  ELF/OutputSections.cpp
  ELF/OutputSections.h
  ELF/Writer.cpp
  ELF/Writer.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19976.56288.patch
Type: text/x-patch
Size: 35656 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160505/cd82f436/attachment.bin>


More information about the llvm-commits mailing list