Skip to content

Commit 518c14e

Browse files
committed
Implement codegen half of LTO
1 parent 2f59205 commit 518c14e

File tree

7 files changed

+290
-88
lines changed

7 files changed

+290
-88
lines changed

build_system/build_sysroot.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ fn build_clif_sysroot_for_triple(
267267
prefix.to_str().unwrap()
268268
));
269269
}
270+
rustflags.push("-Clto=thin".to_owned());
271+
rustflags.push("-Zdylib-lto".to_owned());
272+
rustflags.push("-Cembed-bitcode=yes".to_owned());
270273
compiler.rustflags.extend(rustflags);
271274
let mut build_cmd = STANDARD_LIBRARY.build(&compiler, dirs);
272275
if channel == "release" {

build_system/prepare.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ codegen-units = 10000
4545
debug-assertions = false
4646
overflow-checks = false
4747
codegen-units = 10000
48+
49+
[profile.dev]
50+
lto = "thin"
51+
52+
[profile.release]
53+
lto = "thin"
4854
"#,
4955
)
5056
.unwrap();

build_system/tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl TestCase {
5959
}
6060

6161
const NO_SYSROOT_SUITE: &[TestCase] = &[
62-
TestCase::build_lib("build.mini_core", "example/mini_core.rs", "lib,dylib"),
62+
TestCase::build_lib("build.mini_core", "example/mini_core.rs", "lib"),
6363
TestCase::build_lib("build.example", "example/example.rs", "lib"),
6464
TestCase::jit_bin("jit.mini_core_hello_world", "example/mini_core_hello_world.rs", "abc bcd"),
6565
TestCase::build_bin_and_run(
@@ -468,6 +468,7 @@ impl<'a> TestRunner<'a> {
468468
cmd.arg("--out-dir");
469469
cmd.arg(format!("{}", BUILD_EXAMPLE_OUT_DIR.to_path(&self.dirs).display()));
470470
cmd.arg("-Cdebuginfo=2");
471+
cmd.arg("-Clto=thin");
471472
cmd.arg("--target");
472473
cmd.arg(&self.target_compiler.triple);
473474
cmd.arg("-Cpanic=abort");
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
From 0910cbe862990b0c3a17c67bca199ebb4452b0ec Mon Sep 17 00:00:00 2001
2+
From: bjorn3 <17426603+bjorn3@users.noreply.github.com>
3+
Date: Tue, 28 Mar 2023 17:09:01 +0000
4+
Subject: [PATCH] Disable dylib crate type
5+
6+
---
7+
library/std/Cargo.toml | 2 +-
8+
1 files changed, 1 insertions(+), 1 deletions(-)
9+
10+
diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml
11+
index 598a4bf..3e68680 100644
12+
--- a/library/std/Cargo.toml
13+
+++ b/library/std/Cargo.toml
14+
@@ -7,7 +7,7 @@ description = "The Rust Standard Library"
15+
edition = "2021"
16+
17+
[lib]
18+
-crate-type = ["dylib", "rlib"]
19+
+crate-type = ["rlib"]
20+
21+
[dependencies]
22+
alloc = { path = "../alloc", public = true }
23+
--
24+
2.34.1
25+

src/driver/aot.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,13 +323,13 @@ fn produce_final_output_artifacts(
323323
// These are used in linking steps and will be cleaned up afterward.
324324
}
325325

326-
struct AOTModule {
327-
aot_module: ObjectModule,
328-
unwind_context: UnwindContext,
326+
pub(super) struct AOTModule {
327+
pub(super) aot_module: ObjectModule,
328+
pub(super) unwind_context: UnwindContext,
329329
}
330330

331331
impl AOTModule {
332-
fn finish(self) -> ObjectProduct {
332+
pub(super) fn finish(self) -> ObjectProduct {
333333
let mut product = self.aot_module.finish();
334334
self.unwind_context.emit(&mut product);
335335
product

0 commit comments

Comments
 (0)