[ELF] - Initial support of tree-style linker script implemented.

Approach uses LLVM-style RTTI for representing the linker script
commands in a form of tree for future simplification of parsing.

Core idea and code sample belongs to Rui Ueyama.

Differential revision: https://reviews.llvm.org/D22604

llvm-svn: 276243
diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h
index 3ef318d..20ab4be0 100644
--- a/lld/ELF/LinkerScript.h
+++ b/lld/ELF/LinkerScript.h
@@ -41,16 +41,37 @@
   StringRef SectionPattern;
 };
 
-// This enum represents what we can observe in SECTIONS tag of script:
-// ExprKind is a location counter change, like ". = . + 0x1000"
-// SectionKind is a description of output section, like ".data :..."
-enum SectionsCommandKind { SectionKind, AssignmentKind };
+// This enum represents what we can observe in SECTIONS tag of script.
+// Each sections-command may of be one of the following:
+// (https://sourceware.org/binutils/docs/ld/SECTIONS.html#SECTIONS)
+// * An ENTRY command.
+// * A symbol assignment.
+// * An output section description.
+// * An overlay description.
+// We support only AssignmentKind and OutputSectionKind for now.
+enum SectionsCommandKind { AssignmentKind, OutputSectionKind };
 
-struct SectionsCommand {
-  SectionsCommandKind Kind;
+struct BaseCommand {
+  BaseCommand(int K) : Kind(K) {}
+  virtual ~BaseCommand() {}
+  int Kind;
+};
+
+struct SymbolAssignment : BaseCommand {
+  SymbolAssignment(StringRef Name, std::vector<StringRef> &Expr)
+      : BaseCommand(AssignmentKind), Name(Name), Expr(std::move(Expr)) {}
+  static bool classof(const BaseCommand *C);
+  StringRef Name;
   std::vector<StringRef> Expr;
+};
+
+struct OutputSectionCommand : BaseCommand {
+  OutputSectionCommand(StringRef Name)
+      : BaseCommand(OutputSectionKind), Name(Name) {}
+  static bool classof(const BaseCommand *C);
   StringRef Name;
   std::vector<StringRef> Phdrs;
+  std::vector<uint8_t> Filler;
 };
 
 struct PhdrsCommand {
@@ -69,7 +90,7 @@
   llvm::StringMap<std::vector<uint8_t>> Filler;
 
   // Used to assign addresses to sections.
-  std::vector<SectionsCommand> Commands;
+  std::vector<std::unique_ptr<BaseCommand>> Commands;
 
   // Used to assign sections to headers.
   std::vector<PhdrsCommand> PhdrsCommands;