Is it possible to use `wasm-ld` to link `dlmalloc` against my WebAssembly binary?

Hello!

I am creating the compiler for a pure, functional programming language. This compiler will output .wasm files.

There is some data that can live in the stack, but most of it will need to live in the heap, and managing the heap manually is a recipe for disaster. So the obvious option here is to add a memory allocator, like dlmalloc.

I saw that wasi-libc (and wasi-sdk, by extension) offers the entire libc, but at the moment, the only thing that I need is an allocator. Bringing everything would be overkill. And wasi isn’t really widely supported by browsers yet, too.

Ideally, the .wasm files that results from the compilation process of my language will be blissfully unaware of the heap. They will only need to mention __heap_base, dlmalloc, dlcalloc, dlrealloc and dlfree, because I am assuming that wasm-ld should be able to link dlmalloc to my .wasm file.

What are the steps for me to achieve this?