This is an archive of the discontinued LLVM Phabricator instance.

[lld] Teach LLD how to parse complete linker scripts
AbandonedPublic

Authored by rafaelauler on Oct 17 2014, 5:00 PM.

Details

Summary

This patch does *not* implement any semantic actions, but it is a first step to
teach LLD how to read complete linker scripts. The additional linker scripts
statements whose parsing is now supported are:

  • SEARCH_DIR directive
  • SECTIONS directive
  • Symbol definitions inside SECTIONS including PROVIDE and PROVIDE_HIDDEN
  • C-like expressions used in many places in linker scripts
  • Input to output sections mapping

The goal of this patch was guided towards completely parsing a default GNU ld
linker script and the linker script used to link the FreeBSD kernel. Thus, it
also adds a test case based on the default linker script used in GNU ld for
x86_64 ELF targets.

Note: Sorry for the size of this patch. I started with the goal of incrementally
developing this parser but ultimately failed. On the other side, the logic of the
parser is kind of repetitive, as one would expect, so this patch does not feature
lots of new things.

Diff Detail

Event Timeline

rafaelauler abandoned this revision.Oct 17 2014, 5:00 PM
rafaelauler updated this revision to Diff 15105.
rafaelauler retitled this revision from to [lld] Teach LLD how to parse complete linker scripts.
rafaelauler updated this object.
rafaelauler edited the test plan for this revision. (Show Details)
rafaelauler added reviewers: Bigcheese, shankarke.
rafaelauler added subscribers: ruiu, rafael.

Forgot to add llvm-commits to subscribers. Opened a new revision and added it.

ruiu added a comment.Oct 17 2014, 5:28 PM

Because this is a large patch, it'll take some time to review.
Let me send out my first comment in the meantime.

include/lld/ReaderWriter/LinkerScript.h
402

Is there any reason to have these member functions to mutate object's fields? It seems to me that we can make the constructor to take all these values. If we do so, we can handle all BinOps as const, which helps readers to understand the code.

The same comments are applied to all other classes representing ast nodes.

Hi Ruiu, sorry, I messed up this revision because I forgot to add llvm-commits to subscribers. I opened a new one in D5852, I will answer will question there. Thanks for sharing your opinion.