Index: llvm/lib/LTO/LTO.cpp =================================================================== --- llvm/lib/LTO/LTO.cpp +++ llvm/lib/LTO/LTO.cpp @@ -415,7 +415,8 @@ // Flag as visible outside of ThinLTO if visible from a regular object or // if this is a reference in the regular LTO partition. GlobalRes.VisibleOutsideThinLTO |= - (Res.VisibleToRegularObj || (Partition == GlobalResolution::RegularLTO)); + (Res.VisibleToRegularObj || Sym.isUsed() || + Partition == GlobalResolution::RegularLTO); } static void writeToResolutionFile(raw_ostream &OS, InputFile *Input, Index: llvm/lib/Object/IRSymtab.cpp =================================================================== --- llvm/lib/Object/IRSymtab.cpp +++ llvm/lib/Object/IRSymtab.cpp @@ -163,6 +163,9 @@ Sym.ComdatIndex = -1; auto *GV = Msym.dyn_cast(); if (!GV) { + // Undefined module asm symbols act as GC roots and are implicitly used. + if (Flags & object::BasicSymbolRef::SF_Undefined) + Sym.Flags |= 1 << storage::Symbol::FB_used; setStr(Sym.IRName, ""); return Error::success(); } Index: llvm/test/LTO/Resolution/X86/Inputs/mod-asm-used.ll =================================================================== --- /dev/null +++ llvm/test/LTO/Resolution/X86/Inputs/mod-asm-used.ll @@ -0,0 +1,4 @@ +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@foo = global i32 1, align 4 Index: llvm/test/LTO/Resolution/X86/mod-asm-used.ll =================================================================== --- /dev/null +++ llvm/test/LTO/Resolution/X86/mod-asm-used.ll @@ -0,0 +1,10 @@ +; RUN: opt -module-summary -o %t.bc %s +; RUN: opt -module-summary -o %t2.bc %S/Inputs/mod-asm-used.ll +; RUN: llvm-lto2 run %t.bc -r %t.bc,foo,l %t2.bc -r %t2.bc,foo,pl -o %t3 +; RUN: llvm-nm %t3.1 | FileCheck %s + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; CHECK: D foo +module asm ".quad foo"