Implement visibility checking during linking. Also implement protected
visibility support for bitcode. llvm-svn: 36577
This commit is contained in:
parent
1684cee5a2
commit
31fc4f9526
|
@ -59,6 +59,7 @@ static GlobalValue::VisibilityTypes GetDecodedVisibility(unsigned Val) {
|
||||||
default: // Map unknown visibilities to default.
|
default: // Map unknown visibilities to default.
|
||||||
case 0: return GlobalValue::DefaultVisibility;
|
case 0: return GlobalValue::DefaultVisibility;
|
||||||
case 1: return GlobalValue::HiddenVisibility;
|
case 1: return GlobalValue::HiddenVisibility;
|
||||||
|
case 2: return GlobalValue::ProtectedVisibility;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -187,8 +187,9 @@ static unsigned getEncodedLinkage(const GlobalValue *GV) {
|
||||||
static unsigned getEncodedVisibility(const GlobalValue *GV) {
|
static unsigned getEncodedVisibility(const GlobalValue *GV) {
|
||||||
switch (GV->getVisibility()) {
|
switch (GV->getVisibility()) {
|
||||||
default: assert(0 && "Invalid visibility!");
|
default: assert(0 && "Invalid visibility!");
|
||||||
case GlobalValue::DefaultVisibility: return 0;
|
case GlobalValue::DefaultVisibility: return 0;
|
||||||
case GlobalValue::HiddenVisibility: return 1;
|
case GlobalValue::HiddenVisibility: return 1;
|
||||||
|
case GlobalValue::ProtectedVisibility: return 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -365,7 +365,9 @@ static void CopyGVAttributes(GlobalValue *DestGV, const GlobalValue *SrcGV) {
|
||||||
/// the result will look like in the destination module. In particular, it
|
/// the result will look like in the destination module. In particular, it
|
||||||
/// computes the resultant linkage type, computes whether the global in the
|
/// computes the resultant linkage type, computes whether the global in the
|
||||||
/// source should be copied over to the destination (replacing the existing
|
/// source should be copied over to the destination (replacing the existing
|
||||||
/// one), and computes whether this linkage is an error or not.
|
/// one), and computes whether this linkage is an error or not. It also performs
|
||||||
|
/// visibility checks: we cannot link together two symbols with different
|
||||||
|
/// visibilities.
|
||||||
static bool GetLinkageResult(GlobalValue *Dest, GlobalValue *Src,
|
static bool GetLinkageResult(GlobalValue *Dest, GlobalValue *Src,
|
||||||
GlobalValue::LinkageTypes <, bool &LinkFromSrc,
|
GlobalValue::LinkageTypes <, bool &LinkFromSrc,
|
||||||
std::string *Err) {
|
std::string *Err) {
|
||||||
|
@ -435,6 +437,11 @@ static bool GetLinkageResult(GlobalValue *Dest, GlobalValue *Src,
|
||||||
return Error(Err, "Linking globals named '" + Src->getName() +
|
return Error(Err, "Linking globals named '" + Src->getName() +
|
||||||
"': symbol multiply defined!");
|
"': symbol multiply defined!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check visibility
|
||||||
|
if (Dest && Src->getVisibility() != Dest->getVisibility())
|
||||||
|
return Error(Err, "Linking globals named '" + Src->getName() +
|
||||||
|
"': symbols have different visibilities!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -617,6 +624,12 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
|
||||||
RecursiveResolveTypes(SF->getType(), DF->getType(),
|
RecursiveResolveTypes(SF->getType(), DF->getType(),
|
||||||
&Dest->getTypeSymbolTable(), "");
|
&Dest->getTypeSymbolTable(), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check visibility
|
||||||
|
if (DF && !DF->hasInternalLinkage() &&
|
||||||
|
SF->getVisibility() != DF->getVisibility())
|
||||||
|
return Error(Err, "Linking functions named '" + SF->getName() +
|
||||||
|
"': symbols have different visibilities!");
|
||||||
|
|
||||||
if (DF && DF->getType() != SF->getType()) {
|
if (DF && DF->getType() != SF->getType()) {
|
||||||
if (DF->isDeclaration() && !SF->isDeclaration()) {
|
if (DF->isDeclaration() && !SF->isDeclaration()) {
|
||||||
|
|
Loading…
Reference in New Issue