compiler: make package exports self-contained

This commit is contained in:
2026-08-12 01:12:42 +09:00
parent 52f6d6f0d4
commit 9b970eb16a
10 changed files with 965 additions and 82 deletions

View File

@@ -1172,6 +1172,16 @@ ffi_resolve(const char *ident)
return ident;
}
/* Package compilation must not acquire a hidden source dependency on a
* transitive `rt` interface merely so the compiler intrinsic `alloc` learns
* its linker spelling. The WW runtime ABI owns this name in -c mode. Keep
* raw w6c's declaration-driven behavior for compatibility and FFI tests. */
static const char *
alloc_resolve(Cg *c)
{
return c->sep_mode ? "rt_malloc" : ffi_resolve("malloc");
}
static void
ffi_collect(Cg *c, Node *file)
{
@@ -9199,7 +9209,7 @@ cgexpr(Cg *c, Node *n, Local *locals)
char *alloc_ok = mklabel(c, "alloc_ok");
char *alloc_done = mklabel(c, "alloc_done");
ins2(c, A_MOVQ, aimm(sz), areg(D_DI));
ins1(c, A_CALL, asym(ffi_resolve("malloc")));
ins1(c, A_CALL, asym(alloc_resolve(c)));
ins2(c, A_CMPQ, aimm(0), areg(D_AX));
ins1(c, A_JNE, abranch(alloc_ok));
ins2(c, A_MOVQ, aimm(1), areg(D_AX));
@@ -13536,7 +13546,7 @@ cgstmt(Cg *c, Node *n, Local **locals, int *frame)
ins2(c, A_IMULQ, areg(D_BX), areg(D_AX));
}
ins2(c, A_MOVQ, areg(D_AX), areg(D_DI));
ins1(c, A_CALL, asym(ffi_resolve("malloc")));
ins1(c, A_CALL, asym(alloc_resolve(c)));
if (via_tryunw) {
char *ok = mklabel(c, "tryunw_ok");
ins2(c, A_CMPQ, aimm(0), areg(D_AX));