{"action":"opened","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/32546","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/32546/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/32546/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/32546/events","html_url":"https://github.com/rust-lang/rust/issues/32546","id":143914344,"number":32546,"title":"unresolved symbol imports in -pie musl binaries","user":{"login":"m4b","id":1920204,"avatar_url":"https://avatars.githubusercontent.com/u/1920204?v=3","gravatar_id":"","url":"https://api.github.com/users/m4b","html_url":"https://github.com/m4b","followers_url":"https://api.github.com/users/m4b/followers","following_url":"https://api.github.com/users/m4b/following{/other_user}","gists_url":"https://api.github.com/users/m4b/gists{/gist_id}","starred_url":"https://api.github.com/users/m4b/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m4b/subscriptions","organizations_url":"https://api.github.com/users/m4b/orgs","repos_url":"https://api.github.com/users/m4b/repos","events_url":"https://api.github.com/users/m4b/events{/privacy}","received_events_url":"https://api.github.com/users/m4b/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-03-28T07:17:05Z","updated_at":"2016-03-28T07:17:05Z","closed_at":null,"body":"I've noticed that there are two unresolved symbols when a [PIE](https://en.wikipedia.org/wiki/Position-independent_code#Position-independent_executables) is requested via the linker flags with nightly rustc's new musl target, e.g.:\r\n\r\n`rust/bin/rustc --target=x86_64-unknown-linux-musl -C link-args=\"-Wl,-pie\" main.rs`\r\n\r\nyields a binary with two unresolved imports:\r\n\r\n```\r\nELF X86_64 DYN @ 0x4f71\r\nImports (2)\r\n          26e3a0 __dso_handle (0) ~> Unknown\r\n          26e3a8 __cxa_thread_atexit_impl (0) ~> Unresolved\r\n```\r\n\r\nwhich you can see with `objdump -R main`:\r\n\r\n```\r\n0000000000270fd0 R_X86_64_GLOB_DAT  __cxa_thread_atexit_impl\r\n0000000000271008 R_X86_64_64       __dso_handle\r\n```\r\n\r\nbut 0 libraries (i.e., `DT_NEEDED`), so having unresolved imports without dynamic library dependencies is essentially an incoherent binary semantics.  (Not having libraries is fine, in fact that's the point of the musl target, and the `-pie` flag should just make it able to be loaded anywhere in memory, but having unresolved imports without dependencies is where it becomes problematic)\r\n\r\nSimilarly, grepping through the assembly, it looks like `__cxa_thread_atexit_impl` isn't called by anyone, but `__dso_handle` does show up in an external rust linkage symbol (I have no idea what the function of the `__rust_extern_with_linkage____X` is):\r\n```\r\n015:\t48 8d 15 ec 7f 26 00 \tlea    0x267fec(%rip),%rdx        # 271008 <_rust_extern_with_linkage___dso_handle>\r\n```\r\n\r\nAs such, doesn't seem like it's a major problem, but it is very unusual, and again, the lack of dynamic library dependencies + unresolved symbol imports is a red flag, and should probably be investigated.  My guess is that there is some weird interaction with the `link-args` flag and the generated link commands somehow."}}