This is an archive of the discontinued LLVM Phabricator instance.

Splits __wasm_apply_relocs into multiple functions
Needs ReviewPublic

Authored by danchurch on Mar 5 2020, 10:56 AM.

Details

Reviewers
loladiro
sbc100
Group Reviewers
lld
Summary

Rather than having one potentially large wasm_apply_relocs function, wasm_apply_relocs is split into 10 smaller functions, all executed in order.

Safari on iOS struggles with excessively large functions, and for a larger .wasm module (~7mb observed), _wasm_apply_relocs balloons to >500kb, causing Safari iOS to fail with a "max stack size exceeded" error. By splitting __wasm_apply_relocs into multiple smaller methods, relocation functionality is preserved while being able to load/run on iOS.

I understand that this code may not be perfect, setting the initial function count to 10 is a hack, etc. I'm submitting this patch to spark discussion, expecting that the overall approach may need to be modified (or at-least made tune-able with linker flags).

Diff Detail

Event Timeline

danchurch created this revision.Mar 5 2020, 10:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 5 2020, 10:56 AM
tlively added a subscriber: tlively.Mar 9 2020, 9:19 AM

Copying what I said from Discord --

If I were a reviewer on this, I'd say that's too much a hack, and that it would be a much better idea to implement the "TODO(sbc): Encode the relocations in the data section and write a loop here to apply them."

That would allow this function to be both constant and tiny.

I tend to agree that maybe there is a better solution to be found here.

Can I ask what you use case for linking with -fpic is? Presumably you are building with emscripten's SIDE_MODULE/MAIN_MODULE. Would you mind opening an llvm bug for this were we can discuss this further?