Skip to content

Commit 2d123d0

Browse files
committed
Fix LTO tests
FIXME: we now have fat LTO objects even when only bitcode is requested.
1 parent fc2eee5 commit 2d123d0

File tree

8 files changed

+21
-33
lines changed

8 files changed

+21
-33
lines changed

.github/workflows/release.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
- name: Build
5454
run: |
5555
./y.sh prepare --only-libcore
56-
EMBED_LTO_BITCODE=1 ./y.sh build --sysroot --release --release-sysroot
56+
./y.sh build --sysroot --release --release-sysroot
5757
cargo test
5858
./y.sh clean all
5959
@@ -70,4 +70,4 @@ jobs:
7070
run: |
7171
# FIXME(antoyo): we cannot enable LTO for stdarch tests currently because of some failing LTO tests using proc-macros.
7272
echo -n 'lto = "fat"' >> build_system/build_sysroot/Cargo.toml
73-
EMBED_LTO_BITCODE=1 ./y.sh test --release --clean --release-sysroot --build-sysroot ${{ matrix.commands }}
73+
./y.sh test --release --clean --release-sysroot --build-sysroot ${{ matrix.commands }}

Readme.md

-11
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,6 @@ $ CHANNEL="release" $CG_GCCJIT_DIR/y.sh cargo run
119119

120120
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.
121121

