Skip to content
Snippets Groups Projects
Commit 98bc304e authored by Tobias Hieta's avatar Tobias Hieta Committed by Tobias Hieta
Browse files

[lld][COFF] Fix TypeServerSource lookup on GUID collisions

Microsoft shipped a bunch of PDB files with broken/invalid GUIDs
which lead lld to use 0xFF as the key for these files in an internal
cache. When multiple files have this key it will lead to collisions
and confused symbol lookup.

Several approaches to fix this was considered. Including making the key
the path to the PDB file, but this requires some filesystem operations
in order to normalize the file path.

Since this only happens with malformatted PDB files and we haven't
seen this before they malformatted files where shipped with visual
studio we probably shouldn't optimize for this use-case.

Instead we now just don't insert files with Guid == 0xFF into the
cache map and warn if we get collisions so similar problems can be
found in the future instead of being silent.

Discussion about the root issue and the approach to this fix can be found on Github: https://github.com/llvm/llvm-project/issues/54487

Reviewed By: aganea

Differential Revision: https://reviews.llvm.org/D122372
parent 0d8df980
No related branches found
No related tags found
No related merge requests found
......@@ -56,8 +56,15 @@ public:
return;
Guid = expectedInfo->getGuid();
auto it = ctx.typeServerSourceMappings.emplace(Guid, this);
assert(it.second);
(void)it;
if (!it.second) {
// If we hit here we have collision on Guid's in two PDB files.
// This can happen if the PDB Guid is invalid or if we are really
// unlucky. This should fall back on stright file-system lookup.
TypeServerSource *tSrc = (TypeServerSource *)it.first->second;
log("GUID collision between " + file.getFilePath() + " and " +
tSrc->pdbInputFile->session->getPDBFile().getFilePath());
ctx.typeServerSourceMappings.erase(Guid);
}
}
Error mergeDebugT(TypeMerger *m) override;
......
This diff is collapsed.
--- !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
Subsections:
- !Symbols
Records:
- Kind: S_OBJNAME
ObjNameSym:
Signature: 0
ObjectName: 'C:\Users\tobia\code\tmp\a.obj'
- Kind: S_COMPILE3
Compile3Sym:
Flags: [ SecurityChecks, HotPatch ]
Machine: X64
FrontendMajor: 19
FrontendMinor: 29
FrontendBuild: 30140
FrontendQFE: 0
BackendMajor: 19
BackendMinor: 29
BackendBuild: 30140
BackendQFE: 0
Version: 'Microsoft (R) Optimizing Compiler'
- Kind: S_UNAMESPACE
UsingNamespaceSym:
Namespace: __vc_attributes
- Kind: S_UNAMESPACE
UsingNamespaceSym:
Namespace: helper_attributes
- Kind: S_UNAMESPACE
UsingNamespaceSym:
Namespace: atl
- Kind: S_UNAMESPACE
UsingNamespaceSym:
Namespace: std
- !Symbols
Records:
- Kind: S_GDATA32
DataSym:
Type: 4172
DisplayName: foo_gv
- Kind: S_UDT
UDTSym:
Type: 4172
UDTName: Foo
- !StringTable
Strings: []
- !Symbols
Records:
- Kind: S_BUILDINFO
BuildInfoSym:
BuildId: 4122
Relocations:
- VirtualAddress: 184
SymbolName: '?foo_gv@@3UFoo@@A'
Type: IMAGE_REL_AMD64_SECREL
- VirtualAddress: 188
SymbolName: '?foo_gv@@3UFoo@@A'
Type: IMAGE_REL_AMD64_SECTION
- Name: '.debug$T'
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
Alignment: 1
Types:
- Kind: LF_TYPESERVER2
TypeServer2:
Guid: '{FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF}'
Age: 1
Name: 'C:\Users\tobia\code\tmp\a.pdb'
- Name: .bss
Characteristics: [ IMAGE_SCN_CNT_UNINITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
Alignment: 4
SectionData: ''
SizeOfRawData: 4
- Name: .chks64
Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ]
SectionData: 23076615271ABF1A3D62E233B91184E60A19DCEE7A1989FD00000000000000000000000000000000
symbols:
- Name: '@comp.id'
Value: 17135036
SectionNumber: -1
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_STATIC
- Name: '@feat.00'
Value: 2147549584
SectionNumber: -1
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_STATIC
- Name: '@vol.md'
Value: 2
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: 1060
NumberOfRelocations: 2
NumberOfLinenumbers: 0
CheckSum: 0
Number: 0
- Name: '.debug$T'
Value: 0
SectionNumber: 3
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_STATIC
SectionDefinition:
Length: 60
NumberOfRelocations: 0
NumberOfLinenumbers: 0
CheckSum: 0
Number: 0
- Name: .bss
Value: 0
SectionNumber: 4
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_STATIC
SectionDefinition:
Length: 4
NumberOfRelocations: 0
NumberOfLinenumbers: 0
CheckSum: 0
Number: 0
- Name: '?foo_gv@@3UFoo@@A'
Value: 0
SectionNumber: 4
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_EXTERNAL
- Name: .chks64
Value: 0
SectionNumber: 5
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_STATIC
SectionDefinition:
Length: 40
NumberOfRelocations: 0
NumberOfLinenumbers: 0
CheckSum: 0
Number: 0
...
This diff is collapsed.
--- !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
Subsections:
- !Symbols
Records:
- Kind: S_OBJNAME
ObjNameSym:
Signature: 0
ObjectName: 'C:\Users\tobia\code\tmp\b.obj'
- Kind: S_COMPILE3
Compile3Sym:
Flags: [ SecurityChecks, HotPatch ]
Machine: X64
FrontendMajor: 19
FrontendMinor: 29
FrontendBuild: 30140
FrontendQFE: 0
BackendMajor: 19
BackendMinor: 29
BackendBuild: 30140
BackendQFE: 0
Version: 'Microsoft (R) Optimizing Compiler'
- Kind: S_UNAMESPACE
UsingNamespaceSym:
Namespace: __vc_attributes
- Kind: S_UNAMESPACE
UsingNamespaceSym:
Namespace: helper_attributes
- Kind: S_UNAMESPACE
UsingNamespaceSym:
Namespace: atl
- Kind: S_UNAMESPACE
UsingNamespaceSym:
Namespace: std
- !Symbols
Records:
- Kind: S_GDATA32
DataSym:
Type: 4098
DisplayName: bar_gv
- Kind: S_UDT
UDTSym:
Type: 4098
UDTName: Bar
- !StringTable
Strings: []
- !Symbols
Records:
- Kind: S_BUILDINFO
BuildInfoSym:
BuildId: 4122
Relocations:
- VirtualAddress: 184
SymbolName: '?bar_gv@@3UBar@@A'
Type: IMAGE_REL_AMD64_SECREL
- VirtualAddress: 188
SymbolName: '?bar_gv@@3UBar@@A'
Type: IMAGE_REL_AMD64_SECTION
- Name: '.debug$T'
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_DISCARDABLE, IMAGE_SCN_MEM_READ ]
Alignment: 1
Types:
- Kind: LF_TYPESERVER2
TypeServer2:
Guid: '{FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF}'
Age: 1
Name: 'C:\Users\tobia\code\tmp\b.pdb'
- Name: .bss
Characteristics: [ IMAGE_SCN_CNT_UNINITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
Alignment: 4
SectionData: ''
SizeOfRawData: 4
- Name: .chks64
Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ]
SectionData: 23076615271ABF1A7B0457106301BDC96209C2204ABFB8A500000000000000000000000000000000
symbols:
- Name: '@comp.id'
Value: 17135036
SectionNumber: -1
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_STATIC
- Name: '@feat.00'
Value: 2147549584
SectionNumber: -1
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_STATIC
- Name: '@vol.md'
Value: 2
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: 1060
NumberOfRelocations: 2
NumberOfLinenumbers: 0
CheckSum: 0
Number: 0
- Name: '.debug$T'
Value: 0
SectionNumber: 3
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_STATIC
SectionDefinition:
Length: 60
NumberOfRelocations: 0
NumberOfLinenumbers: 0
CheckSum: 0
Number: 0
- Name: .bss
Value: 0
SectionNumber: 4
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_STATIC
SectionDefinition:
Length: 4
NumberOfRelocations: 0
NumberOfLinenumbers: 0
CheckSum: 0
Number: 0
- Name: '?bar_gv@@3UBar@@A'
Value: 0
SectionNumber: 4
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_EXTERNAL
- Name: .chks64
Value: 0
SectionNumber: 5
SimpleType: IMAGE_SYM_TYPE_NULL
ComplexType: IMAGE_SYM_DTYPE_NULL
StorageClass: IMAGE_SYM_CLASS_STATIC
SectionDefinition:
Length: 40
NumberOfRelocations: 0
NumberOfLinenumbers: 0
CheckSum: 0
Number: 0
...
Check that the linker behaves when you have multiple
PDB files with the same Guid. This was first a problem
with Visual Studio 2022 that shipped PDB's with Guid's
that was set to FFFFFF...
RUN: rm -rf %t && mkdir -p %t && cd %t
RUN: yaml2obj %p/Inputs/pdb-type-server-guid-collision-a.yaml -o a.obj
RUN: yaml2obj %p/Inputs/pdb-type-server-guid-collision-b.yaml -o b.obj
RUN: llvm-pdbutil yaml2pdb %S/Inputs/pdb-type-server-guid-collision-a-pdb.yaml -pdb a.pdb
RUN: llvm-pdbutil yaml2pdb %S/Inputs/pdb-type-server-guid-collision-b-pdb.yaml -pdb b.pdb
RUN: lld-link a.obj b.obj -out:collision.dll /debug:ghash -pdb:collision.pdb -nodefaultlib /noentry /dll
RUN: lld-link a.obj b.obj -out:collision.dll /debug:noghash -pdb:collision_noghash.pdb -nodefaultlib /noentry /dll
RUN: llvm-pdbutil dump -globals collision.pdb | FileCheck %s
RUN: llvm-pdbutil dump -globals collision_noghash.pdb | FileCheck %s
CHECK-LABEL: Global Symbols
CHECK: ============================================================
CHECK: 100 | S_GDATA32 [size = 24] `bar_gv`
CHECK-NEXT: type = 0x104E (Bar), addr = 0002:0004
Check that the linker behaves when you have multiple
PDB files with the same Guid. This checks the case
where the Guids are duplicates but not invalid (i.e. not FFFFFF)
RUN: rm -rf %t && mkdir -p %t && cd %t
RUN: sed s/{FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF}/{6C633EB7-46FE-4609-BA83-EB820E6F5683}/ %S/Inputs/pdb-type-server-guid-collision-a.yaml | yaml2obj > a.obj
RUN: sed s/{FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF}/{6C633EB7-46FE-4609-BA83-EB820E6F5683}/ %S/Inputs/pdb-type-server-guid-collision-b.yaml | yaml2obj > b.obj
RUN: sed s/{FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF}/{6C633EB7-46FE-4609-BA83-EB820E6F5683}/ %S/Inputs/pdb-type-server-guid-collision-a-pdb.yaml | llvm-pdbutil yaml2pdb - -pdb a.pdb
RUN: sed s/{FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF}/{6C633EB7-46FE-4609-BA83-EB820E6F5683}/ %S/Inputs/pdb-type-server-guid-collision-b-pdb.yaml | llvm-pdbutil yaml2pdb - -pdb b.pdb
RUN: lld-link a.obj b.obj -out:collision.dll -debug -pdb:collision.pdb -nodefaultlib /noentry /dll -verbose 2>&1 | FileCheck %s -check-prefix LOG
RUN: llvm-pdbutil dump -globals collision.pdb | FileCheck %s -check-prefix DUMP
LOG: lld-link: GUID collision between b.pdb and a.pdb
DUMP-LABEL: Global Symbols
DUMP: ============================================================
DUMP: 100 | S_GDATA32 [size = 24] `bar_gv`
DUMP-NEXT: type = 0x104E (Bar), addr = 0002:0004
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment