Skip to content

blaze-ladder front2: fix #[linkage] AttrMeta parsing, wasm64 weak linkage, and cached/in-body foreign statics - #2901

Merged
mteacher360 merged 4 commits into
mainfrom
fix/front2-linkage-and-inbody-extern-static
Nov 29, 2026
Merged

mteacher360 merged 4 commits into
mainfrom
fix/front2-linkage-and-inbody-extern-static

Conversation

@mteacher360

Copy link
Copy Markdown
Collaborator

Summary

Fixes two high-impact Linux front2 regressions uncovered on origin/main (74c13a89b):

1. #[linkage] regression from 7416f35a3 + compiler_builtins::round on wasm64

  • Root cause (parsing): blaze_lower stores Attr { meta: AttrMeta::KeyValue, args } with args already stripped of the leading = (just the value expression, e.g. "extern_weak", while #[linkage("weak")] is AttrMeta::Tokens and #[linkage] is AttrMeta::Path). 7416f35a3 (committed uncompiled) required args.trim().strip_prefix('='), causing every real #[linkage = ".."] attribute (including std's __dso_handle and statx, plus linkage_tests::a_fn_s_linkage_is_read_by_symbols_of itself) to fail with LinkageRefused::Malformed.
  • Root cause (compiler_builtins::round on wasm64): library/compiler-builtins/compiler-builtins/src/macros.rs:432 emits #[unsafe(no_mangle)] #[cfg_attr(not(any(all(windows, target_env = "gnu"), target_os = "cygwin")), linkage = "weak")] on every intrinsic wrapper (including math::full_availability::round::round), so wasm64-blaze-wasip1 proc-macros calling f64::round -> core::num::imp::libm::round hit #[linkage = "weak"] when run/wasm64.rs linked compiler_builtins::round.
  • Fix:
    • Unified #[linkage] parsing into parse_linkage(AttrMeta, &str) + linkage_of_for(AttrMeta, &str, is_wasm) in crates/blaze-ladder/src/front2/program.rs and wired all four readers (program.rs, statics.rs, export_shim.rs, run/wasm64.rs) through it (one home, Rule 30).
    • Kept Linkage::Weak honestly refused on native targets (preserving 7416f35a3 / Rule 3 where blaze-export writes STB_GLOBAL/N_EXT).
    • Genuinely carried Linkage::Weak on target_family = "wasm": run/wasm64.rs's closed-world module linker now records weak: bool on RustCExport and sorts strong definitions ahead of weak ones so strong overrides weak and weak fallbacks (compiler_builtins::round, std::sys::pal::wasi::cabi_realloc, etc.) resolve internally.

2. Cached / in-body foreign statics (std::sys::env::unix::environ)

  • Root cause: LazyProgram::make_static_value (crates/blaze-ladder/src/front2/program/lazy/fill.rs) bypassed foreign_static_symbol and unconditionally called statics::one_static (constant evaluation). On warm cached-record verification (make_one.rs handling ReadKind::Static for std::sys::env::unix::environ's in-body unsafe extern "C" { static mut environ: *const *const c_char; }), make_static_value attempted to constant-evaluate environ as a Rust static and failed with BodyError::NoBody (its text has no body). make_one.rs also did not prepare ReadKind::ForeignStatic rows or DataTarget::Static foreign relocations in static_over, and nested_exports::walk_every did not record NestedKind::ExternBlock items into Walk::locals for unhinted cold locate_local.
  • Fix:
    • Extracted statics::foreign_static_of (allocator-explicit, zero Global / Box<str> signature additions) shared by statics::static_values, LazyProgram::make_static_value, and LazyProgram::ensure_foreign_static.
    • Handled ReadKind::ForeignStatic alongside ReadKind::Static in make_one.rs and ensured foreign DataTarget::Static targets in static_over.
    • Indexed in-body NestedKind::ExternBlock declarations in nested_exports::walk_every.

Verification

  • cargo test -p blaze-ladder --lib linkage_tests: 5 passed, 0 failed (restored a_fn_s_linkage_is_read_by_symbols_of, added malformed/unknown + target_family = "wasm" compiler_builtins::round tests)
  • cargo test -p blaze-ladder --test local_statics cold_typed_record_foreign_statics: 1 passed, 0 failed
  • cargo test -p blaze-ladder --test local_statics warm_cached_walk: 1 passed, 0 failed (covers in-body environ, in-body extern_weak __dso_handle, macro-expanded statx, top-level extern_weak, and Rust static LOCAL_VAL control across cold + warm cached walks with 0 re-makes)
  • cargo test -p blaze-ladder --test wasm64_rust_e2e: 6 passed, 0 failed (includes weak_definition_resolves_fallback_and_yields_to_strong_on_wasm64)
  • cargo test -p blaze-ladder --test front_equal_rules: 37 passed, 0 failed
  • cargo test -p blaze-ladder --test front2_f128_routines: 2 passed, 0 failed
  • Workspace gates vs origin/main (blaze-ladder): stops 1199->1199 (0), casts 1258->1258 (0), clones 61->60 (-1), allocs Global 558->558 / signatures 227->227 (0), ambient std 286->286 / alloc 0->0 / vec_box 1375->1373 (-2), dups 671->671 (0), homes/domains/rustcsites 0 new sites.
  • git merge-tree --write-tree origin/main HEAD: clean (b484a996523735e320e7fa59f6436ecfa138cb59).

…kage, and cached/in-body foreign statics

1. Fix 7416f35 #[linkage] regression: blaze_lower stores Attr { meta: AttrMeta::KeyValue, args }
   with the leading '=' already stripped (the expression after '='). linkage_of previously called
   strip_prefix('='), causing every #[linkage = ".."] (including std's extern_weak __dso_handle
   and statx, and compiler_builtins' weak math intrinsics) to fail as Malformed.
   - Split into parse_linkage(AttrMeta, &str) + linkage_of_for(AttrMeta, &str, is_wasm) as the
     one home across program.rs, statics.rs, export_shim.rs, and run/wasm64.rs.
   - Keep Linkge::Weak honestly refused on native (where blaze-export emits STB_GLOBAL/N_EXT),
     and genuinely carry Linkage::Weak on target_family = "wasm" where run/wasm64.rs's
     closed-world module linker tracks weak exports and resolves strong definitions over weak
     ones (covering compiler_builtins' round/libm wrappers and std's cabi_realloc).

2. Fix cached/in-body foreign statics (std::sys::env::unix::environ):
   - LazyProgram::make_static_value bypassed foreign_static_symbol and always evaluated via
     statics::one_static, causing warm cached-record verification (make_one.rs ReadKind::Static)
     of in-body extern "C" { static mut environ; } to fail with BodyError::NoBody.
   - Share statics::foreign_static_of across static_values, make_static_value, and
     ensure_foreign_static (also wired into make_one.rs for ReadKind::ForeignStatic and
     static_over DataTarget::Static relocations), and index in-body ExternBlock items in
     nested_exports::walk_every so unhinted cold locate_local finds them too.
@mteacher360

Copy link
Copy Markdown
Collaborator Author

Codex (@codex) review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-29T05:44:27.099111Z f801d70 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0138c304b1

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

match linkage_of_for(a.meta, t, is_wasm).map_err(|refused| Front2Refusal::Linkage { item: path.into(), refused })? {
Linkage::ExternWeak => out.extern_weak = true,
Linkage::External => {}
Linkage::External | Linkage::Weak => {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Route Rust calls through the prevailing weak symbol

When a wasm crate contains a weak #[no_mangle] function plus a strong definition of the same symbol and Rust code calls the weak item through its module path, accepting Linkage::Weak here still tables that call by the weak function's ItemKey/fn_symbol_of_name. The new strong-first selection in collect_rust_c_exports is used only for C-symbol lookups, so such a direct Rust call executes the weak body instead of the prevailing strong definition required by linkage semantics; route these calls through the selected export or keep this form refused.

AGENTS.md reference: AGENTS.md:L116-L120

Useful? React with 👍 / 👎.

// counted for the ordinals and indexed by `walk_every` (`self.every`) so cold
// `locate_local` finds body-local foreign statics/fns (e.g. `std`'s in-body
// `extern "C" { static mut environ; }`); a foreign item is never an export.
let decls = match super::foreign_locals::declared(item_text, self.reading.edition, &mut CrateCfg::with_version(self.reading.atoms, self.reading.cfg_version), alloc) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Skip cfg-disabled extern blocks before reading declarations

When an in-body extern block is removed by an outer #[cfg]/#[cfg_attr], this branch still passes the block to foreign_locals::declared, which evaluates cfg only on the declarations inside the block. A valid disabled block containing a form that this reader refuses, such as a foreign type or macro declaration, therefore makes an unrelated cold local lookup fail with NestedRefusal::Foreign, even though Rust removes the entire extern block; apply the block's own cfg before inspecting its children.

AGENTS.md reference: AGENTS.md:L116-L120

Useful? React with 👍 / 👎.

Ok((_, decls)) => decls,
Err(r) => {
let path = self.out.path(at, "extern", alloc)?;
return Err(NestedRefusal::Foreign { path, why: r.form() });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve module-backed extern macro declarations

When a body-local extern block contains a macro invocation whose declarations are represented by the names library's block module (for example ring's prefixed_extern! pattern), foreign_locals::declared returns Refused::MacroCall and this unconditional error aborts walk_every. Locals::keep explicitly skips that error when the scope has an owned module, so the new cold index must mirror that path; otherwise locating any cold local in such an enclosing body can fail before the module-backed foreign items are reached.

AGENTS.md reference: AGENTS.md:L116-L120

Useful? React with 👍 / 👎.

/// `compiler_builtins`'s `#[linkage = "weak"]` math/soft-float wrappers and `std`'s
/// `cabi_realloc`) with no external ELF/Mach-O symbol table to clash against.
pub const fn carried_for(self, is_wasm: bool) -> bool {
self.carried() || (is_wasm && matches!(self, Linkage::Weak))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Limit weak-linkage acceptance to the memory64 backend

This condition treats every target_family = "wasm" crate as if it will use run/wasm64.rs, so it also accepts #[linkage = "weak"] for targets such as wasm32-wasip1. The weak bit is not retained in Symbols or the ordinary code/static records and is recovered only by the memory64 linker's source scan, so a wasm32 definition is emitted as an ordinary strong definition and can conflict with or prevail over its intended override; gate this on the actual memory64 target/backend or carry the binding through every wasm emission path.

AGENTS.md reference: AGENTS.md:L116-L120

Useful? React with 👍 / 👎.

…dy extern blocks

1. Restrict `#[linkage = "weak"]` acceptance to the memory64 backend
   (`target_arch = "wasm64"`) via `is_wasm64_target`, so `wasm32-wasip1`
   continues to honestly refuse `Linkage::Weak`.
2. In `run/wasm64.rs`, redirect direct Rust path calls, fn-pointer coercions,
   and static references targeting an overridden weak `#[no_mangle]` /
   `#[export_name]` item to the prevailing strong definition so both C-symbol
   and Rust-path callers execute the prevailing strong export.
3. Evaluate an in-body `extern` block's own outer `#[cfg]` / `#[cfg_attr]`
   attributes in `foreign_locals::declared` before inspecting its children so
   cfg-disabled extern blocks (e.g. containing foreign types or macros) are
   skipped cleanly by both `nested_exports::walk_every` and `Locals::keep`.
4. Mirror `Locals::keep` in `nested_exports::walk_every` by skipping
   `foreign_locals::Refused::MacroCall` inside written block modules.
@mteacher360

Copy link
Copy Markdown
Collaborator Author

Addressed all 4 Codex R1 findings in 75b2f0adb:

  1. Limit #[linkage = "weak"] acceptance to memory64 (target_arch = "wasm64"):
    • Added is_wasm64_target(atoms) in front2/program.rs (checking target_arch = "wasm64", not target_family = "wasm"), wired through Linkage::carried_for, linkage_of_for, symbols_of, and statics::static_attrs_of so wasm32-wasip1 continues to honestly refuse Linkage::Weak.
    • Added unit test wasm64_honours_compiler_builtins_weak_linkage_while_wasm32_and_other_linkages_are_refused.
  2. Route direct Rust path calls / fn-pointers / statics targeting an overridden weak item to the prevailing strong export on wasm64:
    • run/wasm64.rs (collect_rust_c_exports) now records weak_fn_overrides and weak_static_overrides mapping each superseded weak ItemKey to its prevailing strong ItemKey.
    • compile_worklist_to_wasm64 intercepts overridden weak items at the worklist dispatch site, enqueuing the prevailing winner and aliasing both func_by_sym and foreign_static_alias so extern "C" calls, direct Rust module-path calls, and fn-pointer/static references all resolve to the strong definition.
    • Strengthened wasm64_rust_e2e::weak_definition_resolves_fallback_and_yields_to_strong_on_wasm64 to invoke the overridden weak item via extern "C", direct Rust path (weak_provider::overridable()), and static fn-pointer (OVERRIDABLE_FP()), asserting the emitted .wasm contains the strong body (0x3333_4444) and unoverridden weak fallback (0x2222_3333), and never emits the overridden weak body (0x1111_2222).
  3. Skip cfg-disabled in-body extern blocks before reading their declarations:
    • Evaluated the extern block's own outer #[cfg] / #[cfg_attr] attributes in front2/foreign_locals.rs::declared (the single home shared by both nested_exports::walk_every and locals::Locals::keep) before inspecting children, returning an empty declaration list for disabled blocks while preserving inner #[cfg] handling on active blocks.
    • Added unit test nested_exports::tests::cfg_disabled_in_body_extern_block_is_skipped_by_walk_every.
  4. Preserve module-backed extern macro declarations in nested_exports::walk_every:
    • Mirrored locals::Locals::keep by skipping foreign_locals::Refused::MacroCall when in_written is true, while continuing to refuse macro calls inside unwritten-block extern blocks.
    • Added unit test nested_exports::tests::macro_call_in_written_block_extern_is_skipped_by_walk_every.

Verification:

  • Tests: linkage_tests (5/5), nested_exports::tests (3/3), ring_in_body_tests (7/7), local_statics (warm_cached_walk 1/1, cold_typed_record_foreign_statics 1/1), wasm64_rust_e2e (6/6), front_equal_rules (37/37), front2_f128_routines (2/2) — 62/62 passed.
  • Gates (blaze-ladder vs origin/main): 0 net new sites across stops (1199), casts (1258), clones (-1), allocs (558/227), ambient (286/0/1373, -2 vec_box), dups, homes (35/35 ok), domains, and rustcsites (4, none new). Clean git merge-tree --write-tree origin/main HEAD.

Codex (@codex) review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 75b2f0adb5

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

Comment thread crates/blaze-ladder/src/run/wasm64.rs Outdated
Comment on lines +414 to +418
} else if path == "linkage"
&& let Ok(args_text) = v.text_at(a.args)
&& crate::front2::program::parse_linkage(a.meta, args_text) == Ok(crate::front2::program::Linkage::Weak)
{
weak = true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Include block-local weak exports in override collection

When a function body declares a #[no_mangle] #[linkage = "weak"] function and another item provides the strong definition, a direct lexical call to the local function still executes the weak body. collect_rust_c_exports derives weak overrides only from Records::each_item, while block-local items use synthesized keys from nested_exports/Locals and never enter that iterator; consequently no override is recorded when this new branch recognizes weak linkage. Include nested exported definitions in the collection (or refuse weak linkage on them) so the worklist aliases their direct calls to the prevailing strong item.

AGENTS.md reference: AGENTS.md:L116-L120

Useful? React with 👍 / 👎.

Comment on lines +1145 to +1146
if !foreign_static_alias.iter().any(|&(from, _)| from == symbol.0) {
foreign_static_alias.push((symbol.0, winner_sym.0));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Apply weak-static aliases when exporting globals

When compile_items_to_wasm64 roots a weak static that is superseded by a strong definition and opts.export_globals names the weak static's symbol, this branch skips emitting the weak datum and records only the weak-to-winner alias. Section 7 later looks up the unaliased requested symbol directly in static_datums, so the build returns UnresolvedSymbol instead of exporting the prevailing strong static's address; resolve exported-global symbols through foreign_static_alias just like function and datum relocations.

AGENTS.md reference: AGENTS.md:L116-L120

Useful? React with 👍 / 👎.

1. Walk block-local `#[no_mangle]` / `#[export_name]` items via
   `nested_exports::walk_in_body` during `collect_rust_c_exports`, and add an
   on-the-fly `find_local_weak_override` fallback in `compile_worklist_to_wasm64`
   (for written-block and post-macro block-local weak items) so direct lexical
   calls to any overridden block-local weak item route to the prevailing strong
   definition.
2. Resolve `Wasm64BuildOpts::export_globals` through `foreign_static_alias`
   before looking up `static_datums` so exporting a superseded weak static
   resolves cleanly to the prevailing strong static's address.
@mteacher360

Copy link
Copy Markdown
Collaborator Author

Addressed both Codex R2 findings in 72bbc8470:

  1. Include block-local weak exports in wasm64 override resolution (run/wasm64.rs):
    • collect_rust_c_exports now walks block-local #[no_mangle] / #[export_name] fns and statics inside Function | Static | Const bodies via nested_exports::walk_in_body (sharing parse_rust_c_export_attrs with the module-level scan).
    • Added an on-the-fly find_local_weak_override fallback in compile_worklist_to_wasm64 (via Maker::local_weak_export_text -> LazyProgram::local_weak_export_text) so written-block and post-macro block-local weak items also redirect to the prevailing strong export.
  2. Apply weak-static aliases when resolving Wasm64BuildOpts::export_globals (run/wasm64.rs):
    • Section 7 now looks up each requested global symbol through foreign_static_alias before querying static_datums, so exporting a superseded weak static resolves cleanly to the prevailing strong static's address.
  3. Regression test: Added wasm64_rust_e2e::block_local_weak_fn_and_exported_weak_static_resolve_to_strong_on_wasm64 covering both unwritten and written block-local weak fns called lexically plus exporting a superseded weak static via export_globals.

Verification:

  • Tests: linkage_tests (5/5), nested_exports::tests (3/3), ring_in_body_tests (7/7), local_statics (warm_cached_walk 1/1, cold_typed_record_foreign_statics 1/1), wasm64_rust_e2e (7/7), front_equal_rules (37/37), front2_f128_routines (2/2) — 63/63 passed.
  • Gates (blaze-ladder vs latest origin/main): 0 net new sites across all 9 gates (stops 1199, casts 1258, clones -1, allocs 558/227, ambient 286/0/1373, dups, homes 35/35 ok, domains, rustcsites 4, none new). Clean git merge-tree --write-tree origin/main HEAD.

Codex (@codex) review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 72bbc84702

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

Comment thread crates/blaze-ladder/src/run/wasm64.rs Outdated
cfg_version,
alloc,
};
if let Ok(walked) = crate::front2::nested_exports::walk_in_body(top, top_body, reading) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Do not discard nested-export scan failures

When an item body contains a valid form that walk_in_body currently refuses—such as an unwritten body-local extern block containing a macro declaration or foreign type—this if let Ok silently discards the entire walk, including unrelated block-local #[no_mangle] exports already found in that body. An extern "C" call to one of those exports then misses rust_exports and fails as an unresolved import; propagate the refusal or make the export-only walk skip irrelevant extern declarations instead. Fresh evidence in this revision is the new fallible walk_in_body call whose error path is ignored.

AGENTS.md reference: AGENTS.md:L121-L123

Useful? React with 👍 / 👎.

Comment on lines +1217 to +1218
&& let Some(winner_item) = find_weak_override(weak_fn_overrides.as_slice(), tabled)
.or_else(|| find_local_weak_override(maker, tabled, false, rust_exports.as_slice(), alloc))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Initialize local metadata before resolving a weak root

When a fresh Maker receives a written-block or post-macro block-local weak function/static as its first explicit root (or first walk row), the pre-scan intentionally lacks that synthesized local key and find_local_weak_override also returns None because Maker::local_weak_export_text only consults self.made, which is initialized by the later build. The branch therefore compiles the weak body or datum instead of aliasing it to the strong definition; resolve or locate the local before this lookup rather than depending on an earlier work item having initialized the maker. Fresh evidence is that the new fallback is invoked before the first build_lir_with_reach_in/make_static call.

AGENTS.md reference: AGENTS.md:L116-L120

Useful? React with 👍 / 👎.

if !is_raw && inner.contains('"') {
return Err(malformed());
}
Linkage::ALL.into_iter().find(|l| l.written() == inner).ok_or_else(|| LinkageRefused::Unknown { written: inner.into() })

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Decode linkage string literals before matching

When #[linkage] uses a valid escaped string such as #[linkage = "\x77eak"], Rust parses the literal value as weak, but this code compares the unescaped source text directly against the linkage names and returns Unknown. This rejects programs accepted by the pinned compiler—and on wasm64 prevents the intended weak-definition resolution—so parse the string literal with the normal literal decoder before matching it.

AGENTS.md reference: AGENTS.md:L116-L120

Useful? React with 👍 / 👎.

Comment on lines +1236 to +1238
if kind == RowKind::Static
&& let Some(winner_item) = find_weak_override(weak_static_overrides.as_slice(), tabled)
.or_else(|| find_local_weak_override(maker, tabled, true, rust_exports.as_slice(), alloc))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Apply weak overrides to thread-local statics

When a wasm64 target enables atomics, static_attrs_of preserves #[thread_local] statics as TLS, and the worklist consequently reaches a weak exported definition as RowKind::ThreadLocal. Although collection records it in weak_static_overrides, this branch only handles RowKind::Static and then hardcodes static_symbol plus a Static winner, so a direct Rust access emits the weak TLS datum while the same-symbol strong TLS definition may never be rooted. Resolve this case with tls_symbol/RowKind::ThreadLocal, or refuse weak thread-local definitions until that binding is supported.

AGENTS.md reference: AGENTS.md:L116-L120

Useful? React with 👍 / 👎.

1. Add export-only `nested_exports::walk_in_body_exports` skipping unrelated
   unreadable `extern` blocks (e.g. foreign types or unwritten-block macros)
   and unreadable sibling items, and propagate scan errors in
   `collect_rust_c_exports` instead of swallowing failures with `if let Ok`.
2. Lazily initialize the maker's `LazyProgram` and locate enclosing bodies via
   `Maker::local_weak_export_text` / `LazyProgram::local_weak_export_text`
   (reading `store.locals.head`) so a written-block or post-macro block-local
   weak root resolves its override even as the very first root on a fresh Maker.
3. Decode string-literal escapes in `front2::program::parse_linkage` through
   `blaze_expand::attr_literal` (the single attribute-literal reader) so valid
   escaped literals like `#[linkage = "\x77eak"]` match as in Rust.
4. Honestly refuse `#[thread_local]` + `#[linkage = "weak"]` in
   `statics::static_attrs_of` (and never alias `#[thread_local]` statics as
   weak overrides in `run/wasm64.rs`), even on `wasm64`.
@mteacher360

Copy link
Copy Markdown
Collaborator Author

Addressed all 4 Codex R3 findings in f801d705b:

  1. Preserve block-local exports beside unrelated unreadable extern blocks and propagate scan errors (nested_exports.rs, run/wasm64.rs):
    • Added export-only nested_exports::walk_in_body_exports (export_scan: true) that counts valid extern declarations for accurate ordinals while skipping unreadable extern blocks (e.g. foreign types or unwritten-block macros) and unreadable sibling items instead of aborting the whole body.
    • collect_rust_c_exports now propagates walk_in_body_exports errors via ? rather than swallowing failures with if let Ok(...).
    • Added unit test nested_exports::tests::walk_in_body_exports_preserves_exports_beside_unreadable_extern_block.
  2. Lazily initialize local metadata before resolving a weak root (front2/program/lazy/mod.rs, run/make_one.rs, run/wasm64.rs):
    • Maker::local_weak_export_text now initializes LazyProgram via self.construct(key) when self.made is None, and LazyProgram::local_weak_export_text calls self.locate(key) and reads self.store.locals.head(key) so even the very first explicit written-block or post-macro weak root on a brand-new Maker resolves its strong override.
    • Added e2e test wasm64_rust_e2e::written_block_weak_fn_as_first_root_resolves_to_strong_on_wasm64.
  3. Decode string-literal escapes in parse_linkage (front2/program.rs, linkage_tests.rs):
    • Delegated raw and escaped string literals in parse_linkage to blaze_expand::attr_literal (the single attribute-literal reader) with a zero-allocation fast path for plain unescaped literals.
    • Added unit tests for "\x77eak", "\u{77}eak", "\x65xtern_weak", and "\u{65}xternal" in linkage_tests::carried_values_are_honoured.
  4. Honestly refuse #[thread_local] + #[linkage = "weak"] (front2/statics.rs, run/wasm64.rs):
    • statics::static_attrs_of now refuses #[thread_local] statics carrying #[linkage = "weak"] even on wasm64, and parse_rust_c_export_attrs never aliases a #[thread_local] static as a weak override so single-threaded and atomics wasm64 both refuse it consistently.
    • Added e2e test wasm64_rust_e2e::thread_local_weak_static_is_refused_on_wasm64 covering both single-threaded wasm64 and wasm64+atomics.

Verification:

  • Tests: linkage_tests (5/5), nested_exports::tests (4/4), ring_in_body_tests (7/7), local_statics (2/2), wasm64_rust_e2e (9/9), front_equal_rules (37/37), front2_f128_routines (2/2) — 66/66 passed.
  • Gates (blaze-ladder vs latest origin/main): 0 net new sites across all 9 gates (stops 1197 [-2], casts 1258, clones 60 [-1], allocs 558/227, ambient 286/0/1373 [-2 vec_box], dups, homes 35/35 ok, domains, rustcsites 4, none new). Clean git merge-tree --write-tree origin/main HEAD.

Codex (@codex) review

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: f801d705bb

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "Codex (@codex) address that feedback".

@mteacher360
mteacher360 merged commit 63ac2ec into main Nov 29, 2026
3 of 5 checks passed
@mteacher360
mteacher360 deleted the fix/front2-linkage-and-inbody-extern-static branch November 29, 2026 05:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant