Skip to content

Commit 72df804

Browse files
When doing linker-plugin based LTO, write LLVM bitcode obj-files
instead of embedding the bitcode into the regular object file.
1 parent 65ff414 commit 72df804

File tree

3 files changed

+24
-28
lines changed

3 files changed

+24
-28
lines changed

src/librustc/session/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub enum CrossLangLto {
104104
}
105105

106106
impl CrossLangLto {
107-
pub fn embed_bitcode(&self) -> bool {
107+
pub fn enabled(&self) -> bool {
108108
match *self {
109109
CrossLangLto::LinkerPlugin(_) |
110110
CrossLangLto::LinkerPluginAuto |

src/librustc_codegen_llvm/back/write.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,10 @@ impl ModuleConfig {
288288
self.no_builtins = no_builtins || sess.target.target.options.no_builtins;
289289
self.time_passes = sess.time_passes();
290290
self.inline_threshold = sess.opts.cg.inline_threshold;
291-
self.obj_is_bitcode = sess.target.target.options.obj_is_bitcode;
291+
self.obj_is_bitcode = sess.target.target.options.obj_is_bitcode ||
292+
sess.opts.debugging_opts.cross_lang_lto.enabled();
292293
let embed_bitcode = sess.target.target.options.embed_bitcode ||
293-
sess.opts.debugging_opts.embed_bitcode ||
294-
sess.opts.debugging_opts.cross_lang_lto.embed_bitcode();
294+
sess.opts.debugging_opts.embed_bitcode;
295295
if embed_bitcode {
296296
match sess.opts.optimize {
297297
config::OptLevel::No |
@@ -1365,7 +1365,7 @@ fn execute_work_item(cgcx: &CodegenContext,
13651365
// Don't run LTO passes when cross-lang LTO is enabled. The linker
13661366
// will do that for us in this case.
13671367
let needs_lto = needs_lto &&
1368-
!cgcx.opts.debugging_opts.cross_lang_lto.embed_bitcode();
1368+
!cgcx.opts.debugging_opts.cross_lang_lto.enabled();
13691369

13701370
if needs_lto {
13711371
Ok(WorkItemResult::NeedsLTO(module))
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,49 @@
11

22
# min-llvm-version 4.0
3-
# ignore-mingw
3+
# ignore-msvc
44

55
-include ../tools.mk
66

7-
# This test makes sure that the expected .llvmbc sections for use by
8-
# linker-based LTO are available in object files when compiling with
9-
# -Z cross-lang-lto
7+
# This test makes sure that the object files we generate are actually
8+
# LLVM bitcode files (as used by linker LTO plugins) when compiling with
9+
# -Z cross-lang-lto.
1010

11-
LLVMBC_SECTION_NAME=\\.llvmbc
11+
ASSERT_IS_BITCODE_OBJ=llvm-bcanalyzer # this only succeeds for bitcode files
12+
EXTRACT_OBJS=(cd $(TMPDIR); rm -f ./*.o; llvm-ar x $(1))
1213

13-
ifeq ($(UNAME),Darwin)
14-
LLVMBC_SECTION_NAME=__bitcode
15-
endif
16-
17-
18-
OBJDUMP=llvm-objdump
19-
SECTION_HEADERS=$(OBJDUMP) -section-headers
20-
21-
BUILD_LIB=$(RUSTC) lib.rs -Copt-level=2 -Z cross-lang-lto=no-link -Ccodegen-units=1
22-
23-
BUILD_EXE=$(RUSTC) main.rs -Copt-level=2 -Z cross-lang-lto=no-link -Ccodegen-units=1 --emit=obj
14+
BUILD_LIB=$(RUSTC) lib.rs -Copt-level=2 -Z cross-lang-lto=on -Ccodegen-units=1
15+
BUILD_EXE=$(RUSTC) main.rs -Copt-level=2 -Z cross-lang-lto=on -Ccodegen-units=1 --emit=obj
2416

2517
all: staticlib staticlib-fat-lto staticlib-thin-lto rlib exe cdylib rdylib
2618

2719
staticlib: lib.rs
2820
$(BUILD_LIB) --crate-type=staticlib -o $(TMPDIR)/liblib.a
29-
[ "$$($(SECTION_HEADERS) $(TMPDIR)/liblib.a | grep -c $(LLVMBC_SECTION_NAME))" -ne "0" ]
21+
$(call EXTRACT_OBJS, liblib.a)
22+
$(ASSERT_IS_BITCODE_OBJ) $(TMPDIR)/liblib.lib0.rcgu.o
3023

3124
staticlib-fat-lto: lib.rs
3225
$(BUILD_LIB) --crate-type=staticlib -o $(TMPDIR)/liblib-fat-lto.a -Clto=fat
33-
[ "$$($(SECTION_HEADERS) $(TMPDIR)/liblib-fat-lto.a | grep -c $(LLVMBC_SECTION_NAME))" -ne "0" ]
26+
$(call EXTRACT_OBJS, liblib-fat-lto.a)
27+
$(ASSERT_IS_BITCODE_OBJ) $(TMPDIR)/liblib-fat-lto.lib0.rcgu.o
3428

3529
staticlib-thin-lto: lib.rs
3630
$(BUILD_LIB) --crate-type=staticlib -o $(TMPDIR)/liblib-thin-lto.a -Clto=thin
37-
[ "$$($(SECTION_HEADERS) $(TMPDIR)/liblib-thin-lto.a | grep -c $(LLVMBC_SECTION_NAME))" -ne "0" ]
31+
$(call EXTRACT_OBJS, liblib-thin-lto.a)
32+
$(ASSERT_IS_BITCODE_OBJ) $(TMPDIR)/liblib-thin-lto.lib0.rcgu.o
3833

3934
rlib: lib.rs
4035
$(BUILD_LIB) --crate-type=rlib -o $(TMPDIR)/liblib.rlib
41-
[ "$$($(SECTION_HEADERS) $(TMPDIR)/liblib.rlib | grep -c $(LLVMBC_SECTION_NAME))" -ne "0" ]
36+
$(call EXTRACT_OBJS, liblib.rlib)
37+
$(ASSERT_IS_BITCODE_OBJ) $(TMPDIR)/liblib.lib0.rcgu.o
4238

4339
cdylib: lib.rs
4440
$(BUILD_LIB) --crate-type=cdylib --emit=obj -o $(TMPDIR)/cdylib.o
45-
[ "$$($(SECTION_HEADERS) $(TMPDIR)/cdylib.o | grep -c $(LLVMBC_SECTION_NAME))" -ne "0" ]
41+
$(ASSERT_IS_BITCODE_OBJ) $(TMPDIR)/cdylib.o
4642

4743
rdylib: lib.rs
4844
$(BUILD_LIB) --crate-type=dylib --emit=obj -o $(TMPDIR)/rdylib.o
49-
[ "$$($(SECTION_HEADERS) $(TMPDIR)/rdylib.o | grep -c $(LLVMBC_SECTION_NAME))" -ne "0" ]
45+
$(ASSERT_IS_BITCODE_OBJ) $(TMPDIR)/rdylib.o
5046

5147
exe: lib.rs
5248
$(BUILD_EXE) -o $(TMPDIR)/exe.o
53-
[ "$$($(SECTION_HEADERS) $(TMPDIR)/exe.o | grep -c $(LLVMBC_SECTION_NAME))" -ne "0" ]
49+
$(ASSERT_IS_BITCODE_OBJ) $(TMPDIR)/exe.o

0 commit comments

Comments
 (0)