Skip to content

Commit 807d50a

Browse files
committed
Remove EMBED_LTO_BITCODE
1 parent 7cc33be commit 807d50a

File tree

3 files changed

+41
-89
lines changed

3 files changed

+41
-89
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
- name: Build
5656
run: |
5757
./y.sh prepare --only-libcore
58-
EMBED_LTO_BITCODE=1 ./y.sh build --sysroot --release --release-sysroot
58+
./y.sh build --sysroot --release --release-sysroot
5959
./y.sh test --mini-tests
6060
cargo test
6161
./y.sh clean all
@@ -73,11 +73,11 @@ jobs:
7373
run: |
7474
# FIXME(antoyo): we cannot enable LTO for stdarch tests currently because of some failing LTO tests using proc-macros.
7575
echo -n 'lto = "fat"' >> build_system/build_sysroot/Cargo.toml
76-
EMBED_LTO_BITCODE=1 ./y.sh test --release --clean --release-sysroot --build-sysroot --keep-lto-tests ${{ matrix.commands }}
76+
./y.sh test --release --clean --release-sysroot --build-sysroot --keep-lto-tests ${{ matrix.commands }}
7777
7878
- name: Run y.sh cargo build
7979
run: |
80-
EMBED_LTO_BITCODE=1 CHANNEL="release" ./y.sh cargo build --release --manifest-path tests/hello-world/Cargo.toml
80+
CHANNEL="release" ./y.sh cargo build --release --manifest-path tests/hello-world/Cargo.toml
8181
call_found=$(objdump -dj .text tests/hello-world/target/release/hello_world | grep -c "call .*mylib.*my_func" ) ||:
8282
if [ $call_found -gt 0 ]; then
8383
echo "ERROR: call my_func found in asm"

Readme.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,6 @@ $ CHANNEL="release" $CG_GCCJIT_DIR/y.sh cargo run
135135

136136
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.
137137

