File tree 3 files changed +29
-1
lines changed
librustc_codegen_llvm/back
test/run-make-fulldeps/pgo-gen-no-imp-symbols
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(
795
795
} else {
796
796
"\x01 __imp_"
797
797
} ;
798
+
798
799
unsafe {
799
800
let i8p_ty = Type :: i8p_llcx ( llcx) ;
800
801
let globals = base:: iter_globals ( llmod)
801
802
. filter ( |& val| {
802
803
llvm:: LLVMRustGetLinkage ( val) == llvm:: Linkage :: ExternalLinkage &&
803
804
llvm:: LLVMIsDeclaration ( val) == 0
804
805
} )
805
- . map ( move |val| {
806
+ . filter_map ( |val| {
807
+ // Exclude some symbols that we know are not Rust symbols.
806
808
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) | {
807
816
let mut imp_name = prefix. as_bytes ( ) . to_vec ( ) ;
808
817
imp_name. extend ( name. to_bytes ( ) ) ;
809
818
let imp_name = CString :: new ( imp_name) . unwrap ( ) ;
810
819
( imp_name, val)
811
820
} )
812
821
. collect :: < Vec < _ > > ( ) ;
822
+
813
823
for ( imp_name, val) in globals {
814
824
let imp = llvm:: LLVMAddGlobal ( llmod,
815
825
i8p_ty,
@@ -818,4 +828,10 @@ fn create_msvc_imps(
818
828
llvm:: LLVMRustSetLinkage ( imp, llvm:: Linkage :: ExternalLinkage ) ;
819
829
}
820
830
}
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
+ }
821
837
}
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