Skip to content

Commit 2fd3589

Browse files
committed
remove EMBED_LTO_BITCODE
1 parent f2caa52 commit 2fd3589

File tree

6 files changed

+23
-149
lines changed

6 files changed

+23
-149
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
- name: Build
6363
run: |
6464
./y.sh prepare --only-libcore
65-
EMBED_LTO_BITCODE=1 ./y.sh build --sysroot --release --release-sysroot
65+
./y.sh build --sysroot --release --release-sysroot
6666
./y.sh test --cargo-tests
6767
./y.sh clean all
6868
@@ -77,14 +77,12 @@ jobs:
7777

7878
- name: Run tests
7979
run: |
80-
# FIXME(antoyo): we cannot enable LTO for stdarch tests currently because of some failing LTO tests using proc-macros.
81-
# FIXME(antoyo): this should probably not be needed since we embed the LTO bitcode.
8280
printf '[profile.release]\nlto = "fat"\n' >> build/build_sysroot/sysroot_src/library/Cargo.toml
83-
EMBED_LTO_BITCODE=1 ./y.sh test --release --clean --release-sysroot --build-sysroot --keep-lto-tests ${{ matrix.commands }}
81+
./y.sh test --release --clean --release-sysroot --build-sysroot --keep-lto-tests ${{ matrix.commands }}
8482
8583
- name: Run y.sh cargo build
8684
run: |
87-
EMBED_LTO_BITCODE=1 CHANNEL="release" ./y.sh cargo build --release --manifest-path tests/hello-world/Cargo.toml
85+
CHANNEL="release" ./y.sh cargo build --release --manifest-path tests/hello-world/Cargo.toml
8886
call_found=$(objdump -dj .text tests/hello-world/target/release/hello_world | grep -c "call .*mylib.*my_func" ) ||:
8987
if [ $call_found -gt 0 ]; then
9088
echo "ERROR: call my_func found in asm"

Readme.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,7 @@ If you compiled cg_gccjit in debug mode (aka you didn't pass `--release` to `./y
137137

138138
### LTO
139139

140-
To use LTO, you need to set the variable `EMBED_LTO_BITCODE=1` in addition to setting `lto = "fat"` in the `Cargo.toml`.
141-
142-
Failing to set `EMBED_LTO_BITCODE` will give you the following error:
143-
144-
```
145-
error: failed to copy bitcode to object file: No such file or directory (os error 2)
146-
```
140+
To use LTO, you need to set `lto = "fat"` in the `Cargo.toml`.
147141

148142
### Rustc
149143

src/back/lto.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use rustc_errors::{DiagCtxtHandle, FatalError};
3333
use rustc_middle::bug;
3434
use rustc_middle::dep_graph::WorkProduct;
3535
use rustc_session::config::Lto;
36-
use rustc_target::spec::RelocModel;
3736
use tempfile::{TempDir, tempdir};
3837

3938
use crate::back::write::save_temp_bitcode;
@@ -566,13 +565,7 @@ pub fn optimize_thin_module(
566565
};
567566
let module = ModuleCodegen::new_regular(
568567
thin_module.name().to_string(),
569-
GccContext {
570-
context,
571-
should_combine_object_files,
572-
// TODO(antoyo): use the correct relocation model here.
573-
relocation_model: RelocModel::Pic,
574-
temp_dir: None,
575-
},
568+
GccContext { context, should_combine_object_files, temp_dir: None },
576569
);
577570
/*{
578571
let target = &*module.module_llvm.tm;

src/back/write.rs

Lines changed: 18 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{env, fs};
22

3-
use gccjit::{Context, OutputKind};
3+
use gccjit::OutputKind;
44
use rustc_codegen_ssa::back::link::ensure_removed;
55
use rustc_codegen_ssa::back::write::{BitcodeSection, CodegenContext, EmitObj, ModuleConfig};
66
use rustc_codegen_ssa::{CompiledModule, ModuleCodegen};
@@ -9,7 +9,6 @@ use rustc_session::config::OutputType;
99
use rustc_span::fatal_error::FatalError;
1010
use rustc_target::spec::SplitDebuginfo;
1111

12-
use crate::base::add_pic_option;
1312
use crate::errors::CopyBitcode;
1413
use crate::{GccCodegenBackend, GccContext};
1514

@@ -27,11 +26,6 @@ pub(crate) fn codegen(
2726

2827
let should_combine_object_files = module.module_llvm.should_combine_object_files;
2928

30-
// NOTE: Only generate object files with GIMPLE when this environment variable is set for
31-
// now because this requires a particular setup (same gcc/lto1/lto-wrapper commit as libgccjit).
32-
// TODO(antoyo): remove this environment variable.
33-
let fat_lto = env::var("EMBED_LTO_BITCODE").as_deref() == Ok("1");
34-
3529
let bc_out = cgcx.output_filenames.temp_path_for_cgu(
3630
OutputType::Bitcode,
3731
&module.name,
@@ -44,78 +38,24 @@ pub(crate) fn codegen(
4438
);
4539

4640
if config.bitcode_needed() {
47-
if fat_lto {
41+
if config.emit_bc || config.emit_obj == EmitObj::Bitcode {
4842
let _timer = cgcx
4943
.prof
50-
.generic_activity_with_arg("GCC_module_codegen_make_bitcode", &*module.name);
51-
52-
// TODO(antoyo)
53-
/*if let Some(bitcode_filename) = bc_out.file_name() {
54-
cgcx.prof.artifact_size(
55-
"llvm_bitcode",
56-
bitcode_filename.to_string_lossy(),
57-
data.len() as u64,
58-
);
59-
}*/
60-
61-
if config.emit_bc || config.emit_obj == EmitObj::Bitcode {
62-
let _timer = cgcx.prof.generic_activity_with_arg(
63-
"GCC_module_codegen_emit_bitcode",
64-
&*module.name,
65-
);
66-
context.add_command_line_option("-flto=auto");
67-
context.add_command_line_option("-flto-partition=one");
68-
context.compile_to_file(
69-
OutputKind::ObjectFile,
70-
bc_out.to_str().expect("path to str"),
71-
);
72-
}
73-
74-
if config.emit_obj == EmitObj::ObjectCode(BitcodeSection::Full) {
75-
let _timer = cgcx.prof.generic_activity_with_arg(
76-
"GCC_module_codegen_embed_bitcode",
77-
&*module.name,
78-
);
79-
// TODO(antoyo): maybe we should call embed_bitcode to have the proper iOS fixes?
80-
//embed_bitcode(cgcx, llcx, llmod, &config.bc_cmdline, data);
81-
82-
context.add_command_line_option("-flto=auto");
83-
context.add_command_line_option("-flto-partition=one");
84-
context.add_command_line_option("-ffat-lto-objects");
85-
// TODO(antoyo): Send -plugin/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/liblto_plugin.so to linker (this should be done when specifying the appropriate rustc cli argument).
86-
context.compile_to_file(
87-
OutputKind::ObjectFile,
88-
bc_out.to_str().expect("path to str"),
89-
);
90-
}
91-
} else {
92-
if config.emit_bc || config.emit_obj == EmitObj::Bitcode {
93-
let _timer = cgcx.prof.generic_activity_with_arg(
94-
"GCC_module_codegen_emit_bitcode",
95-
&*module.name,
96-
);
97-
context.compile_to_file(
98-
OutputKind::ObjectFile,
99-
bc_out.to_str().expect("path to str"),
100-
);
101-
}
44+
.generic_activity_with_arg("GCC_module_codegen_emit_bitcode", &*module.name);
45+
context
46+
.compile_to_file(OutputKind::ObjectFile, bc_out.to_str().expect("path to str"));
47+
}
10248

103-
if config.emit_obj == EmitObj::ObjectCode(BitcodeSection::Full) {
104-
// TODO(antoyo): we might want to emit to emit an error here, saying to set the
105-
// environment variable EMBED_LTO_BITCODE.
106-
let _timer = cgcx.prof.generic_activity_with_arg(
107-
"GCC_module_codegen_embed_bitcode",
108-
&*module.name,
109-
);
110-
// TODO(antoyo): maybe we should call embed_bitcode to have the proper iOS fixes?
111-
//embed_bitcode(cgcx, llcx, llmod, &config.bc_cmdline, data);
49+
if config.emit_obj == EmitObj::ObjectCode(BitcodeSection::Full) {
50+
let _timer = cgcx
51+
.prof
52+
.generic_activity_with_arg("GCC_module_codegen_embed_bitcode", &*module.name);
53+
// TODO(antoyo): maybe we should call embed_bitcode to have the proper iOS fixes?
54+
//embed_bitcode(cgcx, llcx, llmod, &config.bc_cmdline, data);
11255

113-
// TODO(antoyo): Send -plugin/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/liblto_plugin.so to linker (this should be done when specifying the appropriate rustc cli argument).
114-
context.compile_to_file(
115-
OutputKind::ObjectFile,
116-
bc_out.to_str().expect("path to str"),
117-
);
118-
}
56+
// TODO(antoyo): Send -plugin/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/liblto_plugin.so to linker (this should be done when specifying the appropriate rustc cli argument).
57+
context
58+
.compile_to_file(OutputKind::ObjectFile, bc_out.to_str().expect("path to str"));
11959
}
12060
}
12161

