1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//! Little-endian integers for on-disk structures.
//!
//! Every container format xold reads and writes -- ELF for x86-64, `AArch64`
//! and RISC-V, PE/COFF, and Mach-O -- stores its integers little-endian. The
//! *host* running the linker need not be: xold is meant to build and run
//! anywhere.
//!
//! The on-disk structs are `#[repr(C)]` and viewed over mapped bytes with
//! `bytemuck`, which reinterprets bytes and never reorders them. Declaring
//! their fields as plain `u32`/`u64` would therefore read a file's
//! little-endian bytes as host-endian integers: correct on a little-endian
//! host by coincidence, silently wrong on a big-endian one, in both directions
//! -- garbage in from every input and an invalid image out.
//!
//! These types make the on-disk order explicit instead. Each is
//! `#[repr(transparent)]` over the primitive, so the struct layout, the
//! `bytemuck` casts and the bulk copies the writer relies on are all
//! unchanged; only reading and writing a field converts. On a little-endian
//! host `from_le`/`to_le` are the identity and the conversion compiles away
//! entirely, so this costs nothing where it is not needed.
//!
//! Big-endian *targets* are a separate matter: they would need their own
//! relocation tables and are not supported. This is about the host.
use ;
/// Defines a little-endian newtype over a primitive integer.
}
};
}
little_endian!;
little_endian!;
little_endian!;
little_endian!;