File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,8 @@ use rustc_codegen_ssa::ModuleCodegen;
88use rustc_codegen_ssa:: base:: maybe_create_entry_wrapper;
99use rustc_codegen_ssa:: mono_item:: MonoItemExt ;
1010use rustc_codegen_ssa:: traits:: DebugInfoCodegenMethods ;
11- use rustc_hir:: attrs:: Linkage ;
11+ use rustc_hir:: attrs:: { AttributeKind , Linkage } ;
12+ use rustc_hir:: find_attr;
1213use rustc_middle:: dep_graph;
1314#[ cfg( feature = "master" ) ]
1415use 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
You can’t perform that action at this time.
0 commit comments