diff options
author | Chris Lattner <sabre@nondot.org> | 2004-12-02 21:25:03 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-12-02 21:25:03 +0000 |
commit | e3ad43c828280cf11e8631f1a814a51a0b168016 (patch) | |
tree | 275921b8f77801c72cb1973656a6062871f9d216 /lib | |
parent | 6992afcdb93174117be810b0c52c261b82b781f7 (diff) | |
download | external_llvm-e3ad43c828280cf11e8631f1a814a51a0b168016.zip external_llvm-e3ad43c828280cf11e8631f1a814a51a0b168016.tar.gz external_llvm-e3ad43c828280cf11e8631f1a814a51a0b168016.tar.bz2 |
Initial reimplementation of the -strip pass, with a stub for implementing
-S
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18440 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Transforms/IPO/StripSymbols.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/lib/Transforms/IPO/StripSymbols.cpp b/lib/Transforms/IPO/StripSymbols.cpp new file mode 100644 index 0000000..f611d9c --- /dev/null +++ b/lib/Transforms/IPO/StripSymbols.cpp @@ -0,0 +1,68 @@ +//===- StripSymbols.cpp - Strip symbols and debug info from a module ------===// +// +// The LLVM Compiler Infrastructure +// +// This file was developed by the LLVM research group and is distributed under +// the University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements stripping symbols out of symbol tables. +// +// Specifically, this allows you to strip all of the symbols out of: +// * All functions in a module +// * All non-essential symbols in a module (all function symbols + all module +// scope symbols) +// * Debug information. +// +// 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). +// +//===----------------------------------------------------------------------===// + +#include "llvm/Transforms/IPO.h" +#include "llvm/Module.h" +#include "llvm/SymbolTable.h" +#include "llvm/Pass.h" +using namespace llvm; + +namespace { + class StripSymbols : public ModulePass { + bool OnlyDebugInfo; + public: + StripSymbols(bool ODI = false) : OnlyDebugInfo(ODI) {} + + virtual bool runOnModule(Module &M); + + virtual void getAnalysisUsage(AnalysisUsage &AU) const { + AU.setPreservesAll(); + } + }; + RegisterOpt<StripSymbols> X("strip", "Strip all symbols from a module"); +} + +ModulePass *llvm::createStripSymbolsPass(bool OnlyDebugInfo) { + return new StripSymbols(OnlyDebugInfo); +} + + +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) { + for (Module::giterator I = M.gbegin(), E = M.gend(); I != E; ++I) + if (I->hasInternalLinkage()) + I->setName(""); // Internal symbols can't participate in linkage + + for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) { + if (I->hasInternalLinkage()) + I->setName(""); // Internal symbols can't participate in linkage + I->getSymbolTable().strip(); + } + } + + // FIXME: implement stripping of debug info. + return true; +} |