COFF: When resolving _load_config_used, add it as a GC root.

This fixes the cases where the symbol is defined in a comdat or by bitcode.

Differential Revision: http://reviews.llvm.org/D11673

llvm-svn: 243735
This commit is contained in:
Peter Collingbourne 2015-07-31 05:33:34 +00:00
parent 4be014aebe
commit e7107ec03b
3 changed files with 36 additions and 5 deletions

View File

@ -662,9 +662,8 @@ bool LinkerDriver::link(llvm::ArrayRef<const char *> ArgsArr) {
}
// Windows specific -- if __load_config_used can be resolved, resolve it.
if (Symbol *Sym = Symtab.find(Config->LoadConfigUsed))
if (isa<Lazy>(Sym->Body))
Symtab.addUndefined(Config->LoadConfigUsed);
if (Symtab.find(Config->LoadConfigUsed))
addUndefined(Config->LoadConfigUsed);
if (Symtab.queueEmpty())
break;

15
lld/test/COFF/loadcfg.ll Normal file
View File

@ -0,0 +1,15 @@
; RUN: llvm-as -o %t.obj %s
; RUN: lld -flavor link2 /out:%t.exe %t.obj /entry:main /subsystem:console
; RUN: llvm-readobj -file-headers %t.exe | FileCheck %s
; CHECK: LoadConfigTableRVA: 0x1000
; CHECK: LoadConfigTableSize: 0x70
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-windows-msvc"
@_load_config_used = constant i32 1
define void @main() {
ret void
}

View File

@ -2,7 +2,7 @@
# RUN: lld -flavor link2 /out:%t.exe %t.obj /entry:main /subsystem:console
# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s
# CHECK: LoadConfigTableRVA: 0x1000
# CHECK: LoadConfigTableRVA: 0x1008
# CHECK: LoadConfigTableSize: 0x70
---
@ -14,6 +14,10 @@ sections:
Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
Alignment: 4
SectionData: B82A000000C3
- Name: .text
Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_LNK_COMDAT, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
Alignment: 4
SectionData: B82A000000C3
symbols:
- Name: .text
Value: 0
@ -27,6 +31,19 @@ symbols:
NumberOfLinenumbers: 0
CheckSum: 0
Number: 0
- Name: .text
Value: 0
SectionNumber: 2
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_STATIC
SectionDefinition:
Length: 6
NumberOfRelocations: 0
NumberOfLinenumbers: 0
CheckSum: 0
Number: 0
Selection: IMAGE_COMDAT_SELECT_ANY
- Name: main
Value: 0
SectionNumber: 1
@ -35,7 +52,7 @@ symbols:
StorageClass: IMAGE_SYM_CLASS_EXTERNAL
- Name: _load_config_used
Value: 0
SectionNumber: 1
SectionNumber: 2
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_EXTERNAL