This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] MC layer writes table symbols to object files
AbandonedPublic

Authored by wingo on Nov 27 2020, 1:11 AM.

Details

Summary

Now that the linker handles table symbols, we can allow the frontend to
produce them.

Depends on D91870.

Diff Detail

Event Timeline

wingo created this revision.Nov 27 2020, 1:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 27 2020, 1:11 AM
wingo requested review of this revision.Nov 27 2020, 1:11 AM

Ready for review when you have a moment. Thanks! @sbc100

sbc100 accepted this revision.Jan 15 2021, 1:56 AM
sbc100 added inline comments.
llvm/lib/MC/WasmObjectWriter.cpp
523

I thought the plan was to include this table symbol in a new TABLE_NUMBER reloc to go along with the TABLE_INDEX reloc? Then each call_indirect could have up to two different relocations.

This revision is now accepted and ready to land.Jan 15 2021, 1:56 AM
wingo added inline comments.Jan 15 2021, 4:16 AM
llvm/lib/MC/WasmObjectWriter.cpp
523

The problem isn't the call_indirect, which has a TABLE_NUMBER reloc, and doesn't reach this case. This code is for function pointers, which don't record which table they are against. It ensures that there is an __indirect_function_table if there are function pointers, even if there is never any call_indirect. Does that make sense?

still lgtm

llvm/lib/MC/WasmObjectWriter.cpp
523

Hmm... yes I think makes sense. How about something like this: "any time we have a TABLE_INDEX relocation against a function symbol we need to ensure that table itself is part of the final output too". Perhaps other types of symbols or other types of relocation could apply to other tables, but for now at least TABLE_INDEX against a function symbol always means an index into __indirect_function_table... maybe I'm just re-stating what you already wrote :)

wingo updated this revision to Diff 316912.Jan 15 2021, 5:27 AM

Reword comment

llvm/lib/MC/WasmObjectWriter.cpp
523

Thanks for the reword; applied to the comment. Cheers :)

This revision was landed with ongoing or failed builds.Jan 15 2021, 5:56 AM
This revision was automatically updated to reflect the committed changes.
wingo added a comment.Jan 18 2021, 8:00 AM

Relanded after fixup in precursor; hopefully emscripten builds go green this time!

dmajor added a subscriber: dmajor.Jan 18 2021, 12:07 PM

Hi, after this commit our builds of wasi-sdk have broken because wasi-libc's makefile [1] finds an undefined symbol for __indirect_function_table that wasn't in its expected list [2].

Just to check, is this intended? Does the undefined-symbols.txt need an update?

[1] https://github.com/WebAssembly/wasi-libc/blob/master/Makefile#L506
[2] https://github.com/WebAssembly/wasi-libc/blob/master/expected/wasm32-wasi/undefined-symbols.txt

Hi, after this commit our builds of wasi-sdk have broken because wasi-libc's makefile [1] finds an undefined symbol for __indirect_function_table that wasn't in its expected list [2].

Just to check, is this intended? Does the undefined-symbols.txt need an update?

[1] https://github.com/WebAssembly/wasi-libc/blob/master/Makefile#L506
[2] https://github.com/WebAssembly/wasi-libc/blob/master/expected/wasm32-wasi/undefined-symbols.txt

My understanding is that __indirect_function_table should not be imported (at least not under normal circumstances) but should be created by the linker at link time. Do you happen to have the failing link command or a link to the build log?

Ah yes, that list is a list of undefined symbols in the library/object files. In that case the new symbol *is* expected to exist and wasi-sdk will need to be modified to ignore or handle this new symbol somehow. Probably just ignoring it for now makes sense (so that the Makefile continues to work with new and old versions of llvm).

Hi, after this commit our builds of wasi-sdk have broken because wasi-libc's makefile [1] finds an undefined symbol for __indirect_function_table that wasn't in its expected list [2].

Just to check, is this intended? Does the undefined-symbols.txt need an update?

[1] https://github.com/WebAssembly/wasi-libc/blob/master/Makefile#L506
[2] https://github.com/WebAssembly/wasi-libc/blob/master/expected/wasm32-wasi/undefined-symbols.txt

Yeah as @sbc100 says, this is intended -- object files now can have table symbols, and if the compilation unit takes the address of a function or makes an indirect call, it will have a __indirect_function_table symbol. So the expectations need updating; sorry for the bother!

Note that this could happen again in the future if/when multiple memory support is added, for memory symbols.

Yeah as @sbc100 says, this is intended -- object files now can have table symbols, and if the compilation unit takes the address of a function or makes an indirect call, it will have a __indirect_function_table symbol. So the expectations need updating; sorry for the bother!

Looks like this grep -v would be a good place: https://github.com/WebAssembly/wasi-libc/blob/378fd4b21aab6d390f3a1c1817d53c422ad00a62/Makefile#L452

I've locally changed that to "^__mul\|^__indirect_function_table" and it's been working fine for the past few days.

@sbc100, I see that you're a project contributor, would you mind landing that to /wasi-libc and /wasi-sdk? I'm also happy to send a pair of PRs but I don't have my account handy this week.

Yeah as @sbc100 says, this is intended -- object files now can have table symbols, and if the compilation unit takes the address of a function or makes an indirect call, it will have a __indirect_function_table symbol. So the expectations need updating; sorry for the bother!

Looks like this grep -v would be a good place: https://github.com/WebAssembly/wasi-libc/blob/378fd4b21aab6d390f3a1c1817d53c422ad00a62/Makefile#L452

I've locally changed that to "^__mul\|^__indirect_function_table" and it's been working fine for the past few days.

@sbc100, I see that you're a project contributor, would you mind landing that to /wasi-libc and /wasi-sdk? I'm also happy to send a pair of PRs but I don't have my account handy this week.

Yes, just send a PR when are you get a chance. I don't think its super urgent since most wasi-libc users I think use using stable llvm releases.

Yeah as @sbc100 says, this is intended -- object files now can have table symbols, and if the compilation unit takes the address of a function or makes an indirect call, it will have a __indirect_function_table symbol. So the expectations need updating; sorry for the bother!

Looks like this grep -v would be a good place: https://github.com/WebAssembly/wasi-libc/blob/378fd4b21aab6d390f3a1c1817d53c422ad00a62/Makefile#L452

I've locally changed that to "^__mul\|^__indirect_function_table" and it's been working fine for the past few days.

@sbc100, I see that you're a project contributor, would you mind landing that to /wasi-libc and /wasi-sdk? I'm also happy to send a pair of PRs but I don't have my account handy this week.

Yes, just send a PR when are you get a chance. I don't think its super urgent since most wasi-libc users I think use using stable llvm releases.

Out of interest how did you notice this breakage? Are you integrating ToT llvm with wasi-libc for a specific reason?

Out of interest how did you notice this breakage? Are you integrating ToT llvm with wasi-libc for a specific reason?

In an unofficial repo we do frequent builds of Firefox with a ToT clang, motivated by some past releases where we waited until RC1 to start testing and had a bad time.

We don't specifically set out to test the wasi bits, but some Firefox builds enable wasm sandboxing, which pulls in that code. I must admit I don't fully understand the interaction between the build systems, we have lost some expertise in that area and I'm mostly just keeping things limping along.

This revision is now accepted and ready to land.Jan 26 2021, 1:49 AM
wingo abandoned this revision.Feb 12 2021, 2:50 AM

Abandoning, to merge into D90948.