coral-xyz / anchor

⚓ Solana Sealevel Framework
https://anchor-lang.com
Apache License 2.0
3.36k stars 1.25k forks source link

anchor build error: `Stack offset of 4608 exceeded max offset of 4096` #2956

Closed code-brewer closed 1 month ago

code-brewer commented 1 month ago

example project: https://github.com/coral-xyz/anchor/tree/14309ea14639b8042055e1b432bd6be24434970f/tests/events

let solana v1.18.10 present in ENV/PATH, and anchor build got error: Stack offset of 4608 exceeded max offset of 4096 ...
 ❱❱❱ which solana
/mnt/volume2/solana_dev_env/v1.18.10/solana-release/bin/solana
 ❱❱❱  echo $PATH         
/mnt/volume2/solana_dev_env/v1.18.10/solana-release/bin:/home/ubuntu/.cargo/bin:/usr/local/sbin: ...
 ❱❱❱ /mnt/volume2/solana_dev_env/v1.18.10/solana-release/bin/solana --version
solana-cli 1.18.10 (src:50b3f337; feat:3469865029, client:SolanaLabs)
(events) ❱❱❱ anchor build                                                   
info: uninstalling toolchain 'solana'
info: toolchain 'solana' uninstalled
warning: virtual workspace defaulting to `resolver = "1"` despite one or more workspace members being on edition 2021 which implies `resolver = "2"`
note: to keep the current resolver, specify `workspace.resolver = "1"` in the workspace root's manifest
note: to use the edition 2021 resolver, specify `workspace.resolver = "2"` in the workspace root's manifest
note: for more details see https://doc.rust-lang.org/cargo/reference/resolver.html#resolver-versions
   Compiling proc-macro2 v1.0.79

...

   Compiling anchor-attribute-program v0.28.0
   Compiling anchor-attribute-error v0.28.0
   Compiling anchor-derive-space v0.28.0
   Compiling base64 v0.13.1
Error: Function _ZN112_$LT$solana_program..instruction..InstructionError$u20$as$u20$solana_frozen_abi..abi_example..AbiEnumVisitor$GT$13visit_for_abi17hd196cb48ec8b8db8E Stack offset of 4608 exceeded max offset of 4096 by 512 bytes, please minimize large stack variables
Error: Function _ZN108_$LT$solana_program..vote..state..CircBuf$LT$I$GT$$u20$as$u20$solana_frozen_abi..abi_example..AbiExample$GT$7example17h4b696142e261c9f4E Stack offset of 4640 exceeded max offset of 4096 by 544 bytes, please minimize large stack variables
   Compiling anchor-lang v0.28.0
            ...

Note: this solana was download from: wget https://github.com/anza-xyz/platform-tools/releases/download/v1.41/platform-tools-linux-x86_64.tar.bz2

while let old version solana present in ENV/PATH, anchor build build output so without error.
(events) ❱❱❱  solana --version
solana-cli 1.16.25 (src:8dd7d060; feat:2294205250, client:SolanaLabs)
(events) ❱❱❱ anchor build  # build successfully
info: uninstalling toolchain 'solana'
            ...
acheroncrypto commented 1 month ago

Searching the error on a search engine gets me to https://solana.stackexchange.com/a/9899.

Compiling anchor-lang v0.28.0

You're using anchor-lang 0.28.0 which uses solana-program 1.16, but the problem is fixed in solana-program 1.18.2. You can upgrade Anchor to 0.29.0 or 0.30.0 to be able to use solana-program 1.18.2. See https://github.com/solana-labs/solana/issues/35003#issuecomment-1970028870.