diff --git a/lld/COFF/InputFiles.cpp b/lld/COFF/InputFiles.cpp --- a/lld/COFF/InputFiles.cpp +++ b/lld/COFF/InputFiles.cpp @@ -688,6 +688,8 @@ Sym = Symtab->addRegular(this, SymName); } Symbols.push_back(Sym); + if (ObjSym.isUsed()) + Config->GCRoot.push_back(Sym); } Directives = Obj->getCOFFLinkerOpts(); } diff --git a/lld/test/COFF/used-lto.ll b/lld/test/COFF/used-lto.ll new file mode 100644 --- /dev/null +++ b/lld/test/COFF/used-lto.ll @@ -0,0 +1,15 @@ +; REQUIRES: x86 +; RUN: llvm-as -o %t.obj %s +; RUN: lld-link -dll -debug -opt:ref -noentry -out:%t.dll %t.obj +; RUN: llvm-pdbutil dump -publics %t.pdb | FileCheck %s + +; CHECK: S_PUB32 {{.*}} `foo` + +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-pc-windows-msvc" + +@llvm.used = appending global [1 x i8*] [i8* bitcast (void ()* @foo to i8*)], section "llvm.metadata" + +define void @foo() { + ret void +} diff --git a/llvm/include/llvm/LTO/LTO.h b/llvm/include/llvm/LTO/LTO.h --- a/llvm/include/llvm/LTO/LTO.h +++ b/llvm/include/llvm/LTO/LTO.h @@ -139,6 +139,7 @@ using irsymtab::Symbol::getCOFFWeakExternalFallback; using irsymtab::Symbol::getSectionName; using irsymtab::Symbol::isExecutable; + using irsymtab::Symbol::isUsed; }; /// A range over the symbols in this InputFile.