1 //===- SymbolStripping.cpp - Code to string symbols for methods and modules -=//
3 // This file implements stripping symbols out of symbol tables.
5 // Specifically, this allows you to strip all of the symbols out of:
7 // * All methods in a module
8 // * All symbols in a module (all method symbols + all module scope symbols)
11 // * This pass makes code much less readable, so it should only be used in
12 // situations where the 'strip' utility would be used (such as reducing
13 // code size, and making it harder to reverse engineer code).
15 //===----------------------------------------------------------------------===//
17 #include "llvm/Optimizations/AllOpts.h"
18 #include "llvm/Module.h"
19 #include "llvm/Method.h"
20 #include "llvm/SymbolTable.h"
22 static bool StripSymbolTable(SymbolTable *SymTab) {
23 if (SymTab == 0) return false; // No symbol table? No problem.
24 bool RemovedSymbol = false;
26 for (SymbolTable::iterator I = SymTab->begin(); I != SymTab->end(); ++I) {
27 map<const string, Value *> &Plane = I->second;
29 SymbolTable::type_iterator B;
30 while ((B = Plane.begin()) != Plane.end()) { // Found nonempty type plane!
32 if (isa<ConstPoolVal>(V) || isa<Type>(V))
33 SymTab->type_remove(B);
35 V->setName("", SymTab); // Set name to "", removing from symbol table!
37 assert(Plane.begin() != B && "Symbol not removed from table!");
45 // DoSymbolStripping - Remove all symbolic information from a method
47 bool opt::SymbolStripping::doSymbolStripping(Method *M) {
48 return StripSymbolTable(M->getSymbolTable());
51 // doStripGlobalSymbols - Remove all symbolic information from all methods
52 // in a module, and all module level symbols. (method names, etc...)
54 bool opt::FullSymbolStripping::doStripGlobalSymbols(Module *M) {
55 // Remove all symbols from methods in this module... and then strip all of the
56 // symbols in this module...
58 return StripSymbolTable(M->getSymbolTable());