Skip to main content

rucc_object/
lib.rs

1//! ELF, Mach-O and COFF object writers.
2//!
3//! Design: `spec/11-asm-objects-debug.md`. Layer rank 8, see `spec/18-package-layout.md`.
4//!
5//! # Status
6//!
7//! ELF, which is what Linux and the freestanding targets want and what M3 needs. A text section,
8//! the symbols that say where each function in it is and how long it is, the names it wanted that
9//! are not in it, the relocations that ask a linker to find them, and the marker whose absence
10//! makes the stack executable. An object this writes links with the system linker and runs.
11//!
12//! The variables a file defines are written too: the section each one goes in, the symbol that
13//! says where it is and how long it is, the binding that says who can see it, and the relocations
14//! an image asks for when it holds the address of something. A tentative definition is asked of
15//! the linker rather than put in a section, which is the one case where a variable has a symbol
16//! and no bytes anywhere.
17//!
18//! An [`Alias`] is written as a second symbol at the first one's section, value and size, with a
19//! binding of its own and no second copy of the bytes, which is what a file gets from
20//! `__attribute__((alias("target")))` and what makes one name reach another at no cost.
21//!
22//! What it is given is [`Text`], [`Data`] and the aliases between them, which are here rather than
23//! beside the assembler that fills them in because they are what an object file is made of and
24//! because a writer cannot depend on the thing that produces its input without the layer graph
25//! going the wrong way round.
26//!
27//! Mach-O and COFF are not written yet. Both wait on the target that needs them.
28//!
29//! Every crate in the workspace is published, and publishing implies a promise. This one is
30//! tier 3: its Rust API is explicitly unstable and will change without a major version bump.
31//! Depend on the `rucc` binary's behaviour, not on this.
32
33#![doc(html_root_url = "https://docs.rs/rucc-object/0.7.5")]
34
35mod elf;
36mod section;
37
38pub use crate::elf::{Error, write};
39pub use crate::section::{
40    Alias, Binding, Data, Extent, FUNC_ALIGN, Object, Place, Reference, Reloc, Text,
41};
42
43/// The milestone in `spec/17-milestones.md` that fills this crate in.
44pub const MILESTONE: &str = "M3";
45
46#[cfg(test)]
47mod tests {
48    #[test]
49    fn milestone_is_recorded() {
50        assert!(super::MILESTONE.starts_with('M'));
51    }
52}