Skip to content

Commit

Permalink
set optimizations only for td-shim and td-payload crates
Browse files Browse the repository at this point in the history
Binary size is not critical for tools so we can move the profile from
root of workspace to the folder of crates.

As profile overridden only takes effective under the crates' directory,
we need to switch to the directory before compiling the crates.

Signed-off-by: Jiaqi Gao <[email protected]>
  • Loading branch information
gaojiaqi7 committed Sep 12, 2023
1 parent 34b31e3 commit e2c4b24
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
11 changes: 0 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,5 @@ members = [
"xtask",
]

# the profile used for `cargo build`
[profile.dev]
panic = "abort" # disable stack unwinding on panic
opt-level = "z"
lto = true

# the profile used for `cargo build --release`
[profile.release]
panic = "abort" # disable stack unwinding on panic
lto = true # Link-time optimization

[patch.crates-io]
ring = { path = "library/ring" }
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,26 @@ cargo image --example-payload --release
Build TdShim to launch a payload support Linux Boot Protocol

```
cd td-shim
cargo xbuild -p td-shim --target x86_64-unknown-none --release --features=main,tdx
cd ..
cargo run -p td-shim-tools --bin td-shim-ld --features=linker -- target/x86_64-unknown-none/release/ResetVector.bin target/x86_64-unknown-none/release/td-shim -o target/release/final.bin
```

Build TdShim to launch a executable payload

```
cd td-shim
cargo xbuild -p td-shim --target x86_64-unknown-none --release --features=main,tdx --no-default-features
cd ..
```

Build Elf format payload

```
cd td-payload
cargo xbuild -p td-payload --target x86_64-unknown-none --release --bin example --features=tdx,start,cet-shstk,stack-guard
cd ..
cargo run -p td-shim-tools --bin td-shim-ld -- target/x86_64-unknown-none/release/ResetVector.bin target/x86_64-unknown-none/release/td-shim -t executable -p target/x86_64-unknown-none/release/example -o target/release/final-elf.bin
```

Expand Down
10 changes: 10 additions & 0 deletions td-payload/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# the profile used for `cargo build`
[profile.dev]
panic = "abort" # disable stack unwinding on panic
opt-level = "z"
lto = true

# the profile used for `cargo build --release`
[profile.release]
panic = "abort" # disable stack unwinding on panic
lto = true # Link-time optimization
10 changes: 10 additions & 0 deletions td-shim/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# the profile used for `cargo build`
[profile.dev]
panic = "abort" # disable stack unwinding on panic
opt-level = "z"
lto = true

# the profile used for `cargo build --release`
[profile.release]
panic = "abort" # disable stack unwinding on panic
lto = true # Link-time optimization
6 changes: 6 additions & 0 deletions xtask/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ impl BuildArgs {
self.build_shim_layout()?;

let sh = Shell::new()?;
// Switch to the crate folder to use profile of crate rather than workspace
sh.change_dir(PROJECT_ROOT.join("td-shim"));

cmd!(
sh,
"cargo xbuild -p td-shim --target x86_64-unknown-none --no-default-features"
Expand All @@ -135,6 +138,9 @@ impl BuildArgs {

fn build_example_payload(&self) -> Result<PathBuf> {
let sh = Shell::new()?;
// Switch to the crate folder to use profile of crate rather than workspace
sh.change_dir(PROJECT_ROOT.join("td-payload"));

cmd!(
sh,
"cargo xbuild -p td-payload --bin example --target x86_64-unknown-none"
Expand Down

0 comments on commit e2c4b24

Please sign in to comment.