Rewrite the linking section of "A Freestanding Rust Binary" #577
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request rewrites the section about overwriting the entry point. Instead of recommending to pass platform-specific arguments to the linker, the post now solves the linker errors by compiling for the bare metal
thumbv7em-none-eabihf
target. This makes much more sense, since it is the same approach that we use in the second post (by using a custom bare metal target).We keep the old section about the platform specific linker arguments, but perform the following changes:
cargo build
at the end of the post – is now achieved by building forthumbv7em-none-eabihf
, so we no longer need it for bringing the post to an end.src/main.rs
, we now use_start
on these platforms as well by explicitly overriding the entry point name.mainCRTStartup
andmain
on Windows, we now specifcy the subsystem explicitly. Thus we no longer need to create a function namedmain
so that the linker can infer a default subsystem.System
library on macOS, we force a static binary by passing-static
and-nostartfiles
.rustflags
keys in a.cargo/config
file.#[start]
attribute forno_std
binaries that should run on top of existing OSs.Further, this PR reorganize section levels so that we have more top level sections instead of keeping everything in the "Disabling the Standard Library" section.
Preview
PR to update
post-01
branch: #578