[llvm] r223077 - [NVPTX] Do not emit .weak symbols for NVPTX
Jingyue Wu
jingyue at google.com
Mon Dec 1 13:16:17 PST 2014
Author: jingyue
Date: Mon Dec 1 15:16:17 2014
New Revision: 223077
URL: http://llvm.org/viewvc/llvm-project?rev=223077&view=rev
Log:
[NVPTX] Do not emit .weak symbols for NVPTX
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
Modified:
llvm/trunk/include/llvm/MC/MCAsmInfo.h
llvm/trunk/lib/MC/MCAsmInfo.cpp
llvm/trunk/lib/MC/MCAsmStreamer.cpp
llvm/trunk/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp
llvm/trunk/test/CodeGen/NVPTX/weak-linkage.ll
Modified: llvm/trunk/include/llvm/MC/MCAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCAsmInfo.h?rev=223077&r1=223076&r2=223077&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCAsmInfo.h (original)
+++ llvm/trunk/include/llvm/MC/MCAsmInfo.h Mon Dec 1 15:16:17 2014
@@ -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 {
Modified: llvm/trunk/lib/MC/MCAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmInfo.cpp?rev=223077&r1=223076&r2=223077&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmInfo.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmInfo.cpp Mon Dec 1 15:16:17 2014
@@ -71,6 +71,7 @@ MCAsmInfo::MCAsmInfo() {
HasSingleParameterDotFile = true;
HasIdentDirective = false;
HasNoDeadStrip = false;
+ WeakDirective = "\t.weak\t";
WeakRefDirective = nullptr;
HasWeakDefDirective = false;
HasWeakDefCanBeHiddenDirective = false;
Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=223077&r1=223076&r2=223077&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Mon Dec 1 15:16:17 2014
@@ -443,7 +443,7 @@ bool MCAsmStreamer::EmitSymbolAttribute(
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;
Modified: llvm/trunk/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp?rev=223077&r1=223076&r2=223077&view=diff
==============================================================================
--- llvm/trunk/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp Mon Dec 1 15:16:17 2014
@@ -50,5 +50,6 @@ NVPTXMCAsmInfo::NVPTXMCAsmInfo(StringRef
AscizDirective = " .b8";
// @TODO: Can we just disable this?
+ WeakDirective = "\t// .weak\t";
GlobalDirective = "\t// .globl\t";
}
Modified: llvm/trunk/test/CodeGen/NVPTX/weak-linkage.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/NVPTX/weak-linkage.ll?rev=223077&r1=223076&r2=223077&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/NVPTX/weak-linkage.ll (original)
+++ llvm/trunk/test/CodeGen/NVPTX/weak-linkage.ll Mon Dec 1 15:16:17 2014
@@ -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
More information about the llvm-commits
mailing list