mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
Do not strip llvm.used values.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46045 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
316e984471
commit
8c231e5dda
@ -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 @@ bool StripSymbols::runOnModule(Module &M) {
|
||||
// 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());
|
||||
}
|
||||
|
15
test/Transforms/StripSymbols/2007-01-15-llvm.used.ll
Normal file
15
test/Transforms/StripSymbols/2007-01-15-llvm.used.ll
Normal file
@ -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
|
||||
@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]
|
||||
@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
|
||||
}
|
||||
|
3
test/Transforms/StripSymbols/dg.exp
Normal file
3
test/Transforms/StripSymbols/dg.exp
Normal file
@ -0,0 +1,3 @@
|
||||
load_lib llvm.exp
|
||||
|
||||
RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,llx,c,cpp,tr}]]
|
Loading…
Reference in New Issue
Block a user