Implement visibility checking during linking. Also implement protected
authorAnton Korobeynikov <asl@math.spbu.ru>
Sun, 29 Apr 2007 20:56:48 +0000 (20:56 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Sun, 29 Apr 2007 20:56:48 +0000 (20:56 +0000)
visibility support for bitcode.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36577 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Bitcode/Reader/BitcodeReader.cpp
lib/Bitcode/Writer/BitcodeWriter.cpp
lib/Linker/LinkModules.cpp

index 6157a5db5d9c112b244b46bf93bd9d83144d977c..07089a85afec6313bcd491115d4543181ff10ee9 100644 (file)
@@ -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;
   }
 }
 
index 2a4b13a94783d44ade460232c915bc694ba9f8d4..eccfd429024249a025947efc4065c1dd69f45311 100644 (file)
@@ -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;
   }
 }
 
index 0d4479bfd24bf8e31cb95ec1596e55ee08b44534..cf9f777a53e2155ba7367f8e3b278e85977dd3cf 100644 (file)
@@ -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()) {