llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.59k stars 11.82k forks source link

Exception Code: 0xC000001D after Associative COMDAT symbol #87503

Open ColinHexagon opened 6 months ago

ColinHexagon commented 6 months ago

Hello,

While building a C++ project with clang (Release options, -fprofile-instr-generate -fcoverage-mapping -emit-llvm) on Windows, lld-link.exe crashed? and asked me to create a bug report here.

This following error is printed:

LLVM ERROR: Associative COMDAT symbol '??0type_error@pybind11@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z' does not exist.

Followed by:

1.      Running pass 'Function Pass Manager' on module 'ld-temp.o'.
2.      Running pass 'X86 Assembly Printer' on function '@"??0type_error@pybind11@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z.6331"'
Exception Code: 0xC000001D

Followed by the stacktrace:
 #0 0x00007ff79c94d346 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0xcd346)
 #1 0x00007ffc29271881 (C:\WINDOWS\System32\ucrtbase.dll+0x71881)
 #2 0x00007ffc29272851 (C:\WINDOWS\System32\ucrtbase.dll+0x72851)
 #3 0x00007ff79c9584a3 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0xd84a3)
 #4 0x00007ff79d16cd86 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x8ecd86)
 #5 0x00007ff79d16cfbb (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x8ecfbb)
 #6 0x00007ff79d1944f2 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x9144f2)
 #7 0x00007ff79dae49c0 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x12649c0)
 #8 0x00007ff79dae6b3f (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x1266b3f)
 #9 0x00007ff79cc87039 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x407039)
#10 0x00007ff79d50da5d (C:\PROGRA~1\LLVM\bin\lld-link.exe+0xc8da5d)
#11 0x00007ff79d28dc1a (C:\PROGRA~1\LLVM\bin\lld-link.exe+0xa0dc1a)
#12 0x00007ff79d293903 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0xa13903)
#13 0x00007ff79d28e293 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0xa0e293)
#14 0x00007ff79d037533 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x7b7533)
#15 0x00007ff79d0362f0 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x7b62f0)
#16 0x00007ff79cb29810 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x2a9810)
#17 0x00007ff79cb28f6c (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x2a8f6c)
#18 0x00007ff79ce7c17e (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x5fc17e)
#19 0x00007ff79cb1b743 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x29b743)
#20 0x00007ff79c8c453f (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x4453f)
#21 0x00007ff79c8bd11c (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x3d11c)
#22 0x00007ff79c881cd0 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x1cd0)
#23 0x00007ff79c881444 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x1444)
#24 0x00007ff79f59b1b4 xmlLinkGetData (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x2d1b1b4)
#25 0x00007ffc2b967344 (C:\WINDOWS\System32\KERNEL32.DLL+0x17344)
#26 0x00007ffc2baa26b1 (C:\WINDOWS\SYSTEM32\ntdll.dll+0x526b1)

lld-link --version returns:
LLD 16.0.6

clang --version returns:
clang version 16.0.6
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
llvmbot commented 4 months ago

@llvm/issue-subscribers-lld-coff

Author: None (ColinHexagon)

Hello, While building a C++ project with clang (Release options, -fprofile-instr-generate -fcoverage-mapping -emit-llvm) on Windows, lld-link.exe crashed? and asked me to create a bug report here. This following error is printed: ``` LLVM ERROR: Associative COMDAT symbol '??0type_error@pybind11@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z' does not exist. ``` Followed by: ``` 1. Running pass 'Function Pass Manager' on module 'ld-temp.o'. 2. Running pass 'X86 Assembly Printer' on function '@"??0type_error@pybind11@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z.6331"' Exception Code: 0xC000001D Followed by the stacktrace: #0 0x00007ff79c94d346 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0xcd346) #1 0x00007ffc29271881 (C:\WINDOWS\System32\ucrtbase.dll+0x71881) #2 0x00007ffc29272851 (C:\WINDOWS\System32\ucrtbase.dll+0x72851) #3 0x00007ff79c9584a3 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0xd84a3) #4 0x00007ff79d16cd86 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x8ecd86) #5 0x00007ff79d16cfbb (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x8ecfbb) #6 0x00007ff79d1944f2 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x9144f2) #7 0x00007ff79dae49c0 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x12649c0) #8 0x00007ff79dae6b3f (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x1266b3f) #9 0x00007ff79cc87039 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x407039) #10 0x00007ff79d50da5d (C:\PROGRA~1\LLVM\bin\lld-link.exe+0xc8da5d) #11 0x00007ff79d28dc1a (C:\PROGRA~1\LLVM\bin\lld-link.exe+0xa0dc1a) #12 0x00007ff79d293903 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0xa13903) #13 0x00007ff79d28e293 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0xa0e293) #14 0x00007ff79d037533 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x7b7533) #15 0x00007ff79d0362f0 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x7b62f0) #16 0x00007ff79cb29810 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x2a9810) #17 0x00007ff79cb28f6c (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x2a8f6c) #18 0x00007ff79ce7c17e (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x5fc17e) #19 0x00007ff79cb1b743 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x29b743) #20 0x00007ff79c8c453f (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x4453f) #21 0x00007ff79c8bd11c (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x3d11c) #22 0x00007ff79c881cd0 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x1cd0) #23 0x00007ff79c881444 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x1444) #24 0x00007ff79f59b1b4 xmlLinkGetData (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x2d1b1b4) #25 0x00007ffc2b967344 (C:\WINDOWS\System32\KERNEL32.DLL+0x17344) #26 0x00007ffc2baa26b1 (C:\WINDOWS\SYSTEM32\ntdll.dll+0x526b1) lld-link --version returns: LLD 16.0.6 clang --version returns: clang version 16.0.6 Target: x86_64-pc-windows-msvc Thread model: posix InstalledDir: C:\Program Files\LLVM\bin ```
aganea commented 4 months ago

Are you able to test the link step with the latest LLD, see if the bug is still present?

mstorsjo commented 4 months ago

Are you able to make a link reproducer? Add -reproduce:repro.tar to the lld-link command, and it will bundle up all relevant input files into a file, which can be shared with us, allowing anybody to reproduce the same error.

mizvekov commented 3 months ago

@mstorsjo I have run into this problem as well.

Reproducer attached. repro.zip

mstorsjo commented 2 months ago

@mstorsjo I have run into this problem as well.

Thanks, I'm able to reproduce this error using this package.

mstorsjo commented 1 month ago

@mstorsjo I have run into this problem as well.

Reproducer attached. repro.zip

While it's possible to reproduce the issue with this, it's a bit hard to get an overview of what's really happening...

Are you able to reduce the reproducer on a source level, so that you'd be able to share a minimal (or at least small) source level reproducer for the issue?


I had a quick look at this, and something goes wrong in some of the LTO optimization passes. If looking at the input file root/psinex/build/aarch64-win-rel/ext/catch2/CMakeFiles/ext.catch2.obj.dir/catch2/internal/catch_test_case_tracker.cpp.obj, running llvm-dis on it, I get IR that contains this:

$"??_7SectionTracker@TestCaseTracking@Catch@@6B@" = comdat any
[...]
@"??_7SectionTracker@TestCaseTracking@Catch@@6B@" = linkonce_odr unnamed_addr constant { [6 x ptr] } { [6 x ptr] [ptr @"??_GSectionTracker@TestCaseTracking@Catch@@UEAAPEAXI@Z", ptr @"?isComplete@SectionTracker@TestCaseTracking@Catch@@UEBA_NXZ", ptr @"?close@TrackerBase@TestCaseTracking@Catch@@UEAAXXZ", ptr @"?fail@TrackerBase@TestCaseTracking@Catch@@UEAAXXZ", ptr @"?isSectionTracker@SectionTracker@TestCaseTracking@Catch@@UEBA_NXZ", ptr @"?isGeneratorTracker@ITracker@TestCaseTracking@Catch@@UEBA_NXZ"] }, comdat, !type !0, !type !15, !type !31, !vcall_visibility !1

I.e. we have a declaration and a definition of this comdat object.

If I run the LTO compilation with lld-link @response.txt -lldemit:llvm -out:out.bc, then convert the LTO output with llvm-dis out.bc back into textual IR, I see this:

$"??_7SectionTracker@TestCaseTracking@Catch@@6B@" = comdat any

I only see a declaration of the comdat, but no definition. There's one reference to it elsewhere in the LTO output:

@"__typeid_?AVITracker@TestCaseTracking@Catch@@_32_unique_member" = hidden unnamed_addr constant { [6 x ptr] } { [6 x ptr] [ptr @"??_GSectionTracker@TestCaseTracking@Catch@@UEAAPEAXI@Z.llvm.merged", ptr @"?isComplete@SectionTracker@TestCaseTracking@Catch@@UEBA_NXZ.llvm.merged", ptr @"?close@TrackerBase@TestCaseTracking@Catch@@UEAAXXZ", ptr @"?fail@TrackerBase@TestCaseTracking@Catch@@UEAAXXZ", ptr @"?isSectionTracker@SectionTracker@TestCaseTracking@Catch@@UEBA_NXZ", ptr @"?isGeneratorTracker@ITracker@TestCaseTracking@Catch@@UEBA_NXZ"] }, comdat($"??_7SectionTracker@TestCaseTracking@Catch@@6B@"), !type !54728, !type !54729, !type !55527

So, during the LTO optimization phases, something optimizes out the definition of this comdat, even if it evidently still is needed somewhere.

llvmbot commented 1 month ago

@llvm/issue-subscribers-backend-x86

Author: None (ColinHexagon)

Hello, While building a C++ project with clang (Release options, -fprofile-instr-generate -fcoverage-mapping -emit-llvm) on Windows, lld-link.exe crashed? and asked me to create a bug report here. This following error is printed: ``` LLVM ERROR: Associative COMDAT symbol '??0type_error@pybind11@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z' does not exist. ``` Followed by: ``` 1. Running pass 'Function Pass Manager' on module 'ld-temp.o'. 2. Running pass 'X86 Assembly Printer' on function '@"??0type_error@pybind11@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z.6331"' Exception Code: 0xC000001D Followed by the stacktrace: #0 0x00007ff79c94d346 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0xcd346) #1 0x00007ffc29271881 (C:\WINDOWS\System32\ucrtbase.dll+0x71881) #2 0x00007ffc29272851 (C:\WINDOWS\System32\ucrtbase.dll+0x72851) #3 0x00007ff79c9584a3 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0xd84a3) #4 0x00007ff79d16cd86 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x8ecd86) #5 0x00007ff79d16cfbb (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x8ecfbb) #6 0x00007ff79d1944f2 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x9144f2) #7 0x00007ff79dae49c0 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x12649c0) #8 0x00007ff79dae6b3f (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x1266b3f) #9 0x00007ff79cc87039 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x407039) #10 0x00007ff79d50da5d (C:\PROGRA~1\LLVM\bin\lld-link.exe+0xc8da5d) #11 0x00007ff79d28dc1a (C:\PROGRA~1\LLVM\bin\lld-link.exe+0xa0dc1a) #12 0x00007ff79d293903 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0xa13903) #13 0x00007ff79d28e293 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0xa0e293) #14 0x00007ff79d037533 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x7b7533) #15 0x00007ff79d0362f0 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x7b62f0) #16 0x00007ff79cb29810 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x2a9810) #17 0x00007ff79cb28f6c (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x2a8f6c) #18 0x00007ff79ce7c17e (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x5fc17e) #19 0x00007ff79cb1b743 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x29b743) #20 0x00007ff79c8c453f (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x4453f) #21 0x00007ff79c8bd11c (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x3d11c) #22 0x00007ff79c881cd0 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x1cd0) #23 0x00007ff79c881444 (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x1444) #24 0x00007ff79f59b1b4 xmlLinkGetData (C:\PROGRA~1\LLVM\bin\lld-link.exe+0x2d1b1b4) #25 0x00007ffc2b967344 (C:\WINDOWS\System32\KERNEL32.DLL+0x17344) #26 0x00007ffc2baa26b1 (C:\WINDOWS\SYSTEM32\ntdll.dll+0x526b1) lld-link --version returns: LLD 16.0.6 clang --version returns: clang version 16.0.6 Target: x86_64-pc-windows-msvc Thread model: posix InstalledDir: C:\Program Files\LLVM\bin ```
EugeneZelenko commented 1 month ago

Could you please try 19 or main branch?

mstorsjo commented 1 month ago

Could you please try 19 or main branch?

The reproducer provided by @mizvekov above does reproduce the issue still on latest git main.

mizvekov commented 1 month ago

@mstorsjo

I have managed to produce a whole-project reduction. This became easier with recent non-released c-vise, which added support for recursively adding multiple test cases while keeping project structure intact.

So I am providing attached a cmake-project on zip file: test.zip It needs access to windows sdk libraries. This is the command I use to generate the needed xwin directory:

xwin --accept-license --manifest-version 17 --temp --arch aarch64 splat --preserve-ms-arch-notation --disable-symlinks --output xwin

Then edit CMakeUserConfig.json to point to that xwin directory. You can see the build instructions in the included interestingness test test.sh.

These sources are as produced from c-vise reduction, I have not had time to manually reduce them.

If you need to further reduce them using c-vise, then grab c-vise from main branch and run:

cvise.py --tidy test.sh (find . -type f -not -name test.sh)
mstorsjo commented 1 month ago

@mstorsjo

I have managed to produce a whole-project reduction. This became easier with recent non-released c-vise, which added support for recursively adding multiple test cases while keeping project structure intact.

So I am providing attached a cmake-project on zip file: test.zip It needs access to windows sdk libraries. This is the command I use to generate the needed xwin directory:

xwin --accept-license --manifest-version 17 --temp --arch aarch64 splat --preserve-ms-arch-notation --disable-symlinks --output xwin

Thanks!

I managed to reproduce this (although I used tools installed with http://github.com/mstorsjo/msvc-wine/ so I had to tweak the paths a little bit).

I managed to detach the build procedure from CMake, so the issue can be reproduced with the source files you included, and the following commands:

clang++ -std=gnu++23 --target=aarch64-pc-windows-msvc -fwhole-program-vtables -flto=full -O -Wno-everything -x c++-module -fmodule-output=std.pcm -o std.cppm.obj -c std.cppm
clang++ -std=gnu++23 --target=aarch64-pc-windows-msvc -fwhole-program-vtables -flto=full -O -Wno-everything -fmodule-file=std.pcm -o catch2.cpp.obj -c catch2.cpp
lld-link std.cppm.obj catch2.cpp.obj -out:out.exe libcmt.lib

(Assuming that the right $INCLUDE and $LIB environment variables are set up.)