Fix bugs with attribute weak emission
authorChris Lattner <sabre@nondot.org>
Mon, 3 Nov 2003 17:32:38 +0000 (17:32 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 3 Nov 2003 17:32:38 +0000 (17:32 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9678 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/CBackend/CBackend.cpp
lib/Target/CBackend/Writer.cpp

index e32987cbd2ee351948935b9fa39c25983e53ff42..0fd3046021432566a34c01feb0ce4fbb8e4eb266 100644 (file)
@@ -653,6 +653,7 @@ void CWriter::printModule(Module *M) {
       if ((I->hasInternalLinkage() || !MangledGlobals.count(I)) &&
           !I->getIntrinsicID()) {
         printFunctionSignature(I, true);
+        if (I->hasWeakLinkage()) Out << " __attribute__((weak))";
         Out << ";\n";
       }
     }
@@ -671,7 +672,11 @@ void CWriter::printModule(Module *M) {
       if (!I->isExternal()) {
         Out << "extern ";
         printType(Out, I->getType()->getElementType(), Mang->getValueName(I));
-      
+
+        if (I->hasLinkOnceLinkage())
+          Out << " __attribute__((common))";
+        else if (I->hasWeakLinkage())
+          Out << " __attribute__((weak))";
         Out << ";\n";
       }
   }
@@ -903,8 +908,6 @@ void CWriter::printFunctionSignature(const Function *F, bool Prototype) {
   FunctionInnards << ")";
   // Print out the return type and the entire signature for that matter
   printType(Out, F->getReturnType(), FunctionInnards.str());
-
-  if (F->hasWeakLinkage()) Out << " __attribute((weak))";
 }
 
 void CWriter::printFunction(Function *F) {
index e32987cbd2ee351948935b9fa39c25983e53ff42..0fd3046021432566a34c01feb0ce4fbb8e4eb266 100644 (file)
@@ -653,6 +653,7 @@ void CWriter::printModule(Module *M) {
       if ((I->hasInternalLinkage() || !MangledGlobals.count(I)) &&
           !I->getIntrinsicID()) {
         printFunctionSignature(I, true);
+        if (I->hasWeakLinkage()) Out << " __attribute__((weak))";
         Out << ";\n";
       }
     }
@@ -671,7 +672,11 @@ void CWriter::printModule(Module *M) {
       if (!I->isExternal()) {
         Out << "extern ";
         printType(Out, I->getType()->getElementType(), Mang->getValueName(I));
-      
+
+        if (I->hasLinkOnceLinkage())
+          Out << " __attribute__((common))";
+        else if (I->hasWeakLinkage())
+          Out << " __attribute__((weak))";
         Out << ";\n";
       }
   }
@@ -903,8 +908,6 @@ void CWriter::printFunctionSignature(const Function *F, bool Prototype) {
   FunctionInnards << ")";
   // Print out the return type and the entire signature for that matter
   printType(Out, F->getReturnType(), FunctionInnards.str());
-
-  if (F->hasWeakLinkage()) Out << " __attribute((weak))";
 }
 
 void CWriter::printFunction(Function *F) {