[PATCH] D22589: [ELF] - Introduce output section description class for holding section command

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 20 14:06:05 PDT 2016


ruiu added inline comments.

================
Comment at: ELF/LinkerScript.h:49-59
@@ -48,8 +48,13 @@
 
+struct OutputSectionDescription {
+  std::vector<StringRef> Phdrs;
+  std::vector<uint8_t> Filler;
+};
+
 struct SectionsCommand {
   SectionsCommandKind Kind;
   std::vector<StringRef> Expr;
   StringRef Name;
-  std::vector<StringRef> Phdrs;
+  OutputSectionDescription Section;
 };
 
----------------
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


https://reviews.llvm.org/D22589





More information about the llvm-commits mailing list