//
// The LLVM Compiler Infrastructure
//
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
#include "llvm/ValueSymbolTable.h"
#include "llvm/TypeSymbolTable.h"
#include "llvm/Support/Compiler.h"
+#include "llvm/ADT/SmallPtrSet.h"
using namespace llvm;
namespace {
// 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 GlobalValue*, 8> llvmUsedValues;
+ if (GlobalVariable *LLVMUsed = M.getGlobalVariable("llvm.used")) {
+ llvmUsedValues.insert(LLVMUsed);
+ // Collect values that are preserved as per explicit request.
+ // llvm.used is used to list these values.
+ if (ConstantArray *Inits =
+ dyn_cast<ConstantArray>(LLVMUsed->getInitializer())) {
+ for (unsigned i = 0, e = Inits->getNumOperands(); i != e; ++i) {
+ if (GlobalValue *GV = dyn_cast<GlobalValue>(Inits->getOperand(i)))
+ llvmUsedValues.insert(GV);
+ else if (ConstantExpr *CE =
+ dyn_cast<ConstantExpr>(Inits->getOperand(i)))
+ if (CE->getOpcode() == Instruction::BitCast)
+ if (GlobalValue *GV = dyn_cast<GlobalValue>(CE->getOperand(0)))
+ llvmUsedValues.insert(GV);
+ }
+ }
+ }
+
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
+ }
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());
}