Solana deploy fails 'Section or symbol name .bss._ZN5ahash12 is longer than 16 bytes' — disable ahash default features
Symptom: anchor build / cargo build-sbf succeeds, but solana program deploy rejects the artifact with
Error: ELF error: ELF error: Failed to parse ELF file: Section or symbol name `.bss._ZN5ahash12` is longer than `16` bytesCause: the SBF loader caps ELF section and symbol names at 16 bytes. The ahash crate's default runtime-rng feature creates a lazily initialised static for random hash seeds (OnceBox<[[u64; 4]; 2]>, reached via its fixed-seed path), and the mangled Rust symbol for it lands in a .bss.<mangled> section whose name exceeds the limit. Nothing in your own code is too long, which is why the error looks unrelated to anything you wrote — inspect target/deploy/*-dump.txt after cargo build-sbf --dump to see the offending section.
Fix, both parts:
[dependencies]
ahash = { version = "0.8.11", default-features = false }// avoid the random-seed initialiser entirely
let mut hasher = AHasher::new_with_keys(1234, 5678);Disabling default features removes the runtime-rng code path; using new_with_keys instead of default() avoids the seed static. The trade-off is deterministic rather than randomised hashing, which is fine for non-cryptographic, non-DoS-exposed uses — and on-chain code has no OS entropy source anyway, so randomised seeding was never doing what it does off-chain.
Alternative: drop ahash and hash with solana_program::hash::hashv / keccak / a small FNV implementation, which also removes a dependency from a compute-metered program.
Generalisation worth remembering: any Rust dependency that emits long mangled statics can trip this 16-byte ELF limit at deploy time rather than build time, so a clean build is no guarantee. Seen with anchor-lang 0.30.1 and solana 1.18 platform-tools.
Source: adapted from a Stack Exchange answer by sarugami (question by Midas092), https://solana.stackexchange.com/questions/21172/error-elf-error-elf-error-failed-to-parse-elf-file-section-or-symbol-name — CC BY-SA 4.0