Add weak reference directive.
authorEvan Cheng <evan.cheng@apple.com>
Fri, 1 Dec 2006 20:47:11 +0000 (20:47 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Fri, 1 Dec 2006 20:47:11 +0000 (20:47 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32091 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Target/TargetAsmInfo.h
lib/Target/PowerPC/PPCAsmPrinter.cpp
lib/Target/PowerPC/PPCTargetAsmInfo.cpp
lib/Target/TargetAsmInfo.cpp
lib/Target/X86/X86AsmPrinter.cpp
lib/Target/X86/X86TargetAsmInfo.cpp

index 28c144afa4781e0bf923b573bef8bc990d185449..050949eeb558d4418c9fa566ceb78dba926eedea 100644 (file)
@@ -211,6 +211,10 @@ namespace llvm {
     /// as being used somehow that the assembler can't see.  This prevents dead
     /// code elimination on some targets.
     const char *UsedDirective;            // Defaults to null.
+
+    /// WeakRefDirective - This directive, if non-null, is used to decalre a
+    /// global as being a weak undefined symbol.
+    const char *WeakRefDirective;         // Defaults to null.
     
     //===--- Dwarf Emission Directives -----------------------------------===//
 
@@ -422,6 +426,9 @@ namespace llvm {
     const char *getUsedDirective() const {
       return UsedDirective;
     }
+    const char *getWeakRefDirective() const {
+      return WeakRefDirective;
+    }
     bool hasLEB128() const {
       return HasLEB128;
     }
index 1b9e94a1995977133fc02248835f513b09164c1f..abbcc5725556d6b0bd0ca1f713913927de5c2367 100644 (file)
@@ -647,11 +647,13 @@ bool DarwinAsmPrinter::doFinalization(Module &M) {
     }
   }
 
-  if (ExtWeakSymbols.begin() != ExtWeakSymbols.end())
-    SwitchToDataSection("");
-  for (std::set<std::string>::iterator i = ExtWeakSymbols.begin(),
-       e = ExtWeakSymbols.end(); i != e; ++i) {
-    O << "\t.weak_reference " << *i << "\n";
+  if (TAI->getWeakRefDirective()) {
+    if (ExtWeakSymbols.begin() != ExtWeakSymbols.end())
+      SwitchToDataSection("");
+    for (std::set<std::string>::iterator i = ExtWeakSymbols.begin(),
+         e = ExtWeakSymbols.end(); i != e; ++i) {
+      O << TAI->getWeakRefDirective() << *i << "\n";
+    }
   }
 
   bool isPPC64 = TD->getPointerSizeInBits() == 64;
index f8848f592c5531982d147ae99811caee796a1ad7..1e38009144819070a9cb6a385b0855421d8ac0b8 100644 (file)
@@ -33,6 +33,7 @@ DarwinTargetAsmInfo::DarwinTargetAsmInfo(const PPCTargetMachine &TM) {
   StaticCtorsSection = ".mod_init_func";
   StaticDtorsSection = ".mod_term_func";
   UsedDirective = "\t.no_dead_strip\t";
+  WeakRefDirective = "\t.weak_reference\t";
   InlineAsmStart = "# InlineAsm Start";
   InlineAsmEnd = "# InlineAsm End";
   
index 2b4f2f79c8e95dca69f401cf822d53483872e58d..8b818fb3ea477bc76aa6394d94c64f676d92ccff 100644 (file)
@@ -61,6 +61,7 @@ TargetAsmInfo::TargetAsmInfo() :
   COMMDirectiveTakesAlignment(true),
   HasDotTypeDotSizeDirective(true),
   UsedDirective(0),
+  WeakRefDirective(0),
   HasLEB128(false),
   HasDotLoc(false),
   HasDotFile(false),
index b92a087859d89bb605a89a5e7e5f3c1957fb8eb8..722697527c3c681f458bc3d33d0fe6e7068d89d1 100644 (file)
@@ -278,16 +278,12 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
     O << "\t.ascii \" -export:" << *i << "\"\n";
   }    
 
-  if (!Subtarget->isTargetCygwin()) {
-    // There is no external weak linkage on Mingw32 platform.
-    // Defaulting to external
+  if (TAI->getWeakRefDirective()) {
     if (ExtWeakSymbols.begin() != ExtWeakSymbols.end())
       SwitchToDataSection("");
-
     for (std::set<std::string>::iterator i = ExtWeakSymbols.begin(),
          e = ExtWeakSymbols.end(); i != e; ++i) {
-      O << (Subtarget->isTargetDarwin() ? "\t.weak_reference" : "\t.weak")
-        << " " << *i << "\n";
+      O << TAI->getWeakRefDirective() << *i << "\n";
     }
   }
   
index 4d44b7d591e6636e9f5d139fcf7d85f68c4312c0..ed9f1ac313278fefdb6c3a0f2da9b96541f687e6 100644 (file)
@@ -62,6 +62,7 @@ X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) {
     InlineAsmEnd = "# InlineAsm End";
     SetDirective = "\t.set";
     UsedDirective = "\t.no_dead_strip\t";
+    WeakRefDirective = "\t.weak_reference\t";
     
     NeedsSet = true;
     DwarfAbbrevSection = ".section __DWARF,__debug_abbrev,regular,debug";
@@ -86,6 +87,7 @@ X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) {
     // HasDotFile - True if target asm supports .file directives.
     // bool HasDotFile; // Defaults to false.
     PrivateGlobalPrefix = ".";  // Prefix for private global symbols
+    WeakRefDirective = "\t.weak\t";
     DwarfRequiresFrameSection = false;
     DwarfAbbrevSection =  "\t.section\t.debug_abbrev,\"\",@progbits";
     DwarfInfoSection =    "\t.section\t.debug_info,\"\",@progbits";