138-
### LTO
139-
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-
```
147-
148138
### Rustc
149139

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

src/back/write.rs

Lines changed: 38 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ pub(crate) fn codegen(
2626

2727
let should_combine_object_files = module.module_llvm.should_combine_object_files;
2828

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

4540
if config.bitcode_needed() {
46-
if fat_lto {
41+
let _timer = cgcx
42+
.prof
43+
.generic_activity_with_arg("GCC_module_codegen_make_bitcode", &*module.name);
44+
45+
// TODO(antoyo)
46+
/*if let Some(bitcode_filename) = bc_out.file_name() {
47+
cgcx.prof.artifact_size(
48+
"llvm_bitcode",
49+
bitcode_filename.to_string_lossy(),
50+
data.len() as u64,
51+
);
52+
}*/
53+
54+
if config.emit_bc || config.emit_obj == EmitObj::Bitcode {
4755
let _timer = cgcx
4856
.prof
49-
.generic_activity_with_arg("GCC_module_codegen_make_bitcode", &*module.name);
50-
51-
// TODO(antoyo)
52-
/*if let Some(bitcode_filename) = bc_out.file_name() {
53-
cgcx.prof.artifact_size(
54-
"llvm_bitcode",
55-
bitcode_filename.to_string_lossy(),
56-
data.len() as u64,
57-
);
58-
}*/
59-
60-
if config.emit_bc || config.emit_obj == EmitObj::Bitcode {
61-
let _timer = cgcx.prof.generic_activity_with_arg(
62-
"GCC_module_codegen_emit_bitcode",
63-
&*module.name,
64-
);
65-
context.add_command_line_option("-flto=auto");
66-
context.add_command_line_option("-flto-partition=one");
67-
// TODO(antoyo): remove since we don't want fat objects when it is for Bitcode only.
68-
context.add_command_line_option("-ffat-lto-objects");
69-
context.compile_to_file(
70-
OutputKind::ObjectFile,
71-
bc_out.to_str().expect("path to str"),
72-
);
73-
}
74-
75-
if config.emit_obj == EmitObj::ObjectCode(BitcodeSection::Full) {
76-
let _timer = cgcx.prof.generic_activity_with_arg(
77-
"GCC_module_codegen_embed_bitcode",
78-
&*module.name,
79-
);
80-
// TODO(antoyo): maybe we should call embed_bitcode to have the proper iOS fixes?
81-
//embed_bitcode(cgcx, llcx, llmod, &config.bc_cmdline, data);
82-
83-
context.add_command_line_option("-flto=auto");
84-
context.add_command_line_option("-flto-partition=one");
85-
context.add_command_line_option("-ffat-lto-objects");
86-
// 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).
87-
context.compile_to_file(
88-
OutputKind::ObjectFile,
89-
bc_out.to_str().expect("path to str"),
90-
);
91-
}
92-
} else {
93-
if config.emit_bc || config.emit_obj == EmitObj::Bitcode {
94-
let _timer = cgcx.prof.generic_activity_with_arg(
95-
"GCC_module_codegen_emit_bitcode",
96-
&*module.name,
97-
);
98-
context.compile_to_file(
99-
OutputKind::ObjectFile,
100-
bc_out.to_str().expect("path to str"),
101-
);
102-
}
103-
104-
if config.emit_obj == EmitObj::ObjectCode(BitcodeSection::Full) {
105-
// TODO(antoyo): we might want to emit to emit an error here, saying to set the
106-
// environment variable EMBED_LTO_BITCODE.
107-
let _timer = cgcx.prof.generic_activity_with_arg(
108-
"GCC_module_codegen_embed_bitcode",
109-
&*module.name,
110-
);
111-
// TODO(antoyo): maybe we should call embed_bitcode to have the proper iOS fixes?
112-
//embed_bitcode(cgcx, llcx, llmod, &config.bc_cmdline, data);
57+
.generic_activity_with_arg("GCC_module_codegen_emit_bitcode", &*module.name);
58+
context.add_command_line_option("-flto=auto");
59+
context.add_command_line_option("-flto-partition=one");
60+
// TODO(antoyo): remove since we don't want fat objects when it is for Bitcode only.
61+
context.add_command_line_option("-ffat-lto-objects");
62+
context
63+
.compile_to_file(OutputKind::ObjectFile, bc_out.to_str().expect("path to str"));
64+
}
11365

114-
// 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).
115-
context.compile_to_file(
116-
OutputKind::ObjectFile,
117-
bc_out.to_str().expect("path to str"),
118-
);
119-
}
66+
if config.emit_obj == EmitObj::ObjectCode(BitcodeSection::Full) {
67+
let _timer = cgcx
68+
.prof
69+
.generic_activity_with_arg("GCC_module_codegen_embed_bitcode", &*module.name);
70+
// TODO(antoyo): maybe we should call embed_bitcode to have the proper iOS fixes?
71+
//embed_bitcode(cgcx, llcx, llmod, &config.bc_cmdline, data);
72+
73+
context.add_command_line_option("-flto=auto");
74+
context.add_command_line_option("-flto-partition=one");
75+
context.add_command_line_option("-ffat-lto-objects");
76+
// 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).
77+
context
78+
.compile_to_file(OutputKind::ObjectFile, bc_out.to_str().expect("path to str"));
12079
}
12180
}
12281

@@ -166,6 +125,9 @@ pub(crate) fn codegen(
166125
context.dump_to_file(path, true);
167126
}
168127
if should_combine_object_files {
128+
let fat_lto = config.emit_obj == EmitObj::ObjectCode(BitcodeSection::Full);
129+
// We need to check if we're doing LTO since this code is also used for the
130+
// dummy ThinLTO implementation to combine the object files.
169131
if fat_lto {
170132
context.add_command_line_option("-flto=auto");
171133
context.add_command_line_option("-flto-partition=one");

0 commit comments

Comments
 (0)