When doing linker-plugin based LTO, write LLVM bitcode obj-files
instead of embedding the bitcode into the regular object file.
This commit is contained in:
parent
65ff4141a5
commit
72df804d8e
3 changed files with 24 additions and 28 deletions
|
@ -104,7 +104,7 @@ pub enum CrossLangLto {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CrossLangLto {
|
impl CrossLangLto {
|
||||||
pub fn embed_bitcode(&self) -> bool {
|
pub fn enabled(&self) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
CrossLangLto::LinkerPlugin(_) |
|
CrossLangLto::LinkerPlugin(_) |
|
||||||
CrossLangLto::LinkerPluginAuto |
|
CrossLangLto::LinkerPluginAuto |
|
||||||
|
|
|
@ -288,10 +288,10 @@ impl ModuleConfig {
|
||||||
self.no_builtins = no_builtins || sess.target.target.options.no_builtins;
|
self.no_builtins = no_builtins || sess.target.target.options.no_builtins;
|
||||||
self.time_passes = sess.time_passes();
|
self.time_passes = sess.time_passes();
|
||||||
self.inline_threshold = sess.opts.cg.inline_threshold;
|
self.inline_threshold = sess.opts.cg.inline_threshold;
|
||||||
self.obj_is_bitcode = sess.target.target.options.obj_is_bitcode;
|
self.obj_is_bitcode = sess.target.target.options.obj_is_bitcode ||
|
||||||
|
sess.opts.debugging_opts.cross_lang_lto.enabled();
|
||||||
let embed_bitcode = sess.target.target.options.embed_bitcode ||
|
let embed_bitcode = sess.target.target.options.embed_bitcode ||
|
||||||
sess.opts.debugging_opts.embed_bitcode ||
|
sess.opts.debugging_opts.embed_bitcode;
|
||||||
sess.opts.debugging_opts.cross_lang_lto.embed_bitcode();
|
|
||||||
if embed_bitcode {
|
if embed_bitcode {
|
||||||
match sess.opts.optimize {
|
match sess.opts.optimize {
|
||||||
config::OptLevel::No |
|
config::OptLevel::No |
|
||||||
|
@ -1365,7 +1365,7 @@ fn execute_work_item(cgcx: &CodegenContext,
|
||||||
// Don't run LTO passes when cross-lang LTO is enabled. The linker
|
// Don't run LTO passes when cross-lang LTO is enabled. The linker
|
||||||
// will do that for us in this case.
|
// will do that for us in this case.
|
||||||
let needs_lto = needs_lto &&
|
let needs_lto = needs_lto &&
|
||||||
!cgcx.opts.debugging_opts.cross_lang_lto.embed_bitcode();
|
!cgcx.opts.debugging_opts.cross_lang_lto.enabled();
|
||||||
|
|
||||||
if needs_lto {
|
if needs_lto {
|
||||||
Ok(WorkItemResult::NeedsLTO(module))
|
Ok(WorkItemResult::NeedsLTO(module))
|
||||||
|
|
|
@ -1,53 +1,49 @@
|
||||||
|
|
||||||
# min-llvm-version 4.0
|
# min-llvm-version 4.0
|
||||||
# ignore-mingw
|
# ignore-msvc
|
||||||
|
|
||||||
-include ../tools.mk
|
-include ../tools.mk
|
||||||
|
|
||||||
# This test makes sure that the expected .llvmbc sections for use by
|
# This test makes sure that the object files we generate are actually
|
||||||
# linker-based LTO are available in object files when compiling with
|
# LLVM bitcode files (as used by linker LTO plugins) when compiling with
|
||||||
# -Z cross-lang-lto
|
# -Z cross-lang-lto.
|
||||||
|
|
||||||
LLVMBC_SECTION_NAME=\\.llvmbc
|
ASSERT_IS_BITCODE_OBJ=llvm-bcanalyzer # this only succeeds for bitcode files
|
||||||
|
EXTRACT_OBJS=(cd $(TMPDIR); rm -f ./*.o; llvm-ar x $(1))
|
||||||
|
|
||||||
ifeq ($(UNAME),Darwin)
|
BUILD_LIB=$(RUSTC) lib.rs -Copt-level=2 -Z cross-lang-lto=on -Ccodegen-units=1
|
||||||
LLVMBC_SECTION_NAME=__bitcode
|
BUILD_EXE=$(RUSTC) main.rs -Copt-level=2 -Z cross-lang-lto=on -Ccodegen-units=1 --emit=obj
|
||||||
endif
|
|
||||||
|
|
||||||
|
|
||||||
OBJDUMP=llvm-objdump
|
|
||||||
SECTION_HEADERS=$(OBJDUMP) -section-headers
|
|
||||||
|
|
||||||
BUILD_LIB=$(RUSTC) lib.rs -Copt-level=2 -Z cross-lang-lto=no-link -Ccodegen-units=1
|
|
||||||
|
|
||||||
BUILD_EXE=$(RUSTC) main.rs -Copt-level=2 -Z cross-lang-lto=no-link -Ccodegen-units=1 --emit=obj
|
|
||||||
|
|
||||||
all: staticlib staticlib-fat-lto staticlib-thin-lto rlib exe cdylib rdylib
|
all: staticlib staticlib-fat-lto staticlib-thin-lto rlib exe cdylib rdylib
|
||||||
|
|
||||||
staticlib: lib.rs
|
staticlib: lib.rs
|
||||||
$(BUILD_LIB) --crate-type=staticlib -o $(TMPDIR)/liblib.a
|
$(BUILD_LIB) --crate-type=staticlib -o $(TMPDIR)/liblib.a
|
||||||
[ "$$($(SECTION_HEADERS) $(TMPDIR)/liblib.a | grep -c $(LLVMBC_SECTION_NAME))" -ne "0" ]
|
$(call EXTRACT_OBJS, liblib.a)
|
||||||
|
$(ASSERT_IS_BITCODE_OBJ) $(TMPDIR)/liblib.lib0.rcgu.o
|
||||||
|
|
||||||
staticlib-fat-lto: lib.rs
|
staticlib-fat-lto: lib.rs
|
||||||
$(BUILD_LIB) --crate-type=staticlib -o $(TMPDIR)/liblib-fat-lto.a -Clto=fat
|
$(BUILD_LIB) --crate-type=staticlib -o $(TMPDIR)/liblib-fat-lto.a -Clto=fat
|
||||||
[ "$$($(SECTION_HEADERS) $(TMPDIR)/liblib-fat-lto.a | grep -c $(LLVMBC_SECTION_NAME))" -ne "0" ]
|
$(call EXTRACT_OBJS, liblib-fat-lto.a)
|
||||||
|
$(ASSERT_IS_BITCODE_OBJ) $(TMPDIR)/liblib-fat-lto.lib0.rcgu.o
|
||||||
|
|
||||||
staticlib-thin-lto: lib.rs
|
staticlib-thin-lto: lib.rs
|
||||||
$(BUILD_LIB) --crate-type=staticlib -o $(TMPDIR)/liblib-thin-lto.a -Clto=thin
|
$(BUILD_LIB) --crate-type=staticlib -o $(TMPDIR)/liblib-thin-lto.a -Clto=thin
|
||||||
[ "$$($(SECTION_HEADERS) $(TMPDIR)/liblib-thin-lto.a | grep -c $(LLVMBC_SECTION_NAME))" -ne "0" ]
|
$(call EXTRACT_OBJS, liblib-thin-lto.a)
|
||||||
|
$(ASSERT_IS_BITCODE_OBJ) $(TMPDIR)/liblib-thin-lto.lib0.rcgu.o
|
||||||
|
|
||||||
rlib: lib.rs
|
rlib: lib.rs
|
||||||
$(BUILD_LIB) --crate-type=rlib -o $(TMPDIR)/liblib.rlib
|
$(BUILD_LIB) --crate-type=rlib -o $(TMPDIR)/liblib.rlib
|
||||||
[ "$$($(SECTION_HEADERS) $(TMPDIR)/liblib.rlib | grep -c $(LLVMBC_SECTION_NAME))" -ne "0" ]
|
$(call EXTRACT_OBJS, liblib.rlib)
|
||||||
|
$(ASSERT_IS_BITCODE_OBJ) $(TMPDIR)/liblib.lib0.rcgu.o
|
||||||
|
|
||||||
cdylib: lib.rs
|
cdylib: lib.rs
|
||||||
$(BUILD_LIB) --crate-type=cdylib --emit=obj -o $(TMPDIR)/cdylib.o
|
$(BUILD_LIB) --crate-type=cdylib --emit=obj -o $(TMPDIR)/cdylib.o
|
||||||
[ "$$($(SECTION_HEADERS) $(TMPDIR)/cdylib.o | grep -c $(LLVMBC_SECTION_NAME))" -ne "0" ]
|
$(ASSERT_IS_BITCODE_OBJ) $(TMPDIR)/cdylib.o
|
||||||
|
|
||||||
rdylib: lib.rs
|
rdylib: lib.rs
|
||||||
$(BUILD_LIB) --crate-type=dylib --emit=obj -o $(TMPDIR)/rdylib.o
|
$(BUILD_LIB) --crate-type=dylib --emit=obj -o $(TMPDIR)/rdylib.o
|
||||||
[ "$$($(SECTION_HEADERS) $(TMPDIR)/rdylib.o | grep -c $(LLVMBC_SECTION_NAME))" -ne "0" ]
|
$(ASSERT_IS_BITCODE_OBJ) $(TMPDIR)/rdylib.o
|
||||||
|
|
||||||
exe: lib.rs
|
exe: lib.rs
|
||||||
$(BUILD_EXE) -o $(TMPDIR)/exe.o
|
$(BUILD_EXE) -o $(TMPDIR)/exe.o
|
||||||
[ "$$($(SECTION_HEADERS) $(TMPDIR)/exe.o | grep -c $(LLVMBC_SECTION_NAME))" -ne "0" ]
|
$(ASSERT_IS_BITCODE_OBJ) $(TMPDIR)/exe.o
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue