andrew-johnson-4 / lambda-mountain

Compact Portable Assembler (5K SLOC)
MIT License
11 stars 0 forks source link

Segfault if command does not write to STDOUT, OK if command does write to STDOUT #517

Closed andrew-johnson-4 closed 6 days ago

andrew-johnson-4 commented 1 week ago

The rule of silence, also referred to as the silence is golden rule, is an important part of the Unix philosophy that states that when a program has nothing surprising, interesting or useful to say, it should say nothing. source

Currently the command utility for this compiler has a quite unfortunate bug where not writing to STDOUT results in a segfault. Writing anything from anywhere in the program stops the crash. This is probably something related to invalid memory references or stale data, but there are a few things that anyone could do to help diagnose this bug:

  1. Try running make deploy on your Linux distribution

This bug is currently reliably occurring on my Windows Subsystem for Linux installation of Ubuntu 20.04.2 LTS. Running make deploy will compile the compiler twice and check to see that the result is stable. On my system the crash results in a SEGFAULT during code generation.

  1. Does this bug remind you of anything familiar?

The compiler currently depends on x86-64 Linux system calls sys_open, sys_close, sys_read, sys_write, sys_exit, sys_brk. and nothing else. There are zero dynamically loaded libraries such as libc etc.

  1. Are you a debugging pro?

This is an interesting opportunity to improve the debugging tools for LM. A sealed release has been created to reproduce this bug at any point in the future.

andrew-johnson-4 commented 6 days ago

Coincidentally fixed by the large return value patch.