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

[Bug] ABI generation fails #317

Open
evgenykuzyakov opened this issue Mar 21, 2025 · 1 comment
Open

[Bug] ABI generation fails #317

evgenykuzyakov opened this issue Mar 21, 2025 · 1 comment

Comments

@evgenykuzyakov
Copy link

Background

As part of the work on house of stake contracts, we've discovered that ABI generation fails when using sys crate for direct API access.

To reproduce:

git clone https://github.com/fastnear/house-of-stake-contracts
git checkout 23ac7b4051ffa01670e0651c9eb54624178e22cb
cd venear-contract
cargo near build non-reproducible-wasm

Error:

 error: linking with `cc` failed: exit status: 1
 │   |
 = note: env -u IPHONEOS_DEPLOYMENT_TARGET -u TVOS_DEPLOYMENT_TARGET -u XROS_DEPLOYMENT_TARGET LC_ALL="C" PATH="/....
...
...
...
│   = note: Undefined symbols for architecture arm64:
 │             "_attached_deposit", referenced from:
 │                 near_sdk::environment::env::attached_deposit::he82e1719fa48c466 in libnear_sdk-964dec7928e15740.rlib[3](near_sdk-964dec7928e15740.near_sdk.3f5c6dd446e6932f-cgu.0.rcgu.o)
 │             "_current_account_id", referenced from:
 │                 near_sdk::environment::env::current_account_id::hc703cfdbcc6af662 in libnear_sdk-964dec7928e15740.rlib[3](near_sdk-964dec7928e15740.near_sdk.3f5c6dd446e6932f-cgu.0.rcgu.o)
 │             "_input", referenced from:
 │                 _upgrade in venear_contract.2pp6nk6emeeherydhwfo9kbae.rcgu.o
 │                 _prepare_lockup_code in venear_contract.7qsrv4khoo1u2dgycn4aj57gj.rcgu.o
 │             "_panic_utf8", referenced from:
 │                 near_sdk::environment::env::panic_str::he66a955fc6285268 in libnear_sdk-964dec7928e15740.rlib[3](near_sdk-964dec7928e15740.near_sdk.3f5c6dd446e6932f-cgu.0.rcgu.o)
 │             "_predecessor_account_id", referenced from:
 │                 near_sdk::environment::env::predecessor_account_id::h3ad3fec5c378db42 in libnear_sdk-964dec7928e15740.rlib[3](near_sdk-964dec7928e15740.near_sdk.3f5c6dd446e6932f-cgu.0.rcgu.o)
 │             "_promise_batch_action_deploy_contract", referenced from:
 │                 _upgrade in venear_contract.2pp6nk6emeeherydhwfo9kbae.rcgu.o
 │             "_promise_batch_action_function_call", referenced from:
 │                 _upgrade in venear_contract.2pp6nk6emeeherydhwfo9kbae.rcgu.o
 │             "_promise_batch_action_function_call_weight", referenced from:
 │                 _upgrade in venear_contract.2pp6nk6emeeherydhwfo9kbae.rcgu.o
 │             "_promise_batch_create", referenced from:
 │                 _upgrade in venear_contract.2pp6nk6emeeherydhwfo9kbae.rcgu.o
 │             "_promise_return", referenced from:
 │                 _upgrade in venear_contract.2pp6nk6emeeherydhwfo9kbae.rcgu.o
 │             "_read_register", referenced from:
 │                 near_sdk::environment::env::read_register::h3369f9c10274d905 in libnear_sdk-964dec7928e15740.rlib[3](near_sdk-964dec7928e15740.near_sdk.3f5c6dd446e6932f-cgu.0.rcgu.o)
 │             "_register_len", referenced from:
 │                 near_sdk::environment::env::register_len::hcd0e142d5bdd2155 in libnear_sdk-964dec7928e15740.rlib[3](near_sdk-964dec7928e15740.near_sdk.3f5c6dd446e6932f-cgu.0.rcgu.o)
 │             "_sha256", referenced from:
 │                 venear_contract::lockup::internal_get_hash_and_size::h6a73e28e8ab4d24c in venear_contract.7qsrv4khoo1u2dgycn4aj57gj.rcgu.o
 │             "_storage_read", referenced from:
 │                 near_sdk::environment::env::storage_read::h732e154eecb17557 in libnear_sdk-964dec7928e15740.rlib[3](near_sdk-964dec7928e15740.near_sdk.3f5c6dd446e6932f-cgu.0.rcgu.o)
 │             "_storage_remove", referenced from:
 │                 near_sdk::environment::env::storage_remove::hf4f3d2d05f5e41ec in libnear_sdk-964dec7928e15740.rlib[3](near_sdk-964dec7928e15740.near_sdk.3f5c6dd446e6932f-cgu.0.rcgu.o)
 │             "_storage_write", referenced from:
 │                 _prepare_lockup_code in venear_contract.7qsrv4khoo1u2dgycn4aj57gj.rcgu.o
 │                 near_sdk::environment::env::storage_write::h188107ab1de4908c in libnear_sdk-964dec7928e15740.rlib[3](near_sdk-964dec7928e15740.near_sdk.3f5c6dd446e6932f-cgu.0.rcgu.o)
 │             "_value_return", referenced from:
 │                 _prepare_lockup_code in venear_contract.7qsrv4khoo1u2dgycn4aj57gj.rcgu.o
 │           ld: symbol(s) not found for architecture arm64
 │           clang: error: linker command failed with exit code 1 (use -v to see invocation)
 │           
 │ 
 │ error: could not compile `venear-contract` (lib) due to 1 previous error
Here is the console command if you ever need to re-run it again:
cargo near build non-reproducible-wasm

User Story

Acceptance Criteria

Resources & Additional Notes

No response

Priority

🟡 P2 : Medium

@frol
Copy link
Contributor

frol commented Mar 22, 2025

I have investigated the problem and narrowed it down to the no_mangled functions. Here is a quick fix for the project:

diff --git a/venear-contract/src/lockup.rs b/venear-contract/src/lockup.rs
index 38b0eba..831dacb 100644
--- a/venear-contract/src/lockup.rs
+++ b/venear-contract/src/lockup.rs
@@ -297,6 +297,7 @@ impl Contract {
     }
 }

+#[cfg(target_arch = "wasm32")]
 #[no_mangle]
 pub extern "C" fn prepare_lockup_code() {
     env::setup_panic_hook();
diff --git a/venear-contract/src/upgrade.rs b/venear-contract/src/upgrade.rs
index 9a64254..24c6848 100644
--- a/venear-contract/src/upgrade.rs
+++ b/venear-contract/src/upgrade.rs
@@ -18,6 +18,7 @@ impl Contract {
     }
 }

+#[cfg(target_arch = "wasm32")]
 #[no_mangle]
 pub extern "C" fn upgrade() {
     env::setup_panic_hook();

Yet, I still don't understand why it cannot find the symbols for blockchain host functions during ABI generation step.

@dj8yfo Please, take a look at it after you finish with the current tasks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants