llvm-mos / llvm-mos-sdk

SDK for developing with the llvm-mos compiler
https://www.llvm-mos.org
Other
280 stars 56 forks source link

Uppercase register name in asm volatile() crashes in IRTranslator pass #380

Closed ToboterXP closed 1 month ago

ToboterXP commented 1 month ago

Hello, your program has asked me to submit a bug report. The program and report are attached below. game.zip

LLVM ERROR: unable to translate instruction: call (in function: input_update) PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump:

  1. Program arguments: C:\llvm-mos\bin\ld.lld --gc-sections --sort-section=alignment C:\Users\tobi1\AppData\Local\Temp\main-963441.o C:\Users\tobi1\AppData\Local\Temp\game-eb35af.o C:\Users\tobi1\AppData\Local\Temp\level-68fc57.o C:\Users\tobi1\AppData\Local\Temp\rendering-54baf1.o C:\Users\tobi1\AppData\Local\Temp\input-367787.o C:\Users\tobi1\AppData\Local\Temp\items-1f2c2f.o C:\Users\tobi1\AppData\Local\Temp\monsters-969de4.o C:\Users\tobi1\AppData\Local\Temp\player-acd1c8.o C:\Users\tobi1\AppData\Local\Temp\hud-84c07b.o C:\Users\tobi1\AppData\Local\Temp\utils-c023e4.o C:\Users\tobi1\AppData\Local\Temp\objects-637474.o C:\Users\tobi1\AppData\Local\Temp\inventory-ed1e7d.o C:\Users\tobi1\AppData\Local\Temp\mapgen-5f4e97.o C:\Users\tobi1\AppData\Local\Temp\sound-a006b7.o C:\Users\tobi1\AppData\Local\Temp\zsmkit-fa82e1.o -plugin-opt=mcpu=mosw65c02 -plugin-opt=O2 -plugin-opt=-function-sections=1 -plugin-opt=-data-sections=1 -mllvm -force-precise-rotation-cost -mllvm -jump-inst-cost=6 -mllvm -force-loop-cold-block -mllvm -phi-node-folding-threshold=0 -mllvm -speculate-blocks=0 -mllvm -align-large-globals=false -mllvm -disable-spill-hoist -mllvm -lsr-complexity-limit=10000000 -mllvm -zp-avail=90 -LC:\llvm-mos\bin/../mos-platform/cx16/lib -LC:\llvm-mos\bin/../mos-platform/commodore/lib -LC:\llvm-mos\bin/../mos-platform/common/lib -T link.ld -l:crt0.o -lcrt0 -lcrt -lc -o ./build/vault.prg
  2. Running pass 'Function Pass Manager' on module 'ld-temp.o'.
  3. Running pass 'IRTranslator' on function '@input_update' Exception Code: 0x80000003

    0 0x00007ff6ca6450e1 (C:\llvm-mos\bin\ld.lld.exe+0x750e1)

    1 0x00007ffcba721881 (C:\WINDOWS\System32\ucrtbase.dll+0x71881)

    2 0x00007ffcba722851 (C:\WINDOWS\System32\ucrtbase.dll+0x72851)

    3 0x00007ff6ca639c24 (C:\llvm-mos\bin\ld.lld.exe+0x69c24)

    4 0x00007ff6ca9f824e (C:\llvm-mos\bin\ld.lld.exe+0x42824e)

    5 0x00007ff6ca9f9438 (C:\llvm-mos\bin\ld.lld.exe+0x429438)

    6 0x00007ff6cac679fe (C:\llvm-mos\bin\ld.lld.exe+0x6979fe)

    7 0x00007ff6cb98101b (C:\llvm-mos\bin\ld.lld.exe+0x13b101b)

    8 0x00007ff6cb98121c (C:\llvm-mos\bin\ld.lld.exe+0x13b121c)

    9 0x00007ff6cb981458 (C:\llvm-mos\bin\ld.lld.exe+0x13b1458)

    10 0x00007ff6cb980d26 (C:\llvm-mos\bin\ld.lld.exe+0x13b0d26)

    11 0x00007ff6cab001d0 (C:\llvm-mos\bin\ld.lld.exe+0x5301d0)

    12 0x00007ff6caaffb85 (C:\llvm-mos\bin\ld.lld.exe+0x52fb85)

    13 0x00007ff6caaf9654 (C:\llvm-mos\bin\ld.lld.exe+0x529654)

    14 0x00007ff6caaf8ce3 (C:\llvm-mos\bin\ld.lld.exe+0x528ce3)

    15 0x00007ff6ca7ca8bb (C:\llvm-mos\bin\ld.lld.exe+0x1fa8bb)

    16 0x00007ff6ca7197d7 (C:\llvm-mos\bin\ld.lld.exe+0x1497d7)

    17 0x00007ff6ca723f5a (C:\llvm-mos\bin\ld.lld.exe+0x153f5a)

    18 0x00007ff6ca73894a (C:\llvm-mos\bin\ld.lld.exe+0x16894a)

    19 0x00007ff6ca73814c (C:\llvm-mos\bin\ld.lld.exe+0x16814c)

    20 0x00007ff6ca691825 (C:\llvm-mos\bin\ld.lld.exe+0xc1825)

    21 0x00007ff6ca620afe (C:\llvm-mos\bin\ld.lld.exe+0x50afe)

    22 0x00007ff6ca620da7 (C:\llvm-mos\bin\ld.lld.exe+0x50da7)

    23 0x00007ff6cba60370 (C:\llvm-mos\bin\ld.lld.exe+0x1490370)

    24 0x00007ffcbb5e7374 (C:\WINDOWS\System32\KERNEL32.DLL+0x17374)

    25 0x00007ffcbcafcc91 (C:\WINDOWS\SYSTEM32\ntdll.dll+0x4cc91)

    mos-clang: error: ld.lld command failed due to signal (use -v to see invocation)

