Handle attribute(used) global variables that are i8.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46090 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2008-01-16 21:35:43 +00:00
parent 48ae02fe62
commit 1e9aa716e9

View File

@@ -101,20 +101,21 @@ bool StripSymbols::runOnModule(Module &M) {
// If we're not just stripping debug info, strip all symbols from the // If we're not just stripping debug info, strip all symbols from the
// functions and the names from any internal globals. // functions and the names from any internal globals.
if (!OnlyDebugInfo) { if (!OnlyDebugInfo) {
SmallPtrSet<const Constant *, 8> llvmUsedValues; SmallPtrSet<const GlobalValue*, 8> llvmUsedValues;
Value *LLVMUsed = M.getValueSymbolTable().lookup("llvm.used"); if (GlobalVariable *LLVMUsed = M.getGlobalVariable("llvm.used")) {
if (LLVMUsed) { llvmUsedValues.insert(LLVMUsed);
// Collect values that are preserved as per explicit request. // Collect values that are preserved as per explicit request.
// llvm.used is used to list these values. // llvm.used is used to list these values.
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(LLVMUsed)) { if (ConstantArray *Inits =
if (ConstantArray *InitList = dyn_cast<ConstantArray>(LLVMUsed->getInitializer())) {
dyn_cast<ConstantArray>(GV->getInitializer())) { for (unsigned i = 0, e = Inits->getNumOperands(); i != e; ++i) {
for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) { if (GlobalValue *GV = dyn_cast<GlobalValue>(Inits->getOperand(i)))
if (ConstantExpr *CE = llvmUsedValues.insert(GV);
dyn_cast<ConstantExpr>(InitList->getOperand(i))) else if (ConstantExpr *CE =
if (CE->isCast()) dyn_cast<ConstantExpr>(Inits->getOperand(i)))
llvmUsedValues.insert(CE->getOperand(0)); if (CE->getOpcode() == Instruction::BitCast)
} if (GlobalValue *GV = dyn_cast<GlobalValue>(CE->getOperand(0)))
llvmUsedValues.insert(GV);
} }
} }
} }
@@ -123,8 +124,6 @@ bool StripSymbols::runOnModule(Module &M) {
I != E; ++I) { I != E; ++I) {
if (I->hasInternalLinkage() && llvmUsedValues.count(I) == 0) if (I->hasInternalLinkage() && llvmUsedValues.count(I) == 0)
I->setName(""); // Internal symbols can't participate in linkage 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) { for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {