backengineering/llvm-msvc

[bug] crash with flto and __readmsr

VexatiousCheff opened this issue · 1 comments

#include <iostream>

int main(){
    *(unsigned long long*)0x12341234 = __readmsr(1);
}

flto both on clang and lld-link

temp fix: use inline assembly

Stack dump:
0.	Program arguments: C:\\LLVM-18.0.0git-win64\\bin\\lld-link -out:clangbug.exe "-libpath:C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.39.33519\\lib\\x64" "-libpath:C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.39.33519\\atlmfc\\lib\\x64" "-libpath:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.22621.0\\ucrt\\x64" "-libpath:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.22621.0\\um\\x64" -nologo -debug /subsystem:console CMakeFiles/clangbug.dir/main.cpp.obj /MANIFEST:EMBED /implib:clangbug.lib /pdb:clangbug.pdb /version:0.0 kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib oldnames.lib
1.	Running pass 'Function Pass Manager' on module 'ld-temp.o'.
2.	Running pass 'X86 DAG->DAG Instruction Selection' on function '@main'
Exception Code: 0xC0000005
 #0 0x00007ff6ef7a272b (C:\LLVM-18.0.0git-win64\bin\lld-link.exe+0xd2272b)
 #1 0x00007ff6ef7a1986 (C:\LLVM-18.0.0git-win64\bin\lld-link.exe+0xd21986)
 #2 0x00007ff6ef7a15ec (C:\LLVM-18.0.0git-win64\bin\lld-link.exe+0xd215ec)
 #3 0x00007ff6ef7a3d9a (C:\LLVM-18.0.0git-win64\bin\lld-link.exe+0xd23d9a)
 #4 0x00007ff6ef7a3d40 (C:\LLVM-18.0.0git-win64\bin\lld-link.exe+0xd23d40)
 #5 0x00007ff6ef69e37e (C:\LLVM-18.0.0git-win64\bin\lld-link.exe+0xc1e37e)
 #6 0x00007ff6ef6a705d (C:\LLVM-18.0.0git-win64\bin\lld-link.exe+0xc2705d)
 #7 0x00007ff6eee992d4 (C:\LLVM-18.0.0git-win64\bin\lld-link.exe+0x4192d4)
 #8 0x00007ff6ef69f933 (C:\LLVM-18.0.0git-win64\bin\lld-link.exe+0xc1f933)
 #9 0x00007ff6ef69efb4 (C:\LLVM-18.0.0git-win64\bin\lld-link.exe+0xc1efb4)
#10 0x00007ff6ef6a399e (C:\LLVM-18.0.0git-win64\bin\lld-link.exe+0xc2399e)
#11 0x00007ff6ef6ab530 (C:\LLVM-18.0.0git-win64\bin\lld-link.exe+0xc2b530)
#12 0x00007ff6eeea9ebc (C:\LLVM-18.0.0git-win64\bin\lld-link.exe+0x429ebc)
#13 0x00007ff6efa0a70e (C:\LLVM-18.0.0git-win64\bin\lld-link.exe+0xf8a70e)
#14 0x00007ff6f0995c93 (C:\LLVM-18.0.0git-win64\bin\lld-link.exe+0x1f15c93)
#15 0x00007ff6f0995eb3 (C:\LLVM-18.0.0git-win64\bin\lld-link.exe+0x1f15eb3)
#16 0x00007ff6f09960e4 (C:\LLVM-18.0.0git-win64\bin\lld-link.exe+0x1f160e4)
#17 0x00007ff6f0995990 (C:\LLVM-18.0.0git-win64\bin\lld-link.exe+0x1f15990)
#18 0x00007ff6ef8e7372 (C:\LLVM-18.0.0git-win64\bin\lld-link.exe+0xe67372)
#19 0x00007ff6ef8e6940 (C:\LLVM-18.0.0git-win64\bin\lld-link.exe+0xe66940)
#20 0x00007ff6ef8df738 (C:\LLVM-18.0.0git-win64\bin\lld-link.exe+0xe5f738)
#21 0x00007ff6ef8deaa9 (C:\LLVM-18.0.0git-win64\bin\lld-link.exe+0xe5eaa9)
#22 0x00007ff6eebfe377 (C:\LLVM-18.0.0git-win64\bin\lld-link.exe+0x17e377)
#23 0x00007ff6eebbf363 (C:\LLVM-18.0.0git-win64\bin\lld-link.exe+0x13f363)
#24 0x00007ff6eeba941d (C:\LLVM-18.0.0git-win64\bin\lld-link.exe+0x12941d)
#25 0x00007ff6eeba3805 (C:\LLVM-18.0.0git-win64\bin\lld-link.exe+0x123805)
#26 0x00007ff6eeb85142 (C:\LLVM-18.0.0git-win64\bin\lld-link.exe+0x105142)
#27 0x00007ff6eeb01f2c (C:\LLVM-18.0.0git-win64\bin\lld-link.exe+0x81f2c)
#28 0x00007ff6eeb02104 (C:\LLVM-18.0.0git-win64\bin\lld-link.exe+0x82104)
#29 0x00007ff6f0ab2580 (C:\LLVM-18.0.0git-win64\bin\lld-link.exe+0x2032580)
#30 0x00007ffbfc99257d (C:\WINDOWS\System32\KERNEL32.DLL+0x1257d)
#31 0x00007ffbfda6aa48 (C:\WINDOWS\SYSTEM32\ntdll.dll+0x5aa48)