diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp index 5613c2e6993a5..b2d0edd8cb260 100644 --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -2472,6 +2472,10 @@ void LinkerDriver::linkerMain(ArrayRef argsArr) { // resolve symbols and write indices, but don't generate native code or link). ctx.symtab.compileBitcodeFiles(); + if (Defined *d = + dyn_cast_or_null(ctx.symtab.findUnderscore("_tls_used"))) + config->gcroot.push_back(d); + // If -thinlto-index-only is given, we should create only "index // files" and not object files. Index file creation is already done // in addCombinedLTOObject, so we are done if that's the case. diff --git a/lld/test/COFF/tls-used-gc.s b/lld/test/COFF/tls-used-gc.s new file mode 100644 index 0000000000000..4736be6749498 --- /dev/null +++ b/lld/test/COFF/tls-used-gc.s @@ -0,0 +1,21 @@ +# REQUIRES: x86 +# RUN: llvm-mc -triple=x86_64-windows-gnu -filetype=obj -o %t.obj %s +# RUN: lld-link %t.obj /out:%t.exe /entry:main /subsystem:console /opt:ref +# RUN: llvm-readobj --file-headers %t.exe | FileCheck %s + +# CHECK: TLSTableRVA: 0x1000 +# CHECK: TLSTableSize: 0x28 + + .section .text@main,"xr",one_only,main + .globl main +main: + ret + + .section .tls$aaa +tlsvar: + .long 1 + + .section .rdata$_tls_used,"dr",one_only,_tls_used + .globl _tls_used +_tls_used: + .zero 40