`PAGESIZE` macro set to garbage value in shared libraries

Open
#778 1 comment 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
c, cpp, wasm

Research direction

Start in __macro__PAGESIZE.h and inspect the preprocessor guard used for LLVM v22 and later, then trace how wasm-ld defines __wasm_first_page_end for shared libraries. Compare that path with the imported __heap_end and related symbols mentioned in the issue. Done means shared-library builds use a valid PAGESIZE and dlmalloc no longer reaches the alignment-related sbrk abort.

Written by the indexing model from the issue text.

Description

While experimenting with C++ exception handling support for shared libraries, I discovered that the support for custom page sizes in __macro__PAGESIZE.h (which is only enabled for LLVM v22 and later) is broken for shared libraries, leading to an alignment-related abort() in sbrk when dlmalloc asks for more memory.

I was able to work around this by adding a && !defined __pic__ clause to the preprocessor guard, causing PAGESIZE to be hard-coded to the traditional 0x10000 value when compiling with -fPIC. I'm not sure what the proper way to handle custom page sizes in shared libraries is, but perhaps rather than rely on wasm-ld to define __wasm_first_page_end, it could be imported from env similar to e.g. __heap_end and friends.

Dominant language
C
Stars
1k
Forks
268
Avg merge
1d 3h
Merged PRs (30d)
20

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from WebAssembly/wasi-libc

All issues in WebAssembly/wasi-libc

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.