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.
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:
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