{"action":"created","issue":{"url":"https://api.github.com/repos/rust-embedded/wg/issues/160","repository_url":"https://api.github.com/repos/rust-embedded/wg","labels_url":"https://api.github.com/repos/rust-embedded/wg/issues/160/labels{/name}","comments_url":"https://api.github.com/repos/rust-embedded/wg/issues/160/comments","events_url":"https://api.github.com/repos/rust-embedded/wg/issues/160/events","html_url":"https://github.com/rust-embedded/wg/issues/160","id":349634992,"node_id":"MDU6SXNzdWUzNDk2MzQ5OTI=","number":160,"title":"[RFC] [breaking-change] change the default linker of the `thumbv*m-none-eabi*` targets","user":{"login":"japaric","id":5018213,"node_id":"MDQ6VXNlcjUwMTgyMTM=","avatar_url":"https://avatars3.githubusercontent.com/u/5018213?v=4","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":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2018-08-10T19:41:02Z","updated_at":"2018-08-12T20:46:02Z","closed_at":null,"author_association":"MEMBER","body":"# Summary\r\n\r\nChange the default linker of the Thumb targets from `arm-none-eabi-gcc` to rustc's LLD (`rust-lld`).\r\nThe following targets would be affected:\r\n\r\n- `thumbv6m-none-eabi`\r\n- `thumbv7m-none-eabi`\r\n- `thumbv7em-none-eabi`\r\n- `thumbv7em-none-eabihf`\r\n\r\n# Background\r\n\r\nThe Thumb targets were added to the compiler well over a year ago. Back then we didn't know if we\r\nwere going to ship LLD with rustc so `arm-none-eabi-gcc` was selected as the default linker.\r\n\r\nFast forward to today LLD ships with rustc on tier 1 platforms (x86_64 Linux, macOS and Windows),\r\nand rustc supports GCC-style, LLD-style and LD-style ELF linkers (the linker can be chosen using `-C\r\nlinker` and `-Z linker-flavor`).\r\n\r\n# Motivation\r\n\r\nWe want to simplify the development setup for embedded developers that will be using the stable\r\nchannel. Right now the linker can't be changed on stable because the `-Z linker-flavor` flag is\r\nunstable. Thus the default of GCC forces ARM Cortex-M developers to install `arm-none-eabi-gcc`\r\nbefore they can build even the smallest embedded Rust program.\r\n\r\nWith the change proposed in this RFC those developers would be able to build and link embedded Rust\r\nprograms without having to install a C toolchain.\r\n\r\n# Detailed design\r\n\r\nOn the compiler side the change is simple so this section will focus on how end users will have to\r\ndeal with the breaking change.\r\n\r\n## Dealing with breakage\r\n\r\nThis change will be breaking for all users that are customizing the linking process with any of\r\nthese flags: `-C link-arg`, `-C link-args`, `-Z pre-link-arg` and `-Z pre-link-args` --\r\nunfortunately this is the majority of users.\r\n\r\nThe user has two ways to fix their code:\r\n\r\nThey can switch back to GCC. Pass the flags `-C linker=arm-none-eabi-gcc -Z linker-flavor=gcc` to\r\nthe compiler and you'll be using GCC again. Note that once rust-lang/rust#52101 the unstable `-Z\r\nlinker-flavor` flag won't be required.\r\n\r\nThey can change their custom linker flags to make them compatible with LLD. `rust-lld` will be using\r\nthe LD linker flavor which is incompatible with the current default linker flavor of GCC. The\r\nchanges will mostly consist of removing the `-Wl,` prefix that GCC uses. For example, `-C\r\nlink-arg=-Wl,-Tlink.x` would become `-C link-arg=-Tlink.x`.\r\n\r\n## Rust stability promise\r\n\r\n\"This is a breaking change. Isn't this against Rust stability principle of \"code never breaks when\r\nmoving to a newer stable release\"?\"\r\n\r\nThis is technically a breaking change but it will only affect nightly users because the linker is\r\nonly used to build binary crates, cdylibs crates and the like; all those types of crate require the\r\nstill unstable `#[panic_implementation]` feature. As long as this change is done before or at the\r\nsame time `#[panic_implementation]` is stabilized it won't break Rust stability promise.\r\n\r\n# Alternatives\r\n\r\nWe can leave things as they are. It won't be possible to use `rust-lld` on stable until either `-Z\r\nlinker-flavor` is stabilized (`-C linker=rust-lld -Z linker-flavor=ld.lld`), or rust-lang/rust#52101\r\nlands and the proposed idea of a `ld_flavor` field for target specifications (see\r\nhttps://github.com/rust-lang/rust/pull/52101#issuecomment-411933481) is implemented.\r\n\r\nInstead of changing the default linker we could stabilize `-Z linker-flavor` then it would be\r\npossible to switch to `rust-lld` on stable using these flags: `-C linker=rust-lld -C\r\nlinker-flavor=ld.lld`.\r\n\r\n## Disadvantages\r\n\r\nThe disadvantage of using LLD as the default linker is that it doesn't have a default library search\r\npath. If you need to link to a system library like newlib compiled for ARM Cortex-M you would need\r\nto supply the path to that library using the `-L` flag. This is not a problem if you are linking to\r\nC code compiled using a build script.\r\n\r\nGCC is a better linker in that case because it already knows where the system libraries are so it's\r\nnot necessary to pass a library search path that depends on a particular installation. However, it's\r\npossible to switch the linker to GCC to make this scenario simpler (`-C linker=arm-none-eabi-gcc`\r\nonce rust-lang/rust#52101 lands).\r\n\r\n---\r\n\r\nWe need the approval of the Cortex-M community to land this change in rustc. Do you think the change\r\nis worth it?\r\n\r\ncc @rust-embedded/all\r\ncc @alevy (Tock OS)"},"comment":{"url":"https://api.github.com/repos/rust-embedded/wg/issues/comments/412370628","html_url":"https://github.com/rust-embedded/wg/issues/160#issuecomment-412370628","issue_url":"https://api.github.com/repos/rust-embedded/wg/issues/160","id":412370628,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMjM3MDYyOA==","user":{"login":"thejpster","id":959887,"node_id":"MDQ6VXNlcjk1OTg4Nw==","avatar_url":"https://avatars3.githubusercontent.com/u/959887?v=4","gravatar_id":"","url":"https://api.github.com/users/thejpster","html_url":"https://github.com/thejpster","followers_url":"https://api.github.com/users/thejpster/followers","following_url":"https://api.github.com/users/thejpster/following{/other_user}","gists_url":"https://api.github.com/users/thejpster/gists{/gist_id}","starred_url":"https://api.github.com/users/thejpster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thejpster/subscriptions","organizations_url":"https://api.github.com/users/thejpster/orgs","repos_url":"https://api.github.com/users/thejpster/repos","events_url":"https://api.github.com/users/thejpster/events{/privacy}","received_events_url":"https://api.github.com/users/thejpster/received_events","type":"User","site_admin":false},"created_at":"2018-08-12T20:46:02Z","updated_at":"2018-08-12T20:46:02Z","author_association":"COLLABORATOR","body":"Well, if it's working for Tock then that gives me some confidence, and sooner is better than later with this sort of thing.\r\n\r\n+1 from me."}}
{"actor":{"display_login":"thejpster"}}