The driver flip moves build artifacts from next-to-source <stem>.s to a .sepwork/ scratch dir. 29 Pattern-B gates now build `ww build --sep -o <stem>` and read <stem>.sepwork/__root.s (multi-package gates concat all <stem>.sepwork/*.s, since cross-package labels live in per-package .s). All intermediates redirect to /tmp (WW_PKGCACHE + -o), so the corpus runs parallel-safe with no source-tree pollution. Tests pass now (--sep is live) and survive the flip. 915 additionally retargeted off strconv's PRIVATE left_shift_table (a let, not export) — which separate compilation correctly hides — onto a test-local package that exports its own probe table (#96). The combined path only linked it via a single-unit private leak; encapsulation is now honored under sep. Test-only; all 5 *_ww binaries HOLD. 989_m1mangle_run deferred (blocked by #99, imported-package fn main mangling under sep).
161 lines
4.6 KiB
C
161 lines
4.6 KiB
C
/*
|
|
* 989_m1mangle_sym — M1 (#22) symbol-name proof. Builds a fixture that
|
|
* imports the real nested DIRECTORY package `encoding.utf8` to `.s` on
|
|
* BOTH stages and asserts the emitted symbol table:
|
|
*
|
|
* needle | want | proves
|
|
* --------------------------+------+-----------------------------------
|
|
* "encoding.utf8.runesz" | yes | nested pkg path-mangles (the M1
|
|
* | | DELTA: leaf `utf8` → path
|
|
* | | `encoding.utf8`)
|
|
* "TEXT main," | yes | root entry stays BARE (#32)
|
|
* "TEXT utf8.runesz," | no | the pre-M1 leaf-only mangle is gone
|
|
*
|
|
* Plus cstage.s == wwstage.s byte-for-byte on the re-baselined names
|
|
* (rule-10 — the cs==ww gate over the new symbols).
|
|
*/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <sys/wait.h>
|
|
|
|
static int
|
|
runwait(const char *cmd)
|
|
{
|
|
int rc = system(cmd);
|
|
if (rc == -1) return -1;
|
|
if (WIFEXITED(rc)) return WEXITSTATUS(rc);
|
|
return -1;
|
|
}
|
|
|
|
static int
|
|
file_has(const char *path, const char *needle)
|
|
{
|
|
FILE *f = fopen(path, "rb");
|
|
if (!f) return -1;
|
|
char line[4096];
|
|
int found = 0;
|
|
while (fgets(line, sizeof line, f)) {
|
|
if (strstr(line, needle)) { found = 1; break; }
|
|
}
|
|
fclose(f);
|
|
return found;
|
|
}
|
|
|
|
struct check { const char *needle; int want; };
|
|
|
|
static const struct check checks[] = {
|
|
{ "encoding.utf8.runesz", 1 },
|
|
{ "TEXT main,", 1 },
|
|
{ "TEXT utf8.runesz,", 0 },
|
|
};
|
|
|
|
/* build_s — build `src` via `driver`, leaving the unit asm at `<stem>.s`;
|
|
* returns 0 on success.
|
|
* #93 sep layout: `--sep -o <stem>` splits the asm across
|
|
* <stem>.sepwork/<pkg>.s (root in __root.s, the imported encoding.utf8 in
|
|
* encoding.utf8.s). The mangled `encoding.utf8.runesz` definition lives in
|
|
* the per-pkg .s and `TEXT main,` in __root.s, so we CONCAT all the
|
|
* per-unit .s (sorted glob order is deterministic) into a single <stem>.s
|
|
* for the needle scans + the rule-10 cmp downstream. WW_PKGCACHE is pinned
|
|
* beside <stem> to leave the shared out/.pkgcache untouched. */
|
|
static int
|
|
build_s(const char *driver, const char *src, const char *stem)
|
|
{
|
|
char cmd[1024];
|
|
snprintf(cmd, sizeof cmd,
|
|
"WW_PKGCACHE='%s.pkgc' timeout 180 %s build --sep -o '%s' '%s' "
|
|
"2>/dev/null && cat '%s.sepwork/'*.s > '%s.s'",
|
|
stem, driver, stem, src, stem, stem);
|
|
return runwait(cmd);
|
|
}
|
|
|
|
static int
|
|
checkall(const char *name, const char *sp)
|
|
{
|
|
int fail = 0;
|
|
for (int i = 0; i < (int)(sizeof checks / sizeof checks[0]); i++) {
|
|
int got = file_has(sp, checks[i].needle);
|
|
if (got != checks[i].want) {
|
|
fprintf(stderr, "m1mangle_sym[%s]: '%s' present=%d want=%d\n",
|
|
name, checks[i].needle, got, checks[i].want);
|
|
fail++;
|
|
}
|
|
}
|
|
return fail;
|
|
}
|
|
|
|
int
|
|
main(void)
|
|
{
|
|
const char *bin = getenv("BIN");
|
|
if (!bin) bin = "out/bin";
|
|
char absbin[1024];
|
|
if (bin[0] != '/') {
|
|
char cwd[1024];
|
|
if (getcwd(cwd, sizeof cwd) == NULL) return 1;
|
|
snprintf(absbin, sizeof absbin, "%s/%s", cwd, bin);
|
|
bin = absbin;
|
|
}
|
|
char cdrv[1024], wdrv[1024];
|
|
snprintf(cdrv, sizeof cdrv, "%s/ww", bin);
|
|
snprintf(wdrv, sizeof wdrv, "%s/ww_ww", bin);
|
|
|
|
char src[64];
|
|
snprintf(src, sizeof src, "/tmp/m1sym_%d.ww", getpid());
|
|
FILE *f = fopen(src, "wb");
|
|
if (!f) return 1;
|
|
fputs("package main;\n"
|
|
"import encoding.utf8;\n"
|
|
"export fn main() int = { return utf8.runesz('A'): int; };\n", f);
|
|
fclose(f);
|
|
|
|
int fail = 0;
|
|
|
|
char cstem[64], cs[80];
|
|
snprintf(cstem, sizeof cstem, "/tmp/m1sym_c_%d", getpid());
|
|
snprintf(cs, sizeof cs, "%s.s", cstem);
|
|
if (build_s(cdrv, src, cstem) != 0) {
|
|
fprintf(stderr, "m1mangle_sym: cstage build failed\n");
|
|
fail++;
|
|
} else {
|
|
fail += checkall("cstage", cs);
|
|
}
|
|
|
|
int have_ww = (access(wdrv, X_OK) == 0);
|
|
char wstem[64], ws[80];
|
|
snprintf(wstem, sizeof wstem, "/tmp/m1sym_w_%d", getpid());
|
|
snprintf(ws, sizeof ws, "%s.s", wstem);
|
|
if (have_ww) {
|
|
if (build_s(wdrv, src, wstem) != 0) {
|
|
fprintf(stderr, "m1mangle_sym: wwstage build failed\n");
|
|
fail++;
|
|
} else {
|
|
fail += checkall("wwstage", ws);
|
|
/* rule-10: cs.s == ww.s on the new mangled names. */
|
|
char cmp[256];
|
|
snprintf(cmp, sizeof cmp, "cmp -s '%s' '%s'", cs, ws);
|
|
if (runwait(cmp) != 0) {
|
|
fprintf(stderr, "m1mangle_sym: cstage.s != "
|
|
"wwstage.s (byte-id break)\n");
|
|
fail++;
|
|
}
|
|
}
|
|
} else {
|
|
fprintf(stderr, "m1mangle_sym: skip wwstage (no ww_ww)\n");
|
|
}
|
|
|
|
char cmd[256];
|
|
/* #93: -rf to also drop the per-stem .sepwork scratch + pinned pkgc. */
|
|
snprintf(cmd, sizeof cmd, "rm -rf '%s' '%s'* '%s'*", src, cstem, wstem);
|
|
runwait(cmd);
|
|
|
|
if (fail) {
|
|
fprintf(stderr, "m1mangle_sym: %d checks failed\n", fail);
|
|
return 1;
|
|
}
|
|
printf("m1mangle_sym: ok\n");
|
|
return 0;
|
|
}
|