{"action":"created","issue":{"url":"https://api.github.com/repos/WebAssembly/binaryen/issues/577","repository_url":"https://api.github.com/repos/WebAssembly/binaryen","labels_url":"https://api.github.com/repos/WebAssembly/binaryen/issues/577/labels{/name}","comments_url":"https://api.github.com/repos/WebAssembly/binaryen/issues/577/comments","events_url":"https://api.github.com/repos/WebAssembly/binaryen/issues/577/events","html_url":"https://github.com/WebAssembly/binaryen/issues/577","id":158915795,"number":577,"title":"Explicit registration of passes required","user":{"login":"jasonwilliams200OK","id":2031765,"avatar_url":"https://avatars.githubusercontent.com/u/2031765?v=3","gravatar_id":"","url":"https://api.github.com/users/jasonwilliams200OK","html_url":"https://github.com/jasonwilliams200OK","followers_url":"https://api.github.com/users/jasonwilliams200OK/followers","following_url":"https://api.github.com/users/jasonwilliams200OK/following{/other_user}","gists_url":"https://api.github.com/users/jasonwilliams200OK/gists{/gist_id}","starred_url":"https://api.github.com/users/jasonwilliams200OK/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jasonwilliams200OK/subscriptions","organizations_url":"https://api.github.com/users/jasonwilliams200OK/orgs","repos_url":"https://api.github.com/users/jasonwilliams200OK/repos","events_url":"https://api.github.com/users/jasonwilliams200OK/events{/privacy}","received_events_url":"https://api.github.com/users/jasonwilliams200OK/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":11,"created_at":"2016-06-07T12:55:21Z","updated_at":"2016-06-10T22:43:25Z","closed_at":null,"body":"Punch line: MS-VCR build does not comply with UD behavior of GCC for static initialization\r\n\r\nOn Windows 10 with VS2015Update2, git2+ and cmake3+ in PATH, I built binaryen:\r\n\r\n```cmd\r\ngit clone https://github.com/WebAssembly/binaryen.git --recursive\r\ncd binaryen\r\ncmake .\r\ncmake --build . --config Release\r\n```\r\n\r\nWhen I tried running the hello world example: `bin/asm2wasm ./test/hello_world.asm.js` in Windows PowerShell, it gives me: `Fatal: Could not find pass: dce`.\r\n\r\nApparently, `dce` and many other passes do not get initialized; only print, print-minimized and print-full get attention of static initializer. This is because the compiler/linker are optimizing those code paths out as suspected by @kripken: https://github.com/WebAssembly/binaryen/pull/576#issuecomment-224125210.\r\n\r\nI have confirmed this by placing `#pragma comment(linker, \"/INCLUDE:wasm::registerPass\")` after [asm2wasm.cpp#L29](https://github.com/WebAssembly/binaryen/blob/e4a81f9/src/tools/asm2wasm.cpp#L29) and using `/OPT:NOREF` switch, the linker throws:\r\n\r\n> LNK2001\tunresolved external symbol wasm::registerPass\tasm2wasm\r\n\r\nSimilar case study: http://stackoverflow.com/q/9459980 (see Edit section of original post)\r\n\r\nInteresting comments:\r\n\r\n> \r\n* Relying on static initialization to register functions is probably a bit error prone in the long run. Have you considered just doing explicit registration?\r\n* I think if you want something initialized, try to initialize them MANUALLY other than depending on compiler's work"},"comment":{"url":"https://api.github.com/repos/WebAssembly/binaryen/issues/comments/225313240","html_url":"https://github.com/WebAssembly/binaryen/issues/577#issuecomment-225313240","issue_url":"https://api.github.com/repos/WebAssembly/binaryen/issues/577","id":225313240,"user":{"login":"dschuff","id":1122856,"avatar_url":"https://avatars.githubusercontent.com/u/1122856?v=3","gravatar_id":"","url":"https://api.github.com/users/dschuff","html_url":"https://github.com/dschuff","followers_url":"https://api.github.com/users/dschuff/followers","following_url":"https://api.github.com/users/dschuff/following{/other_user}","gists_url":"https://api.github.com/users/dschuff/gists{/gist_id}","starred_url":"https://api.github.com/users/dschuff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dschuff/subscriptions","organizations_url":"https://api.github.com/users/dschuff/orgs","repos_url":"https://api.github.com/users/dschuff/repos","events_url":"https://api.github.com/users/dschuff/events{/privacy}","received_events_url":"https://api.github.com/users/dschuff/received_events","type":"User","site_admin":false},"created_at":"2016-06-10T22:43:25Z","updated_at":"2016-06-10T22:43:25Z","body":"I'm in favor of doing something like #582 rather than making the registration magically use strings.\r\n\r\nRegarding \"whatever LLVM does\":\r\nLLVM tries to have it both ways, because it does have explicit `createFooPass()` calls but also tries to have auto-registration by name e.g. for `opt`. One reason they have the explicit way is because they need to support several different ways of building and linking all the passes (e.g. linking everything into a single DSO, and static linking with different archive libraries, etc) and support different platforms, so there ends up being some redundancy. Often you can get away with avoiding some of it for one use case but not for others. I think our use case is actually similar. If we intend for people to use parts of Binaryen in their own projects we have to support a variety of ways of linking, and that means having things more explicit. If we do the extra work to make things work with strings like in LLVM we can support that too, but I don't think it's worth it. I'd vote for just having `createFooPass()` for each pass and being done with it; it's a little extra boilerplate, but not that much, and it means things will just work. To me, our users are better served by giving them something that will more reliably work and be more tolerant of different environments than saving them a few lines of copy/paste.\r\n\r\nAs for things being defacto standard over ISO.... Well \"whatever LLVM does\" doesn't override ISO, but \"whatever works on the platforms we care about\" does :)"}}
{"actor":{"display_login":"dschuff"}}