{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/47974","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/47974/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/47974/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/47974/events","html_url":"https://github.com/rust-lang/rust/issues/47974","id":294026214,"number":47974,"title":"dlclose() does not behave properly on Mac","user":{"login":"dradtke","id":929204,"avatar_url":"https://avatars1.githubusercontent.com/u/929204?v=4","gravatar_id":"","url":"https://api.github.com/users/dradtke","html_url":"https://github.com/dradtke","followers_url":"https://api.github.com/users/dradtke/followers","following_url":"https://api.github.com/users/dradtke/following{/other_user}","gists_url":"https://api.github.com/users/dradtke/gists{/gist_id}","starred_url":"https://api.github.com/users/dradtke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dradtke/subscriptions","organizations_url":"https://api.github.com/users/dradtke/orgs","repos_url":"https://api.github.com/users/dradtke/repos","events_url":"https://api.github.com/users/dradtke/events{/privacy}","received_events_url":"https://api.github.com/users/dradtke/received_events","type":"User","site_admin":false},"labels":[{"id":36953,"url":"https://api.github.com/repos/rust-lang/rust/labels/A-runtime","name":"A-runtime","color":"d7e102","default":false},{"id":650731663,"url":"https://api.github.com/repos/rust-lang/rust/labels/C-bug","name":"C-bug","color":"f5f1fd","default":false},{"id":123111,"url":"https://api.github.com/repos/rust-lang/rust/labels/O-macos","name":"O-macos","color":"6e6ec0","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2018-02-02T21:17:46Z","updated_at":"2018-04-28T14:53:45Z","closed_at":null,"author_association":"NONE","body":"This report will reference this repository which reproduces the issue: https://github.com/dradtke/rust-dylib-issues\r\n\r\n### The Issue\r\n\r\nThe repository contains an application library, built as a `dylib`, and two example main programs, one in Rust and one in C. Each main application runs in a loop, loading the library with `dlopen()`, calling a method, and then closing with `dlclose()`. The expectation is that any changes to the library will be picked up immediately by the main application when it is recompiled.\r\n\r\nHowever, the behavior between the two programs differs. If I run the two main programs side-by-side, then make a change to the returned message and recompile the library, only the C program immediately reflects the change. The Rust main program won't reflect any changes until it is fully restarted.\r\n\r\nIt appears that this is Mac-specific behavior. When the same test is run on Debian, the two main programs behave identically.\r\n\r\n### The Environment\r\n\r\n**Operating System**: macOS Sierra 10.12.6\r\n**Rust Version**:\r\n```\r\nrustc 1.23.0 (766bd11c8 2018-01-01)\r\nbinary: rustc\r\ncommit-hash: 766bd11c8a3c019ca53febdcd77b2215379dd67d\r\ncommit-date: 2018-01-01\r\nhost: x86_64-apple-darwin\r\nrelease: 1.23.0\r\nLLVM version: 4.0\r\n```\r\n\r\n**C Compiler**:\r\n```\r\nConfigured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1\r\nApple LLVM version 8.0.0 (clang-800.0.38)\r\nTarget: x86_64-apple-darwin16.7.0\r\nThread model: posix\r\nInstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin\r\n```"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/385181771","html_url":"https://github.com/rust-lang/rust/issues/47974#issuecomment-385181771","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/47974","id":385181771,"user":{"login":"Lisoph","id":3426722,"avatar_url":"https://avatars0.githubusercontent.com/u/3426722?v=4","gravatar_id":"","url":"https://api.github.com/users/Lisoph","html_url":"https://github.com/Lisoph","followers_url":"https://api.github.com/users/Lisoph/followers","following_url":"https://api.github.com/users/Lisoph/following{/other_user}","gists_url":"https://api.github.com/users/Lisoph/gists{/gist_id}","starred_url":"https://api.github.com/users/Lisoph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Lisoph/subscriptions","organizations_url":"https://api.github.com/users/Lisoph/orgs","repos_url":"https://api.github.com/users/Lisoph/repos","events_url":"https://api.github.com/users/Lisoph/events{/privacy}","received_events_url":"https://api.github.com/users/Lisoph/received_events","type":"User","site_admin":false},"created_at":"2018-04-28T14:53:45Z","updated_at":"2018-04-28T14:53:45Z","author_association":"NONE","body":"I'm experiencing this problem as well, on High Sierra (10.13.4). I noticed the following:\r\n\r\nWhen `dlclose`ing a library written in C (`clang -shared`), the dylib gets unloaded as expected.\r\n```\r\ndlclose(0x7fc3eaf8b000)\r\n3043 dlclose(), found unused image 0x7fc3eaf8b000 libhsgame.dylib\r\n3044 dlclose(), deleting 0x7fc3eaf8b000 libhsgame.dylib\r\n```\r\n\r\nWhen I try the same exact thing again with an identical cdylib written in Rust, `dlclose` does not unload the library. A refcount > 0 can't be the problem, because even when I `dlclose` the cdylib 100 times in a loop, `dlclose` still refuses to release the library (`DYLD_PRINT_APIS=1` confirms it only gets opened once and closed 100 times).\r\n\r\nTo my knowledge, `dlclose` only refuses to release a dylib when, other than refcount > 0,  the dylib is still being used somewhere (pointers holding addresses of the lib's symbols still exist), to avoid dangling pointers.\r\n\r\nIf that's the case, then the question is, where do these pointers come from? If not, what the hell else is going on?"}}
{"actor":{"display_login":"Lisoph"}}