Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign up[RFC] [breaking-change] change the default linker of the `thumbv*m-none-eabi*` targets #160
Comments
This comment has been minimized.
This comment has been minimized.
korken89
commented
Aug 10, 2018
|
I think it is worth it, let's pull this band-aid now before it becomes a real issue to do the switch. As long as we clearly state the migration path to the users it will cause minimal pain. |
This comment has been minimized.
This comment has been minimized.
|
It is the better and more self-contained solution in the long run. So break it early to make it nicer in the long run. |
This comment has been minimized.
This comment has been minimized.
|
I've already already used binutils Even for So +1 from me and thanks for writing it up, @japaric. |
japaric
referenced this issue
Aug 10, 2018
Merged
targets: aarch64: Add bare-metal aarch64 target #53233
This comment has been minimized.
This comment has been minimized.
|
As long as setting the linker back to GCC doesn't require a nightly flag (as it seems from your comment in the other issue), I don't have any issue with this. Being able to switch back without nightly would allow the user to regain the old behavior, in case they run in to an issue with LLD before we have used LLD for a significant enough amount of time. |
This comment has been minimized.
This comment has been minimized.
Unless I'm misunderstanding, this is currently the case and may remain the case for 2018 edition; we need rust-lang/rust#52101 to land before it's possible to set without nightly. |
This comment has been minimized.
This comment has been minimized.
alevy
commented
Aug 12, 2018
|
@japaric speaking for the Tock project, we've already manually switched over both userland and the kernel from GCC to LLD as the linker, so this change would be strictly better for us. |
This comment has been minimized.
This comment has been minimized.
|
Well, if it's working for Tock then that gives me some confidence, and sooner is better than later with this sort of thing. +1 from me. |
This comment has been minimized.
This comment has been minimized.
japaric
added
the
RFC
label
Aug 17, 2018
This comment has been minimized.
This comment has been minimized.
|
The prerequisite for this (PR rust-lang/rust#52101) has been approved. |
This comment has been minimized.
This comment has been minimized.
The PR has landed This RFC has received approval, in the form of GH reactions and comments, from 20+ people representing the embedded WG, the TockOS project and the embed-rs organization. The only concern raised so far is that it should be possible to switch to GCC on stable and that have been solved by PR rust-lang/rust#52101 which landed a few hours ago. I'll start preparing a rust-lang/rust PR to change the default linker, and an accompanying announcement about the upcoming breakage and the migration path. I won't submit the PR until the end of the week to give other people more time to comment on this RFC. Consider the RFC in Final Comment Period (FCP) phase with disposition to accept it. |
japaric
added
the
disposition-merge
label
Aug 20, 2018
This was referenced Aug 20, 2018
This comment has been minimized.
This comment has been minimized.
sekineh
commented
Aug 20, 2018
|
@japaric In that case CI should build some binary using both linkers. |
This comment has been minimized.
This comment has been minimized.
Via rustc flags actually but you can use either something like [target.thumbv7m-none-eabi]
rustflags = ["-C", "linker=arm-none-eabi-gcc"]
Yes, we should test both linkers in rust-lang/rust CI. |
This was referenced Aug 20, 2018
japaric
added
decision-accepted
and removed
disposition-merge
labels
Aug 23, 2018
This comment has been minimized.
This comment has been minimized.
|
This RFC is now officially accepted. Thanks everyone for your input! i have sent a PR to change the default linker (see rust-lang/rust#53648) and I have written an announcement explaining the breakage and how to fix the builds (see #196). (The announcement hasn't go out yet; it's only up for review right now.) |
japaric commentedAug 10, 2018
Summary
Change the default linker of the Thumb targets from
arm-none-eabi-gccto rustc's LLD (rust-lld).The following targets would be affected:
thumbv6m-none-eabithumbv7m-none-eabithumbv7em-none-eabithumbv7em-none-eabihfBackground
The Thumb targets were added to the compiler well over a year ago. Back then we didn't know if we
were going to ship LLD with rustc so
arm-none-eabi-gccwas selected as the default linker.Fast forward to today LLD ships with rustc on tier 1 platforms (x86_64 Linux, macOS and Windows),
and rustc supports GCC-style, LLD-style and LD-style ELF linkers (the linker can be chosen using
-C linkerand-Z linker-flavor).Motivation
We want to simplify the development setup for embedded developers that will be using the stable
channel. Right now the linker can't be changed on stable because the
-Z linker-flavorflag isunstable. Thus the default of GCC forces ARM Cortex-M developers to install
arm-none-eabi-gccbefore they can build even the smallest embedded Rust program.
With the change proposed in this RFC those developers would be able to build and link embedded Rust
programs without having to install a C toolchain.
Detailed design
On the compiler side the change is simple so this section will focus on how end users will have to
deal with the breaking change.
Dealing with breakage
This change will be breaking for all users that are customizing the linking process with any of
these flags:
-C link-arg,-C link-args,-Z pre-link-argand-Z pre-link-args--unfortunately this is the majority of users.
The user has two ways to fix their code:
They can switch back to GCC. Pass the flags
-C linker=arm-none-eabi-gcc -Z linker-flavor=gcctothe compiler and you'll be using GCC again. Note that once rust-lang/rust#52101 the unstable
-Z linker-flavorflag won't be required.They can change their custom linker flags to make them compatible with LLD.
rust-lldwill be usingthe LD linker flavor which is incompatible with the current default linker flavor of GCC. The
changes will mostly consist of removing the
-Wl,prefix that GCC uses. For example,-C link-arg=-Wl,-Tlink.xwould become-C link-arg=-Tlink.x.Rust stability promise
"This is a breaking change. Isn't this against Rust stability principle of "code never breaks when
moving to a newer stable release"?"
This is technically a breaking change but it will only affect nightly users because the linker is
only used to build binary crates, cdylibs crates and the like; all those types of crate require the
still unstable
#[panic_implementation]feature. As long as this change is done before or at thesame time
#[panic_implementation]is stabilized it won't break Rust stability promise.Alternatives
We can leave things as they are. It won't be possible to use
rust-lldon stable until either-Z linker-flavoris stabilized (-C linker=rust-lld -Z linker-flavor=ld.lld), or rust-lang/rust#52101lands and the proposed idea of a
ld_flavorfield for target specifications (seerust-lang/rust#52101 (comment)) is implemented.
Instead of changing the default linker we could stabilize
-Z linker-flavorthen it would bepossible to switch to
rust-lldon stable using these flags:-C linker=rust-lld -C linker-flavor=ld.lld.Disadvantages
The disadvantage of using LLD as the default linker is that it doesn't have a default library search
path. If you need to link to a system library like newlib compiled for ARM Cortex-M you would need
to supply the path to that library using the
-Lflag. This is not a problem if you are linking toC code compiled using a build script.
GCC is a better linker in that case because it already knows where the system libraries are so it's
not necessary to pass a library search path that depends on a particular installation. However, it's
possible to switch the linker to GCC to make this scenario simpler (
-C linker=arm-none-eabi-gcconce rust-lang/rust#52101 lands).
We need the approval of the Cortex-M community to land this change in rustc. Do you think the change
is worth it?
cc @rust-embedded/all
cc @alevy (Tock OS)