{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/27438","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/27438/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/27438/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/27438/events","html_url":"https://github.com/rust-lang/rust/issues/27438","id":98422921,"number":27438,"title":"Correctly handle dllimport on Windows/MSVC","user":{"login":"alexcrichton","id":64996,"avatar_url":"https://avatars.githubusercontent.com/u/64996?v=3","gravatar_id":"","url":"https://api.github.com/users/alexcrichton","html_url":"https://github.com/alexcrichton","followers_url":"https://api.github.com/users/alexcrichton/followers","following_url":"https://api.github.com/users/alexcrichton/following{/other_user}","gists_url":"https://api.github.com/users/alexcrichton/gists{/gist_id}","starred_url":"https://api.github.com/users/alexcrichton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexcrichton/subscriptions","organizations_url":"https://api.github.com/users/alexcrichton/orgs","repos_url":"https://api.github.com/users/alexcrichton/repos","events_url":"https://api.github.com/users/alexcrichton/events{/privacy}","received_events_url":"https://api.github.com/users/alexcrichton/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rust-lang/rust/labels/A-windows","name":"A-windows","color":"d7e102"},{"url":"https://api.github.com/repos/rust-lang/rust/labels/I-nominated","name":"I-nominated","color":"e10c02"},{"url":"https://api.github.com/repos/rust-lang/rust/labels/T-compiler","name":"T-compiler","color":"bfd4f2"},{"url":"https://api.github.com/repos/rust-lang/rust/labels/T-lang","name":"T-lang","color":"bfd4f2"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":53,"created_at":"2015-07-31T16:20:45Z","updated_at":"2015-09-22T22:11:10Z","closed_at":null,"body":"Currently the compiler makes basically no attempt to correctly use `dllimport`. As a bit of a refresher, the Windows linker requires that if you're importing symbols from a DLL that they're tagged with `dllimport`. This helps wire things up correctly at runtime and link-time. To help us out, though, the linker will patch up a few cases where `dllimport` is missing where it would otherwise be required. If a function in another DLL is linked to without `dllimport` then the linker will inject a local shim which adds a bit of indirection and runtime overhead but allows the crate to link correctly. For importing constants from other DLLs, however, the linker requires that `dllimport` is annotated correctly.\r\n\r\nIf we're targeting MSVC then the compiler currently puts `dllimport` on all imported constants from external crates, regardless of whether it's actually being imported from another crate. We rely on the linker fixing up all imports of functions. This ends up meaning that some crates don't link correctly, however (see this comment: https://github.com/rust-lang/rust/issues/26591#issuecomment-123513631).\r\n\r\nWe should fix the compiler's handling of dllimport in a few ways:\r\n\r\n* Functions should be tagged with `dllimport` where appropriate\r\n* FFI functions should also be tagged with `dllimport` where appropriate\r\n* Constants should not always be tagged with `dllimport` if they're not actually being imported from a DLL.\r\n\r\nI currently have a few thoughts running around in my head for fixing this, but nothing seems plausible enough to push on."},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/142436637","html_url":"https://github.com/rust-lang/rust/issues/27438#issuecomment-142436637","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/27438","id":142436637,"user":{"login":"brson","id":147214,"avatar_url":"https://avatars.githubusercontent.com/u/147214?v=3","gravatar_id":"","url":"https://api.github.com/users/brson","html_url":"https://github.com/brson","followers_url":"https://api.github.com/users/brson/followers","following_url":"https://api.github.com/users/brson/following{/other_user}","gists_url":"https://api.github.com/users/brson/gists{/gist_id}","starred_url":"https://api.github.com/users/brson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brson/subscriptions","organizations_url":"https://api.github.com/users/brson/orgs","repos_url":"https://api.github.com/users/brson/repos","events_url":"https://api.github.com/users/brson/events{/privacy}","received_events_url":"https://api.github.com/users/brson/received_events","type":"User","site_admin":false},"created_at":"2015-09-22T22:11:10Z","updated_at":"2015-09-22T22:11:10Z","body":"Nominating this to escalate. This seems to be something of a showstopper for MSVC support and may require language changes."}}