https://github.com/sunfishcode/origin/tree/d0c8ff8c6b4e39b8cb6c2571e2db0a431c2a1f71/example-crates/tiny
Finally, we add a RUSTFLAGS flag with .cargo/config.toml:
rustflags = ["-Z", "trap-unreachable=no"]
This disables the use of trap instructions, such as ud2 on x86-64, at places the compiler thinks should be unreachable, such as after the jmp in _start or after the syscall that calls exit_group, because rustix uses the noreturn inline asm option. Normally this is a very good thing, but it does take a few extra bytes.
This will not prevent an ud2 instruction from being generated after the exit_group syscall on the latest version of rustix due to bytecodealliance/rustix#1444, discussed in bytecodealliance/rustix#1433. Perhaps this should be removed from example-crates/tiny to prevent confusion. Anyone who wants to save space by omitting the ud2 instruction can use the syscalls crate to issue the relevant syscall directly.
As an alternative, bytecodealliance/rustix#1444 can be put behind a feature gate, something like seccomp-bpf-compat, or as an opt-out, no-seccomp-bpf-compat.
https://github.com/sunfishcode/origin/tree/d0c8ff8c6b4e39b8cb6c2571e2db0a431c2a1f71/example-crates/tiny
This will not prevent an
ud2instruction from being generated after theexit_groupsyscall on the latest version ofrustixdue to bytecodealliance/rustix#1444, discussed in bytecodealliance/rustix#1433. Perhaps this should be removed fromexample-crates/tinyto prevent confusion. Anyone who wants to save space by omitting theud2instruction can use the syscalls crate to issue the relevant syscall directly.As an alternative, bytecodealliance/rustix#1444 can be put behind a feature gate, something like
seccomp-bpf-compat, or as an opt-out,no-seccomp-bpf-compat.