Index: include/llvm/MC/MCAsmInfo.h =================================================================== --- include/llvm/MC/MCAsmInfo.h +++ include/llvm/MC/MCAsmInfo.h @@ -215,7 +215,8 @@ //===--- 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 @@ /// 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 @@ 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: lib/MC/MCAsmInfo.cpp =================================================================== --- lib/MC/MCAsmInfo.cpp +++ lib/MC/MCAsmInfo.cpp @@ -71,6 +71,7 @@ HasSingleParameterDotFile = true; HasIdentDirective = false; HasNoDeadStrip = false; + WeakDirective = "\t.weak\t"; WeakRefDirective = nullptr; HasWeakDefDirective = false; HasWeakDefCanBeHiddenDirective = false; Index: lib/MC/MCAsmStreamer.cpp =================================================================== --- lib/MC/MCAsmStreamer.cpp +++ lib/MC/MCAsmStreamer.cpp @@ -443,7 +443,7 @@ 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: lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp =================================================================== --- lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp +++ lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp @@ -50,5 +50,6 @@ AscizDirective = " .b8"; // @TODO: Can we just disable this? + WeakDirective = "\t// .weak\t"; GlobalDirective = "\t// .globl\t"; } Index: test/CodeGen/NVPTX/weak-linkage.ll =================================================================== --- test/CodeGen/NVPTX/weak-linkage.ll +++ 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