{"action":"created","comment":{"url":"https://api.github.com/repos/WebAssembly/tool-conventions/pulls/comments/88817476","pull_request_review_id":9378521,"id":88817476,"diff_hunk":"@@ -0,0 +1,27 @@\n+WebAssembly Dynamic Linking\n+===========================\n+\n+This document describes the early plans for how dynamic linking of WebAssembly modules might work.\n+\n+# Shared Libraries\n+\n+A WebAssembly shared library has some conventions for how it should be loaded and used:\n+\n+ * The module can import `env.memory` for memory that is shared with the outside. If it does so, it should import `env.memoryBase`, an `i32`, in which the loader will provide the start of the region in memory which has been reserved for this module.\n+ * The module can import `env.table` for a table that is shared with the outside. If it does so, it should import `env.tableBase`, an `i32`, in which the loader will provide the start of the region in the table which has been reserved for this module.\n+ * The module can export a function called `__start_module`. If it is so exported, the loader will call it after creating the module and before it is used. (Note: we cannot use the WebAssembly `start` method due to reentrancy issues.)\n+ * While exported functions are straightforward, exported globals - i.e., exported addresses of locations in memory - are done *before* relocation. This is necessary since the module cannot add `memoryBase` before it exports them. The loader, which knows `memoryBase`, adds it to those exports before they are used.\n+\n+The loader must know how much space in the memory and table to reserve for the module, and must know that *before* the module is created. To that end, a WebAssembly shared library is a small wrapper around a WebAssembly module, with suffix `.wso` (WebAssembly Shared Object), and contents\n+\n+ * 4 bytes: `\\0wso`\n+ * 8 bytes: Size of memory (unsigned little-endian integer) (note: can be larger than the memory segments in the module)\n+ * 8 bytes: Size of table (unsigned little-endian integer)","path":"DynamicLinking.md","position":19,"original_position":19,"commit_id":"9bf104763e4355ddda12218cbc4cec77d5c2892f","original_commit_id":"b0796e99e4f8143e470b0c3a9b95405db601b206","user":{"login":"kripken","id":173661,"avatar_url":"https://avatars.githubusercontent.com/u/173661?v=3","gravatar_id":"","url":"https://api.github.com/users/kripken","html_url":"https://github.com/kripken","followers_url":"https://api.github.com/users/kripken/followers","following_url":"https://api.github.com/users/kripken/following{/other_user}","gists_url":"https://api.github.com/users/kripken/gists{/gist_id}","starred_url":"https://api.github.com/users/kripken/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kripken/subscriptions","organizations_url":"https://api.github.com/users/kripken/orgs","repos_url":"https://api.github.com/users/kripken/repos","events_url":"https://api.github.com/users/kripken/events{/privacy}","received_events_url":"https://api.github.com/users/kripken/received_events","type":"User","site_admin":false},"body":"Well, the main wasm spec is used by the VMs themselves, while this section is in \"userspace\" in the sense that it would be used by a loader, in JS initially and maybe wasm eventually, but not as part of the VM. These are different levels, and maybe have different considerations.","created_at":"2016-11-21T00:51:33Z","updated_at":"2016-11-21T00:51:33Z","html_url":"https://github.com/WebAssembly/tool-conventions/pull/4#discussion_r88817476","pull_request_url":"https://api.github.com/repos/WebAssembly/tool-conventions/pulls/4","_links":{"self":{"href":"https://api.github.com/repos/WebAssembly/tool-conventions/pulls/comments/88817476"},"html":{"href":"https://github.com/WebAssembly/tool-conventions/pull/4#discussion_r88817476"},"pull_request":{"href":"https://api.github.com/repos/WebAssembly/tool-conventions/pulls/4"}}},"pull_request":{"url":"https://api.github.com/repos/WebAssembly/tool-conventions/pulls/4","id":94470511,"html_url":"https://github.com/WebAssembly/tool-conventions/pull/4","diff_url":"https://github.com/WebAssembly/tool-conventions/pull/4.diff","patch_url":"https://github.com/WebAssembly/tool-conventions/pull/4.patch","issue_url":"https://api.github.com/repos/WebAssembly/tool-conventions/issues/4","number":4,"state":"open","locked":false,"title":"Dynamic linking and shared libraries","user":{"login":"kripken","id":173661,"avatar_url":"https://avatars.githubusercontent.com/u/173661?v=3","gravatar_id":"","url":"https://api.github.com/users/kripken","html_url":"https://github.com/kripken","followers_url":"https://api.github.com/users/kripken/followers","following_url":"https://api.github.com/users/kripken/following{/other_user}","gists_url":"https://api.github.com/users/kripken/gists{/gist_id}","starred_url":"https://api.github.com/users/kripken/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kripken/subscriptions","organizations_url":"https://api.github.com/users/kripken/orgs","repos_url":"https://api.github.com/users/kripken/repos","events_url":"https://api.github.com/users/kripken/events{/privacy}","received_events_url":"https://api.github.com/users/kripken/received_events","type":"User","site_admin":false},"body":"This adds a proposal for shared libraries. There is a lot more to say about this, here there is just the very basics, the ability to create, load, and use a wasm file. That is sufficient for `dlopen` style loading of shared libraries etc.\r\n\r\nI've implemented this in emscripten (`binaryen-linking` branches, if you want to take a look), and at this point most tests pass so the approach seems viable.\r\n\r\nDetails are in PR code. One issue perhaps worth more detail is that the proposal describes a `.wso` file, which is a small wrapper around a wasm module that describes the memory and table size. Alternatively, this could have been a user section inside the wasm. No strong feelings either way. Some reasons why it makes sense to have a different suffix/format:\r\n\r\n * Follows convention in native platforms (`exe` vs `dll`; no suffix vs `.so`; etc.). Which in turn makes sense as it avoids confusion (less likely to try to load a wasm as a shared library that actually isn't one), the `file` commandline tool works on it, etc.\r\n * Wrapping around the wasm in a trivial way as described in the document makes it easy for loaders and other tools to create and access `.wso`s. Such tools might not be in JS, so they can't use any JS APIs we create for user sections. In particular, this way was easier for the implementation I wrote.\r\n\r\nAlternatively, some reasons why a user section might be nice:\r\n\r\n * Avoids a new file format.\r\n * Wasm-inspecting tools can (somewhat) use these files without being taught anything (not sure how high a priority this is for others - I've argued for it myself).","created_at":"2016-11-19T04:34:21Z","updated_at":"2016-11-21T00:51:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"45da4db815d590555e387d734d3204cbdaa84c23","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/WebAssembly/tool-conventions/pulls/4/commits","review_comments_url":"https://api.github.com/repos/WebAssembly/tool-conventions/pulls/4/comments","review_comment_url":"https://api.github.com/repos/WebAssembly/tool-conventions/pulls/comments{/number}","comments_url":"https://api.github.com/repos/WebAssembly/tool-conventions/issues/4/comments","statuses_url":"https://api.github.com/repos/WebAssembly/tool-conventions/statuses/9bf104763e4355ddda12218cbc4cec77d5c2892f","head":{"label":"WebAssembly:dynamic-linking","ref":"dynamic-linking","sha":"9bf104763e4355ddda12218cbc4cec77d5c2892f","user":{"login":"WebAssembly","id":11578470,"avatar_url":"https://avatars.githubusercontent.com/u/11578470?v=3","gravatar_id":"","url":"https://api.github.com/users/WebAssembly","html_url":"https://github.com/WebAssembly","followers_url":"https://api.github.com/users/WebAssembly/followers","following_url":"https://api.github.com/users/WebAssembly/following{/other_user}","gists_url":"https://api.github.com/users/WebAssembly/gists{/gist_id}","starred_url":"https://api.github.com/users/WebAssembly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WebAssembly/subscriptions","organizations_url":"https://api.github.com/users/WebAssembly/orgs","repos_url":"https://api.github.com/users/WebAssembly/repos","events_url":"https://api.github.com/users/WebAssembly/events{/privacy}","received_events_url":"https://api.github.com/users/WebAssembly/received_events","type":"Organization","site_admin":false},"repo":{"id":59792075,"name":"tool-conventions","full_name":"WebAssembly/tool-conventions","owner":{"login":"WebAssembly","id":11578470,"avatar_url":"https://avatars.githubusercontent.com/u/11578470?v=3","gravatar_id":"","url":"https://api.github.com/users/WebAssembly","html_url":"https://github.com/WebAssembly","followers_url":"https://api.github.com/users/WebAssembly/followers","following_url":"https://api.github.com/users/WebAssembly/following{/other_user}","gists_url":"https://api.github.com/users/WebAssembly/gists{/gist_id}","starred_url":"https://api.github.com/users/WebAssembly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WebAssembly/subscriptions","organizations_url":"https://api.github.com/users/WebAssembly/orgs","repos_url":"https://api.github.com/users/WebAssembly/repos","events_url":"https://api.github.com/users/WebAssembly/events{/privacy}","received_events_url":"https://api.github.com/users/WebAssembly/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/WebAssembly/tool-conventions","description":"Conventions supporting interoperatibility between tools working with WebAssembly.","fork":false,"url":"https://api.github.com/repos/WebAssembly/tool-conventions","forks_url":"https://api.github.com/repos/WebAssembly/tool-conventions/forks","keys_url":"https://api.github.com/repos/WebAssembly/tool-conventions/keys{/key_id}","collaborators_url":"https://api.github.com/repos/WebAssembly/tool-conventions/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/WebAssembly/tool-conventions/teams","hooks_url":"https://api.github.com/repos/WebAssembly/tool-conventions/hooks","issue_events_url":"https://api.github.com/repos/WebAssembly/tool-conventions/issues/events{/number}","events_url":"https://api.github.com/repos/WebAssembly/tool-conventions/events","assignees_url":"https://api.github.com/repos/WebAssembly/tool-conventions/assignees{/user}","branches_url":"https://api.github.com/repos/WebAssembly/tool-conventions/branches{/branch}","tags_url":"https://api.github.com/repos/WebAssembly/tool-conventions/tags","blobs_url":"https://api.github.com/repos/WebAssembly/tool-conventions/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/WebAssembly/tool-conventions/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/WebAssembly/tool-conventions/git/refs{/sha}","trees_url":"https://api.github.com/repos/WebAssembly/tool-conventions/git/trees{/sha}","statuses_url":"https://api.github.com/repos/WebAssembly/tool-conventions/statuses/{sha}","languages_url":"https://api.github.com/repos/WebAssembly/tool-conventions/languages","stargazers_url":"https://api.github.com/repos/WebAssembly/tool-conventions/stargazers","contributors_url":"https://api.github.com/repos/WebAssembly/tool-conventions/contributors","subscribers_url":"https://api.github.com/repos/WebAssembly/tool-conventions/subscribers","subscription_url":"https://api.github.com/repos/WebAssembly/tool-conventions/subscription","commits_url":"https://api.github.com/repos/WebAssembly/tool-conventions/commits{/sha}","git_commits_url":"https://api.github.com/repos/WebAssembly/tool-conventions/git/commits{/sha}","comments_url":"https://api.github.com/repos/WebAssembly/tool-conventions/comments{/number}","issue_comment_url":"https://api.github.com/repos/WebAssembly/tool-conventions/issues/comments{/number}","contents_url":"https://api.github.com/repos/WebAssembly/tool-conventions/contents/{+path}","compare_url":"https://api.github.com/repos/WebAssembly/tool-conventions/compare/{base}...{head}","merges_url":"https://api.github.com/repos/WebAssembly/tool-conventions/merges","archive_url":"https://api.github.com/repos/WebAssembly/tool-conventions/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/WebAssembly/tool-conventions/downloads","issues_url":"https://api.github.com/repos/WebAssembly/tool-conventions/issues{/number}","pulls_url":"https://api.github.com/repos/WebAssembly/tool-conventions/pulls{/number}","milestones_url":"https://api.github.com/repos/WebAssembly/tool-conventions/milestones{/number}","notifications_url":"https://api.github.com/repos/WebAssembly/tool-conventions/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/WebAssembly/tool-conventions/labels{/name}","releases_url":"https://api.github.com/repos/WebAssembly/tool-conventions/releases{/id}","deployments_url":"https://api.github.com/repos/WebAssembly/tool-conventions/deployments","created_at":"2016-05-27T00:35:36Z","updated_at":"2016-11-02T22:23:11Z","pushed_at":"2016-11-20T23:53:37Z","git_url":"git://github.com/WebAssembly/tool-conventions.git","ssh_url":"git@github.com:WebAssembly/tool-conventions.git","clone_url":"https://github.com/WebAssembly/tool-conventions.git","svn_url":"https://github.com/WebAssembly/tool-conventions","homepage":null,"size":11,"stargazers_count":1,"watchers_count":1,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":1,"default_branch":"master"}},"base":{"label":"WebAssembly:master","ref":"master","sha":"b7bdecc0cff5853dab2f02d5c502c47e1d03c750","user":{"login":"WebAssembly","id":11578470,"avatar_url":"https://avatars.githubusercontent.com/u/11578470?v=3","gravatar_id":"","url":"https://api.github.com/users/WebAssembly","html_url":"https://github.com/WebAssembly","followers_url":"https://api.github.com/users/WebAssembly/followers","following_url":"https://api.github.com/users/WebAssembly/following{/other_user}","gists_url":"https://api.github.com/users/WebAssembly/gists{/gist_id}","starred_url":"https://api.github.com/users/WebAssembly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WebAssembly/subscriptions","organizations_url":"https://api.github.com/users/WebAssembly/orgs","repos_url":"https://api.github.com/users/WebAssembly/repos","events_url":"https://api.github.com/users/WebAssembly/events{/privacy}","received_events_url":"https://api.github.com/users/WebAssembly/received_events","type":"Organization","site_admin":false},"repo":{"id":59792075,"name":"tool-conventions","full_name":"WebAssembly/tool-conventions","owner":{"login":"WebAssembly","id":11578470,"avatar_url":"https://avatars.githubusercontent.com/u/11578470?v=3","gravatar_id":"","url":"https://api.github.com/users/WebAssembly","html_url":"https://github.com/WebAssembly","followers_url":"https://api.github.com/users/WebAssembly/followers","following_url":"https://api.github.com/users/WebAssembly/following{/other_user}","gists_url":"https://api.github.com/users/WebAssembly/gists{/gist_id}","starred_url":"https://api.github.com/users/WebAssembly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WebAssembly/subscriptions","organizations_url":"https://api.github.com/users/WebAssembly/orgs","repos_url":"https://api.github.com/users/WebAssembly/repos","events_url":"https://api.github.com/users/WebAssembly/events{/privacy}","received_events_url":"https://api.github.com/users/WebAssembly/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/WebAssembly/tool-conventions","description":"Conventions supporting interoperatibility between tools working with WebAssembly.","fork":false,"url":"https://api.github.com/repos/WebAssembly/tool-conventions","forks_url":"https://api.github.com/repos/WebAssembly/tool-conventions/forks","keys_url":"https://api.github.com/repos/WebAssembly/tool-conventions/keys{/key_id}","collaborators_url":"https://api.github.com/repos/WebAssembly/tool-conventions/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/WebAssembly/tool-conventions/teams","hooks_url":"https://api.github.com/repos/WebAssembly/tool-conventions/hooks","issue_events_url":"https://api.github.com/repos/WebAssembly/tool-conventions/issues/events{/number}","events_url":"https://api.github.com/repos/WebAssembly/tool-conventions/events","assignees_url":"https://api.github.com/repos/WebAssembly/tool-conventions/assignees{/user}","branches_url":"https://api.github.com/repos/WebAssembly/tool-conventions/branches{/branch}","tags_url":"https://api.github.com/repos/WebAssembly/tool-conventions/tags","blobs_url":"https://api.github.com/repos/WebAssembly/tool-conventions/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/WebAssembly/tool-conventions/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/WebAssembly/tool-conventions/git/refs{/sha}","trees_url":"https://api.github.com/repos/WebAssembly/tool-conventions/git/trees{/sha}","statuses_url":"https://api.github.com/repos/WebAssembly/tool-conventions/statuses/{sha}","languages_url":"https://api.github.com/repos/WebAssembly/tool-conventions/languages","stargazers_url":"https://api.github.com/repos/WebAssembly/tool-conventions/stargazers","contributors_url":"https://api.github.com/repos/WebAssembly/tool-conventions/contributors","subscribers_url":"https://api.github.com/repos/WebAssembly/tool-conventions/subscribers","subscription_url":"https://api.github.com/repos/WebAssembly/tool-conventions/subscription","commits_url":"https://api.github.com/repos/WebAssembly/tool-conventions/commits{/sha}","git_commits_url":"https://api.github.com/repos/WebAssembly/tool-conventions/git/commits{/sha}","comments_url":"https://api.github.com/repos/WebAssembly/tool-conventions/comments{/number}","issue_comment_url":"https://api.github.com/repos/WebAssembly/tool-conventions/issues/comments{/number}","contents_url":"https://api.github.com/repos/WebAssembly/tool-conventions/contents/{+path}","compare_url":"https://api.github.com/repos/WebAssembly/tool-conventions/compare/{base}...{head}","merges_url":"https://api.github.com/repos/WebAssembly/tool-conventions/merges","archive_url":"https://api.github.com/repos/WebAssembly/tool-conventions/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/WebAssembly/tool-conventions/downloads","issues_url":"https://api.github.com/repos/WebAssembly/tool-conventions/issues{/number}","pulls_url":"https://api.github.com/repos/WebAssembly/tool-conventions/pulls{/number}","milestones_url":"https://api.github.com/repos/WebAssembly/tool-conventions/milestones{/number}","notifications_url":"https://api.github.com/repos/WebAssembly/tool-conventions/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/WebAssembly/tool-conventions/labels{/name}","releases_url":"https://api.github.com/repos/WebAssembly/tool-conventions/releases{/id}","deployments_url":"https://api.github.com/repos/WebAssembly/tool-conventions/deployments","created_at":"2016-05-27T00:35:36Z","updated_at":"2016-11-02T22:23:11Z","pushed_at":"2016-11-20T23:53:37Z","git_url":"git://github.com/WebAssembly/tool-conventions.git","ssh_url":"git@github.com:WebAssembly/tool-conventions.git","clone_url":"https://github.com/WebAssembly/tool-conventions.git","svn_url":"https://github.com/WebAssembly/tool-conventions","homepage":null,"size":11,"stargazers_count":1,"watchers_count":1,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/WebAssembly/tool-conventions/pulls/4"},"html":{"href":"https://github.com/WebAssembly/tool-conventions/pull/4"},"issue":{"href":"https://api.github.com/repos/WebAssembly/tool-conventions/issues/4"},"comments":{"href":"https://api.github.com/repos/WebAssembly/tool-conventions/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/WebAssembly/tool-conventions/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/WebAssembly/tool-conventions/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/WebAssembly/tool-conventions/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/WebAssembly/tool-conventions/statuses/9bf104763e4355ddda12218cbc4cec77d5c2892f"}}}}
{"actor":{"display_login":"kripken"}}