{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/38406","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/38406/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/38406/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/38406/events","html_url":"https://github.com/rust-lang/rust/issues/38406","id":195984107,"number":38406,"title":"[thumbv6m-none-eabi] LLVM ERROR: unsupported relocation on symbol","user":{"login":"japaric","id":5018213,"avatar_url":"https://avatars.githubusercontent.com/u/5018213?v=3","gravatar_id":"","url":"https://api.github.com/users/japaric","html_url":"https://github.com/japaric","followers_url":"https://api.github.com/users/japaric/followers","following_url":"https://api.github.com/users/japaric/following{/other_user}","gists_url":"https://api.github.com/users/japaric/gists{/gist_id}","starred_url":"https://api.github.com/users/japaric/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/japaric/subscriptions","organizations_url":"https://api.github.com/users/japaric/orgs","repos_url":"https://api.github.com/users/japaric/repos","events_url":"https://api.github.com/users/japaric/events{/privacy}","received_events_url":"https://api.github.com/users/japaric/received_events","type":"User","site_admin":false},"labels":[{"id":108333,"url":"https://api.github.com/repos/rust-lang/rust/labels/A-llvm","name":"A-llvm","color":"d7e102","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-12-16T05:30:57Z","updated_at":"2016-12-16T15:28:05Z","closed_at":null,"body":"### STR\r\n\r\n```\r\n$ cargo new --bin app && cd $_\r\n```\r\n\r\n``` rust\r\n$ edit src/main.rs && cat $_\r\n#![feature(asm)]\r\n#![feature(lang_items)]\r\n#![no_main]\r\n#![no_std]\r\n\r\n#[no_mangle]\r\npub fn _start() -> ! {\r\n    unsafe {\r\n        asm!(\"b foo\");\r\n    }\r\n\r\n    loop {}\r\n}\r\n\r\n#[no_mangle]\r\npub fn foo() {}\r\n\r\n#[lang = \"panic_fmt\"]\r\nfn panic_fmt() {}\r\n\r\n#[no_mangle]\r\npub fn __aeabi_unwind_cpp_pr0() {}\r\n```\r\n\r\n```\r\n# Instead of Xargo, you could explicitly depend on (rust-src's) core and just use Cargo\r\n$ xargo rustc --target thumbv6m-none-eabi --verbose -- -C link-arg=-nostartfiles\r\n   Compiling app v0.1.0 (file:///home/japaric/tmp/app)\r\nLLVM ERROR: unsupported relocation on symbol\r\nerror: Could not compile `app`.\r\n\r\nTo learn more, run the command again with --verbose.\r\n```\r\n\r\nWorks fine with `thumbv7m-none-eabi`:\r\n\r\n```\r\n$ xargo rustc --target thumbv7m-none-eabi --verbose -- -C link-arg=-nostartfiles && echo OK\r\nOK\r\n```\r\n\r\nThis is a bug in LLVM ([30279](https://llvm.org/bugs/show_bug.cgi?id=30279)) that has already been fixed in [r280651](http://llvm.org/viewvc/llvm-project?view=revision&revision=280651). We only have to backport the fix.\r\n\r\ncc @alexcrichton @thejpster"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/267618702","html_url":"https://github.com/rust-lang/rust/issues/38406#issuecomment-267618702","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/38406","id":267618702,"user":{"login":"nagisa","id":679122,"avatar_url":"https://avatars.githubusercontent.com/u/679122?v=3","gravatar_id":"","url":"https://api.github.com/users/nagisa","html_url":"https://github.com/nagisa","followers_url":"https://api.github.com/users/nagisa/followers","following_url":"https://api.github.com/users/nagisa/following{/other_user}","gists_url":"https://api.github.com/users/nagisa/gists{/gist_id}","starred_url":"https://api.github.com/users/nagisa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nagisa/subscriptions","organizations_url":"https://api.github.com/users/nagisa/orgs","repos_url":"https://api.github.com/users/nagisa/repos","events_url":"https://api.github.com/users/nagisa/events{/privacy}","received_events_url":"https://api.github.com/users/nagisa/received_events","type":"User","site_admin":false},"created_at":"2016-12-16T15:28:05Z","updated_at":"2016-12-16T15:28:05Z","body":"> Honest question: How does one pass a function to asm! with the goal of using it as a label? And does that handle the mangling of the function?\r\n\r\nThere’s no support for doing that directly in LLVM sadly, mostly because this is not a very desired feature; and you can work around the issue with some indirection, which not only handles mangling but also any relocation business you might have going on:\r\n\r\n```\r\n#![feature(asm)]\r\n\r\nfn boom() {\r\n    ::std::process::exit(42)\r\n}\r\n\r\nfn main() { unsafe {\r\n    asm!(\"jmpq *$0\" : : \"r\"(boom as fn()));\r\n} }\r\n```\r\n\r\ncompiles to code like this (PIC)\r\n\r\n```\r\n\tlea\trax, [rip + _ZN8rust_out4boom17he6750988c06a519cE]\r\n\tjmp\trax\r\n```\r\n\r\nor \t\r\n\r\n```\r\nmovl\t$_ZN4test4boom17h7dba417bfc620c55E, %eax\r\njmpq\t*%rax\r\n```\r\n\r\nin static relocation mode."}}
{"actor":{"display_login":"nagisa"}}