Skip to content

Duplicated symbol error after compiling against [email protected] #878

@nymius

Description

@nymius

Description:
While implementing the rust-secp256k1 bindings for silentpayments, #876 I hit a duplicated symbol error when running tests, after building the library against the tip of the libsecp256k1 branch including the silent payment module.

I traced the error back to the last commit in libsecp256k1 against which rust-secp256k1 bindings compiled and ran tests normally.

The latest working commit is: bitcoin-core/secp256k1@1b1fc09
The first commit on which the duplicated symbol error appears is: bitcoin-core/secp256k1@432ac57

This commit belongs to the [email protected] release.

The error is triggered by the change from a const <type> *<var> to a const <type> *const <var>.
I'm having a hard time understanding the origin of the issue.

Full `duplicated symbol` error
$ cargo test
   Compiling serde v1.0.217
   Compiling hex_lit v0.1.1
   Compiling rand_core v0.9.3
   Compiling half v1.8.3
   Compiling byteorder v1.5.0
   Compiling rand_xoshiro v0.7.0
   Compiling bincode v1.3.3
   Compiling serde_test v1.0.177
   Compiling serde_cbor v0.10.2
   Compiling secp256k1 v0.32.0-beta.2 (~/rust-secp256k1)
error: linking with `cc` failed: exit status: 1
  |
  = note:  "cc" "-m64" "/tmp/rustc2xYw0V/symbols.o" "<17 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "~/rust-secp256k1/target/debug/deps/{libsecp256k1-a0b13cfe2052608d,libsecp256k1_sys-b1b59c933f23d7ba}.rlib" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib/{libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,libcfg_if-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,liblibc-*,librustc_std_workspace_core-*,liballoc-*,libcore-*,libcompiler_builtins-*}.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-L" "/tmp/rustc2xYw0V/raw-dylibs" "-B<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/bin/gcc-ld" "-fuse-ld=lld" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "~/rust-secp256k1/target/debug/build/secp256k1-sys-26ff80809ab77d67/out" "-L" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "~/rust-secp256k1/target/debug/examples/sign_verify-44611d3e60e6c624" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_context_static
          >>> defined at secp256k1.h:233 (depend/secp256k1/include/secp256k1.h:233)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_context_static) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:233 (depend/secp256k1/src/../include/secp256k1.h:233)
          >>>            fce6141bfa9bf74c-secp256k1.o:(.data.rel.ro.local.rustsecp256k1_v0_12_context_static+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_context_no_precomp
          >>> defined at secp256k1.h:236 (depend/secp256k1/include/secp256k1.h:236)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_context_no_precomp) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:236 (depend/secp256k1/src/../include/secp256k1.h:236)
          >>>            fce6141bfa9bf74c-secp256k1.o:(.data.rel.ro.local.rustsecp256k1_v0_12_context_no_precomp+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_nonce_function_rfc6979
          >>> defined at secp256k1.h:638 (depend/secp256k1/include/secp256k1.h:638)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_nonce_function_rfc6979) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:638 (depend/secp256k1/src/../include/secp256k1.h:638)
          >>>            fce6141bfa9bf74c-secp256k1.o:(.data.rel.ro.local.rustsecp256k1_v0_12_nonce_function_rfc6979+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_nonce_function_default
          >>> defined at secp256k1.h:641 (depend/secp256k1/include/secp256k1.h:641)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_nonce_function_default) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:641 (depend/secp256k1/src/../include/secp256k1.h:641)
          >>>            fce6141bfa9bf74c-secp256k1.o:(.data.rel.ro.local.rustsecp256k1_v0_12_nonce_function_default+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_context_static
          >>> defined at secp256k1.h:233 (depend/secp256k1/include/secp256k1.h:233)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_context_static) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:233 (depend/secp256k1/src/../include/secp256k1.h:233)
          >>>            fce6141bfa9bf74c-precomputed_ecmult_gen.o:(.rodata.rustsecp256k1_v0_12_context_static+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_context_no_precomp
          >>> defined at secp256k1.h:236 (depend/secp256k1/include/secp256k1.h:236)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_context_no_precomp) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:236 (depend/secp256k1/src/../include/secp256k1.h:236)
          >>>            fce6141bfa9bf74c-precomputed_ecmult_gen.o:(.rodata.rustsecp256k1_v0_12_context_no_precomp+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_nonce_function_rfc6979
          >>> defined at secp256k1.h:638 (depend/secp256k1/include/secp256k1.h:638)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_nonce_function_rfc6979) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:638 (depend/secp256k1/src/../include/secp256k1.h:638)
          >>>            fce6141bfa9bf74c-precomputed_ecmult_gen.o:(.rodata.rustsecp256k1_v0_12_nonce_function_rfc6979+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_nonce_function_default
          >>> defined at secp256k1.h:641 (depend/secp256k1/include/secp256k1.h:641)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_nonce_function_default) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:641 (depend/secp256k1/src/../include/secp256k1.h:641)
          >>>            fce6141bfa9bf74c-precomputed_ecmult_gen.o:(.rodata.rustsecp256k1_v0_12_nonce_function_default+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_context_static
          >>> defined at secp256k1.h:233 (depend/secp256k1/include/secp256k1.h:233)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_context_static) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:233 (depend/secp256k1/src/../include/secp256k1.h:233)
          >>>            fce6141bfa9bf74c-precomputed_ecmult.o:(.rodata.rustsecp256k1_v0_12_context_static+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_context_no_precomp
          >>> defined at secp256k1.h:236 (depend/secp256k1/include/secp256k1.h:236)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_context_no_precomp) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:236 (depend/secp256k1/src/../include/secp256k1.h:236)
          >>>            fce6141bfa9bf74c-precomputed_ecmult.o:(.rodata.rustsecp256k1_v0_12_context_no_precomp+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_nonce_function_rfc6979
          >>> defined at secp256k1.h:638 (depend/secp256k1/include/secp256k1.h:638)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_nonce_function_rfc6979) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:638 (depend/secp256k1/src/../include/secp256k1.h:638)
          >>>            fce6141bfa9bf74c-precomputed_ecmult.o:(.rodata.rustsecp256k1_v0_12_nonce_function_rfc6979+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_nonce_function_default
          >>> defined at secp256k1.h:641 (depend/secp256k1/include/secp256k1.h:641)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_nonce_function_default) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:641 (depend/secp256k1/src/../include/secp256k1.h:641)
          >>>            fce6141bfa9bf74c-precomputed_ecmult.o:(.rodata.rustsecp256k1_v0_12_nonce_function_default+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          collect2: error: ld returned 1 exit status


error: could not compile `secp256k1` (example "sign_verify") due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: linking with `cc` failed: exit status: 1
  |
  = note:  "cc" "-m64" "/tmp/rustcMguYmr/symbols.o" "<6 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib/{libtest-*,libgetopts-*,librustc_std_workspace_std-*}.rlib" "~/rust-secp256k1/target/debug/deps/{libsecp256k1-a0b13cfe2052608d,libsecp256k1_sys-b1b59c933f23d7ba}.rlib" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib/{libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,libcfg_if-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,liblibc-*,librustc_std_workspace_core-*,liballoc-*,libcore-*,libcompiler_builtins-*}.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-L" "/tmp/rustcMguYmr/raw-dylibs" "-B<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/bin/gcc-ld" "-fuse-ld=lld" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "~/rust-secp256k1/target/debug/build/secp256k1-sys-26ff80809ab77d67/out" "-L" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "~/rust-secp256k1/target/debug/deps/api-5fb020599b5dc4b5" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_context_static
          >>> defined at secp256k1.h:233 (depend/secp256k1/include/secp256k1.h:233)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_context_static) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:233 (depend/secp256k1/src/../include/secp256k1.h:233)
          >>>            fce6141bfa9bf74c-secp256k1.o:(.data.rel.ro.local.rustsecp256k1_v0_12_context_static+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_context_no_precomp
          >>> defined at secp256k1.h:236 (depend/secp256k1/include/secp256k1.h:236)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_context_no_precomp) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:236 (depend/secp256k1/src/../include/secp256k1.h:236)
          >>>            fce6141bfa9bf74c-secp256k1.o:(.data.rel.ro.local.rustsecp256k1_v0_12_context_no_precomp+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_nonce_function_rfc6979
          >>> defined at secp256k1.h:638 (depend/secp256k1/include/secp256k1.h:638)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_nonce_function_rfc6979) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:638 (depend/secp256k1/src/../include/secp256k1.h:638)
          >>>            fce6141bfa9bf74c-secp256k1.o:(.data.rel.ro.local.rustsecp256k1_v0_12_nonce_function_rfc6979+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_nonce_function_default
          >>> defined at secp256k1.h:641 (depend/secp256k1/include/secp256k1.h:641)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_nonce_function_default) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:641 (depend/secp256k1/src/../include/secp256k1.h:641)
          >>>            fce6141bfa9bf74c-secp256k1.o:(.data.rel.ro.local.rustsecp256k1_v0_12_nonce_function_default+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_context_static
          >>> defined at secp256k1.h:233 (depend/secp256k1/include/secp256k1.h:233)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_context_static) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:233 (depend/secp256k1/src/../include/secp256k1.h:233)
          >>>            fce6141bfa9bf74c-precomputed_ecmult.o:(.rodata.rustsecp256k1_v0_12_context_static+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_context_no_precomp
          >>> defined at secp256k1.h:236 (depend/secp256k1/include/secp256k1.h:236)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_context_no_precomp) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:236 (depend/secp256k1/src/../include/secp256k1.h:236)
          >>>            fce6141bfa9bf74c-precomputed_ecmult.o:(.rodata.rustsecp256k1_v0_12_context_no_precomp+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_nonce_function_rfc6979
          >>> defined at secp256k1.h:638 (depend/secp256k1/include/secp256k1.h:638)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_nonce_function_rfc6979) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:638 (depend/secp256k1/src/../include/secp256k1.h:638)
          >>>            fce6141bfa9bf74c-precomputed_ecmult.o:(.rodata.rustsecp256k1_v0_12_nonce_function_rfc6979+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_nonce_function_default
          >>> defined at secp256k1.h:641 (depend/secp256k1/include/secp256k1.h:641)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_nonce_function_default) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:641 (depend/secp256k1/src/../include/secp256k1.h:641)
          >>>            fce6141bfa9bf74c-precomputed_ecmult.o:(.rodata.rustsecp256k1_v0_12_nonce_function_default+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_context_static
          >>> defined at secp256k1.h:233 (depend/secp256k1/include/secp256k1.h:233)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_context_static) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:233 (depend/secp256k1/src/../include/secp256k1.h:233)
          >>>            fce6141bfa9bf74c-precomputed_ecmult_gen.o:(.rodata.rustsecp256k1_v0_12_context_static+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_context_no_precomp
          >>> defined at secp256k1.h:236 (depend/secp256k1/include/secp256k1.h:236)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_context_no_precomp) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:236 (depend/secp256k1/src/../include/secp256k1.h:236)
          >>>            fce6141bfa9bf74c-precomputed_ecmult_gen.o:(.rodata.rustsecp256k1_v0_12_context_no_precomp+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_nonce_function_rfc6979
          >>> defined at secp256k1.h:638 (depend/secp256k1/include/secp256k1.h:638)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_nonce_function_rfc6979) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:638 (depend/secp256k1/src/../include/secp256k1.h:638)
          >>>            fce6141bfa9bf74c-precomputed_ecmult_gen.o:(.rodata.rustsecp256k1_v0_12_nonce_function_rfc6979+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_nonce_function_default
          >>> defined at secp256k1.h:641 (depend/secp256k1/include/secp256k1.h:641)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_nonce_function_default) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:641 (depend/secp256k1/src/../include/secp256k1.h:641)
          >>>            fce6141bfa9bf74c-precomputed_ecmult_gen.o:(.rodata.rustsecp256k1_v0_12_nonce_function_default+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          collect2: error: ld returned 1 exit status


error: could not compile `secp256k1` (test "api") due to 1 previous error
error: linking with `cc` failed: exit status: 1
  |
  = note:  "cc" "-m64" "/tmp/rustcxQ3jML/symbols.o" "<136 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib/{libtest-*,libgetopts-*,librustc_std_workspace_std-*}.rlib" "~/rust-secp256k1/target/debug/deps/{libserde_test-8e6afadce4872644,libserde-2e3dac7503457b0b,libhex_lit-26a49f471131e64f,libsecp256k1_sys-b1b59c933f23d7ba}.rlib" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib/{libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,libcfg_if-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,liblibc-*,librustc_std_workspace_core-*,liballoc-*,libcore-*,libcompiler_builtins-*}.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-L" "/tmp/rustcxQ3jML/raw-dylibs" "-B<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/bin/gcc-ld" "-fuse-ld=lld" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "~/rust-secp256k1/target/debug/build/secp256k1-sys-26ff80809ab77d67/out" "-L" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "~/rust-secp256k1/target/debug/deps/secp256k1-411d26ba1b5f353b" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_context_static
          >>> defined at secp256k1.h:233 (depend/secp256k1/include/secp256k1.h:233)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_context_static) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:233 (depend/secp256k1/src/../include/secp256k1.h:233)
          >>>            fce6141bfa9bf74c-precomputed_ecmult.o:(.rodata.rustsecp256k1_v0_12_context_static+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_context_no_precomp
          >>> defined at secp256k1.h:236 (depend/secp256k1/include/secp256k1.h:236)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_context_no_precomp) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:236 (depend/secp256k1/src/../include/secp256k1.h:236)
          >>>            fce6141bfa9bf74c-precomputed_ecmult.o:(.rodata.rustsecp256k1_v0_12_context_no_precomp+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_nonce_function_rfc6979
          >>> defined at secp256k1.h:638 (depend/secp256k1/include/secp256k1.h:638)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_nonce_function_rfc6979) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:638 (depend/secp256k1/src/../include/secp256k1.h:638)
          >>>            fce6141bfa9bf74c-precomputed_ecmult.o:(.rodata.rustsecp256k1_v0_12_nonce_function_rfc6979+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_nonce_function_default
          >>> defined at secp256k1.h:641 (depend/secp256k1/include/secp256k1.h:641)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_nonce_function_default) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:641 (depend/secp256k1/src/../include/secp256k1.h:641)
          >>>            fce6141bfa9bf74c-precomputed_ecmult.o:(.rodata.rustsecp256k1_v0_12_nonce_function_default+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_context_static
          >>> defined at secp256k1.h:233 (depend/secp256k1/include/secp256k1.h:233)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_context_static) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:233 (depend/secp256k1/src/../include/secp256k1.h:233)
          >>>            fce6141bfa9bf74c-precomputed_ecmult_gen.o:(.rodata.rustsecp256k1_v0_12_context_static+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_context_no_precomp
          >>> defined at secp256k1.h:236 (depend/secp256k1/include/secp256k1.h:236)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_context_no_precomp) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:236 (depend/secp256k1/src/../include/secp256k1.h:236)
          >>>            fce6141bfa9bf74c-precomputed_ecmult_gen.o:(.rodata.rustsecp256k1_v0_12_context_no_precomp+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_nonce_function_rfc6979
          >>> defined at secp256k1.h:638 (depend/secp256k1/include/secp256k1.h:638)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_nonce_function_rfc6979) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:638 (depend/secp256k1/src/../include/secp256k1.h:638)
          >>>            fce6141bfa9bf74c-precomputed_ecmult_gen.o:(.rodata.rustsecp256k1_v0_12_nonce_function_rfc6979+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_nonce_function_default
          >>> defined at secp256k1.h:641 (depend/secp256k1/include/secp256k1.h:641)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_nonce_function_default) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:641 (depend/secp256k1/src/../include/secp256k1.h:641)
          >>>            fce6141bfa9bf74c-precomputed_ecmult_gen.o:(.rodata.rustsecp256k1_v0_12_nonce_function_default+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_context_static
          >>> defined at secp256k1.h:233 (depend/secp256k1/include/secp256k1.h:233)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_context_static) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:233 (depend/secp256k1/src/../include/secp256k1.h:233)
          >>>            fce6141bfa9bf74c-secp256k1.o:(.data.rel.ro.local.rustsecp256k1_v0_12_context_static+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_context_no_precomp
          >>> defined at secp256k1.h:236 (depend/secp256k1/include/secp256k1.h:236)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_context_no_precomp) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:236 (depend/secp256k1/src/../include/secp256k1.h:236)
          >>>            fce6141bfa9bf74c-secp256k1.o:(.data.rel.ro.local.rustsecp256k1_v0_12_context_no_precomp+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_nonce_function_rfc6979
          >>> defined at secp256k1.h:638 (depend/secp256k1/include/secp256k1.h:638)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_nonce_function_rfc6979) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:638 (depend/secp256k1/src/../include/secp256k1.h:638)
          >>>            fce6141bfa9bf74c-secp256k1.o:(.data.rel.ro.local.rustsecp256k1_v0_12_nonce_function_rfc6979+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib

          rust-lld: error: duplicate symbol: rustsecp256k1_v0_12_nonce_function_default
          >>> defined at secp256k1.h:641 (depend/secp256k1/include/secp256k1.h:641)
          >>>            4d6b2bbe68124288-lax_der_parsing.o:(rustsecp256k1_v0_12_nonce_function_default) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          >>> defined at secp256k1.h:641 (depend/secp256k1/src/../include/secp256k1.h:641)
          >>>            fce6141bfa9bf74c-secp256k1.o:(.data.rel.ro.local.rustsecp256k1_v0_12_nonce_function_default+0x0) in archive ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib
          collect2: error: ld returned 1 exit status


error: could not compile `secp256k1` (lib test) due to 1 previous error

What I've tried:
I created a patch, nymius/rust-secp256k1@6d0b801, compiling against the latest working commit, 1b1fc09341c956e8918adba1eeaa43b47d73ea84, and reviewed the symbols created:

$ nm -A ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib | rg "context_no_precomp"
nm: lib.rmeta: no symbols
~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib:secp256k1_sys-b1b59c933f23d7ba.5j2437td37q4axursxx0h9100.12jl1g7.rcgu.o: U rustsecp256k1_v0_12_context_no_precomp
~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib:fce6141bfa9bf74c-secp256k1.o:0000000000000000 D rustsecp256k1_v0_12_context_no_precomp

And another patch, nymius/rust-secp256k1@4df7ac6, compiling against the first failing commit, 432ac57705b8e2f6a5874095214c443f1f8ea9bf, and reviewed the symbols as well:

$ nm -A ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib | rg "context_no_precomp"
nm: lib.rmeta: no symbols
~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib:secp256k1_sys-b1b59c933f23d7ba.5j2437td37q4axursxx0h9100.1kpnmkg.rcgu.o:                 U rustsecp256k1_v0_12_context_no_precomp
~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib:4d6b2bbe68124288-lax_der_parsing.o:0000000000000000 R rustsecp256k1_v0_12_context_no_precomp
~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib:fce6141bfa9bf74c-precomputed_ecmult_gen.o:0000000000000000 R rustsecp256k1_v0_12_context_no_precomp
~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib:fce6141bfa9bf74c-precomputed_ecmult.o:0000000000000000 R rustsecp256k1_v0_12_context_no_precomp
~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib:fce6141bfa9bf74c-secp256k1.o:0000000000000000 D rustsecp256k1_v0_12_context_no_precomp

Previous to the failing commit, const <type> *<var> was being translated in a single common symbol, but after adding the const qualifier to the pointer, there are three read only repeated symbols

I've found that by setting SECP256K1_API to extern, nymius/rust-secp256k1@f949266 or removing it completely (letting libsecp256k1 set it by itself), the issue disappears, and the symbols get unified:

$ nm -A ~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib | rg "context_no_precomp"
nm: lib.rmeta: no symbols
~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib:secp256k1_sys-b1b59c933f23d7ba.5j2437td37q4axursxx0h9100.0u8ohs8.rcgu.o: U rustsecp256k1_v0_12_context_no_precomp
~/rust-secp256k1/target/debug/deps/libsecp256k1_sys-b1b59c933f23d7ba.rlib:fce6141bfa9bf74c-secp256k1.o:0000000000000000 D rustsecp256k1_v0_12_context_no_precomp

More context:
Originally I thought the issue was related to SECP256K1_API setting, as in later commits of libsecp256k1 it caused other issues that piled up.

Now I'm not sure it is the source of this original error.

Still, SECP256K1_API setting seems to have been set by the wrong reasons], ee1103a as the use of Some("") is still setting the variable with "". The right approach to not set it is to remove it, rather than giving a None or Some("") value. However, I'm not sure what's the best approach to visibility from the rust standing point.
From my short understanding, looking at this comment about downstream uses of the API in libsecp256k1 and the latest refactors on visibility in libsecp256k1, bitcoin-core/secp256k1#1696, we shouldn't be touching this variable, and let libsecp256k1 set it by itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions