diff --git a/lld/test/COFF/Inputs/delayimporttables-alpha.yaml b/lld/test/COFF/Inputs/delayimporttables-alpha.yaml new file mode 100644 --- /dev/null +++ b/lld/test/COFF/Inputs/delayimporttables-alpha.yaml @@ -0,0 +1,120 @@ +--- !COFF +header: + Machine: IMAGE_FILE_MACHINE_AMD64 + Characteristics: [ ] +sections: + - Name: .drectve + Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ] + Alignment: 1 + SectionData: 2020202F44454641554C544C49423A224C4942434D5422202F44454641554C544C49423A224F4C444E414D455322202F4558504F52543A6F6E65202F4558504F52543A74776F20 + - Name: '.debug$S' + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ] + Alignment: 1 + SectionData: 04000000F1000000670000002900011100000000443A5C536372617463685C726561646F626A2D726570726F5C416C7068612E6F626A003A003C1100620000D000130010009369010013001000936901004D6963726F736F667420285229204F7074696D697A696E6720436F6D70696C65720000 + Subsections: + - !Symbols + Records: + - Kind: S_OBJNAME + ObjNameSym: + Signature: 0 + ObjectName: 'D:\Scratch\readobj-repro\Alpha.obj' + - Kind: S_COMPILE3 + Compile3Sym: + Flags: [ NoDbgInfo, SecurityChecks, HotPatch ] + Machine: X64 + FrontendMajor: 19 + FrontendMinor: 16 + FrontendBuild: 27027 + FrontendQFE: 1 + BackendMajor: 19 + BackendMinor: 16 + BackendBuild: 27027 + BackendQFE: 1 + Version: 'Microsoft (R) Optimizing Compiler' + - Name: '.text$mn' + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: C20000CCCCCCCCCCCCCCCCCCCCCCCCCCC20000CCCCCCCCCCCCCCCCCCCCCCCCCC4C894424188954241048894C240833C0C3 + - Name: .chks64 + Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ] + SectionData: 542F239133C7DB75C11D578BC4A1E02E6E3900D26CEA22270000000000000000 +symbols: + - Name: '@comp.id' + Value: 17066387 + SectionNumber: -1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: '@feat.00' + Value: 2147484048 + SectionNumber: -1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: .drectve + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 71 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 4081356488 + Number: 0 + - Name: '.debug$S' + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 116 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: '.text$mn' + Value: 0 + SectionNumber: 3 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 49 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 405845281 + Number: 0 + - Name: one + Value: 0 + SectionNumber: 3 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: two + Value: 16 + SectionNumber: 3 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: DllMain + Value: 32 + SectionNumber: 3 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: .chks64 + Value: 0 + SectionNumber: 4 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 32 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 +... diff --git a/lld/test/COFF/Inputs/delayimporttables-beta.yaml b/lld/test/COFF/Inputs/delayimporttables-beta.yaml new file mode 100644 --- /dev/null +++ b/lld/test/COFF/Inputs/delayimporttables-beta.yaml @@ -0,0 +1,120 @@ +--- !COFF +header: + Machine: IMAGE_FILE_MACHINE_AMD64 + Characteristics: [ ] +sections: + - Name: .drectve + Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ] + Alignment: 1 + SectionData: 2020202F44454641554C544C49423A224C4942434D5422202F44454641554C544C49423A224F4C444E414D455322202F4558504F52543A6C656674202F4558504F52543A726967687420 + - Name: '.debug$S' + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ] + Alignment: 1 + SectionData: 04000000F1000000660000002800011100000000443A5C536372617463685C726561646F626A2D726570726F5C426574612E6F626A003A003C1100620000D000130010009369010013001000936901004D6963726F736F667420285229204F7074696D697A696E6720436F6D70696C6572000000 + Subsections: + - !Symbols + Records: + - Kind: S_OBJNAME + ObjNameSym: + Signature: 0 + ObjectName: 'D:\Scratch\readobj-repro\Beta.obj' + - Kind: S_COMPILE3 + Compile3Sym: + Flags: [ NoDbgInfo, SecurityChecks, HotPatch ] + Machine: X64 + FrontendMajor: 19 + FrontendMinor: 16 + FrontendBuild: 27027 + FrontendQFE: 1 + BackendMajor: 19 + BackendMinor: 16 + BackendBuild: 27027 + BackendQFE: 1 + Version: 'Microsoft (R) Optimizing Compiler' + - Name: '.text$mn' + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: C20000CCCCCCCCCCCCCCCCCCCCCCCCCCC20000CCCCCCCCCCCCCCCCCCCCCCCCCC4C894424188954241048894C240833C0C3 + - Name: .chks64 + Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ] + SectionData: ACF1D7AD8CF1837E5F99ECB18EC6DFD46E3900D26CEA22270000000000000000 +symbols: + - Name: '@comp.id' + Value: 17066387 + SectionNumber: -1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: '@feat.00' + Value: 2147484048 + SectionNumber: -1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: .drectve + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 74 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 127731413 + Number: 0 + - Name: '.debug$S' + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 116 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: '.text$mn' + Value: 0 + SectionNumber: 3 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 49 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 405845281 + Number: 0 + - Name: left + Value: 0 + SectionNumber: 3 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: right + Value: 16 + SectionNumber: 3 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: DllMain + Value: 32 + SectionNumber: 3 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: .chks64 + Value: 0 + SectionNumber: 4 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 32 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 +... diff --git a/lld/test/COFF/Inputs/delayimporttables-root.yaml b/lld/test/COFF/Inputs/delayimporttables-root.yaml new file mode 100644 --- /dev/null +++ b/lld/test/COFF/Inputs/delayimporttables-root.yaml @@ -0,0 +1,211 @@ +--- !COFF +header: + Machine: IMAGE_FILE_MACHINE_AMD64 + Characteristics: [ ] +sections: + - Name: .drectve + Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ] + Alignment: 1 + SectionData: 2020202F44454641554C544C49423A224C4942434D5422202F44454641554C544C49423A224F4C444E414D45532220 + - Name: '.debug$S' + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ] + Alignment: 1 + SectionData: 04000000F1000000660000002800011100000000443A5C536372617463685C726561646F626A2D726570726F5C526F6F742E6F626A003A003C1100620000D000130010009369010013001000936901004D6963726F736F667420285229204F7074696D697A696E6720436F6D70696C6572000000 + Subsections: + - !Symbols + Records: + - Kind: S_OBJNAME + ObjNameSym: + Signature: 0 + ObjectName: 'D:\Scratch\readobj-repro\Root.obj' + - Kind: S_COMPILE3 + Compile3Sym: + Flags: [ NoDbgInfo, SecurityChecks, HotPatch ] + Machine: X64 + FrontendMajor: 19 + FrontendMinor: 16 + FrontendBuild: 27027 + FrontendQFE: 1 + BackendMajor: 19 + BackendMinor: 16 + BackendBuild: 27027 + BackendQFE: 1 + Version: 'Microsoft (R) Optimizing Compiler' + - Name: '.text$mn' + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: 4889542410894C24084883EC28FF1500000000FF1500000000FF1500000000FF150000000033C04883C428C3CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC488954241048894C240833C0C3 + Relocations: + - VirtualAddress: 15 + SymbolName: __imp_one + Type: IMAGE_REL_AMD64_REL32 + - VirtualAddress: 21 + SymbolName: __imp_two + Type: IMAGE_REL_AMD64_REL32 + - VirtualAddress: 27 + SymbolName: __imp_left + Type: IMAGE_REL_AMD64_REL32 + - VirtualAddress: 33 + SymbolName: __imp_right + Type: IMAGE_REL_AMD64_REL32 + - Name: .xdata + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: 010D01000D420000 + - Name: .pdata + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ] + Alignment: 4 + SectionData: 000000002C00000000000000 + Relocations: + - VirtualAddress: 0 + SymbolName: '$LN3' + Type: IMAGE_REL_AMD64_ADDR32NB + - VirtualAddress: 4 + SymbolName: '$LN3' + Type: IMAGE_REL_AMD64_ADDR32NB + - VirtualAddress: 8 + SymbolName: '$unwind$main' + Type: IMAGE_REL_AMD64_ADDR32NB + - Name: .chks64 + Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ] + SectionData: 23076615271ABF1A82E028CFBB983F63E412EA1753300CC062CD8FF1935DC06E7CEEA1911EC9CA9E0000000000000000 +symbols: + - Name: '@comp.id' + Value: 17066387 + SectionNumber: -1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: '@feat.00' + Value: 2147484048 + SectionNumber: -1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: .drectve + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 47 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: '.debug$S' + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 116 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 + - Name: '.text$mn' + Value: 0 + SectionNumber: 3 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 77 + NumberOfRelocations: 4 + NumberOfLinenumbers: 0 + CheckSum: 2180067621 + Number: 0 + - Name: __imp_one + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: __imp_two + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: __imp_left + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: __imp_right + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: main + Value: 0 + SectionNumber: 3 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: __delayLoadHelper2 + Value: 64 + SectionNumber: 3 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: '$LN3' + Value: 0 + SectionNumber: 3 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_LABEL + - Name: .xdata + Value: 0 + SectionNumber: 4 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 8 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 3881120648 + Number: 0 + - Name: '$unwind$main' + Value: 0 + SectionNumber: 4 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: .pdata + Value: 0 + SectionNumber: 5 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 12 + NumberOfRelocations: 3 + NumberOfLinenumbers: 0 + CheckSum: 2933487385 + Number: 0 + - Name: '$pdata$main' + Value: 0 + SectionNumber: 5 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + - Name: .chks64 + Value: 0 + SectionNumber: 6 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 48 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 0 +... diff --git a/lld/test/COFF/delayimporttables.test b/lld/test/COFF/delayimporttables.test new file mode 100644 --- /dev/null +++ b/lld/test/COFF/delayimporttables.test @@ -0,0 +1,45 @@ +# RUN: yaml2obj %p/Inputs/delayimporttables-alpha.yaml > %t-alpha.obj +# RUN: yaml2obj %p/Inputs/delayimporttables-beta.yaml > %t-beta.obj +# RUN: yaml2obj %p/Inputs/delayimporttables-root.yaml > %t-root.obj +# RUN: lld-link /nodefaultlib /entry:DllMain /out:%T/delayimporttables-alpha.dll /dll /implib:%t-alpha.lib %t-alpha.obj +# RUN: lld-link /nodefaultlib /entry:DllMain /out:%T/delayimporttables-beta.dll /dll /implib:%t-beta.lib %t-beta.obj +# RUN: lld-link /nodefaultlib /entry:main /out:%t-root.exe /delayload:delayimporttables-alpha.dll /delayload:delayimporttables-beta.dll %t-root.obj %t-alpha.lib %t-beta.lib +# RUN: llvm-readobj --coff-imports %t-root.exe |FileCheck %s + +# CHECK:Format: COFF-x86-64 +# CHECK-NEXT:Arch: x86_64 +# CHECK-NEXT:AddressSize: 64bit +# CHECK-NEXT:DelayImport { +# CHECK-NEXT: Name: delayimporttables-alpha.dll +# CHECK-NEXT: Attributes: 0x1 +# CHECK-NEXT: ModuleHandle: 0x3000 +# CHECK-NEXT: ImportAddressTable: 0x3010 +# CHECK-NEXT: ImportNameTable: 0x2060 +# CHECK-NEXT: BoundDelayImportTable: 0x0 +# CHECK-NEXT: UnloadDelayImportTable: 0x0 +# CHECK-NEXT: Import { +# CHECK-NEXT: Symbol: one (0) +# CHECK-NEXT: Address: 0x14000104D +# CHECK-NEXT: } +# CHECK-NEXT: Import { +# CHECK-NEXT: Symbol: two (0) +# CHECK-NEXT: Address: 0x1400010A4 +# CHECK-NEXT: } +# CHECK-NEXT:} +# CHECK-NEXT:DelayImport { +# CHECK-NEXT: Name: delayimporttables-beta.dll +# CHECK-NEXT: Attributes: 0x1 +# CHECK-NEXT: ModuleHandle: 0x3008 +# CHECK-NEXT: ImportAddressTable: 0x3028 +# CHECK-NEXT: ImportNameTable: 0x2078 +# CHECK-NEXT: BoundDelayImportTable: 0x0 +# CHECK-NEXT: UnloadDelayImportTable: 0x0 +# CHECK-NEXT: Import { +# CHECK-NEXT: Symbol: left (0) +# CHECK-NEXT: Address: 0x1400010FB +# CHECK-NEXT: } +# CHECK-NEXT: Import { +# CHECK-NEXT: Symbol: right (0) +# CHECK-NEXT: Address: 0x140001152 +# CHECK-NEXT: } +# CHECK-NEXT:} diff --git a/llvm/lib/Object/COFFObjectFile.cpp b/llvm/lib/Object/COFFObjectFile.cpp --- a/llvm/lib/Object/COFFObjectFile.cpp +++ b/llvm/lib/Object/COFFObjectFile.cpp @@ -1457,7 +1457,7 @@ std::error_code DelayImportDirectoryEntryRef:: getDelayImportTable(const delay_import_directory_table_entry *&Result) const { - Result = Table; + Result = &Table[Index]; return std::error_code(); }