swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.57k stars 10.36k forks source link

[SR-13225] Linker fails with CodeView debug info enabled #55665

Open lxbndr opened 4 years ago

lxbndr commented 4 years ago
Previous ID SR-13225
Radar None
Original Reporter @lxbndr
Type Bug

Attachment: Download

Environment Swift version 5.3-dev (LLVM 8cbcb6870920db3, Swift fc4539767b04ffe) Target: x86_64-unknown-windows-msvc
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, DebugInfo, Windows | |Assignee | None | |Priority | Medium | md5: cae9499a812e80c65bb24b71a5c5a084

relates to:

Issue Description:

Similar to SR-10671, but reproducible with different settings and code. Build configuration: Release with Debug Info.

Code contains infinite loop, but it is actually reduced from real-life example where loop contains reachable break:

struct S {
    func f() {
        let c = {
            while true {
            }
        }
        print(c)
    }
}

Compiler invocation:

%SWIFTC% -emit-library -O -g -debug-info-format=codeview sr13225.swift -o sr13225.dll

Output:

sr13225-1dece9.o : fatal error LNK1318: Unexpected PDB error; OK (0) ''
clang: error: linker command failed with exit code 1318 (use -v to see invocation)
<unknown>:0: error: link command failed with exit code 1318 (use -v to see invocation)

UPD

Using lld-link (with assertions enabled) gives more informative output:

Assertion failed: indices.size() == 2, file D:\Development\swift-windows-gha\w\s\llvm-project\lld\COFF\PDB.cpp, line 731

The assertion is located in translateIdSymbols() function:

...
TypeIndex *ti =
    reinterpret_cast<TypeIndex *>(content.data() + refs[0].Offset);
// `ti` is the index of a FuncIdRecord or MemberFuncIdRecord which lives in
// the IPI stream, whose `FunctionType` member refers to the TPI stream.
// Note that LF_FUNC_ID and LF_MEMFUNC_ID have the same record layout, and
// in both cases we just need the second type index.
>;if (!ti->isSimple() && !ti->isNoneType()) {
    CVType funcIdData = iDTable.getType(*ti);
    SmallVector<TypeIndex, 2> indices;
    discoverTypeIndices(funcIdData, indices);
    assert(indices.size() == 2);
    *ti = indices[1];
}
...
compnerd commented 2 years ago

This is likely the known issue that we generate references to non-code entities which link refuses to resolve as it is invalid.