1 //===- StripSymbols.cpp - Strip symbols and debug info from a module ------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements stripping symbols out of symbol tables.
12 // Specifically, this allows you to strip all of the symbols out of:
13 // * All functions in a module
14 // * All non-essential symbols in a module (all function symbols + all module
16 // * Debug information.
19 // * This pass makes code much less readable, so it should only be used in
20 // situations where the 'strip' utility would be used (such as reducing
21 // code size, and making it harder to reverse engineer code).
23 //===----------------------------------------------------------------------===//
25 #include "llvm/Transforms/IPO.h"
26 #include "llvm/Module.h"
27 #include "llvm/SymbolTable.h"
28 #include "llvm/Pass.h"
32 class StripSymbols : public ModulePass {
35 StripSymbols(bool ODI = false) : OnlyDebugInfo(ODI) {}
37 virtual bool runOnModule(Module &M);
39 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
43 RegisterOpt<StripSymbols> X("strip", "Strip all symbols from a module");
46 ModulePass *llvm::createStripSymbolsPass(bool OnlyDebugInfo) {
47 return new StripSymbols(OnlyDebugInfo);
51 bool StripSymbols::runOnModule(Module &M) {
52 // If we're not just stripping debug info, strip all symbols from the
53 // functions and the names from any internal globals.
55 for (Module::giterator I = M.gbegin(), E = M.gend(); I != E; ++I)
56 if (I->hasInternalLinkage())
57 I->setName(""); // Internal symbols can't participate in linkage
59 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
60 if (I->hasInternalLinkage())
61 I->setName(""); // Internal symbols can't participate in linkage
62 I->getSymbolTable().strip();
66 // FIXME: implement stripping of debug info.