selfhost+test: cgdot LEAQ-of-fn for module-qualified N_DOT (#12)
wwstage cgdot lacked a TY_FN branch for module-qualified N_DOT
rvalues. `let p = mod1.ping` fell through to the MOVQ/LEAQ-narrow
fallback, loading 8 prologue bytes from the fn's first instruction
instead of taking its address. Cstage cgdot already handled this
case (wired during #9, f1440bf).
Mirror cstage: gate on fnretlookup(c, fld) before the localloadop
fallback; emit `LEAQ <module>.<name>(SB), AX` via emitfnname with
the hint from lhs.str.
Extend 706_fnlabel_mangle: pos.ww now stores mod1.ping/mod2.ping
into local fn-pointer slots and dispatches through them in addition
to the existing direct calls. Expected exit 56 → 112. Regression
shape: without the new branch, MOVQ leaf(SB) loads the prologue
bytes; indirect call jumps into garbage → SIGSEGV.
ww2 == ww3 == ww4 byte-identical at the new emit.
This commit is contained in:
@@ -3,30 +3,33 @@
|
||||
* modules can each `export fn ping` (and each define a private
|
||||
* `fn helper`) without colliding at link time.
|
||||
*
|
||||
* The fixture in test/wcc/data/fnlabelmangle/ pins three of the four
|
||||
* label-emit sites #9 touches:
|
||||
* The fixture in test/wcc/data/fnlabelmangle/ pins all four
|
||||
* label-emit sites #9 / #12 touch:
|
||||
* mod{1,2}/mod{1,2}.ww
|
||||
* export fn ping = bareval + helper() + fpi();
|
||||
* fn helper — private, same-leaf across modules
|
||||
* fn fpi — `let h = helper; h();` pins LEAQ N_IDENT
|
||||
* pos.ww
|
||||
* return mod1.ping() + mod2.ping(); // CALL N_DOT × 2
|
||||
* let p1 = mod1.ping; let p2 = mod2.ping; // LEAQ N_DOT × 2
|
||||
* return mod1.ping() + mod2.ping() // CALL N_DOT × 2
|
||||
* + p1() + p2(); // through fn ptr
|
||||
*
|
||||
* mod1.ping = 3 + 11 + 11 = 25
|
||||
* mod2.ping = 5 + 13 + 13 = 31
|
||||
* total = 56
|
||||
* total = 25 + 31 + 25 + 31 = 112
|
||||
*
|
||||
* Pre-fix (cgen emitted bare `TEXT ping` for both modules' exports;
|
||||
* non-exported `helper` already mangled, so that half is incidental
|
||||
* regression coverage), the linker collapsed both `ping` symbols and
|
||||
* one dispatch landed on the wrong body. The bare-IDENT helper /
|
||||
* `let h = helper` callsites would also pick whichever module the
|
||||
* lookup found first, silently miscompiling fpi's intra-module call.
|
||||
* Pre-#9 (cgen emitted bare `TEXT ping` for both modules' exports),
|
||||
* the linker collapsed both `ping` symbols and one dispatch landed
|
||||
* on the wrong body. The bare-IDENT helper / `let h = helper` call-
|
||||
* sites would also pick whichever module the lookup found first,
|
||||
* silently miscompiling fpi's intra-module call.
|
||||
*
|
||||
* Pre-#12 wwstage cgdot's `let p = mod.ping` fell through to the
|
||||
* MOVQ leaf(SB) module-qualified-value fallback, loading 8 bytes
|
||||
* of fn-prologue into AX; `p()` then jumped into mid-prologue
|
||||
* garbage. Cstage cgdot already had a TY_FN LEAQ branch from #9.
|
||||
*
|
||||
* Coverage notes:
|
||||
* - LEAQ N_DOT for fn rvalue (`let p = mod1.ping`) is not exercised.
|
||||
* wwstage cgdot has no working LEAQ-of-fn N_DOT branch — a row
|
||||
* would diverge across stages. Tracked as a follow-up.
|
||||
* - The skip rule's three remaining cases (@symbol / main / empty-
|
||||
* module) are not pinned by a dedicated row because every passing
|
||||
* run of `make test` already exercises them: the bootstrap and
|
||||
@@ -70,10 +73,11 @@ run_pos(const char *driver, const char *fixdir, const char *tag)
|
||||
snprintf(bin, sizeof bin, "%s/pos", fixdir);
|
||||
int got = runwait(bin);
|
||||
unlink(bin);
|
||||
if (got != 56) {
|
||||
if (got != 112) {
|
||||
fprintf(stderr,
|
||||
"fnlabel_mangle[%s]: pos.ww exit=%d want=56 — "
|
||||
"fn labels likely collapsed at link\n", tag, got);
|
||||
"fnlabel_mangle[%s]: pos.ww exit=%d want=112 — "
|
||||
"fn labels likely collapsed at link, or LEAQ-of-fn "
|
||||
"N_DOT branch missing in cgdot\n", tag, got);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user