9.3. Package archive (.a) format
The build output of a library package foo is two files (9.2.15).
| File | Contents |
|---|---|
libfoo.a | A standard ar archive holding the package's objects, one per codegen unit (9.2.16) |
foo.rokhir | The interface used downstream for monomorphization and name resolution (9.4) |
The two files sit in the same directory. --extern foo=libfoo.a and --extern foo=foo.rokhir each locate the sibling (9.2.3). Metadata such as version and producer is in the ROKHIR header (9.4).
9.3.1. Standard ar archive
libfoo.a is a standard Unix ar archive. ar, ranlib, nm, lld and clang handle it without conversion.
ar t libfoo.a
part0.o
part1.o
...
9.3.2. The objects
Each object is a standard ELF / Mach-O / COFF object produced by the AOT build pipeline for one codegen unit. Together they contain only those of the package's concrete fns reachable from the package's roots (9.2.8).
| Section | Contents |
|---|---|
.text | Code of concrete fns |
.rodata | const, literals, ScanTable |
.data | Initial values of statics |
.bss | Zero-initialized statics |
ScanTables are ordinary constant data; generated registration code registers them with the runtime via rok_gc_register_type at process start (8.2.13). There are no rok-specific sections.
9.3.3. Static .a principle
Every library output is a static .a. Dynamic libraries are not a standard rok output. Calling a dynamic library through FFI is allowed.
9.3.4. Version compatibility check
When a dependency's ROKHIR is read, its version and producer (the rokc that produced that ROKHIR) are compared with the current rokc. If they differ, it is an error stating what to rebuild (9.4.9).
9.3.5. Symbol exposure
The symbols an archive exposes are the global symbols of its objects, following Symbol mangling.
nm libfoo.a
0000000000000000 T _Y3f8a1c2b_foo_geom_distance_a7c91d8e44b2f190
0000000000000040 T _Y3f8a1c2b_foo_geom_Point_origin_b1234567...
9.3.6. Standard library
The standard library (rok::bare / core / std) is not distributed as separate archives. It is compiled from source (--bootstrap) and reused from rokc's cache while the toolchain, options and sources are unchanged (9.2.19).
9.3.7. Linking
clang main.o libfoo.a librokr.a -o my_binary
The linker links only the needed symbols from the archive's objects. Functions exposed with #[export_name] can be called directly from C.
extern uint32_t rok_compute(int32_t a, int32_t b); // #[export_name("rok_compute")]
int main(void) { return (int)rok_compute(1, 2); }
clang main.c libfoo.a librokr.a -o my_binary
9.3.8. Stability
The archive format follows the ABI stability policy; the ROKHIR format follows 9.4.