Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9e4a283

Browse files
Rollup merge of #145368 - rcvalle:rust-cfi-fix-142284, r=dianqk
CFI: Make `lto` and `linker-plugin-lto` work the same for `compiler_builtins` Fix #142284 by ensuring that `#![no_builtins]` crates can still emit bitcode when proper (i.e., non-rustc) LTO (i.e., -Clinker-plugin-lto) is used.
2 parents f948c79 + cf8753e commit 9e4a283

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

‎compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,23 +138,12 @@ impl ModuleConfig {
138138

139139
let emit_obj = if !should_emit_obj {
140140
EmitObj::None
141-
} else if sess.target.obj_is_bitcode
142-
|| (sess.opts.cg.linker_plugin_lto.enabled() && !no_builtins)
143-
{
141+
} else if sess.target.obj_is_bitcode || sess.opts.cg.linker_plugin_lto.enabled() {
144142
// This case is selected if the target uses objects as bitcode, or
145143
// if linker plugin LTO is enabled. In the linker plugin LTO case
146144
// the assumption is that the final link-step will read the bitcode
147145
// and convert it to object code. This may be done by either the
148146
// native linker or rustc itself.
149-
//
150-
// Note, however, that the linker-plugin-lto requested here is
151-
// explicitly ignored for `#![no_builtins]` crates. These crates are
152-
// specifically ignored by rustc's LTO passes and wouldn't work if
153-
// loaded into the linker. These crates define symbols that LLVM
154-
// lowers intrinsics to, and these symbol dependencies aren't known
155-
// until after codegen. As a result any crate marked
156-
// `#![no_builtins]` is assumed to not participate in LTO and
157-
// instead goes on to generate object code.
158147
EmitObj::Bitcode
159148
} else if need_bitcode_in_object(tcx) {
160149
EmitObj::ObjectCode(BitcodeSection::Full)

‎tests/ui/sanitizer/cfi/no_builtins.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Verifies that `#![no_builtins]` crates can be built with linker-plugin-lto and CFI.
2+
// See Issue #142284
3+
//
4+
//@ needs-sanitizer-cfi
5+
//@ compile-flags: -Clinker-plugin-lto -Copt-level=0 -Zsanitizer=cfi -Ctarget-feature=-crt-static
6+
//@ compile-flags: --crate-type rlib
7+
//@ build-pass
8+
9+
#![no_builtins]
10+
#![no_std]
11+
12+
pub static FUNC: fn() = initializer;
13+
14+
pub fn initializer() {
15+
call(fma_with_fma);
16+
}
17+
18+
pub fn call(fn_ptr: fn()) {
19+
fn_ptr();
20+
}
21+
22+
pub fn fma_with_fma() {}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /