2002-04-07 20:49:59 +00:00
|
|
|
//===- SymbolStripping.cpp - Strip symbols for functions and modules ------===//
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
|
|
|
// This file implements stripping symbols out of symbol tables.
|
|
|
|
//
|
|
|
|
// Specifically, this allows you to strip all of the symbols out of:
|
2002-04-07 20:49:59 +00:00
|
|
|
// * A function
|
|
|
|
// * All functions in a module
|
|
|
|
// * All symbols in a module (all function symbols + all module scope symbols)
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
|
|
|
// Notice that:
|
|
|
|
// * This pass makes code much less readable, so it should only be used in
|
|
|
|
// situations where the 'strip' utility would be used (such as reducing
|
|
|
|
// code size, and making it harder to reverse engineer code).
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2002-01-21 23:17:48 +00:00
|
|
|
#include "llvm/Transforms/SymbolStripping.h"
|
2001-06-06 20:29:01 +00:00
|
|
|
#include "llvm/Module.h"
|
2002-04-07 20:49:59 +00:00
|
|
|
#include "llvm/Function.h"
|
2001-06-06 20:29:01 +00:00
|
|
|
#include "llvm/SymbolTable.h"
|
2002-02-26 21:46:54 +00:00
|
|
|
#include "llvm/Pass.h"
|
2001-06-06 20:29:01 +00:00
|
|
|
|
|
|
|
static bool StripSymbolTable(SymbolTable *SymTab) {
|
|
|
|
if (SymTab == 0) return false; // No symbol table? No problem.
|
|
|
|
bool RemovedSymbol = false;
|
|
|
|
|
2001-06-27 23:41:11 +00:00
|
|
|
for (SymbolTable::iterator I = SymTab->begin(); I != SymTab->end(); ++I) {
|
2002-01-20 22:54:45 +00:00
|
|
|
std::map<const std::string, Value *> &Plane = I->second;
|
2001-06-06 20:29:01 +00:00
|
|
|
|
2001-09-07 16:43:50 +00:00
|
|
|
SymbolTable::type_iterator B;
|
2001-06-06 20:29:01 +00:00
|
|
|
while ((B = Plane.begin()) != Plane.end()) { // Found nonempty type plane!
|
2001-09-07 16:43:50 +00:00
|
|
|
Value *V = B->second;
|
2001-12-03 22:26:30 +00:00
|
|
|
if (isa<Constant>(V) || isa<Type>(V))
|
2001-09-07 16:43:50 +00:00
|
|
|
SymTab->type_remove(B);
|
|
|
|
else
|
|
|
|
V->setName("", SymTab); // Set name to "", removing from symbol table!
|
2001-06-06 20:29:01 +00:00
|
|
|
RemovedSymbol = true;
|
2001-09-07 16:43:50 +00:00
|
|
|
assert(Plane.begin() != B && "Symbol not removed from table!");
|
2001-06-06 20:29:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return RemovedSymbol;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-04-07 20:49:59 +00:00
|
|
|
// DoSymbolStripping - Remove all symbolic information from a function
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
2002-04-07 20:49:59 +00:00
|
|
|
static bool doSymbolStripping(Function *F) {
|
|
|
|
return StripSymbolTable(F->getSymbolTable());
|
2001-06-06 20:29:01 +00:00
|
|
|
}
|
|
|
|
|
2002-04-07 20:49:59 +00:00
|
|
|
// doStripGlobalSymbols - Remove all symbolic information from all functions
|
|
|
|
// in a module, and all module level symbols. (function names, etc...)
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
2002-02-26 21:46:54 +00:00
|
|
|
static bool doStripGlobalSymbols(Module *M) {
|
2002-04-07 20:49:59 +00:00
|
|
|
// Remove all symbols from functions in this module... and then strip all of
|
|
|
|
// the symbols in this module...
|
2001-06-06 20:29:01 +00:00
|
|
|
//
|
2001-10-18 01:32:34 +00:00
|
|
|
return StripSymbolTable(M->getSymbolTable());
|
2001-06-06 20:29:01 +00:00
|
|
|
}
|
2002-02-26 21:46:54 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
struct SymbolStripping : public MethodPass {
|
2002-04-07 20:49:59 +00:00
|
|
|
virtual bool runOnMethod(Function *F) {
|
|
|
|
return doSymbolStripping(F);
|
2002-02-26 21:46:54 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FullSymbolStripping : public SymbolStripping {
|
|
|
|
virtual bool doInitialization(Module *M) {
|
|
|
|
return doStripGlobalSymbols(M);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
Pass *createSymbolStrippingPass() {
|
|
|
|
return new SymbolStripping();
|
|
|
|
}
|
|
|
|
|
|
|
|
Pass *createFullSymbolStrippingPass() {
|
|
|
|
return new FullSymbolStripping();
|
|
|
|
}
|