Elymas icon indicating copy to clipboard operation
Elymas copied to clipboard

`die` also prints "Illegal instruction" to stdout using `elymas/shared`

Open vblz opened this issue 8 months ago • 3 comments

Way to reproduce:

# elymas/shared
"Oops" die
OopsIllegal instruction

where Oops goes to stderr Illegal instruction goes to stdout

vblz avatar Apr 20 '25 22:04 vblz

The program executed UD2 (dedicated undefined instruction) and is now very dead. Illegal instruction is probably printed by the enclosing shell. (cf. https://github.com/Drahflow/Elymas/blob/1433018210b9bb420a51929700056228a141bbe2/compiler/elymasGlobal.ey#L1227 The assembly continues afterwards in case you used die as a trappoint only and catch the UD2 via a debugger)

What behavior would you like to see instead?

Drahflow avatar Apr 23 '25 08:04 Drahflow

I would expect no "Illegal instruction" output

vblz avatar Apr 23 '25 10:04 vblz

% echo '"Oops" die' | strace -f ./optimized
execve("./optimized", ["./optimized"], 0x7ffc99ed0888 /* 50 vars */) = 0
open("/proc/self/exe", O_RDONLY)        = 3
mmap(0x600000000000, 17825792, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 3, 0x11d000) = 0x600000000000
mmap(0x500000000000, 139264, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 3, 0x121d000) = 0x500000000000
mmap(0x400000000000, 139264, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 3, 0x123f000) = 0x400000000000
close(3)                                = 0
open("/dev/stdin", O_RDONLY)            = 3
read(3, "\"Oops\" die\n", 4096)         = 11
write(2, "Oops", 4Oops)                     = 4
--- SIGILL {si_signo=SIGILL, si_code=ILL_ILLOPN, si_addr=0x3000001153fc} ---
+++ killed by SIGILL +++
zsh: done                          echo '"Oops" die' | 
zsh: illegal hardware instruction  strace -f ./optimized

Elymas is not outputting things to stderr (see above for the actual syscalls). But die is killing the program.

Drahflow avatar Jun 11 '25 20:06 Drahflow