summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorAnton Korobeynikov <asl@math.spbu.ru>2007-04-29 20:56:48 +0000
committerAnton Korobeynikov <asl@math.spbu.ru>2007-04-29 20:56:48 +0000
commit31fc4f95265a3dd38fba5594425d5bc3dd089683 (patch)
treeb896aa24b67b603ee2530b13db2c0b61332a6187 /llvm/lib
parent1684cee5a2f8cc6f1c9fff309db765eeafa52438 (diff)
downloadbcm5719-llvm-31fc4f95265a3dd38fba5594425d5bc3dd089683.tar.gz
bcm5719-llvm-31fc4f95265a3dd38fba5594425d5bc3dd089683.zip
Implement visibility checking during linking. Also implement protected
visibility support for bitcode. llvm-svn: 36577
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp1
-rw-r--r--llvm/lib/Bitcode/Writer/BitcodeWriter.cpp5
-rw-r--r--llvm/lib/Linker/LinkModules.cpp15
3 files changed, 18 insertions, 3 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 6157a5db5d9..07089a85afe 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -59,6 +59,7 @@ static GlobalValue::VisibilityTypes GetDecodedVisibility(unsigned Val) {
default: // Map unknown visibilities to default.
case 0: return GlobalValue::DefaultVisibility;
case 1: return GlobalValue::HiddenVisibility;
+ case 2: return GlobalValue::ProtectedVisibility;
}
}
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 2a4b13a9478..eccfd429024 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -187,8 +187,9 @@ static unsigned getEncodedLinkage(const GlobalValue *GV) {
static unsigned getEncodedVisibility(const GlobalValue *GV) {
switch (GV->getVisibility()) {
default: assert(0 && "Invalid visibility!");
- case GlobalValue::DefaultVisibility: return 0;
- case GlobalValue::HiddenVisibility: return 1;
+ case GlobalValue::DefaultVisibility: return 0;
+ case GlobalValue::HiddenVisibility: return 1;
+ case GlobalValue::ProtectedVisibility: return 2;
}
}
diff --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp
index 0d4479bfd24..cf9f777a53e 100644
--- a/llvm/lib/Linker/LinkModules.cpp
+++ b/llvm/lib/Linker/LinkModules.cpp
@@ -365,7 +365,9 @@ static void CopyGVAttributes(GlobalValue *DestGV, const GlobalValue *SrcGV) {
/// the result will look like in the destination module. In particular, it
/// computes the resultant linkage type, computes whether the global in the
/// 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,
GlobalValue::LinkageTypes &LT, bool &LinkFromSrc,
std::string *Err) {
@@ -435,6 +437,11 @@ static bool GetLinkageResult(GlobalValue *Dest, GlobalValue *Src,
return Error(Err, "Linking globals named '" + Src->getName() +
"': 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;
}
@@ -617,6 +624,12 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
RecursiveResolveTypes(SF->getType(), DF->getType(),
&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->isDeclaration() && !SF->isDeclaration()) {
OpenPOWER on IntegriCloud