Skip to content

Commit

Permalink
No wasm nm (#263)
Browse files Browse the repository at this point in the history
# Motivation
We use `wasm-nm` (the Wasm version of
[`nm`](https://web.mit.edu/gnu/doc/html/binutils_3.html)) to geta list
of exported functions.

Unfortunately `wasm-nm` is no longer maintained and fails with the
latest Wasm files that have new instructions.

`ic-wasm info` provides the same information, but not in a machine
readable form. Where we have switched to ic-wasm we use sed to extract
the interesting information, at which point the output is practically in
the standard `nm` output format.

I propose to ask upstream to provide a machine readable output,
preferably in the `nm` format, and in the meantime make a polyfill.

## Alternatives considered

Copy and paste the sed incantation into the one place we use `wasm-nm`
in this repository. I'd rather get a clean solution pushed upstream.

---------

Co-authored-by: Max Murphy <max@winning.black>
  • Loading branch information
bitdivine and bitdivine authored Nov 8, 2023
1 parent a379abf commit 10f86e3
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 50 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,12 @@ jobs:
- uses: actions/checkout@v3
- name: Install apt-dependencies
run: sudo apt-get update && sudo apt-get install moreutils -yy && command -v more
- name: Install cargo binstall
uses: ./.github/actions/install_binstall
- name: Install tools
run: ./bin/dfx-software-wasm-nm-install
run: |
. bin/versions.bash
cargo binstall --force --no-confirm "ic-wasm@${IC_WASM_VERSION}"
- name: "Test the sns aggregator version command"
run: ./bin/dfx-software-sns-aggregator-version.test
env:
Expand Down Expand Up @@ -117,8 +121,12 @@ jobs:
run: ./bin/dfx-software-nns-dapp-version.test
env:
GH_TOKEN: ${{ github.token }}
- name: Install cargo binstall
uses: ./.github/actions/install_binstall
- name: Install tools
run: ./bin/dfx-software-wasm-nm-install
run: |
. bin/versions.bash
cargo binstall --force --no-confirm "ic-wasm@${IC_WASM_VERSION}"
- name: "Test the nns-dapp url command"
run: ./bin/dfx-software-nns-dapp-ci-wasm-url.test
env:
Expand Down
2 changes: 1 addition & 1 deletion bin/dfx-canister-nm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ source "$SOURCE_DIR/clap.bash"
source "$(clap.build)"

# The only meaningful export from canister wasms is function names.
canister_nm=(wasm-nm -je)
canister_nm=(wasm-nm -j -e)

canister_wasm="$1"
case "$(file "$canister_wasm")" in
Expand Down
47 changes: 0 additions & 47 deletions bin/dfx-software-wasm-nm-install

This file was deleted.

1 change: 1 addition & 0 deletions bin/versions.bash
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ DIDC_VERSION=2023-07-25
QUILL_VERSION=0.4.0
IDL2JSON_VERSION=0.8.5
BINSTALL_VERSION=1.3.0
IC_WASM_VERSION=0.6.0
52 changes: 52 additions & 0 deletions bin/wasm-nm
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash
set -euo pipefail
SOURCE_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]}")")"
PATH="$SOURCE_DIR:$PATH"

print_help() {
cat <<-EOF
Polyfill for the now outdated wasm-nm.
Supports only:
wasm-nm -e SOMEFILE.wasm
wasm-nm -e -j SOMEFILE.wasm
Note: ic-wasm now provides much the same information, but not in a very machine-readable format.
EOF
}

# Source the clap.bash file ---------------------------------------------------
source "$SOURCE_DIR/clap.bash"
# Define options
clap.define short=e long=export desc="Display only export symbols." variable=ONLY_EXPORT nargs=0
clap.define short=j long=export desc="Just display the symbol names (no type)." variable=NO_TYPE nargs=0
# Source the output file ----------------------------------------------------------
source "$(clap.build)"

(($# == 1)) || {
echo "ERROR: Please provide the Wasm filename as a positional argument, like this:"
echo " wasm-nm -e my-file.wasm"
exit 1
} >&2

WASM_FILENAME="${1:-}"

export_symbols() {
ic-wasm "${WASM_FILENAME:-}" info | sed -nE '/^Exported methods:/,/^]/p' | sed '1d;$d' | sed -E 's/.*"(.*)",/\1/;s/ *\(.*//g' | {
if [[ "${NO_TYPE:-}" == "true" ]]; then
cat
else
sed 's/^/e /g'
fi
}
}

if [[ "${ONLY_EXPORT}" == "true" ]]; then
export_symbols
else
{
echo "ERROR: Action not supported, sorry."
exit 1
} >&2
fi

0 comments on commit 10f86e3

Please sign in to comment.