File tree Expand file tree Collapse file tree 3 files changed +29
-1
lines changed
librustc_codegen_llvm/back
test/run-make-fulldeps/pgo-gen-no-imp-symbols Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -795,21 +795,31 @@ fn create_msvc_imps(
795795 } else {
796796 "\x01 __imp_"
797797 } ;
798+
798799 unsafe {
799800 let i8p_ty = Type :: i8p_llcx ( llcx) ;
800801 let globals = base:: iter_globals ( llmod)
801802 . filter ( |& val| {
802803 llvm:: LLVMRustGetLinkage ( val) == llvm:: Linkage :: ExternalLinkage &&
803804 llvm:: LLVMIsDeclaration ( val) == 0
804805 } )
805- . map ( move |val| {
806+ . filter_map ( |val| {
807+ // Exclude some symbols that we know are not Rust symbols.
806808 let name = CStr :: from_ptr ( llvm:: LLVMGetValueName ( val) ) ;
809+ if ignored ( name. to_bytes ( ) ) {
810+ None
811+ } else {
812+ Some ( ( val, name) )
813+ }
814+ } )
815+ . map ( move |( val, name) | {
807816 let mut imp_name = prefix. as_bytes ( ) . to_vec ( ) ;
808817 imp_name. extend ( name. to_bytes ( ) ) ;
809818 let imp_name = CString :: new ( imp_name) . unwrap ( ) ;
810819 ( imp_name, val)
811820 } )
812821 . collect :: < Vec < _ > > ( ) ;
822+
813823 for ( imp_name, val) in globals {
814824 let imp = llvm:: LLVMAddGlobal ( llmod,
815825 i8p_ty,
@@ -818,4 +828,10 @@ fn create_msvc_imps(
818828 llvm:: LLVMRustSetLinkage ( imp, llvm:: Linkage :: ExternalLinkage ) ;
819829 }
820830 }
831+
832+ // Use this function to exclude certain symbols from `__imp` generation.
833+ fn ignored ( symbol_name : & [ u8 ] ) -> bool {
834+ // These are symbols generated by LLVM's profiling instrumentation
835+ symbol_name. starts_with ( b"__llvm_profile_" )
836+ }
821837}
Original file line number Diff line number Diff line change 1+ -include ../tools.mk
2+
3+ all :
4+ ifeq ($(PROFILER_SUPPORT ) ,1)
5+ $(RUSTC) -O -Ccodegen-units=1 -Z pgo-gen="$(TMPDIR)/test.profraw" --emit=llvm-ir test.rs
6+ # We expect symbols starting with "__llvm_profile_".
7+ $(CGREP) "__llvm_profile_" < $(TMPDIR)/test.ll
8+ # We do NOT expect the "__imp_" version of these symbols.
9+ $(CGREP) -v "__imp___llvm_profile_" < $(TMPDIR)/test.ll # 64 bit
10+ $(CGREP) -v "__imp____llvm_profile_" < $(TMPDIR)/test.ll # 32 bit
11+ endif
Original file line number Diff line number Diff line change 1+ fn main ( ) { }
You can’t perform that action at this time.
0 commit comments