Skip to content

Commit

Permalink
Simplify bitcode embedding - either None or Full
Browse files Browse the repository at this point in the history
  • Loading branch information
thombles committed May 7, 2020
1 parent a390803 commit 4fea9cd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
8 changes: 3 additions & 5 deletions src/librustc_codegen_llvm/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,10 +651,8 @@ pub(crate) unsafe fn codegen(
"LLVM_module_codegen_embed_bitcode",
&module.name[..],
);
embed_bitcode(cgcx, llcx, llmod, &config.bc_cmdline, Some(data));
embed_bitcode(cgcx, llcx, llmod, &config.bc_cmdline, data);
}
} else if config.emit_obj == EmitObj::ObjectCode(BitcodeSection::Marker) {
embed_bitcode(cgcx, llcx, llmod, &config.bc_cmdline, None);
}

if config.emit_ir {
Expand Down Expand Up @@ -790,9 +788,9 @@ unsafe fn embed_bitcode(
llcx: &llvm::Context,
llmod: &llvm::Module,
cmdline: &str,
bitcode: Option<&[u8]>,
bitcode: &[u8],
) {
let llconst = common::bytes_in_context(llcx, bitcode.unwrap_or(&[]));
let llconst = common::bytes_in_context(llcx, bitcode);
let llglobal = llvm::LLVMAddGlobal(
llmod,
common::val_ty(llconst),
Expand Down
22 changes: 6 additions & 16 deletions src/librustc_codegen_ssa/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ pub enum BitcodeSection {
// No bitcode section.
None,

// An empty bitcode section (to placate tools such as the iOS linker that
// require this section even if they don't use it).
Marker,

// A full, uncompressed bitcode section.
Full,
}
Expand Down Expand Up @@ -148,16 +144,8 @@ impl ModuleConfig {
|| sess.opts.cg.linker_plugin_lto.enabled()
{
EmitObj::Bitcode
} else if sess.target.target.options.forces_embed_bitcode {
} else if need_bitcode_in_object(sess) {
EmitObj::ObjectCode(BitcodeSection::Full)
} else if need_crate_bitcode_for_rlib(sess) {
let force_full = need_crate_bitcode_for_rlib(sess);
match sess.opts.optimize {
config::OptLevel::No | config::OptLevel::Less if !force_full => {
EmitObj::ObjectCode(BitcodeSection::Marker)
}
_ => EmitObj::ObjectCode(BitcodeSection::Full),
}
} else {
EmitObj::ObjectCode(BitcodeSection::None)
};
Expand Down Expand Up @@ -376,10 +364,12 @@ pub struct CompiledModules {
pub allocator_module: Option<CompiledModule>,
}

fn need_crate_bitcode_for_rlib(sess: &Session) -> bool {
sess.opts.cg.embed_bitcode
fn need_bitcode_in_object(sess: &Session) -> bool {
let requested_for_rlib = sess.opts.cg.embed_bitcode
&& sess.crate_types.borrow().contains(&CrateType::Rlib)
&& sess.opts.output_types.contains_key(&OutputType::Exe)
&& sess.opts.output_types.contains_key(&OutputType::Exe);
let forced_by_target = sess.target.target.options.forces_embed_bitcode;
requested_for_rlib || forced_by_target
}

fn need_pre_lto_bitcode_for_incr_comp(sess: &Session) -> bool {
Expand Down

0 comments on commit 4fea9cd

Please sign in to comment.