@@ -7,6 +7,7 @@ use rustc_middle::middle::codegen_fn_attrs::{
77 TargetFeature ,
88} ;
99use rustc_middle:: ty:: { self , Instance , TyCtxt } ;
10+ use rustc_sanitizers:: ignorelist:: SanitizerIgnoreList ;
1011use rustc_session:: config:: {
1112 BranchProtection , FunctionReturn , InstrumentMcount , InstrumentMcountOpts , OptLevel , PAuthKey ,
1213 PacRet ,
@@ -476,7 +477,7 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
476477 llfn : & ' ll Value ,
477478 codegen_fn_attrs : & CodegenFnAttrs ,
478479 instance : Option < ty:: Instance < ' tcx > > ,
479- sanitizer_ignorelist : Option < & crate :: llvm :: SanitizerIgnoreList > ,
480+ sanitizer_ignorelist : Option < & SanitizerIgnoreList > ,
480481) {
481482 let sess = tcx. sess ;
482483 let mut to_add = SmallVec :: < [ _ ; 16 ] > :: new ( ) ;
@@ -541,59 +542,12 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
541542 let mut enabled = tcx. sess . sanitizers ( ) - codegen_fn_attrs. sanitizers . disabled ;
542543 if let Some ( ignorelist) = sanitizer_ignorelist {
543544 if let Some ( instance) = instance {
544- let sym_name = tcx. symbol_name ( instance) . name ;
545- let span = tcx. def_span ( instance. def_id ( ) ) ;
546- let source_map = tcx. sess . source_map ( ) ;
547- let filename =
548- source_map. span_to_filename ( span) . prefer_local_unconditionally ( ) . to_string ( ) ;
549-
550- let mainfile = tcx
551- . sess
552- . local_crate_source_file ( )
553- . and_then ( |path| path. local_path ( ) . map ( |p| p. display ( ) . to_string ( ) ) )
554- . unwrap_or_default ( ) ;
555-
556- let demangled = rustc_middle:: ty:: print:: with_no_trimmed_paths!(
557- tcx. def_path_str( instance. def_id( ) )
558- ) ;
559- let is_ignored = |section : & std:: ffi:: CStr | -> bool {
560- ignorelist. contains_prefix ( section, c"fun" , sym_name)
561- || ignorelist. contains_prefix ( section, c"fun" , & demangled)
562- || ignorelist. contains_prefix ( section, c"src" , & filename)
563- || ( !mainfile. is_empty ( )
564- && ignorelist. contains_prefix ( section, c"mainfile" , & mainfile) )
565- } ;
566-
567- let ignore_address = is_ignored ( c"address" ) ;
568- let ignore_kernel_address = ignore_address || is_ignored ( c"kernel-address" ) ;
569- let ignore_hwaddress = is_ignored ( c"hwaddress" ) ;
570- let ignore_kernel_hwaddress = ignore_hwaddress || is_ignored ( c"kernel-hwaddress" ) ;
571-
572- if enabled. contains ( SanitizerSet :: ADDRESS ) && ignore_address {
573- enabled. remove ( SanitizerSet :: ADDRESS ) ;
574- }
575- if enabled. contains ( SanitizerSet :: KERNELADDRESS ) && ignore_kernel_address {
576- enabled. remove ( SanitizerSet :: KERNELADDRESS ) ;
577- }
578- if enabled. contains ( SanitizerSet :: MEMORY ) && is_ignored ( c"memory" ) {
579- enabled. remove ( SanitizerSet :: MEMORY ) ;
580- }
581- if enabled. contains ( SanitizerSet :: THREAD ) && is_ignored ( c"thread" ) {
582- enabled. remove ( SanitizerSet :: THREAD ) ;
583- }
584- if enabled. contains ( SanitizerSet :: HWADDRESS ) && ignore_hwaddress {
585- enabled. remove ( SanitizerSet :: HWADDRESS ) ;
586- }
587- if enabled. contains ( SanitizerSet :: KERNELHWADDRESS ) && ignore_kernel_hwaddress {
588- enabled. remove ( SanitizerSet :: KERNELHWADDRESS ) ;
589- }
590- if enabled. contains ( SanitizerSet :: SAFESTACK ) && is_ignored ( c"safestack" ) {
591- enabled. remove ( SanitizerSet :: SAFESTACK ) ;
592- }
593- if is_ignored ( c"cfi" ) {
545+ let result = ignorelist. filter_instance_sanitizers ( tcx, instance, enabled) ;
546+ enabled = result. enabled ;
547+ if result. ignore_cfi {
594548 to_add. push ( llvm:: CreateAttrString ( cx. llcx , "no-sanitize-cfi" ) ) ;
595549 }
596- if is_ignored ( c"kcfi" ) {
550+ if result . ignore_kcfi {
597551 to_add. push ( llvm:: CreateAttrString ( cx. llcx , "no-sanitize-kcfi" ) ) ;
598552 }
599553 }
0 commit comments