Skip to content

Commit bc8520d

Browse files
committed
Revert "Fix LTO tests"
This reverts commit 2d123d0.
1 parent 2d123d0 commit bc8520d

File tree

8 files changed

+33
-21
lines changed

8 files changed

+33
-21
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-
./y.sh build --sysroot --release --release-sysroot
56+
EMBED_LTO_BITCODE=1 ./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-
./y.sh test --release --clean --release-sysroot --build-sysroot ${{ matrix.commands }}
73+
EMBED_LTO_BITCODE=1 ./y.sh test --release --clean --release-sysroot --build-sysroot ${{ matrix.commands }}

Readme.md

+11
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,17 @@ $ 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+
122133
### Rustc
123134

124135
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,6 +387,12 @@ 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+
}*/
390396
// FIXME(antoyo): remove once the atomic shim is gone
391397
if os_name == "Darwin" {
392398
rustflags.extend_from_slice(&[

src/back/lto.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ 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;
311310
module
312311
.module_llvm
313312
.context
@@ -490,6 +489,7 @@ fn thin_lto(
490489
//let path = module_buffer.0.to_str().expect("path");
491490
//let my_path = PathBuf::from(path);
492491
//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,6 +626,11 @@ 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+
629634
context.add_driver_option(path);
630635
should_combine_object_files = true;
631636
/*module.module_llvm.should_combine_object_files = true;
@@ -643,12 +648,7 @@ pub unsafe fn optimize_thin_module(
643648
}
644649
};
645650
let module = ModuleCodegen {
646-
module_llvm: GccContext {
647-
context,
648-
should_combine_object_files,
649-
fat_lto: false,
650-
temp_dir: None,
651-
},
651+
module_llvm: GccContext { context, should_combine_object_files, temp_dir: None },
652652
name: thin_module.name().to_string(),
653653
kind: ModuleKind::Regular,
654654
};

src/back/write.rs

+7-8
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 = module.module_llvm.fat_lto;
35+
let fat_lto = env::var("EMBED_LTO_BITCODE").as_deref() == Ok("1");
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() {
40+
if config.bitcode_needed() && fat_lto {
4141
let _timer = cgcx
4242
.prof
4343
.generic_activity_with_arg("GCC_module_codegen_make_bitcode", &*module.name);
@@ -57,8 +57,6 @@ 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");
6260
context
6361
.compile_to_file(OutputKind::ObjectFile, bc_out.to_str().expect("path to str"));
6462
}
@@ -120,11 +118,11 @@ pub(crate) unsafe fn codegen(
120118
if fat_lto {
121119
context.add_command_line_option("-flto=auto");
122120
context.add_command_line_option("-flto-partition=one");
123-
}
124121

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");
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");
125+
}
128126

129127
context.add_driver_option("-Wl,-r");
130128
// NOTE: we need -nostdlib, otherwise, we get the following error:
@@ -137,6 +135,7 @@ pub(crate) unsafe fn codegen(
137135
obj_out.to_str().expect("path to str"),
138136
);
139137
} else {
138+
//println!("Combining to object file");
140139
context.compile_to_file(
141140
OutputKind::ObjectFile,
142141
obj_out.to_str().expect("path to str"),

src/base.rs

-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ 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,
229228
should_combine_object_files: false,
230229
temp_dir: None,
231230
},

src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ 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,
308307
should_combine_object_files: false,
309308
temp_dir: None,
310309
};
@@ -337,7 +336,6 @@ impl ExtraBackendMethods for GccCodegenBackend {
337336
pub struct GccContext {
338337
context: Arc<SyncContext>,
339338
should_combine_object_files: bool,
340-
fat_lto: bool,
341339
// Temporary directory used by LTO. We keep it here so that it's not removed before linking.
342340
temp_dir: Option<TempDir>,
343341
}

tests/failing-ui-tests.txt

-1
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,3 @@ 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)