-
Notifications
You must be signed in to change notification settings - Fork 150
wasm: when function names are present, include them #131
Conversation
@justinclift - I don't have any issues with that |
172bf40
to
7b50413
Compare
Codecov Report
@@ Coverage Diff @@
## master #131 +/- ##
=========================================
+ Coverage 68.48% 69.09% +0.6%
=========================================
Files 42 42
Lines 4848 4866 +18
=========================================
+ Hits 3320 3362 +42
+ Misses 1254 1220 -34
- Partials 274 284 +10
Continue to review full report at Codecov.
|
@mastersingh24 Excellent. Thanks. 😄 |
As an aside, the
|
Looking into adding some new test data now, incorporating a custom section with function names. |
Adding some TinyGo (via LLVM) generated test data with function names in custom sections probably isn't going to be workable at the moment. 😦 Testing various TinyGo generated .wasm files locally here. The way encoding the They're padded with four Lines 54 to 56 in c2df253
|
It looks like this padding is common to all .wasm generated via LLVM at the moment. At least with LLVM ~8.0.1-rc2. Saying that after trying with C compiled to wasm too (using Using |
7b50413
to
1029cf9
Compare
Submitted upstream: go-interpreter/wagon#131
Just created a PR adding myself to the CONTRIBUTORS and AUTHORS files, as per the contributor guidelines: go-interpreter/license#16 |
1029cf9
to
a4d3891
Compare
26a9f34
to
46b51bf
Compare
Just recreated this, based on the exist Wagon unmarshalling code for name sections. Sorry @mastersingh24... your code wasn't needed after all. 😉 |
46b51bf
to
703dbf3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the overall code looks fine.
could you add a test for this, though?
Not 100% sure how at the moment. No LLVM generated wasm will pass the current Wagon test suite due to the Call function padding problem (above). 😦 If I can somehow get something generated which incorporates custom functions, then I can write a test. |
Oh. I'll investigate using Wagon to generate .wasm files directly. That might work (haven't looked). 😄 |
Killed the branch when cleaning up my fork, and it turns out GitHub uses that as a signal to automatically close the PR. Oops. 😉 |
to follow-up on this, one possible avenue (instead of relying on the LLVM machinery), one could perhaps generate a
and make sure we correctly parse that WDYT? |
Ahhh, sorry, got busy with other stuff. I'll get back to this in the next few days. 🙄 |
703dbf3
to
3dc46eb
Compare
3dc46eb
to
1438190
Compare
Well, this is interesting. That failure is looking suspiciously like a problem with Wagon's Saying that because I took a fairly cheating approach to generate the wasm test data... 😉 Wrote a small util to read in an LLVM generated .wasm file, re-encode it with Wagon, and write that out. It looks like the encoded byte stream created by Wagon will have the exports in any order. Running it multiple times, even on its own re-encoded output, can ~randomly change around the ordering:
Note That's probably going to break / disallow any non-trivial example data with the current approach for testing. Bug? |
We're probably iterating over a map somewhere and not ensuring some order... |
Yeah, it's a pretty classic case of that. I'll try and take a look in the next few days, to see if changing to a slice or something with stable ordering is simple. |
This was the culprit for the unstable order: Line 618 in 2691113
It compares by numerical index, not taking into account it's common to have several things with the same index number. It'd probably be better to check for that condition first, and use a straight string compare of the export name for those. Everything else can still be sorted by index number correctly. |
9256c21
to
47abda2
Compare
This should be ok to merge now. Updated that small util to re-write each of the code body sections using Nicely, because Wagon's byte code assembler is a bit more efficient than the current LLVM one, a side effect is slightly reduced file size. That util could probably be used as a general purpose way to shave off a few more bytes from the file size when a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
(apologies for the belated feedback: holidays)
Roger that. |
LLVM generates (optional) function names, including them in a custom section on the end of the .wasm file.
It's useful to have them handy when working with decoded wasm data, so adding them directly to the Function struct seems like a good spot.
This PR originally included code by @mastersingh24, from the Life project. The below comment was regarding allowing that piece of code to be incorporated here with BSD licencing.
However, it turns out to be unneeded, as Wagon already has the ability to decode Custom Name sections, so it was simpler to reuse that.