ToboterXP commented 1 month ago

I just downloaded llvm today, so it's the current release Windows executable

AGPX commented 1 month ago

Similar issue here:

Code generated successfully.
Error during the process of compilation:
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.  Program arguments: C:\\tools\\llvm-mos\\bin\\ld.lld --gc-sections --sort-section=alignment C:\\Users\\AGPX\\AppData\\Local\\Temp\\SpacePong_NTSC-c108a6.o C:\\Users\\AGPX\\AppData\\Local\\Temp\\ldiv16u-3aa326.o C:\\Users\\AGPX\\AppData\\Local\\Temp\\setupframe-6e9260.o -plugin-opt=O0 -plugin-opt=-function-sections=1 -plugin-opt=-data-sections=1 -mllvm -force-precise-rotation-cost -mllvm -jump-inst-cost=6 -mllvm -force-loop-cold-block -mllvm -phi-node-folding-threshold=0 -mllvm -speculate-blocks=0 -mllvm -align-large-globals=false -mllvm -disable-spill-hoist -mllvm -lsr-complexity-limit=10000000 -mllvm -zp-avail=110 -LC:\\tools\\llvm-mos\\bin/../mos-platform/c64/lib -LC:\\tools\\llvm-mos\\bin/../mos-platform/commodore/lib -LC:\\tools\\llvm-mos\\bin/../mos-platform/common/lib -T link.ld -T C:/Users/AGPX/AppData/Local/Temp/linker.ld -l:crt0.o -lcrt0 -lcrt -lc -o C:/Users/AGPX/AppData/Local/Temp/SpacePong_NTSC.prg
1.  Running pass 'Function Pass Manager' on module 'ld-temp.o'.
2.  Running pass 'InstructionSelect' on function '@_ZN5Actor14__setupFrame__Ev'
Exception Code: 0xC0000005
 #0 0x00007ff6af9c3fc8 (C:\tools\llvm-mos\bin\ld.lld.exe+0xf73fc8)
 #1 0x00007ff6af9c3f50 (C:\tools\llvm-mos\bin\ld.lld.exe+0xf73f50)
 #2 0x00007ff6af0d7372 (C:\tools\llvm-mos\bin\ld.lld.exe+0x687372)
 #3 0x00007ff6af0dcd37 (C:\tools\llvm-mos\bin\ld.lld.exe+0x68cd37)
 #4 0x00007ff6aee023a7 (C:\tools\llvm-mos\bin\ld.lld.exe+0x3b23a7)
 #5 0x00007ff6aedfad7e (C:\tools\llvm-mos\bin\ld.lld.exe+0x3aad7e)
 #6 0x00007ff6aedfb60e (C:\tools\llvm-mos\bin\ld.lld.exe+0x3ab60e)
 #7 0x00007ff6aedfcf3c (C:\tools\llvm-mos\bin\ld.lld.exe+0x3acf3c)
 #8 0x00007ff6aedfcddb (C:\tools\llvm-mos\bin\ld.lld.exe+0x3acddb)
 #9 0x00007ff6aee84c3f (C:\tools\llvm-mos\bin\ld.lld.exe+0x434c3f)
