[PATCH] [PECOFF] Add a pass to ensure the correct ordering of grouped sections.

Shankar Kalpathi Easwaran shankarke at gmail.com
Tue Jun 18 08:08:07 PDT 2013


  I think this should be handled while writing the file than having another pass. Easier to deal with this in the Writer.


================
Comment at: lib/ReaderWriter/PECOFF/Atoms.cpp:1-32
@@ +1,32 @@
+//===- lib/ReaderWriter/PECOFF/Atoms.cpp ----------------------------------===//
+//
+//                             The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "Atoms.h"
+
+#include <memory>
+
+namespace lld {
+namespace coff {
+
+namespace {
+void addEdge(COFFDefinedAtom *a, COFFDefinedAtom *b,
+             lld::Reference::Kind kind) {
+  auto ref = new COFFReference(kind);
+  ref->setTarget(b);
+  a->addReference(std::unique_ptr<COFFReference>(ref));
+}
+}
+
+void connectAtomsWithLayoutEdge(COFFDefinedAtom *a, COFFDefinedAtom *b) {
+  addEdge(a, b, lld::Reference::kindLayoutAfter);
+  addEdge(b, a, lld::Reference::kindLayoutBefore);
+}
+
+} // namespace coff
+} // namespace lld
----------------
This code should probably go in Atoms.h. 

================
Comment at: lib/ReaderWriter/PECOFF/GroupedSectionsPass.h:54
@@ +53,3 @@
+namespace {
+bool compareByFileOrdinal(const DefinedAtom *a, const DefinedAtom *b) {
+  return a->file().ordinal() > b->file().ordinal();
----------------
const

================
Comment at: lib/ReaderWriter/PECOFF/GroupedSectionsPass.h:9-24
@@ +8,18 @@
+//===----------------------------------------------------------------------===//
+///
+/// \file \brief This pass adds layout-{before,after} references to atoms in
+/// grouped sections, so that they will appear in the correct order in the
+/// output.
+///
+/// In COFF, sections will be merged into one section by the linker if their
+/// names are the same after discarding the "$" character and all characters
+/// follow it from their names. The characters following the "$" character
+/// determines the merge order. Assume there's an object file containing four
+/// data sections in the following order.
+///
+///   - .data$2
+///   - .data$3
+///   - .data$1
+///   - .data
+///
+/// In this case, the resulting binary should have ".data" section with the
----------------
I think this can be handled in the writer, when you merge each section rather than adding it to the layout pass. 

================
Comment at: lib/ReaderWriter/PECOFF/GroupedSectionsPass.h:10-12
@@ +9,5 @@
+///
+/// \file \brief This pass adds layout-{before,after} references to atoms in
+/// grouped sections, so that they will appear in the correct order in the
+/// output.
+///
----------------
Is this comment doxygen compatible ?

================
Comment at: lib/ReaderWriter/PECOFF/GroupedSectionsPass.h:93
@@ +92,3 @@
+    // is a sorted map.
+    for (auto &i : sectionToHeadAtoms) {
+      StringRef sectionName = i.first;
----------------
are you modifying i ? I dont see that being modified.


http://llvm-reviews.chandlerc.com/D998



More information about the llvm-commits mailing list