Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: improve linker script and target settings #21

Merged
merged 4 commits into from
Nov 7, 2019

Conversation

josephlr
Copy link
Contributor

@josephlr josephlr commented Nov 6, 2019

This change is a few small fixes to target.json and layout.ld

  • Set stripping in layout.ld
    • Fixes my mistake from Update toolchain, improve linker script, and reduce binary size. #20
    • We already set linking flags in layout.ld, we shouldn't also be setting them in a second place.
    • I updated the comments to explain why we can also do this for panic = "abort"
      • Without setting the default target to be target.json, cargo check and cargo clippy will break when building for the host target.
  • Merge .bss into .data
    • This .bss section normally represents "uninitialized/zero" data that will later be written by the program. Generally this means it has a runtime memory area, but no corresponding data in the output binary. The program header just says where to load it.
    • To make the loader's job easier (including the custom loader we will need for Support building as flat BIOS image #5), we put the .bss section in .data. This now puts explicitly zeroed data in .data instead of relying on the loader to "expand" the .bss data at runtime.
    • EDK2 uses a similar trick
    • This doesn't currently have an effect on binary size, as ld.ldd (unlike the gnutools ld) just directly zeros the .bss region in the file. However, this isn't a stable behavior to rely on.
  • Set more parameters in target.json
    • As we're building a firmware, we have no need for Rust's (on by default) Position Independent Code (PIC). This is controlled by the relocation-mode option.
    • We also explicitly set code-model and dynamic-linking-available to make our linking assumptions clear.
    • This makes the binary a little smaller and a little faster, but the main reason to do this is to making linking simpler.

Signed-off-by: Joe Richey [email protected]

@josephlr josephlr force-pushed the master branch 2 times, most recently from 09d9ec8 to ef5f1c9 Compare November 6, 2019 19:56
We should only be setting linker flags in one place.

Signed-off-by: Joe Richey <[email protected]>
Also, explain why we still need
  panic = "abort"
in the Cargo.toml

Signed-off-by: Joe Richey <[email protected]>
This moves the .bss section from "uninitialized" memory that gets
allocated by the loader to explictily zeroed memory in the .data
section.

This makes the loader's job much easier, as it can just map the file in
one contiguous section of memory. Before, it would have to "expand" the
.bss section.

Signed-off-by: Joe Richey <[email protected]>
A firmware blob is an _extermely_ static binary, and our `target.json`
settings should reflect this. It also saves us some code size to use a
"static" relocation model.

Signed-off-by: Joe Richey <[email protected]>
@josephlr josephlr changed the title build: Use target.json to control linking build: improve linker script and target settings Nov 7, 2019
@rbradford rbradford merged commit 158a56a into cloud-hypervisor:master Nov 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants