mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-13 20:32:21 +00:00
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
This commit is contained in:
parent
70bbf9a3dd
commit
30235dad4b
@ -55,11 +55,17 @@ namespace llvm {
|
||||
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 {
|
||||
@ -79,7 +85,7 @@ namespace llvm {
|
||||
|
||||
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);
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
#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"
|
||||
@ -84,17 +85,18 @@ getLTOLinkageType(GlobalValue *v)
|
||||
|
||||
// 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.
|
||||
@ -104,11 +106,15 @@ findExternalRefs(Value *value, std::set<const char *> &references) {
|
||||
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);
|
||||
|
||||
@ -118,19 +124,19 @@ LinkTimeOptimizer::readLLVMObjectFile(const std::string &InputFilename,
|
||||
|
||||
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();
|
||||
@ -138,13 +144,13 @@ LinkTimeOptimizer::readLLVMObjectFile(const std::string &InputFilename,
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user