[llvm-commits] [llvm] r78160 - in /llvm/trunk: docs/LangRef.html lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp lib/VMCore/Verifier.cpp

Chris Lattner sabre at nondot.org
Tue Aug 4 22:21:07 PDT 2009


Author: lattner
Date: Wed Aug  5 00:21:07 2009
New Revision: 78160

URL: http://llvm.org/viewvc/llvm-project?rev=78160&view=rev
Log:
Clarify common linkage and the requirements on it.  Enforce
them in the verifier.


Modified:
    llvm/trunk/docs/LangRef.html
    llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
    llvm/trunk/lib/VMCore/Verifier.cpp

Modified: llvm/trunk/docs/LangRef.html
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/LangRef.html?rev=78160&r1=78159&r2=78160&view=diff

==============================================================================
--- llvm/trunk/docs/LangRef.html (original)
+++ llvm/trunk/docs/LangRef.html Wed Aug  5 00:21:07 2009
@@ -552,19 +552,22 @@
       translation unit that uses it.  Unreferenced <tt>linkonce</tt> globals are
       allowed to be discarded.</dd>
 
+  <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
+  <dd>"<tt>weak</tt>" linkage has the same merging semantics as
+      <tt>linkonce</tt> linkage, except that unreferenced globals with
+      <tt>weak</tt> linkage may not be discarded.  This is used for globals that
+      are declared "weak" in C source code.</dd>
+
   <dt><tt><b><a name="linkage_common">common</a></b></tt>: </dt>
-  <dd>"<tt>common</tt>" linkage is exactly the same as <tt>linkonce</tt>
-     linkage, except that unreferenced <tt>common</tt> globals may not be
-     discarded.  This is used for globals that may be emitted in multiple
-     translation units, but that are not guaranteed to be emitted into every
-     translation unit that uses them.  One example of this is tentative
-     definitions in C, such as "<tt>int X;</tt>" at global scope.</dd>
+  <dd>"<tt>common</tt>" linkage is most similar to "<tt>weak</tt>" linkage, but
+      they are used for tentative definitions in C, such as "<tt>int X;</tt>" at
+      global scope.
+      Symbols with "<tt>common</tt>" linkage are merged in the same way as
+      <tt>weak symbols</tt>, and they may not be deleted if unreferenced.
+      Further, <tt>common</tt> symbols may not have an explicit section, and
+      must have a zero initializer.  Functions and aliases may not have common
+      linkage.</dd>
 
-  <dt><tt><b><a name="linkage_weak">weak</a></b></tt>: </dt>
-  <dd>"<tt>weak</tt>" linkage is the same as <tt>common</tt> linkage, except
-      that some targets may choose to emit different assembly sequences for them
-      for target-dependent reasons.  This is used for globals that are declared
-      "weak" in C source code.</dd>
 
   <dt><tt><b><a name="linkage_appending">appending</a></b></tt>: </dt>
   <dd>"<tt>appending</tt>" linkage may only be applied to global variables of

Modified: llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp?rev=78160&r1=78159&r2=78160&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp Wed Aug  5 00:21:07 2009
@@ -782,8 +782,13 @@
   if (Subtarget->isTargetELF())
     O << "\t.type\t" << name << ", at object\n";
 
+  
+  SectionKind GVKind = TargetLoweringObjectFile::getKindForGlobal(GVar, TM);
+  
+  
+  
   const MCSection *TheSection =
-    getObjFileLowering().SectionForGlobal(GVar, Mang, TM);
+    getObjFileLowering().SectionForGlobal(GVar, GVKind, Mang, TM);
   SwitchToSection(TheSection);
 
   // FIXME: get this stuff from section kind flags.

Modified: llvm/trunk/lib/VMCore/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Verifier.cpp?rev=78160&r1=78159&r2=78160&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Verifier.cpp (original)
+++ llvm/trunk/lib/VMCore/Verifier.cpp Wed Aug  5 00:21:07 2009
@@ -378,6 +378,12 @@
             "Global variable initializer type does not match global "
             "variable type!", &GV);
 
+    // If the global has common linkage, it must have a zero initializer.
+    if (GV.hasCommonLinkage())
+      Assert1(GV.getInitializer()->isNullValue(),
+              "'common' global must have a zero initializer!", &GV);
+    
+    
     // Verify that any metadata used in a global initializer points only to
     // other globals.
     if (MDNode *FirstNode = dyn_cast<MDNode>(GV.getInitializer())) {
@@ -544,6 +550,7 @@
   const FunctionType *FT = F.getFunctionType();
   unsigned NumArgs = F.arg_size();
 
+  Assert1(!F.hasCommonLinkage(), "Functions may not have common linkage", &F);
   Assert2(FT->getNumParams() == NumArgs,
           "# formal arguments must match # of arguments for function type!",
           &F, FT);





More information about the llvm-commits mailing list