LTOLinkageTypes getLinkage() const { return linkage; }
void mayBeNotUsed();
- LLVMSymbol (enum LTOLinkageTypes lt, GlobalValue *g) : linkage(lt), gv(g) {}
+ LLVMSymbol (enum LTOLinkageTypes lt, GlobalValue *g, std::string n,
+ std::string m) : linkage(lt), gv(g), name(n), mangledName(m) {}
+
+ const char *getName() { return name.c_str(); }
+ const char *getMangledName() { return mangledName.c_str(); }
private:
enum LTOLinkageTypes linkage;
GlobalValue *gv;
+ std::string name;
+ std::string mangledName;
};
class string_compare {
enum LTOStatus readLLVMObjectFile(const std::string &InputFilename,
NameToSymbolMap &symbols,
- std::set<const char*> &references);
+ std::set<std::string> &references);
enum LTOStatus optimizeModules(const std::string &OutputFilename,
std::vector<const char*> &exportList);
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/SystemUtils.h"
+#include "llvm/Support/Mangler.h"
#include "llvm/System/Program.h"
#include "llvm/System/Signals.h"
#include "llvm/Analysis/Passes.h"
// Find exeternal symbols referenced by VALUE. This is a recursive function.
static void
-findExternalRefs(Value *value, std::set<const char *> &references) {
+findExternalRefs(Value *value, std::set<std::string> &references,
+ Mangler &mangler) {
if (GlobalValue *gv = dyn_cast<GlobalValue>(value)) {
LTOLinkageTypes lt = getLTOLinkageType(gv);
if (lt != LTOInternalLinkage && strncmp (gv->getName().c_str(), "llvm.", 5))
- references.insert(addUnderscore(gv->getName().c_str()));
+ references.insert(mangler.getValueName(gv));
}
else if (Constant *c = dyn_cast<Constant>(value))
// Handle ConstantExpr, ConstantStruct, ConstantArry etc..
for (unsigned i = 0, e = c->getNumOperands(); i != e; ++i)
- findExternalRefs(c->getOperand(i), references);
+ findExternalRefs(c->getOperand(i), references, mangler);
}
/// InputFilename is a LLVM bytecode file. Read it using bytecode reader.
enum LTOStatus
LinkTimeOptimizer::readLLVMObjectFile(const std::string &InputFilename,
NameToSymbolMap &symbols,
- std::set<const char *> &references)
+ std::set<std::string> &references)
{
Module *m = ParseBytecodeFile(InputFilename);
if (!m)
return LTO_READ_FAILURE;
+
+ // Use mangler to add GlobalPrefix to names to match linker names.
+ // FIXME : Instead of hard coding "-" use GlobalPrefix.
+ Mangler mangler(*m, "_");
modules.push_back(m);
if (!f->isExternal() && lt != LTOInternalLinkage
&& strncmp (f->getName().c_str(), "llvm.", 5)) {
- const char *name = addUnderscore(f->getName().c_str());
- LLVMSymbol *newSymbol = new LLVMSymbol(lt, f);
- symbols[name] = newSymbol;
- allSymbols[name] = newSymbol;
+ LLVMSymbol *newSymbol = new LLVMSymbol(lt, f, f->getName(),
+ mangler.getValueName(f));
+ symbols[newSymbol->getMangledName()] = newSymbol;
+ allSymbols[newSymbol->getMangledName()] = newSymbol;
}
-
+
// Collect external symbols referenced by this function.
for (Function::iterator b = f->begin(), fe = f->end(); b != fe; ++b)
for (BasicBlock::iterator i = b->begin(), be = b->end();
i != be; ++i)
for (unsigned count = 0, total = i->getNumOperands();
count != total; ++count)
- findExternalRefs(i->getOperand(count), references);
+ findExternalRefs(i->getOperand(count), references, mangler);
}
for (Module::global_iterator v = m->global_begin(), e = m->global_end();
LTOLinkageTypes lt = getLTOLinkageType(v);
if (!v->isExternal() && lt != LTOInternalLinkage
&& strncmp (v->getName().c_str(), "llvm.", 5)) {
- const char *name = addUnderscore(v->getName().c_str());
- LLVMSymbol *newSymbol = new LLVMSymbol(lt,v);
- symbols[name] = newSymbol;
+ LLVMSymbol *newSymbol = new LLVMSymbol(lt, v, v->getName(),
+ mangler.getValueName(v));
+ symbols[newSymbol->getMangledName()] = newSymbol;
for (unsigned count = 0, total = v->getNumOperands();
count != total; ++count)
- findExternalRefs(v->getOperand(count), references);
+ findExternalRefs(v->getOperand(count), references, mangler);
}
}