Skip to content

wasi-libc: __stack_chk_fail.c is linked even when stack protector is disabled #15005

Closed as not planned

Description

@jedisct1

Zig Version

0.11.0-dev.2157+f56f3c582

Steps to Reproduce and Observed Behavior

Compiling C code to wasm32-wasi causes __stack_chk_fail.c to be unconditionally linked, even with -fno-stack-protector.

It's not necessary, but is generally harmless.

But the file includes a constructor:

__attribute__((constructor(60)))
static void __wasilibc_init_ssp(void) {
    uintptr_t entropy;
    int r = __wasi_random_get((uint8_t *)&entropy, sizeof(uintptr_t));
    __init_ssp(r ? NULL : &entropy);
}

That constructor depends on wasi_snapshot_preview1::random_get being imported. And that becomes an issue in the context of the preview1->preview2 transition state.

wasm-tools refuses to transform a module created by Zig into a component due to this.

Expected Behavior

Don't link __stack_chk_fail.c if the stack protector is disabled.

Activity

  1. added
    enhancement
    contributor friendly
    os-wasi
    on Mar 19, 2023
  2. added this to the 0.12.0 milestone on Apr 10, 2023
  3. removed this from the urgent milestone on Oct 4, 2026
  4. added a commit that references this issue on Oct 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    contributor friendlyenhancementos-wasi

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions