[PATCH] [lld] [LinkerScript] Implement semantics for simple sections mappings

Shankar Kalpathi Easwaran shankarke at gmail.com
Sun Mar 8 20:12:32 PDT 2015


can we split this patch by functionalities too, its easier for review.


================
Comment at: include/lld/ReaderWriter/LinkerScript.h:168
@@ -163,2 +167,3 @@
     Sections,
+    SortedGroup,
     SymbolAssignment,
----------------
Could you represent all the different kinds of functions that can operate on the input sections as Functions instead of InputSectionKinds ?

================
Comment at: include/lld/ReaderWriter/LinkerScript.h:759-760
@@ -745,1 +758,4 @@
 
+  const_iterator begin() const { return _outputSectionCommands.begin(); }
+  const_iterator end() const { return _outputSectionCommands.end(); }
+  StringRef name() const { return _sectionName; }
----------------
this could be simplified if you use lld::range.

================
Comment at: include/lld/ReaderWriter/LinkerScript.h:1122
@@ +1121,3 @@
+  struct SectionKey {
+    StringRef archiveName;
+    StringRef memberName;
----------------
can you rename this to archiveNameOrPath

================
Comment at: include/lld/ReaderWriter/LinkerScript.h:1127-1130
@@ +1126,6 @@
+
+  /// A custom hash operator to teach the STL how to handle our custom keys.
+  /// This will be used in our hash table mapping Sections to a Layout Order
+  /// number (caching results).
+  struct SectionKeyHash {
+    int64_t operator()(const SectionKey &k) const {
----------------
caching layout order is error prone, as users may selectively want to specify a layout order from one rule to another.

================
Comment at: include/lld/ReaderWriter/LinkerScript.h:1154
@@ +1153,3 @@
+
+  std::vector<std::unique_ptr<Parser>> &getLinkerScripts() { return _scripts; }
+
----------------
All the end users should be using Sema right ? So This function could be made private.

================
Comment at: include/lld/ReaderWriter/LinkerScript.h:1159
@@ +1158,3 @@
+  /// scripts have been parsed.
+  void perform();
+
----------------
returns void ?

================
Comment at: include/lld/ReaderWriter/LinkerScript.h:1186
@@ +1185,3 @@
+  /// to the same set of expressions because of wildcards rules.
+  std::vector<const SymbolAssignment *> getExprs(const SectionKey &key);
+
----------------
Could we evaluate as and when the input section is appended to the output section ?

================
Comment at: lib/ReaderWriter/ELF/DefaultLayout.h:229-235
@@ +228,9 @@
+
+  /// \brief Add extra chunks to a segment just before including the input
+  /// section given by <archiveName, memberName, sectionName>. This is used by
+  /// ScriptLayout to add linker script expressions before each section.
+  virtual void addExtraChunksToSegment(Segment<ELFT> *segment,
+                                       StringRef archiveName,
+                                       StringRef memberName,
+                                       StringRef sectionName) {}
+
----------------
If you can associate the expression also to an outputsection, this would not be needed. The code gets overly simplified too.

================
Comment at: lib/ReaderWriter/ELF/SegmentChunks.h:437
@@ -402,1 +436,3 @@
+        if (auto expr = dyn_cast<ExpressionChunk<ELFT>>(section))
+          fileOffset += expr->virtualAddr() - lastVirtualAddress;
       // Align fileoffset to the alignment of the section.
----------------
why would you do this ?

http://reviews.llvm.org/D8157

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the llvm-commits mailing list