notes

The x86_64 target spec, field by field

An appendix to notes/std.md, which is the page to read. This file holds milestone 184's reasoning for each field of targets/x86_64-unknown-nife.json, the SSE probe and the entry-point stub. The directory notes/std/ and this file's stem are provisional names. Naming is calef's.

The records this file cites by number:

The x86_64 spec, field by field (milestone 184)

It is the built-in x86_64-unknown-none spec with four deliberate differences, because that spec is a kernel's and this one is a ring-3 program's:

How you would know if SSE leaked in. Absence of xmm in a program that does no float work proves nothing, so the check is a probe that does real f64 and f32 arithmetic. Built for x86_64-unknown-nife it disassembles to zero instructions naming an xmm, mm or x87 register and nine calls into compiler-builtins' __adddf3, __muldf3, __divdf3, __subdf3, __mulsf3 and __floatundidf. The identical probe against a copy of the spec with +sse,+sse2 and no rustc-abi has 92 vector-register instructions and no helper calls, so the grep sees SSE when it is there:

$ llvm-objdump -d --no-show-raw-insn <elf> | grep -Eci 'xmm|ymm|zmm|%mm[0-7]|%st|fld|fstp|fild'

The entry point differs on x86_64, and only there. The kernel enters ring 3 with rsp on a page boundary (rsp % 16 == 0), while the x86-64 psABI promises a function rsp % 16 == 8, as if a call had just pushed a return address. aarch64 and RISC-V push nothing on a call, so they have no such offset. sys/pal/nife/mod.rs therefore makes _start a two-instruction global_asm! stub (call the Rust entry, then ud2), which makes the psABI's assumption true rather than hoping the soft-float code never depends on it. Nothing faults on a misaligned stack without SSE, which is exactly why it would have stayed latent.

The build also passes -Zbuild-std-features=compiler-builtins-mem to supply memcpy/memset for the bare target.