feat(asm): emit linkable ELF and Mach-O objects with external symbols

Assisted-by: Qwen 3.8 Max Preview
This commit is contained in:
2026-07-16 20:52:20 +02:00
parent b914c0e390
commit 900c9772b1
9 changed files with 1165 additions and 56 deletions
+11 -4
View File
@@ -243,10 +243,17 @@ File-level assembly (`AssembleFile`) goes beyond single functions: it
materialises the file's static symbols (`GLOBL`/`DATA`) in a data section
behind the code and resolves references to them (`mask<>(SB)`) to
RIP-relative loads whose displacements point inside the resulting image, so
the bytes are self-consistent at any base address. External (non-file-local)
symbols are rejected: they need object-file emission, which — together with
the remaining EVEX forms and the other architectures — is the rest of
Phase 2.
the bytes are self-consistent at any base address. References to symbols no
`GLOBL` defines are kept as relocations on the function layout, and the
object-file emitters turn the whole image into a linkable object: the ELF
and Mach-O writers (`gasm asm --format elf|macho`) lay the code and data out
as `.text`/`.data` (or `__text`/`__data`) sections, export a symbol per
`TEXT` and `GLOBL` (the `<>` ones local, the rest global) and emit one
PC-relative relocation per static-symbol reference — undefined external
symbols included, so the output links with the system toolchain. GOOBJ
emission, the format the Go linker consumes directly, is the remaining
piece of Phase 2 (together with the rest of the EVEX set and the other
architectures).
## Extension points