diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d5242926eb4..f0b1212986d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -53,7 +53,7 @@ jobs: - name: Build run: | ./y.sh prepare --only-libcore - EMBED_LTO_BITCODE=1 ./y.sh build --sysroot --release --release-sysroot + ./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 - EMBED_LTO_BITCODE=1 ./y.sh test --release --clean --release-sysroot --build-sysroot ${{ matrix.commands }} + ./y.sh test --release --clean --release-sysroot --build-sysroot ${{ matrix.commands }} diff --git a/Readme.md b/Readme.md index bd552b84f92..d0b57d2c729 100644 --- a/Readme.md +++ b/Readme.md @@ -119,17 +119,6 @@ $ 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 30321939f64..965aedd8be8 100644 --- a/build_system/src/config.rs +++ b/build_system/src/config.rs @@ -387,12 +387,6 @@ 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 19573628b1b..88eff198739 100644 --- a/src/back/lto.rs +++ b/src/back/lto.rs @@ -307,6 +307,7 @@ 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 @@ -489,7 +490,6 @@ 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,11 +626,6 @@ 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; @@ -648,7 +643,12 @@ pub unsafe fn optimize_thin_module( } }; let module = ModuleCodegen { - module_llvm: GccContext { context, should_combine_object_files, temp_dir: None }, + module_llvm: GccContext { + context, + should_combine_object_files, + fat_lto: false, + 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 b9bb62a0351..8922e7e742b 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 = env::var("EMBED_LTO_BITCODE").as_deref() == Ok("1"); + let fat_lto = module.module_llvm.fat_lto; 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() && fat_lto { + if config.bitcode_needed() { let _timer = cgcx .prof .generic_activity_with_arg("GCC_module_codegen_make_bitcode", &*module.name); @@ -57,6 +57,8 @@ 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")); } @@ -118,12 +120,12 @@ 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: // /usr/bin/ld: cannot find -lgcc_s: No such file or directory @@ -135,7 +137,6 @@ 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 be149ffe5a1..0287c73569a 100644 --- a/src/base.rs +++ b/src/base.rs @@ -225,6 +225,7 @@ 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 1132b0cd2f5..123cebf5137 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -304,6 +304,7 @@ 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, }; @@ -336,6 +337,7 @@ 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 ce867be7390..5a55bdb156e 100644 --- a/tests/failing-ui-tests.txt +++ b/tests/failing-ui-tests.txt @@ -94,3 +94,4 @@ 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