2 2

os::exec::exitstr causes abort call

Message ID
DKIM signature
Download raw message
Platform: Linux - NixOS
Commit: 5f65a5c112dd15efc0f0223ee895c2582e8f4915[0]

The provided Hare code produces the following output:

[user@hostname: ~] $ hare run main.ha
/dev/fd/3: unrecognized option: -Y
Usage: /dev/fd/3 [-h] <subcommand> args...
Abort: os/exec/+linux/process.ha:154:14: execution reached unreachable code (compiler bug)
/tmp/838ac565d6b6c2b4/os/exec/+linux/process.ha:154:22 os::exec::exitstr+0x4b [0x80209f2]
/tmp/838ac565d6b6c2b4/main.ha:18:51 main+0x47a [0x8033d45]
|                       "hare", exec::exitstr(code))!;
/tmp/838ac565d6b6c2b4/rt/+linux/start.ha:13:13 rt::start_ha+0xe [0x80040ae]
/tmp/838ac565d6b6c2b4/rt/+linux/platformstart-libc.ha:8:17 rt::start_linux+0x3a [0x8004295]
Aborted (core dumped)

Hare code:

use fmt;
use os;
use os::exec;
use unix::signal;

export fn main() void = {
	let cmd = exec::cmd("hare", "-Y")!;

	let proc = exec::start(&cmd)!;

	let status = exec::wait(&proc)!;

	match(exec::check(&status)) {
	case void =>
	case let code: exec::exit_status =>
		fmt::errorfln("cmd \"{}\" failed: {}",
			"hare", exec::exitstr(code))!;

Looking at the stdlib code, perhaps the abort call is being caused by the
type casting in `os::exec::exit`[1]? Since, when `os::exec::check`
doesn't return `void`, it calls and returns the former.

I do not know much about the `rt` module, but it also could be the
culprit, since both of the aforementioned functions use it[2][3].

[0]: https://git.sr.ht/~sircmpwn/hare/tree/5f65a5c112dd15efc0f0223ee895c2582e8f4915
[1]: https://git.sr.ht/~sircmpwn/hare/tree/5f65a5c112dd15efc0f0223ee895c2582e8f4915/item/os/exec/+linux/process.ha#L172
[2]: https://git.sr.ht/~sircmpwn/hare/tree/5f65a5c112dd15efc0f0223ee895c2582e8f4915/item/os/exec/+linux/process.ha#L171
[3]: https://git.sr.ht/~sircmpwn/hare/tree/5f65a5c112dd15efc0f0223ee895c2582e8f4915/item/os/exec/+linux/process.ha#L183
Message ID
<9f9cbd54bb5e2813134aef59b60a3e94@onemoresuza.mailer.me> (view parent)
DKIM signature
Download raw message
On Sat Feb 10, 2024 at 14:09 +0000, Coutinho de Souza wrote:
> 	case let code: exec::exit_status =>

This match case is not correct - it should be

    case let code: !exec::exit_status => ...

Note that the '!' is very important because exec::check returns
!exec::exit_status, not exec::exit_status. Those are distinct types.

The compiler is supposed to give an error in this case. Somehow, the code
successfully typechecks and then causes a miscompilation that ultimately leads
to the crash.

This issue is known and has been reported to the bug tracker:

Until it's solved, just be extra careful when working with types that have '!'
or 'const' flags.
Message ID
<CZ5SLXCFDUS6.1195P46OYYHF9@disroot.org> (view parent)
DKIM signature
Download raw message
I see. Thanks for the info, Alexey.
Reply to thread Export thread (mbox)