[lld] r231615 - PECOFF: Create layout-afters instead of layout-befores.

Rui Ueyama ruiu at google.com
Sun Mar 8 17:06:07 PDT 2015


Author: ruiu
Date: Sun Mar  8 19:06:07 2015
New Revision: 231615

URL: http://llvm.org/viewvc/llvm-project?rev=231615&view=rev
Log:
PECOFF: Create layout-afters instead of layout-befores.

All readers except PE/COFF reader create layout-after edges to preserve
the original symbol order. PE/COFF uses layout-before edges as primary
edges for no reason.

This patch makes PE/COFF reader to create layout-after edges.
Resolver is updated to recognize reverse edges of layout-after edges
in the garbage collection pass.

Now we can retire layout-before edges. I don't do that in this patch
because if I do, I would have updated many tests to replace all
occurrrences of "layout-before" with "layout-after". So that's a TODO.

Modified:
    lld/trunk/lib/Core/Resolver.cpp
    lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
    lld/trunk/test/core/sectiongroup-deadstrip.objtxt

Modified: lld/trunk/lib/Core/Resolver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/Resolver.cpp?rev=231615&r1=231614&r2=231615&view=diff
==============================================================================
--- lld/trunk/lib/Core/Resolver.cpp (original)
+++ lld/trunk/lib/Core/Resolver.cpp Sun Mar  8 19:06:07 2015
@@ -382,7 +382,7 @@ void Resolver::markLive(const Atom *atom
 static bool isBackref(const Reference *ref) {
   if (ref->kindNamespace() != lld::Reference::KindNamespace::all)
     return false;
-  return (ref->kindValue() == lld::Reference::kindLayoutBefore ||
+  return (ref->kindValue() == lld::Reference::kindLayoutAfter ||
           ref->kindValue() == lld::Reference::kindGroupChild);
 }
 

Modified: lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp?rev=231615&r1=231614&r2=231615&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp Sun Mar  8 19:06:07 2015
@@ -747,14 +747,14 @@ std::error_code FileCOFF::AtomizeDefined
     if (atoms.size() > 0)
       atoms[0]->setAlignment(getAlignment(section));
 
-    // Connect atoms with layout-before edges. It prevents atoms
+    // Connect atoms with layout-after edges. It prevents atoms
     // from being GC'ed if there is a reference to one of the atoms
-    // in the same layout-before chain. In such case we want to emit
+    // in the same layout-after chain. In such case we want to emit
     // all the atoms appeared in the same chain, because the "live"
     // atom may reference other atoms in the same chain.
     if (atoms.size() >= 2)
       for (auto it = atoms.begin(), e = atoms.end(); it + 1 != e; ++it)
-        addLayoutEdge(*(it + 1), *it, lld::Reference::kindLayoutBefore);
+        addLayoutEdge(*it, *(it + 1), lld::Reference::kindLayoutAfter);
 
     for (COFFDefinedFileAtom *atom : atoms) {
       _sectionAtoms[section].push_back(atom);

Modified: lld/trunk/test/core/sectiongroup-deadstrip.objtxt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/core/sectiongroup-deadstrip.objtxt?rev=231615&r1=231614&r2=231615&view=diff
==============================================================================
--- lld/trunk/test/core/sectiongroup-deadstrip.objtxt (original)
+++ lld/trunk/test/core/sectiongroup-deadstrip.objtxt Sun Mar  8 19:06:07 2015
@@ -18,6 +18,9 @@ defined-atoms:
   - name:            f1
     scope:           global
     type:            code
+    references:
+      - kind:            layout-after
+        target:          anotherfunction
   - name:            f2
     scope:           global
     type:            code
@@ -42,9 +45,6 @@ defined-atoms:
   - name:            anotherfunction
     scope:           global
     type:            data
-    references:
-      - kind:            layout-before
-        target:          f1
 ---
 undefined-atoms:
     - name:              f1
@@ -71,6 +71,10 @@ undefined-atoms:
 #CHECK:         target:          [[GCHILD:[a-zA-Z\.0-9_]+]]
 #CHECK:   - name:            f1
 #CHECK:     scope:           global
+#CHECK:     references:
+#CHECK:       - kind:            layout-after
+#CHECK:         offset:          0
+#CHECK:         target:          anotherfunction
 #CHECK:   - name:            f2
 #CHECK:     scope:           global
 #CHECK:   - name:            d1
@@ -82,7 +86,3 @@ undefined-atoms:
 #CHECK:   - name:            anotherfunction
 #CHECK:     scope:           global
 #CHECK:     type:            data
-#CHECK:     references:
-#CHECK:       - kind:            layout-before
-#CHECK:         offset:          0
-#CHECK:         target:          f1





More information about the llvm-commits mailing list