File tree 6 files changed +41
-3
lines changed
tests/run-make/wasm-builtins-import
6 files changed +41
-3
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,24 @@ pub fn crate_type_allows_lto(crate_type: CrateType) -> bool {
39
39
}
40
40
}
41
41
42
+ fn get_llvm_preserved_symbols ( ) -> Vec < String > {
43
+ let mut len = 0 ;
44
+ unsafe {
45
+ let symbols = llvm:: LLVMRustPreservedSymbols ( & mut len) ;
46
+ let symbols: & [ * const _ ] = slice:: from_raw_parts ( symbols, len) ;
47
+ symbols
48
+ . iter ( )
49
+ . filter_map ( |& symbol| {
50
+ if symbol. is_null ( ) {
51
+ None
52
+ } else {
53
+ Some ( String :: from_utf8 ( CStr :: from_ptr ( symbol) . to_bytes ( ) . to_vec ( ) ) . unwrap ( ) )
54
+ }
55
+ } )
56
+ . collect ( )
57
+ }
58
+ }
59
+
42
60
fn prepare_lto (
43
61
cgcx : & CodegenContext < LlvmCodegenBackend > ,
44
62
diag_handler : & Handler ,
@@ -53,8 +71,13 @@ fn prepare_lto(
53
71
Lto :: No => panic ! ( "didn't request LTO but we're doing LTO" ) ,
54
72
} ;
55
73
74
+ let llvm_reserved_symbols = get_llvm_preserved_symbols ( ) ;
75
+
56
76
let symbol_filter = & |& ( ref name, info) : & ( String , SymbolExportInfo ) | {
57
- if info. level . is_below_threshold ( export_threshold) || info. used {
77
+ if info. level . is_below_threshold ( export_threshold)
78
+ || info. used
79
+ || llvm_reserved_symbols. contains ( name)
80
+ {
58
81
Some ( CString :: new ( name. as_str ( ) ) . unwrap ( ) )
59
82
} else {
60
83
None
Original file line number Diff line number Diff line change @@ -2170,6 +2170,7 @@ extern "C" {
2170
2170
pub fn LLVMRustSetLLVMOptions ( Argc : c_int , Argv : * const * const c_char ) ;
2171
2171
pub fn LLVMRustPrintPasses ( ) ;
2172
2172
pub fn LLVMRustSetNormalizedTarget ( M : & Module , triple : * const c_char ) ;
2173
+ pub fn LLVMRustPreservedSymbols ( len : * mut usize ) -> * const * const c_char ;
2173
2174
pub fn LLVMRustRunRestrictionPass ( M : & Module , syms : * const * const c_char , len : size_t ) ;
2174
2175
2175
2176
pub fn LLVMRustOpenArchive ( path : * const c_char ) -> Option < & ' static mut Archive > ;
Original file line number Diff line number Diff line change @@ -1043,6 +1043,20 @@ extern "C" void LLVMRustPrintPasses() {
1043
1043
PB.printPassNames (outs ());
1044
1044
}
1045
1045
1046
+ // from https://github.com/llvm/llvm-project/blob/7021182d6b43de9488ab70de626192ce70b3a4a6/llvm/lib/Object/IRSymtab.cpp#L48-L57
1047
+ static const char *PreservedSymbols[] = {
1048
+ #define HANDLE_LIBCALL (code, name ) name,
1049
+ #include " llvm/IR/RuntimeLibcalls.def"
1050
+ #undef HANDLE_LIBCALL
1051
+ " __ssp_canary_word" ,
1052
+ " __stack_chk_guard" ,
1053
+ };
1054
+
1055
+ extern " C" const char **LLVMRustPreservedSymbols (size_t *len) {
1056
+ *len = sizeof (PreservedSymbols) / sizeof (PreservedSymbols[0 ]);
1057
+ return PreservedSymbols;
1058
+ }
1059
+
1046
1060
extern " C" void LLVMRustRunRestrictionPass (LLVMModuleRef M, char **Symbols,
1047
1061
size_t Len) {
1048
1062
auto PreserveFunctions = [=](const GlobalValue &GV) {
File renamed without changes.
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ fn my_panic(_info: &core::panic::PanicInfo) -> ! {
8
8
9
9
#[ no_mangle]
10
10
pub fn multer ( a : i128 , b : i128 ) -> i128 {
11
- // Trigger usage of the __multi3 compiler intrinsic which then leads to an imported
12
- // panic function in case of a bug. We verify that no imports exist in our verifier.
11
+ // Trigger usage of the __multi3 compiler intrinsic which then leads to an imported function
12
+ // such as panic or __multi3 in case of a bug. We verify that no imports exist in our verifier.
13
13
a * b
14
14
}
File renamed without changes.
You can’t perform that action at this time.
0 commit comments