Skip to content

Commit

Permalink
[NVPTX] Do not emit .weak symbols for NVPTX
Browse files Browse the repository at this point in the history
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

llvm-svn: 223077
  • Loading branch information
Jingyue Wu committed Dec 1, 2014
1 parent 35fc363 commit 5b62eb9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
7 changes: 6 additions & 1 deletion llvm/include/llvm/MC/MCAsmInfo.h
Expand Up @@ -215,7 +215,8 @@ class MCAsmInfo {

//===--- 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
Expand Down Expand Up @@ -264,6 +265,9 @@ class MCAsmInfo {
/// 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;
Expand Down Expand Up @@ -452,6 +456,7 @@ class MCAsmInfo {
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 {
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/MC/MCAsmInfo.cpp
Expand Up @@ -71,6 +71,7 @@ MCAsmInfo::MCAsmInfo() {
HasSingleParameterDotFile = true;
HasIdentDirective = false;
HasNoDeadStrip = false;
WeakDirective = "\t.weak\t";
WeakRefDirective = nullptr;
HasWeakDefDirective = false;
HasWeakDefCanBeHiddenDirective = false;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/MC/MCAsmStreamer.cpp
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp
Expand Up @@ -50,5 +50,6 @@ NVPTXMCAsmInfo::NVPTXMCAsmInfo(StringRef TT) {
AscizDirective = " .b8";

// @TODO: Can we just disable this?
WeakDirective = "\t// .weak\t";
GlobalDirective = "\t// .globl\t";
}
8 changes: 7 additions & 1 deletion llvm/test/CodeGen/NVPTX/weak-linkage.ll
@@ -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
Expand Down

0 comments on commit 5b62eb9

Please sign in to comment.