Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add -Zexport-executable-symbols to unstable book #104549

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# `export-executable-symbols`

The tracking issue for this feature is: [#84161](https://github.com/rust-lang/rust/issues/84161).

------------------------

The `-Zexport-executable-symbols` compiler flag makes `rustc` export symbols from executables. The resulting binary is runnable, but can also be used as a dynamic library. This is useful for interoperating with programs written in other languages, in particular languages with a runtime like Java or Lua.

For example on windows:
```rust
#[no_mangle]
fn my_function() -> usize {
return 42;
}

fn main() {
println!("Hello, world!");
}
```

A standard `cargo build` will produce a `.exe` without an export directory. When the `export-executable-symbols` flag is added

```Bash
export RUSTFLAGS="-Zexport-executable-symbols"
cargo build
```

the binary has an export directory with the functions:

```plain
The Export Tables (interpreted .edata section contents)

...

[Ordinal/Name Pointer] Table
[ 0] my_function
[ 1] main
```
(the output of `objdump -x` on the binary)

Please note that the `#[no_mangle]` attribute is required. Without it, the symbol is not exported.

The equivalent of this flag in C and C++ compilers is the `__declspec(dllexport)` annotation or the `-rdynamic` linker flag.