mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-05-28 00:40:54 +00:00
Fix the logic in the name mangler. If there are two symbols named 'X', and one
is external, make sure to mangle the *internal* one, not external one git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11424 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
dc5feab7fd
commit
a6acb4f5fd
@ -80,22 +80,37 @@ std::string Mangler::getValueName(const Value *V) {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Mangler::InsertName(GlobalValue *GV,
|
||||||
|
std::map<std::string, GlobalValue*> &Names) {
|
||||||
|
if (!GV->hasName()) { // We must mangle unnamed globals.
|
||||||
|
MangledGlobals.insert(GV);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Figure out if this is already used.
|
||||||
|
GlobalValue *&ExistingValue = Names[GV->getName()];
|
||||||
|
if (!ExistingValue) {
|
||||||
|
ExistingValue = GV;
|
||||||
|
} else {
|
||||||
|
// If GV is external but the existing one is static, mangle the existing one
|
||||||
|
if (GV->hasExternalLinkage() && !ExistingValue->hasExternalLinkage()) {
|
||||||
|
MangledGlobals.insert(ExistingValue);
|
||||||
|
ExistingValue = GV;
|
||||||
|
} else {
|
||||||
|
// Otherwise, mangle GV
|
||||||
|
MangledGlobals.insert(GV);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Mangler::Mangler(Module &m, bool addUnderscorePrefix)
|
Mangler::Mangler(Module &m, bool addUnderscorePrefix)
|
||||||
: M(m), AddUnderscorePrefix(addUnderscorePrefix), Count(0) {
|
: M(m), AddUnderscorePrefix(addUnderscorePrefix), Count(0) {
|
||||||
// Calculate which global values have names that will collide when we throw
|
// Calculate which global values have names that will collide when we throw
|
||||||
// away type information.
|
// away type information.
|
||||||
std::set<std::string> FoundNames;
|
std::map<std::string, GlobalValue*> Names;
|
||||||
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
|
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
|
||||||
if (I->hasName()) // If the global has a name...
|
InsertName(I, Names);
|
||||||
if (FoundNames.count(I->getName())) // And the name is already used
|
|
||||||
MangledGlobals.insert(I); // Mangle the name
|
|
||||||
else
|
|
||||||
FoundNames.insert(I->getName()); // Otherwise, keep track of name
|
|
||||||
|
|
||||||
for (Module::giterator I = M.gbegin(), E = M.gend(); I != E; ++I)
|
for (Module::giterator I = M.gbegin(), E = M.gend(); I != E; ++I)
|
||||||
if (I->hasName()) // If the global has a name...
|
InsertName(I, Names);
|
||||||
if (FoundNames.count(I->getName())) // And the name is already used
|
|
||||||
MangledGlobals.insert(I); // Mangle the name
|
|
||||||
else
|
|
||||||
FoundNames.insert(I->getName()); // Otherwise, keep track of name
|
|
||||||
}
|
}
|
||||||
|
@ -80,22 +80,37 @@ std::string Mangler::getValueName(const Value *V) {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Mangler::InsertName(GlobalValue *GV,
|
||||||
|
std::map<std::string, GlobalValue*> &Names) {
|
||||||
|
if (!GV->hasName()) { // We must mangle unnamed globals.
|
||||||
|
MangledGlobals.insert(GV);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Figure out if this is already used.
|
||||||
|
GlobalValue *&ExistingValue = Names[GV->getName()];
|
||||||
|
if (!ExistingValue) {
|
||||||
|
ExistingValue = GV;
|
||||||
|
} else {
|
||||||
|
// If GV is external but the existing one is static, mangle the existing one
|
||||||
|
if (GV->hasExternalLinkage() && !ExistingValue->hasExternalLinkage()) {
|
||||||
|
MangledGlobals.insert(ExistingValue);
|
||||||
|
ExistingValue = GV;
|
||||||
|
} else {
|
||||||
|
// Otherwise, mangle GV
|
||||||
|
MangledGlobals.insert(GV);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Mangler::Mangler(Module &m, bool addUnderscorePrefix)
|
Mangler::Mangler(Module &m, bool addUnderscorePrefix)
|
||||||
: M(m), AddUnderscorePrefix(addUnderscorePrefix), Count(0) {
|
: M(m), AddUnderscorePrefix(addUnderscorePrefix), Count(0) {
|
||||||
// Calculate which global values have names that will collide when we throw
|
// Calculate which global values have names that will collide when we throw
|
||||||
// away type information.
|
// away type information.
|
||||||
std::set<std::string> FoundNames;
|
std::map<std::string, GlobalValue*> Names;
|
||||||
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
|
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
|
||||||
if (I->hasName()) // If the global has a name...
|
InsertName(I, Names);
|
||||||
if (FoundNames.count(I->getName())) // And the name is already used
|
|
||||||
MangledGlobals.insert(I); // Mangle the name
|
|
||||||
else
|
|
||||||
FoundNames.insert(I->getName()); // Otherwise, keep track of name
|
|
||||||
|
|
||||||
for (Module::giterator I = M.gbegin(), E = M.gend(); I != E; ++I)
|
for (Module::giterator I = M.gbegin(), E = M.gend(); I != E; ++I)
|
||||||
if (I->hasName()) // If the global has a name...
|
InsertName(I, Names);
|
||||||
if (FoundNames.count(I->getName())) // And the name is already used
|
|
||||||
MangledGlobals.insert(I); // Mangle the name
|
|
||||||
else
|
|
||||||
FoundNames.insert(I->getName()); // Otherwise, keep track of name
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user