[NVPTX] Do not emit .weak symbols for NVPTX
authorJingyue Wu <jingyue@google.com>
Mon, 1 Dec 2014 21:16:17 +0000 (21:16 +0000)
committerJingyue Wu <jingyue@google.com>
Mon, 1 Dec 2014 21:16:17 +0000 (21:16 +0000)
Summary:
".weak" symbols cannot be consumed by ptxas (PR21685). This patch makes the
weak directive in MCAsmPrinter customizable, and disables emitting ".weak"
symbols for NVPTX.

Test Plan: weak-linkage.ll

Reviewers: jholewinski

Reviewed By: jholewinski

Subscribers: majnemer, jholewinski, llvm-commits

Differential Revision: http://reviews.llvm.org/D6455

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

include/llvm/MC/MCAsmInfo.h
lib/MC/MCAsmInfo.cpp
lib/MC/MCAsmStreamer.cpp
lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp
test/CodeGen/NVPTX/weak-linkage.ll

index 4f38aacd3b2202f81959d34f07a9932b7ee6d0a1..c2f180504225369e4b3c069b118934db2706f9c5 100644 (file)
@@ -215,7 +215,8 @@ protected:
 
   //===--- Global Variable Emission Directives --------------------------===//
 
-  /// This is the directive used to declare a global entity.  Defaults to NULL.
+  /// This is the directive used to declare a global entity. Defaults to
+  /// ".globl".
   const char *GlobalDirective;
 
   /// True if the expression
@@ -264,6 +265,9 @@ protected:
   /// to false.
   bool HasNoDeadStrip;
 
+  /// Used to declare a global as being a weak symbol. Defaults to ".weak".
+  const char *WeakDirective;
+
   /// This directive, if non-null, is used to declare a global as being a weak
   /// undefined symbol.  Defaults to NULL.
   const char *WeakRefDirective;
@@ -452,6 +456,7 @@ public:
   bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
   bool hasIdentDirective() const { return HasIdentDirective; }
   bool hasNoDeadStrip() const { return HasNoDeadStrip; }
+  const char *getWeakDirective() const { return WeakDirective; }
   const char *getWeakRefDirective() const { return WeakRefDirective; }
   bool hasWeakDefDirective() const { return HasWeakDefDirective; }
   bool hasWeakDefCanBeHiddenDirective() const {
index 2fb558f1f3e39157e94ade1c87db79a70209a2b6..053061823ff93158f16b30aa4412b81e3803aae2 100644 (file)
@@ -71,6 +71,7 @@ MCAsmInfo::MCAsmInfo() {
   HasSingleParameterDotFile = true;
   HasIdentDirective = false;
   HasNoDeadStrip = false;
+  WeakDirective = "\t.weak\t";
   WeakRefDirective = nullptr;
   HasWeakDefDirective = false;
   HasWeakDefCanBeHiddenDirective = false;
index f60c7fc50415ffa4840656a8e131bc9800c7b013..84eb093776562dfdf0709f4dbacf5cdda58478cb 100644 (file)
@@ -443,7 +443,7 @@ bool MCAsmStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
     break;
   case MCSA_Protected:      OS << "\t.protected\t";       break;
   case MCSA_Reference:      OS << "\t.reference\t";       break;
-  case MCSA_Weak:           OS << "\t.weak\t";            break;
+  case MCSA_Weak:           OS << MAI->getWeakDirective(); break;
   case MCSA_WeakDefinition:
     OS << "\t.weak_definition\t";
     break;
index 4fd5bdda8c731208ab57bb754069b4d6044ce4f7..11d737ec187f6ac193c83a042021006948423f8a 100644 (file)
@@ -50,5 +50,6 @@ NVPTXMCAsmInfo::NVPTXMCAsmInfo(StringRef TT) {
   AscizDirective = " .b8";
 
   // @TODO: Can we just disable this?
+  WeakDirective = "\t// .weak\t";
   GlobalDirective = "\t// .globl\t";
 }
index 7a133578364201a723d103855b24519231de3f8c..5df57b29249ec00403639b03209f1f7393cc7951 100644 (file)
@@ -1,11 +1,17 @@
 ; RUN: llc < %s -march=nvptx -mcpu=sm_20 | FileCheck %s
 
-
+; CHECK: // .weak foo
 ; CHECK: .weak .func foo
 define weak void @foo() {
   ret void
 }
 
+; CHECK: // .weak baz
+; CHECK: .weak .func baz
+define weak_odr void @baz() {
+  ret void
+}
+
 ; CHECK: .visible .func bar
 define void @bar() {
   ret void