w6a: DATAW directive for writable .data section

First step toward top-level mutable `let`. Adds a sibling directive to
DATA whose bytes land in a separate writable .data PROGBITS section
(SHF_ALLOC|SHF_WRITE, STT_OBJECT) instead of .text. The section is
emitted only when DATAW was used, so inputs without it produce a
byte-identical .o — tests 991 (selfhost .o diff) and 995 (self-rebuild)
keep passing unchanged.

w6l still treats data-resident syms as undefined; that's the next step.
This commit is contained in:
2026-05-12 11:35:50 +09:00
parent 922877309b
commit 1b0955c97b
7 changed files with 381 additions and 18 deletions

View File

@@ -52,6 +52,7 @@ struct Asym {
const char *name;
int defined; /* 1 if we own its address */
int is_text; /* if 1, address is in .text */
int is_data; /* if 1, address is in .data (mutually exclusive with is_text) */
int is_global; /* exported (TEXT) */
u64 addr; /* offset within section if defined */
int idx; /* ELF symtab index, filled at emit time */
@@ -81,6 +82,12 @@ struct Asm {
u8 *text;
u64 textcap, textlen;
/* output data section (writable). Empty unless any DATAW directive
* was seen; in that case obj.c emits an extra .data PROGBITS
* section with SHF_WRITE. */
u8 *data;
u64 datacap, datalen;
/* symbols */
Asym *syms;
Areloc *relocs;
@@ -102,6 +109,7 @@ int a_emit_elf(Asm*, FILE *out);
Asym *a_intern(Asm*, const char *name);
void a_emit_byte(Asm*, u8);
void a_emit_u32(Asm*, u32);
void a_emit_data_byte(Asm*, u8);
void a_addreloc(Asm*, u64 off, int kind, Asym *s, i64 add);
#endif