Skip to content

Instantly share code, notes, and snippets.

@delta1
Last active May 3, 2024 13:52
Show Gist options
  • Save delta1/07e15aed5248590817d8e752e4d828fc to your computer and use it in GitHub Desktop.
Save delta1/07e15aed5248590817d8e752e4d828fc to your computer and use it in GitHub Desktop.

simplicity fuzz link error

reproduction

clone the simp-fuzz-debug branch of my elements fork

https://github.com/delta1/elements/tree/simp-fuzz-debug

this includes just one new commit on top of the simplicity branch, creating a new fuzz target

https://github.com/delta1/elements/commit/405de1e82c5c5fc98f24d0e82cba3512eaa9c09b

compile in the usual way

./autogen.sh
./configure --with-incompatible-bdb
make -j15 # or however many cpus you want to use

the error occurs during linking of the fuzz binary

CXXLD    test/fuzz/fuzz
/usr/bin/ld: test/fuzz/fuzz-simplicity.o: in function `simplicity_fuzz_target(Span<unsigned char const>)':
./test/fuzz/simplicity.cpp:40: undefined reference to `elements_simplicity_mallocTapEnv(rawTapEnv const*)'
/usr/bin/ld: ./test/fuzz/simplicity.cpp:47: undefined reference to `elements_simplicity_execSimplicity(simplicity_err*, unsigned char*, transaction const*, unsigned long, tapEnv const*, unsigned char const*, long, unsigned char const*, unsigned char const*, unsigned long)'
collect2: error: ld returned 1 exit status

use verbose mode to see additional information

make -j15 V=1
libtool: link: /usr/bin/ccache g++ -std=c++17 -fdebug-prefix-map=/home/byron/code/elements/src=. -fstack-reuse=none -Wstack-protector -fstack-protector-all -fcf-protection=full -fstack-clash-protection -Wall -Wextra -Wformat -Wformat-security -Wvla -Wswitch -Wredundant-decls -Wunused-variable -Wdate-time -Wsign-compare -Wduplicated-branches -Wduplicated-cond -Wlogical-op -Woverloaded-virtual -Wsuggest-override -Wimplicit-fallthrough -Wno-unused-parameter -Wno-deprecated-copy -fPIE -g -O2 -fno-extended-identifiers -Wl,-z -Wl,relro -Wl,-z -Wl,now -Wl,-z -Wl,separate-code -pie -pthread -o test/fuzz/fuzz test/fuzz/fuzz-addition_overflow.o test/fuzz/fuzz-addrdb.o test/fuzz/fuzz-addrman.o test/fuzz/fuzz-asmap.o test/fuzz/fuzz-asmap_direct.o test/fuzz/fuzz-autofile.o test/fuzz/fuzz-banman.o test/fuzz/fuzz-base_encode_decode.o test/fuzz/fuzz-bech32.o test/fuzz/fuzz-block.o test/fuzz/fuzz-block_header.o test/fuzz/fuzz-blockfilter.o test/fuzz/fuzz-bloom_filter.o test/fuzz/fuzz-buffered_file.o test/fuzz/fuzz-chain.o test/fuzz/fuzz-checkqueue.o test/fuzz/fuzz-coins_view.o test/fuzz/fuzz-connman.o test/fuzz/fuzz-crypto.o test/fuzz/fuzz-crypto_aes256.o test/fuzz/fuzz-crypto_aes256cbc.o test/fuzz/fuzz-crypto_chacha20.o test/fuzz/fuzz-crypto_chacha20_poly1305_aead.o test/fuzz/fuzz-crypto_common.o test/fuzz/fuzz-crypto_hkdf_hmac_sha256_l32.o test/fuzz/fuzz-crypto_poly1305.o test/fuzz/fuzz-cuckoocache.o test/fuzz/fuzz-data_stream.o test/fuzz/fuzz-decode_tx.o test/fuzz/fuzz-descriptor_parse.o test/fuzz/fuzz-deserialize.o test/fuzz/fuzz-eval_script.o test/fuzz/fuzz-fee_rate.o test/fuzz/fuzz-fees.o test/fuzz/fuzz-flatfile.o test/fuzz/fuzz-float.o test/fuzz/fuzz-golomb_rice.o test/fuzz/fuzz-hex.o test/fuzz/fuzz-http_request.o test/fuzz/fuzz-i2p.o test/fuzz/fuzz-integer.o test/fuzz/fuzz-key.o test/fuzz/fuzz-key_io.o test/fuzz/fuzz-kitchen_sink.o test/fuzz/fuzz-load_external_block_file.o test/fuzz/fuzz-locale.o test/fuzz/fuzz-merkleblock.o test/fuzz/fuzz-message.o test/fuzz/fuzz-muhash.o test/fuzz/fuzz-multiplication_overflow.o test/fuzz/fuzz-net.o test/fuzz/fuzz-net_permissions.o test/fuzz/fuzz-netaddress.o test/fuzz/fuzz-netbase_dns_lookup.o test/fuzz/fuzz-node_eviction.o test/fuzz/fuzz-p2p_transport_serialization.o test/fuzz/fuzz-parse_hd_keypath.o test/fuzz/fuzz-parse_iso8601.o test/fuzz/fuzz-parse_numbers.o test/fuzz/fuzz-parse_script.o test/fuzz/fuzz-parse_univalue.o test/fuzz/fuzz-policy_estimator.o test/fuzz/fuzz-policy_estimator_io.o test/fuzz/fuzz-pow.o test/fuzz/fuzz-prevector.o test/fuzz/fuzz-primitives_transaction.o test/fuzz/fuzz-process_message.o test/fuzz/fuzz-process_messages.o test/fuzz/fuzz-protocol.o test/fuzz/fuzz-psbt.o test/fuzz/fuzz-random.o test/fuzz/fuzz-rbf.o test/fuzz/fuzz-rolling_bloom_filter.o test/fuzz/fuzz-rpc.o test/fuzz/fuzz-script.o test/fuzz/fuzz-script_assets_test_minimizer.o test/fuzz/fuzz-script_bitcoin_consensus.o test/fuzz/fuzz-script_descriptor_cache.o test/fuzz/fuzz-script_flags.o test/fuzz/fuzz-script_interpreter.o test/fuzz/fuzz-script_ops.o test/fuzz/fuzz-script_sigcache.o test/fuzz/fuzz-script_sign.o test/fuzz/fuzz-scriptnum_ops.o test/fuzz/fuzz-secp256k1_ec_seckey_import_export_der.o test/fuzz/fuzz-secp256k1_ecdsa_signature_parse_der_lax.o test/fuzz/fuzz-signature_checker.o test/fuzz/fuzz-signet.o test/fuzz/fuzz-simplicity.o test/fuzz/fuzz-socks5.o test/fuzz/fuzz-span.o test/fuzz/fuzz-spanparsing.o test/fuzz/fuzz-string.o test/fuzz/fuzz-strprintf.o test/fuzz/fuzz-system.o test/fuzz/fuzz-timedata.o test/fuzz/fuzz-torcontrol.o test/fuzz/fuzz-transaction.o test/fuzz/fuzz-tx_in.o test/fuzz/fuzz-tx_out.o test/fuzz/fuzz-tx_pool.o test/fuzz/fuzz-txrequest.o test/fuzz/fuzz-utxo_snapshot.o test/fuzz/fuzz-validation_load_mempool.o test/fuzz/fuzz-versionbits.o test/fuzz/fuzz-witness_program.o  -lpthread libtest_util.a libbitcoin_server.a libbitcoin_common.a libbitcoin_util.a crypto/libbitcoin_crypto_base.a libtest_fuzz.a libbitcoin_server.a libbitcoin_common.a libbitcoin_util.a crypto/libbitcoin_crypto_base.a libbitcoin_server.a libbitcoin_wallet.a libbitcoin_common.a libbitcoin_util.a libelements_consensus.a crypto/libbitcoin_crypto_base.a crypto/libbitcoin_crypto_sse41.a crypto/libbitcoin_crypto_avx2.a crypto/libbitcoin_crypto_shani.a libbitcoin_cli.a univalue/.libs/libunivalue.a leveldb/libleveldb.a crc32c/libcrc32c.a crc32c/libcrc32c_sse42.a -L/usr/lib/x86_64-linux-gnu -lboost_system -lboost_filesystem leveldb/libmemenv.a secp256k1/.libs/libsecp256k1.a ./.libs/libelementssimplicity.a -levent -levent_pthreads -levent -lminiupnpc -lnatpmp -lsqlite3 -ldb_cxx libbitcoin_zmq.a -lzmq -pthread
/usr/bin/ld: test/fuzz/fuzz-simplicity.o: in function `simplicity_fuzz_target(Span<unsigned char const>)':
./test/fuzz/simplicity.cpp:40: undefined reference to `elements_simplicity_mallocTapEnv(rawTapEnv const*)'
/usr/bin/ld: ./test/fuzz/simplicity.cpp:47: undefined reference to `elements_simplicity_execSimplicity(simplicity_err*, unsigned char*, transaction const*, unsigned long, tapEnv const*, unsigned char const*, long, unsigned char const*, unsigned char const*, unsigned long)'
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:6894: test/fuzz/fuzz] Error 1

in the link command you can see the reference to ./.libs/libelementssimplicity.a

running nm ./src/.libs/libelementssimplicity.a does show those exported symbols

libelementssimplicity_la-env.o:
...
00000000000030f0 T elements_simplicity_mallocTapEnv
libelementssimplicity_la-exec.o:
...
0000000000000000 T elements_simplicity_execSimplicity
@delta1
Copy link
Author

delta1 commented May 3, 2024

Fixed in delta1/elements@7f24c04

the includes in test/fuzz/simplicity.cpp needed extern C

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment