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 @@ -41,6 +41,24 @@ pub fn crate_type_allows_lto(crate_type: CrateType) -> bool {
41
41
}
42
42
}
43
43
44
+ fn get_llvm_preserved_symbols ( ) -> Vec < String > {
45
+ let mut len = 0 ;
46
+ unsafe {
47
+ let symbols = llvm:: LLVMRustPreservedSymbols ( & mut len) ;
48
+ let symbols: & [ * const _ ] = slice:: from_raw_parts ( symbols, len) ;
49
+ symbols
50
+ . iter ( )
51
+ . filter_map ( |& symbol| {
52
+ if symbol. is_null ( ) {
53
+ None
54
+ } else {
55
+ Some ( String :: from_utf8 ( CStr :: from_ptr ( symbol) . to_bytes ( ) . to_vec ( ) ) . unwrap ( ) )
56
+ }
57
+ } )
58
+ . collect ( )
59
+ }
60
+ }
61
+
44
62
fn prepare_lto (
45
63
cgcx : & CodegenContext < LlvmCodegenBackend > ,
46
64
diag_handler : & Handler ,
@@ -55,8 +73,13 @@ fn prepare_lto(
55
73
Lto :: No => panic ! ( "didn't request LTO but we're doing LTO" ) ,
56
74
} ;
57
75
76
+ let llvm_reserved_symbols = get_llvm_preserved_symbols ( ) ;
77
+
58
78
let symbol_filter = & |& ( ref name, info) : & ( String , SymbolExportInfo ) | {
59
- if info. level . is_below_threshold ( export_threshold) || info. used {
79
+ if info. level . is_below_threshold ( export_threshold)
80
+ || info. used
81
+ || llvm_reserved_symbols. contains ( name)
82
+ {
60
83
Some ( CString :: new ( name. as_str ( ) ) . unwrap ( ) )
61
84
} else {
62
85
None
Original file line number Diff line number Diff line change @@ -2187,6 +2187,7 @@ extern "C" {
2187
2187
pub fn LLVMRustSetLLVMOptions ( Argc : c_int , Argv : * const * const c_char ) ;
2188
2188
pub fn LLVMRustPrintPasses ( ) ;
2189
2189
pub fn LLVMRustSetNormalizedTarget ( M : & Module , triple : * const c_char ) ;
2190
+ pub fn LLVMRustPreservedSymbols ( len : * mut usize ) -> * const * const c_char ;
2190
2191
pub fn LLVMRustRunRestrictionPass ( M : & Module , syms : * const * const c_char , len : size_t ) ;
2191
2192
2192
2193
pub fn LLVMRustOpenArchive ( path : * const c_char ) -> Option < & ' static mut Archive > ;
Original file line number Diff line number Diff line change @@ -1120,6 +1120,20 @@ extern "C" void LLVMRustPrintPasses() {
1120
1120
PB.printPassNames (outs ());
1121
1121
}
1122
1122
1123
+ // from https://github.com/llvm/llvm-project/blob/7021182d6b43de9488ab70de626192ce70b3a4a6/llvm/lib/Object/IRSymtab.cpp#L48-L57
1124
+ static const char *PreservedSymbols[] = {
1125
+ #define HANDLE_LIBCALL (code, name ) name,
1126
+ #include " llvm/IR/RuntimeLibcalls.def"
1127
+ #undef HANDLE_LIBCALL
1128
+ " __ssp_canary_word" ,
1129
+ " __stack_chk_guard" ,
1130
+ };
1131
+
1132
+ extern " C" const char **LLVMRustPreservedSymbols (size_t *len) {
1133
+ *len = sizeof (PreservedSymbols) / sizeof (PreservedSymbols[0 ]);
1134
+ return PreservedSymbols;
1135
+ }
1136
+
1123
1137
extern " C" void LLVMRustRunRestrictionPass (LLVMModuleRef M, char **Symbols,
1124
1138
size_t Len) {
1125
1139
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