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

@@ -120,6 +120,7 @@ opcode_lookup(const char *m)
{ "SYSCALL", A_SYSCALL },
{ "TEXT", A_TEXT },
{ "DATA", A_DATA },
{ "DATAW", A_DATAW },
{ NULL, 0 }
};
for (int i = 0; tab[i].m; i++)
@@ -324,8 +325,9 @@ a_parse(Asm *a)
prg->from.type = D_CONST;
prg->from.offset = a_parsenum(m, NULL);
}
} else if (op == A_DATA) {
/* DATA name(SB),"escaped bytes" */
} else if (op == A_DATA || op == A_DATAW) {
/* DATA name(SB),"escaped bytes" — read-only in .text
* DATAW name(SB),"escaped bytes" — writable in .data */
char nbuf[128] = {0};
int nn = 0;
while (*m && *m != '(' && nn < 127) nbuf[nn++] = *m++;