#10 0x00007ff6aee8519e (C:\tools\llvm-mos\bin\ld.lld.exe+0x43519e)
#11 0x00007ff6aee84bab (C:\tools\llvm-mos\bin\ld.lld.exe+0x434bab)
#12 0x00007ff6af0e79fe (C:\tools\llvm-mos\bin\ld.lld.exe+0x6979fe)
#13 0x00007ff6afe0101b (C:\tools\llvm-mos\bin\ld.lld.exe+0x13b101b)
#14 0x00007ff6afe0121c (C:\tools\llvm-mos\bin\ld.lld.exe+0x13b121c)
#15 0x00007ff6afe01458 (C:\tools\llvm-mos\bin\ld.lld.exe+0x13b1458)
#16 0x00007ff6afe00d26 (C:\tools\llvm-mos\bin\ld.lld.exe+0x13b0d26)
#17 0x00007ff6aef801d0 (C:\tools\llvm-mos\bin\ld.lld.exe+0x5301d0)
#18 0x00007ff6aef7fb85 (C:\tools\llvm-mos\bin\ld.lld.exe+0x52fb85)
#19 0x00007ff6aef79654 (C:\tools\llvm-mos\bin\ld.lld.exe+0x529654)
#20 0x00007ff6aef78ce3 (C:\tools\llvm-mos\bin\ld.lld.exe+0x528ce3)
#21 0x00007ff6aec4a8bb (C:\tools\llvm-mos\bin\ld.lld.exe+0x1fa8bb)
#22 0x00007ff6aeb997d7 (C:\tools\llvm-mos\bin\ld.lld.exe+0x1497d7)
#23 0x00007ff6aeba3f5a (C:\tools\llvm-mos\bin\ld.lld.exe+0x153f5a)
#24 0x00007ff6aebb894a (C:\tools\llvm-mos\bin\ld.lld.exe+0x16894a)
#25 0x00007ff6aebb814c (C:\tools\llvm-mos\bin\ld.lld.exe+0x16814c)
#26 0x00007ff6aeb11825 (C:\tools\llvm-mos\bin\ld.lld.exe+0xc1825)
#27 0x00007ff6aeaa0afe (C:\tools\llvm-mos\bin\ld.lld.exe+0x50afe)
#28 0x00007ff6aeaa0da7 (C:\tools\llvm-mos\bin\ld.lld.exe+0x50da7)
#29 0x00007ff6afee0370 (C:\tools\llvm-mos\bin\ld.lld.exe+0x1490370)
#30 0x00007ffc8bd5257d (C:\Windows\System32\KERNEL32.DLL+0x1257d)
#31 0x00007ffc8c0aaf08 (C:\Windows\SYSTEM32\ntdll.dll+0x5af08)
mos-clang++: error: ld.lld command failed due to signal (use -v to see invocation)
johnwbyrd commented 1 month ago

Hi guys, I wonder if I could possibly convince you to give us some call stacks, so we have a hint where to look. Perhaps I can convince you to install and replicate the problem with these compiler binaries, and then provide us the corresponding call stacks:

https://github.com/llvm-mos/llvm-mos/releases/tag/llvm-mos-darwin-debug https://github.com/llvm-mos/llvm-mos/releases/tag/llvm-mos-linux-debug https://github.com/llvm-mos/llvm-mos/releases/tag/llvm-mos-darwin-debug

While these problems seem related, I note that they are happening in different compilation passes.

Also, ToboterXP, that seems like a fairly large replication case. Have you been able to narrow down the crash to a particular source file or function?

johnwbyrd commented 1 month ago

@ToboterXP , you have inadvertently uppercased the X in input.c:

"jsr $FF56 \n": "=a"(joya), "=X"(joyx), "=y"(joyy));

Change the =X to =x, and your code will compile correctly.

@AGPX , let's get a replication case in, or more information on your particular crash, in a new bug submission.

johnwbyrd commented 1 month ago

Small replication case for this bug added at https://godbolt.org/z/qYxr994x4 .

mysterymath commented 1 month ago

Going to go ahead and close this one as working-as-intended; the inline assembly specifiers are case-sensitive.

This shouldn't produce a crash, but the actual error message is getting swallowed by an internal compiler exception trap. That's a long-standing issue with GlobalISel, best addressed upstream. (See https://github.com/llvm-mos/llvm-mos/issues/463).

As @johnwbyrd mentioned, @AGPX, your issue is almost certainly unrelated given the different compiler phase affected, so this should be a new issue with a reproducer.

AGPX commented 1 month ago

After extensive debugging, I discovered that my problem was that I had created an (not inlined, external) assembly routine (.s) where I was passing too many parameters (I was using rc16, but I later saw on the wiki that you can use rc15 at most). After removing this parameter, the crash disappeared. Unfortunately, as @mysterymath mentioned, the fact that LLVM crashes when you make an error with the assembly (inline or not), creates a lot of false positives.

mysterymath commented 1 month ago

After extensive debugging, I discovered that my problem was that I had created an (not inlined, external) assembly routine (.s) where I was passing too many parameters (I was using rc16, but I later saw on the wiki that you can use rc15 at most). After removing this parameter, the crash disappeared. Unfortunately, as @mysterymath mentioned, the fact that LLVM crashes when you make an error with the assembly (inline or not), creates a lot of false positives.

This still seems like a compiler bug; there shouldn't be a limit to the number of parameters you can pass to a function, since it should start to use the soft stack.