This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Introduce output section description class for holding section command
AbandonedPublic

Authored by grimar on Jul 20 2016, 1:46 PM.

Details

Reviewers
ruiu
Summary

OutputSectionDescription represents the state of SectionKind linker script command.
Previously Phdrs and Filler were somewhere outside when at fact they are a part
of output section description:
https://sourceware.org/binutils/docs/ld/Output-Section-Description.html#Output-Section-Description

That is the first patch to support "tree" view of LS.

Diff Detail

Event Timeline

grimar updated this revision to Diff 64751.Jul 20 2016, 1:46 PM
grimar retitled this revision from to [ELF] - Introduce output section description class for holding section command.
grimar updated this object.
grimar added a reviewer: ruiu.
grimar added subscribers: llvm-commits, grimar, evgeny777.
ruiu added inline comments.Jul 20 2016, 2:06 PM
ELF/LinkerScript.h
49–59

I think this is towards the right direction, but it doesn't still reflect the structure of SECTIONS linker script command.

As per the linker script manual (#1), SECTIONS command contains one of the following sub-commands:

  • an ENTRY command
  • an overlay description
  • a symbol assignment
  • an output section description

Since we do not support the first two, I'll ignore them in this comment. So focus on the last two. We can represent the two like this.

enum SectionsCommandKind { AssignmentKind, DescriptionKind  };

struct SectionsCommand {
  SectionsCommandKind Kind;
  std::vector<StringRef> Expr;  // For AssignmentKind
  OutputSectionDescription Desc; // For DescriptionKind
};

The above struct doesn't have Name field because SECTIONS doesn't have a name.

Name is instead in output section description as described in #2. To reflect that grammar, you want to define a class like this.

struct OutputSectionDescription {
  StringRef Name;
  std::vector<OutputSectionCommand> Commands;
  std::vector<uint8_t> Filler;
};

And then you want to define OutputSectionCommand to reflect output-section-command as described in #2.

So the point is to construct an AST whose structure logically matches with the grammar.

#1 https://sourceware.org/binutils/docs/ld/SECTIONS.html#SECTIONS
#2 https://sourceware.org/binutils/docs/ld/Output-Section-Description.html#Output-Section-Description

I see, nice.

But we use and have Name and for assignment, because can assign to location counter and to symbols outside of section declarations.
So I think it should be like next ?

struct SectionsCommand {
  SectionsCommandKind Kind;
  AssignmentDescription Assignment;  // For AssignmentKind
  OutputSectionDescription Desc; // For DescriptionKind
};

struct AssignmentDescription {
  StringRef Name;
  std::vector<StringRef> Expr;
};
grimar added a comment.EditedJul 20 2016, 2:29 PM

Probably

struct AssignmentDescription {
  StringRef Symbol;
  std::vector<StringRef> Expr;
};

As location counter is also a special symbol name.
(https://sourceware.org/binutils/docs/ld/Simple-Assignments.html#Simple-Assignments)

ruiu edited edge metadata.Jul 20 2016, 2:42 PM

I feel like the approach of using a simple struct is getting closer to its limit as we are defining more and more different kinds of sections sub-commands. It is probably time to switch to the LLVM-style RTTI.

ruiu added a comment.Jul 20 2016, 2:49 PM

What I was trying to say is https://reviews.llvm.org/D22597. I got to go, so I'm not going to finish this anytime soon. Feel free to take it over.

In D22589#490390, @ruiu wrote:

What I was trying to say is https://reviews.llvm.org/D22597. I got to go, so I'm not going to finish this anytime soon. Feel free to take it over.

I`ll take a look, thanks !

grimar abandoned this revision.Jul 21 2016, 5:35 AM

another design was landed