Skip to content

Commit 290e465

Browse files
committed
Fix #570: Honor #![no_builtins] attribute by passing -fno-builtin to GCC
1 parent 0be3954 commit 290e465

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/base.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use rustc_codegen_ssa::ModuleCodegen;
88
use rustc_codegen_ssa::base::maybe_create_entry_wrapper;
99
use rustc_codegen_ssa::mono_item::MonoItemExt;
1010
use rustc_codegen_ssa::traits::DebugInfoCodegenMethods;
11-
use rustc_hir::attrs::Linkage;
11+
use rustc_hir::attrs::{AttributeKind, Linkage};
12+
use rustc_hir::find_attr;
1213
use rustc_middle::dep_graph;
1314
#[cfg(feature = "master")]
1415
use rustc_middle::mir::mono::Visibility;
@@ -136,6 +137,15 @@ pub fn compile_codegen_unit(
136137
// NOTE: Rust relies on LLVM doing wrapping on overflow.
137138
context.add_command_line_option("-fwrapv");
138139

140+
// NOTE: We need to honor the `#![no_builtins]` attribute to prevent GCC from
141+
// replacing code patterns (like loops) with calls to builtins (like memset).
142+
// This is important for crates like `compiler_builtins` that implement these functions.
143+
// See https://github.com/rust-lang/rustc_codegen_gcc/issues/570
144+
let crate_attrs = tcx.hir_attrs(rustc_hir::CRATE_HIR_ID);
145+
if find_attr!(crate_attrs, AttributeKind::NoBuiltins) {
146+
context.add_command_line_option("-fno-builtin");
147+
}
148+
139149
if let Some(model) = tcx.sess.code_model() {
140150
use rustc_target::spec::CodeModel;
141151

0 commit comments

Comments
 (0)