[PATCH] Dead strip atoms with deadStripAlways attribute even if dead strip is not enabled.

Rui Ueyama ruiu at google.com
Thu Aug 1 19:42:34 PDT 2013


Hi shankarke,

We have three dead-strip attributes: normal, never and always. Normal is for
regular symbols, and never means never. Always is defined but currently not
being used. Looks like the original intention of the attribute is to make the
resolver to dead-strip such atoms even if it is not instructed to do so by the
TargetInfo. So this change.

This change should be useful to support linker-generated symbols. Such symbols
are created internally in the linker and attached to a pseudo file. If the
program being linked does not have any refernce to such symbols, the symbols
need to be stripped. That can easily be done by making the linker internal
symbol to have deadStripAlways attribute.

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

Files:
  lib/Core/Resolver.cpp
  test/dead-strip-attributes.objtxt

Index: lib/Core/Resolver.cpp
===================================================================
--- lib/Core/Resolver.cpp
+++ lib/Core/Resolver.cpp
@@ -272,33 +272,42 @@
 // remove all atoms not actually used
 void Resolver::deadStripOptimize() {
   ScopedTask task(getDefaultDomain(), "deadStripOptimize");
-  // only do this optimization with -dead_strip
-  if (!_targetInfo.deadStrip())
-    return;
 
   // clear liveness on all atoms
   _liveAtoms.clear();
 
-  // By default, shared libraries are built with all globals as dead strip roots
-  if (_targetInfo.globalsAreDeadStripRoots()) {
-    for ( const Atom *atom : _atoms ) {
-      const DefinedAtom *defAtom = dyn_cast<DefinedAtom>(atom);
-      if (defAtom == nullptr)
-        continue;
-      if ( defAtom->scope() == DefinedAtom::scopeGlobal )
-        _deadStripRoots.insert(defAtom);
+  // Add live atoms to _liveAtoms.
+  if (_targetInfo.deadStrip()) {
+    // By default, shared libraries are built with all globals as dead strip roots
+    if (_targetInfo.globalsAreDeadStripRoots()) {
+      for ( const Atom *atom : _atoms ) {
+        const DefinedAtom *defAtom = dyn_cast<DefinedAtom>(atom);
+        if (defAtom == nullptr)
+          continue;
+        if ( defAtom->scope() == DefinedAtom::scopeGlobal )
+          _deadStripRoots.insert(defAtom);
+      }
     }
-  }
 
-  // Or, use list of names that are dead stip roots.
-  for (const StringRef &name : _targetInfo.deadStripRoots()) {
-    const Atom *symAtom = _symbolTable.findByName(name);
-    assert(symAtom->definition() != Atom::definitionUndefined);
-    _deadStripRoots.insert(symAtom);
+    // Or, use list of names that are dead stip roots.
+    for (const StringRef &name : _targetInfo.deadStripRoots()) {
+      const Atom *symAtom = _symbolTable.findByName(name);
+      assert(symAtom->definition() != Atom::definitionUndefined);
+      _deadStripRoots.insert(symAtom);
+    }
+  } else {
+    // If dead strip is disabled, all atoms except deadStripAlways are
+    // considered to be live.
+    for (const Atom *atom : _atoms) {
+      if (const DefinedAtom *defAtom = dyn_cast<DefinedAtom>(atom))
+        if (defAtom->deadStrip() == DefinedAtom::deadStripAlways)
+          continue;
+      _deadStripRoots.insert(atom);
+    }
   }
 
   // mark all roots as live, and recursively all atoms they reference
-  for ( const Atom *dsrAtom : _deadStripRoots) {
+  for (const Atom *dsrAtom : _deadStripRoots) {
     this->markLive(*dsrAtom);
   }
 
Index: test/dead-strip-attributes.objtxt
===================================================================
--- test/dead-strip-attributes.objtxt
+++ test/dead-strip-attributes.objtxt
@@ -24,6 +24,5 @@
 # CHECK-NOT:   dead-strip: always
 # CHECK:       name: _foo2
 # CHECK:       dead-strip: never
-# CHECK:       name: _foo3
-# CHECK:       dead-strip: always
+# CHECK-NOT:       name: _foo3
 # CHECK:       ...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1267.1.patch
Type: text/x-patch
Size: 2910 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130801/f2d23c1a/attachment.bin>


More information about the llvm-commits mailing list