122-
### LTO
123-
124-
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`.
125-
Don't set `FAT_LTO` when compiling the sysroot, though: only set `EMBED_LTO_BITCODE=1`.
126-
127-
Failing to set `EMBED_LTO_BITCODE` will give you the following error:
128-
129-
```
130-
error: failed to copy bitcode to object file: No such file or directory (os error 2)
131-
```
132-
133122
### Rustc
134123

135124
If you want to run `rustc` directly, you can do so with:

build_system/src/config.rs

-6
Original file line numberDiff line numberDiff line change
@@ -387,12 +387,6 @@ impl ConfigInfo {
387387
rustflags.push("-Csymbol-mangling-version=v0".to_string());
388388
}
389389

390-
// Since we don't support ThinLTO, disable LTO completely when not trying to do LTO.
391-
// TODO(antoyo): remove when we can handle ThinLTO.
392-
// TODO: remove:
393-
/*if !env.contains_key(&"FAT_LTO".to_string()) {
394-
rustflags.push("-Clto=off".to_string());
395-
}*/
396390
// FIXME(antoyo): remove once the atomic shim is gone
397391
if os_name == "Darwin" {
398392
rustflags.extend_from_slice(&[

src/back/lto.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ fn fat_lto(
307307
match bc_decoded {
308308
SerializedModule::Local(ref module_buffer) => {
309309
module.module_llvm.should_combine_object_files = true;
310+
module.module_llvm.fat_lto = true;
310311
module
311312
.module_llvm
312313
.context
@@ -489,7 +490,6 @@ fn thin_lto(
489490
//let path = module_buffer.0.to_str().expect("path");
490491
//let my_path = PathBuf::from(path);
491492
//let exists = my_path.exists();
492-
//println!("Path: {:?}: {}", path, exists);
493493
/*module.module_llvm.should_combine_object_files = true;
494494
module
495495
.module_llvm
@@ -626,11 +626,6 @@ pub unsafe fn optimize_thin_module(
626626
match *module {
627627
SerializedModule::Local(ref module_buffer) => {
628628
let path = module_buffer.0.to_str().expect("path");
629-
630-
//let my_path = PathBuf::from(path);
631-
//let exists = my_path.exists();
632-
//println!("Path2: {:?}: {}", path, exists);
633-
634629
context.add_driver_option(path);
635630
should_combine_object_files = true;
636631
/*module.module_llvm.should_combine_object_files = true;
@@ -648,7 +643,12 @@ pub unsafe fn optimize_thin_module(
648643
}
649644
};
650645
let module = ModuleCodegen {
651-
module_llvm: GccContext { context, should_combine_object_files, temp_dir: None },
646+
module_llvm: GccContext {
647+
context,
648+
should_combine_object_files,
649+
fat_lto: false,
650+
temp_dir: None,
651+
},
652652
name: thin_module.name().to_string(),
653653
kind: ModuleKind::Regular,
654654
};

src/back/write.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ pub(crate) unsafe fn codegen(
3232
// NOTE: Only generate object files with GIMPLE when this environment variable is set for
3333
// now because this requires a particular setup (same gcc/lto1/lto-wrapper commit as libgccjit).
3434
// TODO: remove this environment variable.
35-
let fat_lto = env::var("EMBED_LTO_BITCODE").as_deref() == Ok("1");
35+
let fat_lto = module.module_llvm.fat_lto;
3636

3737
let bc_out = cgcx.output_filenames.temp_path(OutputType::Bitcode, module_name);
3838
let obj_out = cgcx.output_filenames.temp_path(OutputType::Object, module_name);
3939

40-
if config.bitcode_needed() && fat_lto {
40+
if config.bitcode_needed() {
4141
let _timer = cgcx
4242
.prof
4343
.generic_activity_with_arg("GCC_module_codegen_make_bitcode", &*module.name);
@@ -57,6 +57,8 @@ pub(crate) unsafe fn codegen(
5757
.generic_activity_with_arg("GCC_module_codegen_emit_bitcode", &*module.name);
5858
context.add_command_line_option("-flto=auto");
5959
context.add_command_line_option("-flto-partition=one");
60+
// TODO: remove since we don't want fat objects when it is for Bitcode only.
61+
context.add_command_line_option("-ffat-lto-objects");
6062
context
6163
.compile_to_file(OutputKind::ObjectFile, bc_out.to_str().expect("path to str"));
6264
}
@@ -118,12 +120,12 @@ pub(crate) unsafe fn codegen(
118120
if fat_lto {
119121
context.add_command_line_option("-flto=auto");
120122
context.add_command_line_option("-flto-partition=one");
121-
122-
// NOTE: without -fuse-linker-plugin, we get the following error:
123-
// lto1: internal compiler error: decompressed stream: Destination buffer is too small
124-
context.add_driver_option("-fuse-linker-plugin");
125123
}
126124

125+
// NOTE: without -fuse-linker-plugin, we get the following error:
126+
// lto1: internal compiler error: decompressed stream: Destination buffer is too small
127+
//context.add_driver_option("-fuse-linker-plugin");
128+
127129
context.add_driver_option("-Wl,-r");
128130
// NOTE: we need -nostdlib, otherwise, we get the following error:
129131
// /usr/bin/ld: cannot find -lgcc_s: No such file or directory
@@ -135,7 +137,6 @@ pub(crate) unsafe fn codegen(
135137
obj_out.to_str().expect("path to str"),
136138
);
137139
} else {
138-
//println!("Combining to object file");
139140
context.compile_to_file(
140141
OutputKind::ObjectFile,
141142
obj_out.to_str().expect("path to str"),

src/base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ pub fn compile_codegen_unit(
225225
name: cgu_name.to_string(),
226226
module_llvm: GccContext {
227227
context: Arc::new(SyncContext::new(context)),
228+
fat_lto: false,
228229
should_combine_object_files: false,
229230
temp_dir: None,
230231
},

src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ impl ExtraBackendMethods for GccCodegenBackend {
304304
) -> Self::Module {
305305
let mut mods = GccContext {
306306
context: Arc::new(SyncContext::new(new_context(tcx))),
307+
fat_lto: false,
307308
should_combine_object_files: false,
308309
temp_dir: None,
309310
};
@@ -336,6 +337,7 @@ impl ExtraBackendMethods for GccCodegenBackend {
336337
pub struct GccContext {
337338
context: Arc<SyncContext>,
338339
should_combine_object_files: bool,
340+
fat_lto: bool,
339341
// Temporary directory used by LTO. We keep it here so that it's not removed before linking.
340342
temp_dir: Option<TempDir>,
341343
}

tests/failing-ui-tests.txt

+1
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,4 @@ tests/ui/consts/const-eval/parse_ints.rs
9494
tests/ui/simd/intrinsic/generic-arithmetic-pass.rs
9595
tests/ui/backtrace/backtrace.rs
9696
tests/ui/lifetimes/tail-expr-lock-poisoning.rs
97+
tests/ui/runtime/rt-explody-panic-payloads.rs

0 commit comments

Comments
 (0)