Spec M5.6 — fixes from the M5.5 review + creat (found during M6-macho)

  1. reloc() only attaches to a raw word. The pending relocation is valid only until the next call to gen_word (emit() or #opcode); any other instruction emitted while a relocation is pending is the error reloc without an immediately following emit (in err_node). Repro: reloc(BRANCH26,"_h"); i64 x = 5; emit(0x94000000); → today the .o comes out invalid; afterwards: a compile error.
  2. Real 16-byte alignment: __data created with align 4; #section's default ALIGN = 4. Repro: uptr names[] = {"abcdefg"}; as the only global → otool -l shows __data with addr a multiple of 16 and align 2^4.
  3. MAXSECS/MAXPARAMS defined once in mc.h; remove the copies in parse.c/gen_arm64.c.
  4. #opcode parameter deliberately shadows a #define — just a comment in do_opcode.
  5. creat instead of variadic open for writing files: libSystem's open is variadic, and on Apple's arm64 the mode argument goes on the stack — the language only passes x0..x7, so .mc code could never pass the mode. Rule "same I/O shape everywhere": stage0/arena.c's write_file now uses creat(path, 0644) (fcntl.h). lib/sys.mc gains extern i64 creat(uptr path, i64 mode); and lib/sys_svc.mc implements creat via the open syscall (5) with flags 0x601 (O_WRONLY|O_CREAT|O_TRUNC) and the mode in x2. src/arena.mc: replace the open+fchmod pair with creat (the only spot in src/ touched in this batch; nothing else in src/).
  6. cmp_cond via a table in gen_arm64.c (optional, ≈ −5 lines). Do not touch type_of_token or any other part of parse.c beyond item 3 (another agent is transliterating parse.c right now).

Acceptance: make stage0 with no warnings, stage0-san, budget, test (mc0 and mc0-san), check-lex; scripts/check-obj.sh BEFORE/AFTER: the .o files change only in __data's alignment (verify that __text, symtab, and relocs are unchanged); repro of item 1 before/after; otool -l for item 2; ls -l of a file written by src/m0.mc showing -rw-r--r--; new test 034-reloc-err.mc — no, errors do not go in the suite; add the case to the report instead. Lines per file.

Edit this page