File tree 6 files changed +89
-4
lines changed
librustc_codegen_llvm/back
test/run-make/wasm-export-all-symbols
6 files changed +89
-4
lines changed Original file line number Diff line number Diff line change @@ -96,9 +96,14 @@ pub unsafe extern fn __rust_start_panic(_payload: usize) -> u32 {
96
96
// runtime at all.
97
97
pub mod personalities {
98
98
#[ no_mangle]
99
- #[ cfg( not( all( target_os = "windows" ,
100
- target_env = "gnu" ,
101
- target_arch = "x86_64" ) ) ) ]
99
+ #[ cfg( not( any(
100
+ target_arch = "wasm32" ,
101
+ all(
102
+ target_os = "windows" ,
103
+ target_env = "gnu" ,
104
+ target_arch = "x86_64" ,
105
+ ) ,
106
+ ) ) ) ]
102
107
pub extern fn rust_eh_personality ( ) { }
103
108
104
109
// On x86_64-pc-windows-gnu we use our own personality function that needs
Original file line number Diff line number Diff line change @@ -89,6 +89,7 @@ impl LinkerInfo {
89
89
Box :: new ( WasmLd {
90
90
cmd,
91
91
sess,
92
+ info : self
92
93
} ) as Box < dyn Linker >
93
94
}
94
95
}
@@ -926,6 +927,7 @@ fn exported_symbols(tcx: TyCtxt, crate_type: CrateType) -> Vec<String> {
926
927
pub struct WasmLd < ' a > {
927
928
cmd : Command ,
928
929
sess : & ' a Session ,
930
+ info : & ' a LinkerInfo ,
929
931
}
930
932
931
933
impl < ' a > Linker for WasmLd < ' a > {
@@ -1021,7 +1023,10 @@ impl<'a> Linker for WasmLd<'a> {
1021
1023
fn build_dylib ( & mut self , _out_filename : & Path ) {
1022
1024
}
1023
1025
1024
- fn export_symbols ( & mut self , _tmpdir : & Path , _crate_type : CrateType ) {
1026
+ fn export_symbols ( & mut self , _tmpdir : & Path , crate_type : CrateType ) {
1027
+ for sym in self . info . exports [ & crate_type] . iter ( ) {
1028
+ self . cmd . arg ( "--export" ) . arg ( & sym) ;
1029
+ }
1025
1030
}
1026
1031
1027
1032
fn subsystem ( & mut self , _subsystem : & str ) {
Original file line number Diff line number Diff line change
1
+ -include ../../run-make-fulldeps/tools.mk
2
+
3
+ ifeq ($(TARGET ) ,wasm32-unknown-unknown)
4
+ all :
5
+ $(RUSTC ) bar.rs --target wasm32-unknown-unknown
6
+ $(RUSTC ) foo.rs --target wasm32-unknown-unknown
7
+ $(NODE ) verify.js $(TMPDIR ) /foo.wasm
8
+ $(RUSTC ) bar.rs --target wasm32-unknown-unknown -O
9
+ $(RUSTC ) foo.rs --target wasm32-unknown-unknown -O
10
+ $(NODE ) verify.js $(TMPDIR ) /foo.wasm
11
+ $(RUSTC ) foo.rs --target wasm32-unknown-unknown -C lto
12
+ $(NODE ) verify.js $(TMPDIR ) /foo.wasm
13
+ else
14
+ all :
15
+ endif
16
+
Original file line number Diff line number Diff line change
1
+ // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2
+ // file at the top-level directory of this distribution and at
3
+ // http://rust-lang.org/COPYRIGHT.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6
+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7
+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8
+ // option. This file may not be copied, modified, or distributed
9
+ // except according to those terms.
10
+
11
+ #![ crate_type = "rlib" ]
12
+
13
+ #[ no_mangle]
14
+ pub extern fn foo ( ) { }
Original file line number Diff line number Diff line change
1
+ // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2
+ // file at the top-level directory of this distribution and at
3
+ // http://rust-lang.org/COPYRIGHT.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6
+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7
+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8
+ // option. This file may not be copied, modified, or distributed
9
+ // except according to those terms.
10
+
11
+ #![ crate_type = "cdylib" ]
12
+
13
+ extern crate bar;
Original file line number Diff line number Diff line change
1
+ // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2
+ // file at the top-level directory of this distribution and at
3
+ // http://rust-lang.org/COPYRIGHT.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6
+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7
+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8
+ // option. This file may not be copied, modified, or distributed
9
+ // except according to those terms.
10
+
11
+ const fs = require ( 'fs' ) ;
12
+ const process = require ( 'process' ) ;
13
+ const assert = require ( 'assert' ) ;
14
+ const buffer = fs . readFileSync ( process . argv [ 2 ] ) ;
15
+
16
+ let m = new WebAssembly . Module ( buffer ) ;
17
+ let list = WebAssembly . Module . exports ( m ) ;
18
+ console . log ( 'exports' , list ) ;
19
+
20
+ const my_exports = { } ;
21
+ let nexports = 0 ;
22
+ for ( const entry of list ) {
23
+ if ( entry . kind !== 'function' )
24
+ continue ;
25
+ my_exports [ entry . name ] = true ;
26
+ nexports += 1 ;
27
+ }
28
+
29
+ if ( nexports != 1 )
30
+ throw new Error ( "should only have one function export" ) ;
31
+ if ( my_exports . foo === undefined )
32
+ throw new Error ( "`foo` wasn't defined" ) ;
You can’t perform that action at this time.
0 commit comments