2001-06-06 20:29:01 +00:00
|
|
|
//===- SymbolStripping.cpp - Code to string symbols for methods and modules -=//
|
|
|
|
//
|
|
|
|
// This file implements stripping symbols out of symbol tables.
|
|
|
|
//
|
|
|
|
// Specifically, this allows you to strip all of the symbols out of:
|
|
|
|
// * A method
|
|
|
|
// * All methods in a module
|
|
|
|
// * All symbols in a module (all method symbols + all module scope symbols)
|
|
|
|
//
|
|
|
|
// 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).
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2001-06-30 04:36:40 +00:00
|
|
|
#include "llvm/Optimizations/AllOpts.h"
|
2001-06-06 20:29:01 +00:00
|
|
|
#include "llvm/Module.h"
|
|
|
|
#include "llvm/Method.h"
|
|
|
|
#include "llvm/SymbolTable.h"
|
|
|
|
|
|
|
|
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) {
|
2001-06-06 20:29:01 +00:00
|
|
|
map<const string, Value *> &Plane = I->second;
|
|
|
|
|
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-10-01 18:26:53 +00:00
|
|
|
if (isa<ConstPoolVal>(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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// DoSymbolStripping - Remove all symbolic information from a method
|
|
|
|
//
|
2001-10-18 01:32:34 +00:00
|
|
|
bool opt::SymbolStripping::doSymbolStripping(Method *M) {
|
2001-06-06 20:29:01 +00:00
|
|
|
return StripSymbolTable(M->getSymbolTable());
|
|
|
|
}
|
|
|
|
|
2001-10-18 01:32:34 +00:00
|
|
|
// doStripGlobalSymbols - Remove all symbolic information from all methods
|
2001-06-06 20:29:01 +00:00
|
|
|
// in a module, and all module level symbols. (method names, etc...)
|
|
|
|
//
|
2001-10-18 01:32:34 +00:00
|
|
|
bool opt::FullSymbolStripping::doStripGlobalSymbols(Module *M) {
|
2001-06-06 20:29:01 +00:00
|
|
|
// Remove all symbols from methods in this module... and then strip all of the
|
|
|
|
// symbols in this module...
|
|
|
|
//
|
2001-10-18 01:32:34 +00:00
|
|
|
return StripSymbolTable(M->getSymbolTable());
|
2001-06-06 20:29:01 +00:00
|
|
|
}
|