{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/28046","repository_url":"https://api.github.com/repos/JuliaLang/julia","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/28046/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/28046/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/28046/events","html_url":"https://github.com/JuliaLang/julia/issues/28046","id":340039777,"node_id":"MDU6SXNzdWUzNDAwMzk3Nzc=","number":28046,"title":"code_native broken on official macOS binaries","user":{"login":"mylincode","id":26829006,"node_id":"MDQ6VXNlcjI2ODI5MDA2","avatar_url":"https://avatars1.githubusercontent.com/u/26829006?v=4","gravatar_id":"","url":"https://api.github.com/users/mylincode","html_url":"https://github.com/mylincode","followers_url":"https://api.github.com/users/mylincode/followers","following_url":"https://api.github.com/users/mylincode/following{/other_user}","gists_url":"https://api.github.com/users/mylincode/gists{/gist_id}","starred_url":"https://api.github.com/users/mylincode/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mylincode/subscriptions","organizations_url":"https://api.github.com/users/mylincode/orgs","repos_url":"https://api.github.com/users/mylincode/repos","events_url":"https://api.github.com/users/mylincode/events{/privacy}","received_events_url":"https://api.github.com/users/mylincode/received_events","type":"User","site_admin":false},"labels":[{"id":97636,"node_id":"MDU6TGFiZWw5NzYzNg==","url":"https://api.github.com/repos/JuliaLang/julia/labels/bug","name":"bug","color":"e10c02","default":true},{"id":47509082,"node_id":"MDU6TGFiZWw0NzUwOTA4Mg==","url":"https://api.github.com/repos/JuliaLang/julia/labels/regression","name":"regression","color":"ff2510","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":19,"created_at":"2018-07-10T23:22:05Z","updated_at":"2018-12-31T17:37:51Z","closed_at":null,"author_association":"NONE","body":"This issue stems from a [discussion I started](https://discourse.julialang.org/t/why-does-code-native-output-32-bit-assembly-in-64-bit-julia/12260) on the Julia Discourse forum.\r\n\r\nIn short, the `code_native()` introspection function seems to work inconsistently (and sometimes break completely) on both Linux and macOS, based on results from several macOS and Linux setups with several Julia versions. I'll be giving the `versioninfo()` for the two setups I used (macOS 10.13.5 on Apple hardware, Fedora 28 inside a Docker container), along with the results of several `code_native()` calls to demonstrate the issue. My macOS setup is running the just-released Julia 0.6.4 as of writing this issue, but I experienced the exact same behavior on macOS with Julia 0.6.3.\r\n\r\n### macOS `versioninfo()`\r\n```\r\nJulia Version 0.6.4\r\nCommit 9d11f62bcb (2018-07-09 19:09 UTC)\r\nPlatform Info:\r\n  OS: macOS (x86_64-apple-darwin14.5.0)\r\n  CPU: Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz\r\n  WORD_SIZE: 64\r\n  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell MAX_THREADS=16)\r\n  LAPACK: libopenblas64_\r\n  LIBM: libopenlibm\r\n  LLVM: libLLVM-3.9.1 (ORCJIT, haswell)\r\n```\r\n\r\n### Fedora `versioninfo()`\r\n```\r\nJulia Version 0.6.3\r\nCommit d55cadc (2018-05-28 20:20 UTC)\r\nPlatform Info:\r\n  OS: Linux (x86_64-redhat-linux)\r\n  CPU: Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz\r\n  WORD_SIZE: 64\r\n  BLAS: libopenblas (DYNAMIC_ARCH NO_AFFINITY Haswell MAX_THREADS=128)\r\n  LAPACK: libopenblasp.so.0\r\n  LIBM: libopenlibm\r\n  LLVM: libLLVM-3.9.1 (ORCJIT, haswell)\r\n```\r\n\r\n## Fedora Behavior\r\nAs a very simple test case, let's dump the assembly for `+(::Int, ::Int)`:\r\n```\r\njulia> code_native(+, (Int, Int), :intel)\r\nWARNING: Could not determine size of symbol\r\n```\r\nThat's strange. If we try wrapping it in another function:\r\n```\r\njulia> f(a, b) = a + b\r\nf (generic function with 1 method)\r\n\r\njulia> code_native(f, (Int, Int), :intel)\r\n        .text\r\nFilename: REPL[3]\r\n        push    rbp\r\n        mov     rbp, rsp\r\nSource line: 1\r\n        lea     rax, [rdi + rsi]\r\n        pop     rbp\r\n        ret\r\n        nop     word ptr [rax + rax]\r\n```\r\nThat works, but I see no reason why dumping code for `+` should fail. I also wonder if the `WARNING` being displayed in place of an assembly printout is text emitted from external code (i.e. not Julia), since I can't think of what the \"Could not determine size of symbol\" would mean in Julia.\r\n\r\n## macOS Behavior\r\nRepeating the same initial test as before:\r\n```\r\njulia> code_native(+, (Int, Int), :intel)\r\n        .section        __TEXT,__text,regular,pure_instructions\r\nFilename: int.jl\r\n        push    ebp\r\n        dec     eax\r\n        mov     ebp, esp\r\nSource line: 32\r\n        dec     eax\r\n        lea     eax, [edi + esi]\r\n        pop     ebp\r\n        ret\r\nSource line: 32\r\n        nop\r\n        nop\r\n        nop\r\n        nop\r\n        nop\r\n        nop\r\n```\r\nThis time we get an assembly printout, but it's *completely wrong*. We're seeing only 32-bit instructions, though the actual code is of course 64-bit. Additionally, we've got needless `dec eax` instructions interspersed, which I suspect aren't actually in the generated code. We can try wrapping `+` in a function again, but we still get the broken ASM.\r\n\r\n---\r\n\r\nTo show that this problem is limited to `code_native`, we can try `code_llvm`, which always gives identical (and correct) output:\r\n```\r\njulia> code_llvm(+, (Int, Int))\r\n\r\ndefine i64 @\"jlsys_+_60291\"(i64, i64) #0 !dbg !5 {\r\ntop:\r\n  %2 = add i64 %1, %0\r\n  ret i64 %2\r\n}\r\n```\r\nWhile I used the `+` case as a minimal example, no `code_native` call I've tried has produced correct (i.e. 64-bit) assembly on my macOS setup. Another user (by the username Per in the discussion linked above) was able to get `code_native` working correctly with a source-built Julia 0.7.0-beta.214 on macOS High Sierra (10.13.x), but experienced the same macOS behavior I did with a downloaded 0.7.0-beta.0 and a downloaded 0.6.3 on macOS Sierra (10.12.x). Finally, with a locally-rebuilt system image in Julia 0.6.3 and macOS Sierra, Per was able to reproduce the `WARNING` output I experienced on Fedora."},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/450672850","html_url":"https://github.com/JuliaLang/julia/issues/28046#issuecomment-450672850","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/28046","id":450672850,"node_id":"MDEyOklzc3VlQ29tbWVudDQ1MDY3Mjg1MA==","user":{"login":"eschnett","id":213514,"node_id":"MDQ6VXNlcjIxMzUxNA==","avatar_url":"https://avatars0.githubusercontent.com/u/213514?v=4","gravatar_id":"","url":"https://api.github.com/users/eschnett","html_url":"https://github.com/eschnett","followers_url":"https://api.github.com/users/eschnett/followers","following_url":"https://api.github.com/users/eschnett/following{/other_user}","gists_url":"https://api.github.com/users/eschnett/gists{/gist_id}","starred_url":"https://api.github.com/users/eschnett/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eschnett/subscriptions","organizations_url":"https://api.github.com/users/eschnett/orgs","repos_url":"https://api.github.com/users/eschnett/repos","events_url":"https://api.github.com/users/eschnett/events{/privacy}","received_events_url":"https://api.github.com/users/eschnett/received_events","type":"User","site_admin":false},"created_at":"2018-12-31T17:37:51Z","updated_at":"2018-12-31T17:37:51Z","author_association":"CONTRIBUTOR","body":"This sounds as if it was worthwhile trying to replace the statements\r\n```C++\r\nstd::string TripleName = sys::getDefaultTargetTriple();\r\nTriple TheTriple(Triple::normalize(TripleName));\r\n```\r\nby\r\n```C++\r\nstd::string TripleName = jl_TargetMachine->getTargetTriple();\r\nTriple TheTriple(TripleName);\r\n```\r\nin `disasm.cpp`.\r\n"}}
{"actor":{"display_login":"eschnett"}}