llvm.org GIT mirror llvm / 30235da
Use mangler, instead of addUnderscore(), to get mangled name. Now, LLVMSymbol keeps symbol original name and mangled name. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29679 91177308-0d34-0410-b5e6-96231b3b80d8 Devang Patel 13 years ago
2 changed file(s) with 28 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
5454 LTOLinkageTypes getLinkage() const { return linkage; }
5555 void mayBeNotUsed();
5656
57 LLVMSymbol (enum LTOLinkageTypes lt, GlobalValue *g) : linkage(lt), gv(g) {}
57 LLVMSymbol (enum LTOLinkageTypes lt, GlobalValue *g, std::string n,
58 std::string m) : linkage(lt), gv(g), name(n), mangledName(m) {}
59
60 const char *getName() { return name.c_str(); }
61 const char *getMangledName() { return mangledName.c_str(); }
5862
5963 private:
6064 enum LTOLinkageTypes linkage;
6165 GlobalValue *gv;
66 std::string name;
67 std::string mangledName;
6268 };
6369
6470 class string_compare {
7884
7985 enum LTOStatus readLLVMObjectFile(const std::string &InputFilename,
8086 NameToSymbolMap &symbols,
81 std::set<const char*> &references);
87 std::set<std::string> &references);
8288 enum LTOStatus optimizeModules(const std::string &OutputFilename,
8389 std::vector &exportList);
8490
2222 #include "llvm/Support/CommandLine.h"
2323 #include "llvm/Support/FileUtilities.h"
2424 #include "llvm/Support/SystemUtils.h"
25 #include "llvm/Support/Mangler.h"
2526 #include "llvm/System/Program.h"
2627 #include "llvm/System/Signals.h"
2728 #include "llvm/Analysis/Passes.h"
8384
8485 // Find exeternal symbols referenced by VALUE. This is a recursive function.
8586 static void
86 findExternalRefs(Value *value, std::set<const char *> &references) {
87 findExternalRefs(Value *value, std::set<std::string> &references,
88 Mangler &mangler) {
8789
8890 if (GlobalValue *gv = dyn_cast(value)) {
8991 LTOLinkageTypes lt = getLTOLinkageType(gv);
9092 if (lt != LTOInternalLinkage && strncmp (gv->getName().c_str(), "llvm.", 5))
91 references.insert(addUnderscore(gv->getName().c_str()));
93 references.insert(mangler.getValueName(gv));
9294 }
9395 else if (Constant *c = dyn_cast(value))
9496 // Handle ConstantExpr, ConstantStruct, ConstantArry etc..
9597 for (unsigned i = 0, e = c->getNumOperands(); i != e; ++i)
96 findExternalRefs(c->getOperand(i), references);
98 findExternalRefs(c->getOperand(i), references, mangler);
9799 }
98100
99101 /// InputFilename is a LLVM bytecode file. Read it using bytecode reader.
103105 enum LTOStatus
104106 LinkTimeOptimizer::readLLVMObjectFile(const std::string &InputFilename,
105107 NameToSymbolMap &symbols,
106 std::set<const char *> &references)
108 std::set<std::string> &references)
107109 {
108110 Module *m = ParseBytecodeFile(InputFilename);
109111 if (!m)
110112 return LTO_READ_FAILURE;
113
114 // Use mangler to add GlobalPrefix to names to match linker names.
115 // FIXME : Instead of hard coding "-" use GlobalPrefix.
116 Mangler mangler(*m, "_");
111117
112118 modules.push_back(m);
113119
117123
118124 if (!f->isExternal() && lt != LTOInternalLinkage
119125 && strncmp (f->getName().c_str(), "llvm.", 5)) {
120 const char *name = addUnderscore(f->getName().c_str());
121 LLVMSymbol *newSymbol = new LLVMSymbol(lt, f);
122 symbols[name] = newSymbol;
123 allSymbols[name] = newSymbol;
126 LLVMSymbol *newSymbol = new LLVMSymbol(lt, f, f->getName(),
127 mangler.getValueName(f));
128 symbols[newSymbol->getMangledName()] = newSymbol;
129 allSymbols[newSymbol->getMangledName()] = newSymbol;
124130 }
125
131
126132 // Collect external symbols referenced by this function.
127133 for (Function::iterator b = f->begin(), fe = f->end(); b != fe; ++b)
128134 for (BasicBlock::iterator i = b->begin(), be = b->end();
129135 i != be; ++i)
130136 for (unsigned count = 0, total = i->getNumOperands();
131137 count != total; ++count)
132 findExternalRefs(i->getOperand(count), references);
138 findExternalRefs(i->getOperand(count), references, mangler);
133139 }
134140
135141 for (Module::global_iterator v = m->global_begin(), e = m->global_end();
137143 LTOLinkageTypes lt = getLTOLinkageType(v);
138144 if (!v->isExternal() && lt != LTOInternalLinkage
139145 && strncmp (v->getName().c_str(), "llvm.", 5)) {
140 const char *name = addUnderscore(v->getName().c_str());
141 LLVMSymbol *newSymbol = new LLVMSymbol(lt,v);
142 symbols[name] = newSymbol;
146 LLVMSymbol *newSymbol = new LLVMSymbol(lt, v, v->getName(),
147 mangler.getValueName(v));
148 symbols[newSymbol->getMangledName()] = newSymbol;
143149
144150 for (unsigned count = 0, total = v->getNumOperands();
145151 count != total; ++count)
146 findExternalRefs(v->getOperand(count), references);
152 findExternalRefs(v->getOperand(count), references, mangler);
147153
148154 }
149155 }