Skip to content

Compilation fails when --stack-first and -Oz are used together. #21215

Closed
@netogallo

Description

@netogallo

Reproduction steps:

  1. Use any c program. Take for example the following main.c
int main(int argc, char** argv) { return 0; }
  1. Compile with /home/ernesto/code/emsdk/upstream/emscripten/emcc -Oz -Wl,--stack-first main.c
  2. Compilation will fail with: "wasm-ld: error: --global-base cannot be less than stack size when --stack-first is used"
  3. Now compile with /home/ernesto/code/emsdk/upstream/emscripten/emcc -Wl,--stack-first main.c compilation succeeds.

Workarounds:

  1. Avoid "-Oz" when compiling with "--stack-first"
  2. Edit "settings.js" and set "var GLOBAL_BASE = 1024;" to the same value as "var STACK_SIZE = 64*1024;"

Potential resolutions:

  1. The "emcc.py" and "em++.py" programs can check if the "-Oz" flag is used together with "--stack-first". If so (Option 1) set the value of GLOBAL_BASE to the same value as STACK_SIZE. (Option 2) Exit with an error informing the user they are using an incompatible combination of flags.

Happy to issue a pull request with the fix above if any of those solutions would be satisfactory.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions