From bc8520d98eb59563be09ca8772501b26a2a58ed9 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Fri, 5 Jul 2024 11:35:16 -0400 Subject: [PATCH] Revert "Fix LTO tests" This reverts commit 2d123d08c98419261bddec8f3ad8b80cadb82515. --- .github/workflows/release.yml | 4 ++-- Readme.md | 11 +++++++++++ build_system/src/config.rs | 6 ++++++ src/back/lto.rs | 14 +++++++------- src/back/write.rs | 15 +++++++-------- src/base.rs | 1 - src/lib.rs | 2 -- tests/failing-ui-tests.txt | 1 - 8 files changed, 33 insertions(+), 21 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f0b1212986d..d5242926eb4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -53,7 +53,7 @@ jobs: - name: Build run: | ./y.sh prepare --only-libcore - ./y.sh build --sysroot --release --release-sysroot + EMBED_LTO_BITCODE=1 ./y.sh build --sysroot --release --release-sysroot cargo test ./y.sh clean all @@ -70,4 +70,4 @@ jobs: run: | # FIXME(antoyo): we cannot enable LTO for stdarch tests currently because of some failing LTO tests using proc-macros. echo -n 'lto = "fat"' >> build_system/build_sysroot/Cargo.toml - ./y.sh test --release --clean --release-sysroot --build-sysroot ${{ matrix.commands }} + EMBED_LTO_BITCODE=1 ./y.sh test --release --clean --release-sysroot --build-sysroot ${{ matrix.commands }} diff --git a/Readme.md b/Readme.md index d0b57d2c729..bd552b84f92 100644 --- a/Readme.md +++ b/Readme.md @@ -119,6 +119,17 @@ $ CHANNEL="release" $CG_GCCJIT_DIR/y.sh cargo run If you compiled cg_gccjit in debug mode (aka you didn't pass `--release` to `./y.sh test`) you should use `CHANNEL="debug"` instead or omit `CHANNEL="release"` completely. +### LTO + +To use LTO, you need to set the variable `FAT_LTO=1` and `EMBED_LTO_BITCODE=1` in addition to setting `lto = "fat"` in the `Cargo.toml`. +Don't set `FAT_LTO` when compiling the sysroot, though: only set `EMBED_LTO_BITCODE=1`. + +Failing to set `EMBED_LTO_BITCODE` will give you the following error: + +``` +error: failed to copy bitcode to object file: No such file or directory (os error 2) +``` + ### Rustc If you want to run `rustc` directly, you can do so with: diff --git a/build_system/src/config.rs b/build_system/src/config.rs index 965aedd8be8..30321939f64 100644 --- a/build_system/src/config.rs +++ b/build_system/src/config.rs @@ -387,6 +387,12 @@ pub fn setup( rustflags.push("-Csymbol-mangling-version=v0".to_string()); } + // Since we don't support ThinLTO, disable LTO completely when not trying to do LTO. + // TODO(antoyo): remove when we can handle ThinLTO. + // TODO: remove: + /*if !env.contains_key(&"FAT_LTO".to_string()) { + rustflags.push("-Clto=off".to_string()); + }*/ // FIXME(antoyo): remove once the atomic shim is gone if os_name == "Darwin" { rustflags.extend_from_slice(&[ diff --git a/src/back/lto.rs b/src/back/lto.rs index 88eff198739..19573628b1b 100644 --- a/src/back/lto.rs +++ b/src/back/lto.rs @@ -307,7 +307,6 @@ fn fat_lto( match bc_decoded { SerializedModule::Local(ref module_buffer) => { module.module_llvm.should_combine_object_files = true; - module.module_llvm.fat_lto = true; module .module_llvm .context @@ -490,6 +489,7 @@ fn thin_lto( //let path = module_buffer.0.to_str().expect("path"); //let my_path = PathBuf::from(path); //let exists = my_path.exists(); + //println!("Path: {:?}: {}", path, exists); /*module.module_llvm.should_combine_object_files = true; module .module_llvm @@ -626,6 +626,11 @@ pub unsafe fn optimize_thin_module( match *module { SerializedModule::Local(ref module_buffer) => { let path = module_buffer.0.to_str().expect("path"); + + //let my_path = PathBuf::from(path); + //let exists = my_path.exists(); + //println!("Path2: {:?}: {}", path, exists); + context.add_driver_option(path); should_combine_object_files = true; /*module.module_llvm.should_combine_object_files = true; @@ -643,12 +648,7 @@ pub unsafe fn optimize_thin_module( } }; let module = ModuleCodegen { - module_llvm: GccContext { - context, - should_combine_object_files, - fat_lto: false, - temp_dir: None, - }, + module_llvm: GccContext { context, should_combine_object_files, temp_dir: None }, name: thin_module.name().to_string(), kind: ModuleKind::Regular, }; diff --git a/src/back/write.rs b/src/back/write.rs index 8922e7e742b..b9bb62a0351 100644 --- a/src/back/write.rs +++ b/src/back/write.rs @@ -32,12 +32,12 @@ pub(crate) unsafe fn codegen( // NOTE: Only generate object files with GIMPLE when this environment variable is set for // now because this requires a particular setup (same gcc/lto1/lto-wrapper commit as libgccjit). // TODO: remove this environment variable. - let fat_lto = module.module_llvm.fat_lto; + let fat_lto = env::var("EMBED_LTO_BITCODE").as_deref() == Ok("1"); let bc_out = cgcx.output_filenames.temp_path(OutputType::Bitcode, module_name); let obj_out = cgcx.output_filenames.temp_path(OutputType::Object, module_name); - if config.bitcode_needed() { + if config.bitcode_needed() && fat_lto { let _timer = cgcx .prof .generic_activity_with_arg("GCC_module_codegen_make_bitcode", &*module.name); @@ -57,8 +57,6 @@ pub(crate) unsafe fn codegen( .generic_activity_with_arg("GCC_module_codegen_emit_bitcode", &*module.name); context.add_command_line_option("-flto=auto"); context.add_command_line_option("-flto-partition=one"); - // TODO: remove since we don't want fat objects when it is for Bitcode only. - context.add_command_line_option("-ffat-lto-objects"); context .compile_to_file(OutputKind::ObjectFile, bc_out.to_str().expect("path to str")); } @@ -120,11 +118,11 @@ pub(crate) unsafe fn codegen( if fat_lto { context.add_command_line_option("-flto=auto"); context.add_command_line_option("-flto-partition=one"); - } - // NOTE: without -fuse-linker-plugin, we get the following error: - // lto1: internal compiler error: decompressed stream: Destination buffer is too small - //context.add_driver_option("-fuse-linker-plugin"); + // NOTE: without -fuse-linker-plugin, we get the following error: + // lto1: internal compiler error: decompressed stream: Destination buffer is too small + context.add_driver_option("-fuse-linker-plugin"); + } context.add_driver_option("-Wl,-r"); // NOTE: we need -nostdlib, otherwise, we get the following error: @@ -137,6 +135,7 @@ pub(crate) unsafe fn codegen( obj_out.to_str().expect("path to str"), ); } else { + //println!("Combining to object file"); context.compile_to_file( OutputKind::ObjectFile, obj_out.to_str().expect("path to str"), diff --git a/src/base.rs b/src/base.rs index 0287c73569a..be149ffe5a1 100644 --- a/src/base.rs +++ b/src/base.rs @@ -225,7 +225,6 @@ fn module_codegen( name: cgu_name.to_string(), module_llvm: GccContext { context: Arc::new(SyncContext::new(context)), - fat_lto: false, should_combine_object_files: false, temp_dir: None, }, diff --git a/src/lib.rs b/src/lib.rs index 123cebf5137..1132b0cd2f5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -304,7 +304,6 @@ fn codegen_allocator( ) -> Self::Module { let mut mods = GccContext { context: Arc::new(SyncContext::new(new_context(tcx))), - fat_lto: false, should_combine_object_files: false, temp_dir: None, }; @@ -337,7 +336,6 @@ fn target_machine_factory( pub struct GccContext { context: Arc, should_combine_object_files: bool, - fat_lto: bool, // Temporary directory used by LTO. We keep it here so that it's not removed before linking. temp_dir: Option, } diff --git a/tests/failing-ui-tests.txt b/tests/failing-ui-tests.txt index 5a55bdb156e..ce867be7390 100644 --- a/tests/failing-ui-tests.txt +++ b/tests/failing-ui-tests.txt @@ -94,4 +94,3 @@ tests/ui/consts/const-eval/parse_ints.rs tests/ui/simd/intrinsic/generic-arithmetic-pass.rs tests/ui/backtrace/backtrace.rs tests/ui/lifetimes/tail-expr-lock-poisoning.rs -tests/ui/runtime/rt-explody-panic-payloads.rs