mirror of
https://github.com/denoland/deno.git
synced 2025-01-21 13:00:36 -05:00
fix(build): don't export all symbols to dynamic symbol table (#16171)
Currently, we use `-rdynamic` for exporting Node API symbols to the symbol table. `-rdynamic` will export *all* symbols, that means previously unused functions will not be optimized away introducing a lot of binary bloat. This patch uses `-exported_symbol` and `--export-dynamic-symbol` link flags (not as universal as `-rdynamic`) to only mark Node API symbols to be put in the dynamic symbol table.
This commit is contained in:
parent
9102ba9b0f
commit
cd1c63ad71
4 changed files with 34 additions and 2 deletions
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
|
@ -40,6 +40,7 @@ jobs:
|
||||||
- os: ${{ github.repository == 'denoland/deno' && 'ubuntu-20.04-xl' || 'ubuntu-20.04' }}
|
- os: ${{ github.repository == 'denoland/deno' && 'ubuntu-20.04-xl' || 'ubuntu-20.04' }}
|
||||||
job: test
|
job: test
|
||||||
profile: debug
|
profile: debug
|
||||||
|
use_sysroot: true
|
||||||
- os: ${{ github.repository == 'denoland/deno' && 'ubuntu-20.04-xl' || 'ubuntu-20.04' }}
|
- os: ${{ github.repository == 'denoland/deno' && 'ubuntu-20.04-xl' || 'ubuntu-20.04' }}
|
||||||
job: lint
|
job: lint
|
||||||
profile: debug
|
profile: debug
|
||||||
|
@ -412,7 +413,7 @@ jobs:
|
||||||
|
|
||||||
# Verify that the binary actually works in the Ubuntu-16.04 sysroot.
|
# Verify that the binary actually works in the Ubuntu-16.04 sysroot.
|
||||||
- name: Check deno binary (in sysroot)
|
- name: Check deno binary (in sysroot)
|
||||||
if: matrix.use_sysroot
|
if: matrix.profile == 'release' && matrix.use_sysroot
|
||||||
run: sudo chroot /sysroot "$(pwd)/target/release/deno" --version
|
run: sudo chroot /sysroot "$(pwd)/target/release/deno" --version
|
||||||
|
|
||||||
# TODO(ry): Because CI is so slow on for OSX and Windows, we currently
|
# TODO(ry): Because CI is so slow on for OSX and Windows, we currently
|
||||||
|
|
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -869,6 +869,7 @@ dependencies = [
|
||||||
"rustyline-derive",
|
"rustyline-derive",
|
||||||
"semver 1.0.14",
|
"semver 1.0.14",
|
||||||
"serde",
|
"serde",
|
||||||
|
"serde_json",
|
||||||
"serde_repr",
|
"serde_repr",
|
||||||
"shell-escape",
|
"shell-escape",
|
||||||
"tar",
|
"tar",
|
||||||
|
|
|
@ -41,6 +41,7 @@ deno_websocket = { version = "0.76.0", path = "../ext/websocket" }
|
||||||
deno_webstorage = { version = "0.66.0", path = "../ext/webstorage" }
|
deno_webstorage = { version = "0.66.0", path = "../ext/webstorage" }
|
||||||
regex = "=1.6.0"
|
regex = "=1.6.0"
|
||||||
serde = { version = "=1.0.144", features = ["derive"] }
|
serde = { version = "=1.0.144", features = ["derive"] }
|
||||||
|
serde_json = "1.0.64"
|
||||||
zstd = '=0.11.2'
|
zstd = '=0.11.2'
|
||||||
|
|
||||||
[target.'cfg(windows)'.build-dependencies]
|
[target.'cfg(windows)'.build-dependencies]
|
||||||
|
|
31
cli/build.rs
31
cli/build.rs
|
@ -344,7 +344,36 @@ fn main() {
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
println!("cargo:rustc-link-arg-bin=deno=-rdynamic");
|
{
|
||||||
|
// Load the symbols file generated by the `napi_sym` macro.
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
struct Symbols {
|
||||||
|
symbols: Vec<String>,
|
||||||
|
}
|
||||||
|
let symbols_json =
|
||||||
|
std::fs::read_to_string("../tools/napi/symbol_exports.json").expect(
|
||||||
|
"Missing tools/napi/symbol_exports.json! This is a bug in napi_sym",
|
||||||
|
);
|
||||||
|
let symbols: Symbols = serde_json::from_str(&symbols_json)
|
||||||
|
.expect("tools/napi/symbol_exports.json is not valid JSON");
|
||||||
|
|
||||||
|
// Don't export all symbols into the dynamic symbol table. -rdynamic exports *all* symbols introducing binary bloat.
|
||||||
|
// We only need to export Node API symbols.
|
||||||
|
for symbol in symbols.symbols {
|
||||||
|
// TODO(@littledivy): We _might_ hit an argument size limit?
|
||||||
|
// Maybe use `--export-dynamic-symbol-list` / `--exported_symbols_list` instead? https://reviews.llvm.org/D107317
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
println!(
|
||||||
|
"cargo:rustc-link-arg-bin=deno=-Wl,-exported_symbol,_{}",
|
||||||
|
symbol
|
||||||
|
);
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
println!(
|
||||||
|
"cargo:rustc-link-arg-bin=deno=-Wl,--export-dynamic-symbol={}",
|
||||||
|
symbol
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// To debug snapshot issues uncomment:
|
// To debug snapshot issues uncomment:
|
||||||
// op_fetch_asset::trace_serializer();
|
// op_fetch_asset::trace_serializer();
|
||||||
|
|
Loading…
Add table
Reference in a new issue