@@ -165,61 +105,16 @@ pub(crate) fn codegen(
165105
context.dump_to_file(path, true);
166106
}
167107
if should_combine_object_files {
168-
if fat_lto {
169-
context.add_command_line_option("-flto=auto");
170-
context.add_command_line_option("-flto-partition=one");
171-
172-
// NOTE: without -fuse-linker-plugin, we get the following error:
173-
// lto1: internal compiler error: decompressed stream: Destination buffer is too small
174-
// TODO(antoyo): since we do not do LTO when the linker is invoked anymore, perhaps
175-
// the following flag is not necessary anymore.
176-
context.add_driver_option("-fuse-linker-plugin");
177-
}
178-
179108
context.add_driver_option("-Wl,-r");
180109
// NOTE: we need -nostdlib, otherwise, we get the following error:
181110
// /usr/bin/ld: cannot find -lgcc_s: No such file or directory
182111
context.add_driver_option("-nostdlib");
183112

184113
let path = obj_out.to_str().expect("path to str");
185114

186-
if fat_lto {
187-
let lto_path = format!("{}.lto", path);
188-
// cSpell:disable
189-
// FIXME(antoyo): The LTO frontend generates the following warning:
190-
// ../build_sysroot/sysroot_src/library/core/src/num/dec2flt/lemire.rs:150:15: warning: type of ‘_ZN4core3num7dec2flt5table17POWER_OF_FIVE_12817ha449a68fb31379e4E’ does not match original declaration [-Wlto-type-mismatch]
191-
// 150 | let (lo5, hi5) = POWER_OF_FIVE_128[index];
192-
// | ^
193-
// lto1: note: ‘_ZN4core3num7dec2flt5table17POWER_OF_FIVE_12817ha449a68fb31379e4E’ was previously declared here
194-
//
195-
// This option is to mute it to make the UI tests pass with LTO enabled.
196-
// cSpell:enable
197-
context.add_driver_option("-Wno-lto-type-mismatch");
198-
// NOTE: this doesn't actually generate an executable. With the above
199-
// flags, it combines the .o files together in another .o.
200-
context.compile_to_file(OutputKind::Executable, &lto_path);
201-
202-
let context = Context::default();
203-
if cgcx.target_arch == "x86" || cgcx.target_arch == "x86_64" {
204-
// NOTE: it seems we need to use add_driver_option instead of
205-
// add_command_line_option here because we use the LTO frontend via gcc.
206-
context.add_driver_option("-masm=intel");
207-
}
208-
209-
// NOTE: these two options are needed to invoke LTO to produce an object file.
210-
// We need to initiate a second compilation because the arguments "-x lto"
211-
// needs to be at the very beginning.
212-
context.add_driver_option("-x");
213-
context.add_driver_option("lto");
214-
add_pic_option(&context, module.module_llvm.relocation_model);
215-
context.add_driver_option(lto_path);
216-
217-
context.compile_to_file(OutputKind::ObjectFile, path);
218-
} else {
219-
// NOTE: this doesn't actually generate an executable. With the above
220-
// flags, it combines the .o files together in another .o.
221-
context.compile_to_file(OutputKind::Executable, path);
222-
}
115+
// NOTE: this doesn't actually generate an executable. With the above
116+
// flags, it combines the .o files together in another .o.
117+
context.compile_to_file(OutputKind::Executable, path);
223118
} else {
224119
context.compile_to_file(
225120
OutputKind::ObjectFile,

src/base.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ pub fn compile_codegen_unit(
246246
cgu_name.to_string(),
247247
GccContext {
248248
context: Arc::new(SyncContext::new(context)),
249-
relocation_model: tcx.sess.relocation_model(),
250249
should_combine_object_files: false,
251250
temp_dir: None,
252251
},

src/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ use rustc_session::Session;
112112
use rustc_session::config::{OptLevel, OutputFilenames};
113113
use rustc_span::Symbol;
114114
use rustc_span::fatal_error::FatalError;
115-
use rustc_target::spec::RelocModel;
116115
use tempfile::TempDir;
117116

118117
use crate::back::lto::ModuleBuffer;
@@ -287,7 +286,6 @@ impl ExtraBackendMethods for GccCodegenBackend {
287286
) -> Self::Module {
288287
let mut mods = GccContext {
289288
context: Arc::new(SyncContext::new(new_context(tcx))),
290-
relocation_model: tcx.sess.relocation_model(),
291289
should_combine_object_files: false,
292290
temp_dir: None,
293291
};
@@ -319,9 +317,6 @@ impl ExtraBackendMethods for GccCodegenBackend {
319317

320318
pub struct GccContext {
321319
context: Arc<SyncContext>,
322-
/// This field is needed in order to be able to set the flag -fPIC when necessary when doing
323-
/// LTO.
324-
relocation_model: RelocModel,
325320
should_combine_object_files: bool,
326321
// Temporary directory used by LTO. We keep it here so that it's not removed before linking.
327322
temp_dir: Option<TempDir>,

0 commit comments

Comments
 (0)