Fix LTO tests

FIXME: we now have fat LTO objects even when only bitcode is requested.
This commit is contained in:
Antoni Boucher 2024-07-05 10:42:03 -04:00
parent fc2eee58d2
commit 2d123d08c9
8 changed files with 21 additions and 33 deletions

View File

@ -53,7 +53,7 @@ jobs:
- name: Build - name: Build
run: | run: |
./y.sh prepare --only-libcore ./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 cargo test
./y.sh clean all ./y.sh clean all
@ -70,4 +70,4 @@ jobs:
run: | run: |
# FIXME(antoyo): we cannot enable LTO for stdarch tests currently because of some failing LTO tests using proc-macros. # 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 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 }}

View File

@ -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. 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 ### Rustc
If you want to run `rustc` directly, you can do so with: If you want to run `rustc` directly, you can do so with:

View File

@ -387,12 +387,6 @@ pub fn setup(
rustflags.push("-Csymbol-mangling-version=v0".to_string()); 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 // FIXME(antoyo): remove once the atomic shim is gone
if os_name == "Darwin" { if os_name == "Darwin" {
rustflags.extend_from_slice(&[ rustflags.extend_from_slice(&[

View File

@ -307,6 +307,7 @@ fn fat_lto(
match bc_decoded { match bc_decoded {
SerializedModule::Local(ref module_buffer) => { SerializedModule::Local(ref module_buffer) => {
module.module_llvm.should_combine_object_files = true; module.module_llvm.should_combine_object_files = true;
module.module_llvm.fat_lto = true;
module module
.module_llvm .module_llvm
.context .context
@ -489,7 +490,6 @@ fn thin_lto(
//let path = module_buffer.0.to_str().expect("path"); //let path = module_buffer.0.to_str().expect("path");
//let my_path = PathBuf::from(path); //let my_path = PathBuf::from(path);
//let exists = my_path.exists(); //let exists = my_path.exists();
//println!("Path: {:?}: {}", path, exists);
/*module.module_llvm.should_combine_object_files = true; /*module.module_llvm.should_combine_object_files = true;
module module
.module_llvm .module_llvm
@ -626,11 +626,6 @@ pub unsafe fn optimize_thin_module(
match *module { match *module {
SerializedModule::Local(ref module_buffer) => { SerializedModule::Local(ref module_buffer) => {
let path = module_buffer.0.to_str().expect("path"); 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); context.add_driver_option(path);
should_combine_object_files = true; should_combine_object_files = true;
/*module.module_llvm.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 { 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(), name: thin_module.name().to_string(),
kind: ModuleKind::Regular, kind: ModuleKind::Regular,
}; };

View File

@ -32,12 +32,12 @@ pub(crate) unsafe fn codegen(
// NOTE: Only generate object files with GIMPLE when this environment variable is set for // 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). // now because this requires a particular setup (same gcc/lto1/lto-wrapper commit as libgccjit).
// TODO: remove this environment variable. // 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 bc_out = cgcx.output_filenames.temp_path(OutputType::Bitcode, module_name);
let obj_out = cgcx.output_filenames.temp_path(OutputType::Object, 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 let _timer = cgcx
.prof .prof
.generic_activity_with_arg("GCC_module_codegen_make_bitcode", &*module.name); .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); .generic_activity_with_arg("GCC_module_codegen_emit_bitcode", &*module.name);
context.add_command_line_option("-flto=auto"); context.add_command_line_option("-flto=auto");
context.add_command_line_option("-flto-partition=one"); 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 context
.compile_to_file(OutputKind::ObjectFile, bc_out.to_str().expect("path to str")); .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 { if fat_lto {
context.add_command_line_option("-flto=auto"); context.add_command_line_option("-flto=auto");
context.add_command_line_option("-flto-partition=one"); 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"); context.add_driver_option("-Wl,-r");
// NOTE: we need -nostdlib, otherwise, we get the following error: // NOTE: we need -nostdlib, otherwise, we get the following error:
// /usr/bin/ld: cannot find -lgcc_s: No such file or directory // /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"), obj_out.to_str().expect("path to str"),
); );
} else { } else {
//println!("Combining to object file");
context.compile_to_file( context.compile_to_file(
OutputKind::ObjectFile, OutputKind::ObjectFile,
obj_out.to_str().expect("path to str"), obj_out.to_str().expect("path to str"),

View File

@ -225,6 +225,7 @@ fn module_codegen(
name: cgu_name.to_string(), name: cgu_name.to_string(),
module_llvm: GccContext { module_llvm: GccContext {
context: Arc::new(SyncContext::new(context)), context: Arc::new(SyncContext::new(context)),
fat_lto: false,
should_combine_object_files: false, should_combine_object_files: false,
temp_dir: None, temp_dir: None,
}, },

View File

@ -304,6 +304,7 @@ fn codegen_allocator(
) -> Self::Module { ) -> Self::Module {
let mut mods = GccContext { let mut mods = GccContext {
context: Arc::new(SyncContext::new(new_context(tcx))), context: Arc::new(SyncContext::new(new_context(tcx))),
fat_lto: false,
should_combine_object_files: false, should_combine_object_files: false,
temp_dir: None, temp_dir: None,
}; };
@ -336,6 +337,7 @@ fn target_machine_factory(
pub struct GccContext { pub struct GccContext {
context: Arc<SyncContext>, context: Arc<SyncContext>,
should_combine_object_files: bool, 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. // Temporary directory used by LTO. We keep it here so that it's not removed before linking.
temp_dir: Option<TempDir>, temp_dir: Option<TempDir>,
} }

View File

@ -94,3 +94,4 @@ tests/ui/consts/const-eval/parse_ints.rs
tests/ui/simd/intrinsic/generic-arithmetic-pass.rs tests/ui/simd/intrinsic/generic-arithmetic-pass.rs
tests/ui/backtrace/backtrace.rs tests/ui/backtrace/backtrace.rs
tests/ui/lifetimes/tail-expr-lock-poisoning.rs tests/ui/lifetimes/tail-expr-lock-poisoning.rs
tests/ui/runtime/rt-explody-panic-payloads.rs