diff --git a/llvm/lib/CodeGen/MIRFSDiscriminator.cpp b/llvm/lib/CodeGen/MIRFSDiscriminator.cpp --- a/llvm/lib/CodeGen/MIRFSDiscriminator.cpp +++ b/llvm/lib/CodeGen/MIRFSDiscriminator.cpp @@ -132,9 +132,10 @@ if (!M->getGlobalVariable(FSDiscriminatorVar)) { auto &Context = M->getContext(); // Create a global variable to flag that FSDiscriminators are used. - new GlobalVariable(*M, Type::getInt1Ty(Context), true, - GlobalValue::WeakAnyLinkage, - ConstantInt::getTrue(Context), FSDiscriminatorVar); + // Using "common" linkage so that it will not gc GC'ed. + new GlobalVariable(*M, Type::getInt1Ty(Context), false, + GlobalValue::CommonLinkage, + ConstantInt::getFalse(Context), FSDiscriminatorVar); } LLVM_DEBUG(dbgs() << "Num of FS Discriminators: " << NumNewD << "\n"); diff --git a/llvm/test/CodeGen/X86/fsafdo_test1.ll b/llvm/test/CodeGen/X86/fsafdo_test1.ll --- a/llvm/test/CodeGen/X86/fsafdo_test1.ll +++ b/llvm/test/CodeGen/X86/fsafdo_test1.ll @@ -1,17 +1,13 @@ ; RUN: llc -enable-fs-discriminator < %s | FileCheck %s ; -; Check that fs-afdo discriminators are generated. +;; Check that fs-afdo discriminators are generated. ; CHECK: .loc 1 7 3 is_stmt 0 discriminator 2 # foo.c:7:3 ; Check: .loc 1 9 5 is_stmt 1 discriminator 2 # foo.c:9:5 ; CHECK: .loc 1 9 5 is_stmt 0 discriminator 268435458 # foo.c:9:5 ; CHECK: .loc 1 7 3 is_stmt 1 discriminator 3892314114 # foo.c:7:3 -; Check that variable __llvm_fs_discriminator__ is generated. -; CHECK: .type __llvm_fs_discriminator__,@object # @__llvm_fs_discriminator__ -; CHECK: .section .rodata,"a",@progbits -; CHECK: .weak __llvm_fs_discriminator__ -; CHECK: __llvm_fs_discriminator__: -; CHECK: .byte 1 -; CHECK: .size __llvm_fs_discriminator__, 1 +;; Check that variable __llvm_fs_discriminator__ is generated. +; CHECK: .type __llvm_fs_discriminator__,@object +; CHECK: .comm __llvm_fs_discriminator__,1,1 target triple = "x86_64-unknown-linux-gnu" diff --git a/llvm/test/CodeGen/X86/fsafdo_test2.ll b/llvm/test/CodeGen/X86/fsafdo_test2.ll --- a/llvm/test/CodeGen/X86/fsafdo_test2.ll +++ b/llvm/test/CodeGen/X86/fsafdo_test2.ll @@ -43,12 +43,8 @@ ; CHECK: .loc 1 23 9 is_stmt 0 discriminator 3623878657 # unroll.c:23:9 ;; ;; Check that variable __llvm_fs_discriminator__ is generated. -; CHECK: .type __llvm_fs_discriminator__,@object # @__llvm_fs_discriminator__ -; CHECK: .section .rodata,"a",@progbits -; CHECK: .weak __llvm_fs_discriminator__ -; CHECK: __llvm_fs_discriminator__: -; CHECK: .byte 1 -; CHECK: .size __llvm_fs_discriminator__, 1 +; CHECK: .type __llvm_fs_discriminator__,@object +; CHECK: .comm __llvm_fs_discriminator__,1,1 target triple = "x86_64-unknown-linux-gnu"