[llvm-commits] [llvm] r46045 - in /llvm/trunk: lib/Transforms/IPO/StripSymbols.cpp test/Transforms/StripSymbols/ test/Transforms/StripSymbols/2007-01-15-llvm.used.ll test/Transforms/StripSymbols/Output/ test/Transforms/StripSymbols/dg.exp
Devang Patel
dpatel at apple.com
Tue Jan 15 19:33:07 PST 2008
Author: dpatel
Date: Tue Jan 15 21:33:05 2008
New Revision: 46045
URL: http://llvm.org/viewvc/llvm-project?rev=46045&view=rev
Log:
Do not strip llvm.used values.
Added:
llvm/trunk/test/Transforms/StripSymbols/
llvm/trunk/test/Transforms/StripSymbols/2007-01-15-llvm.used.ll
llvm/trunk/test/Transforms/StripSymbols/Output/
llvm/trunk/test/Transforms/StripSymbols/dg.exp
Modified:
llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp
Modified: llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp?rev=46045&r1=46044&r2=46045&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp Tue Jan 15 21:33:05 2008
@@ -29,6 +29,7 @@
#include "llvm/ValueSymbolTable.h"
#include "llvm/TypeSymbolTable.h"
#include "llvm/Support/Compiler.h"
+#include "llvm/ADT/SmallPtrSet.h"
using namespace llvm;
namespace {
@@ -100,13 +101,34 @@
// If we're not just stripping debug info, strip all symbols from the
// functions and the names from any internal globals.
if (!OnlyDebugInfo) {
+ SmallPtrSet<const Constant *, 8> llvmUsedValues;
+ Value *LLVMUsed = M.getValueSymbolTable().lookup("llvm.used");
+ if (LLVMUsed) {
+ // Collect values that are preserved as per explicit request.
+ // llvm.used is used to list these values.
+ if (GlobalVariable *GV = dyn_cast<GlobalVariable>(LLVMUsed)) {
+ if (ConstantArray *InitList =
+ dyn_cast<ConstantArray>(GV->getInitializer())) {
+ for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
+ if (ConstantExpr *CE =
+ dyn_cast<ConstantExpr>(InitList->getOperand(i)))
+ if (CE->isCast())
+ llvmUsedValues.insert(CE->getOperand(0));
+ }
+ }
+ }
+ }
+
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
- I != E; ++I)
- if (I->hasInternalLinkage())
+ I != E; ++I) {
+ if (I->hasInternalLinkage() && llvmUsedValues.count(I) == 0)
I->setName(""); // Internal symbols can't participate in linkage
+ else if (I->getName() == "llvm.used") {
+ }
+ }
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
- if (I->hasInternalLinkage())
+ if (I->hasInternalLinkage() && llvmUsedValues.count(I) == 0)
I->setName(""); // Internal symbols can't participate in linkage
StripSymtab(I->getValueSymbolTable());
}
Added: llvm/trunk/test/Transforms/StripSymbols/2007-01-15-llvm.used.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/StripSymbols/2007-01-15-llvm.used.ll?rev=46045&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/StripSymbols/2007-01-15-llvm.used.ll (added)
+++ llvm/trunk/test/Transforms/StripSymbols/2007-01-15-llvm.used.ll Tue Jan 15 21:33:05 2008
@@ -0,0 +1,15 @@
+; RUN: llvm-as < %s | opt -strip | llvm-dis | grep foo | count 2
+; RUN: llvm-as < %s | opt -strip | llvm-dis | grep bar | count 2
+ at llvm.used = appending global [2 x i8*] [ i8* bitcast (i32* @foo to i8*), i8* bitcast (i32 ()* @bar to i8*) ], section "llvm.metadata" ; <[2 x i8*]*> [#uses=0]
+ at foo = internal constant i32 41 ; <i32*> [#uses=1]
+
+define internal i32 @bar() nounwind {
+entry:
+ ret i32 42
+}
+
+define i32 @main() nounwind {
+entry:
+ ret i32 0
+}
+
Added: llvm/trunk/test/Transforms/StripSymbols/dg.exp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/StripSymbols/dg.exp?rev=46045&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/StripSymbols/dg.exp (added)
+++ llvm/trunk/test/Transforms/StripSymbols/dg.exp Tue Jan 15 21:33:05 2008
@@ -0,0 +1,3 @@
+load_lib llvm.exp
+
+RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,llx,c,cpp,tr}]]
More information about the llvm-commits
mailing list