emk/rust-musl-builder

`diesel` link order issues sometimes break build

chrisabruce opened this issue ยท 19 comments

Trying to build with the using-diesel example fails. Here is snippet of error:

error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-Wl,--eh-frame-hdr" "-m64" "-nostdlib" "/home/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/crt1.o" "/home/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/crti.o" "-L" "/home/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib" "/home/rust/src/target/x86_64-unknown-linux-musl/release/deps/using_diesel-94aa5cadffcea30e.using_diesel.dqcexic7-cgu.0.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/release/deps/using_diesel-94aa5cadffcea30e.using_diesel.dqcexic7-cgu.1.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/release/deps/using_diesel-94aa5cadffcea30e.using_diesel.dqcexic7-cgu.10.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/release/deps/using_diesel-94aa5cadffcea30e.using_diesel.dqcexic7-cgu.11.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/release/deps/using_diesel-94aa5cadffcea30e.using_diesel.dqcexic7-cgu.12.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/release/deps/using_diesel-94aa5cadffcea30e.using_diesel.dqcexic7-cgu.13.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/release/deps/using_diesel-94aa5cadffcea30e.using_diesel.dqcexic7-cgu.14.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/release/deps/using_diesel-94aa5cadffcea30e.using_diesel.dqcexic7-cgu.15.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/release/deps/using_diesel-94aa5cadffcea30e.using_diesel.dqcexic7-cgu.2.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/release/deps/using_diesel-94aa5cadffcea30e.using_diesel.dqcexic7-cgu.3.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/release/deps/using_diesel-94aa5cadffcea30e.using_diesel.dqcexic7-cgu.4.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/release/deps/using_diesel-94aa5cadffcea30e.using_diesel.dqcexic7-cgu.5.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/release/deps/using_diesel-94aa5cadffcea30e.using_diesel.dqcexic7-cgu.6.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/release/deps/using_diesel-94aa5cadffcea30e.using_diesel.dqcexic7-cgu.7.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/release/deps/using_diesel-94aa5cadffcea30e.using_diesel.dqcexic7-cgu.8.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/release/deps/using_diesel-94aa5cadffcea30e.using_diesel.dqcexic7-cgu.9.rcgu.o" "-o" "/home/rust/src/target/x86_64-unknown-linux-musl/release/deps/using_diesel-94aa5cadffcea30e" "/home/rust/src/target/x86_64-unknown-linux-musl/release/deps/using_diesel-94aa5cadffcea30e.3n7t9phqceru8m8i.rcgu.o" "-Wl,--gc-sections" "-no-pie" "-Wl,-zrelro" "-Wl,-znow" "-Wl,-O1" "-nodefaultlibs" "-L" "/home/rust/src/target/x86_64-unknown-linux-musl/release/deps" "-L" "/home/rust/src/target/release/deps" "-L" "/home/rust/src/target/x86_64-unknown-linux-musl/release/build/libsqlite3-sys-ac3cf7454f406832/out" "-L" "/usr/local/musl/lib" "-L" "/usr/local/musl/lib/" "-L" "/home/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib" "-Wl,-Bstatic" "/home/rust/src/target/x86_64-unknown-linux-musl/release/deps/libopenssl-0de50740ee181784.rlib" "/home/rust/src/target/x86_64-unknown-linux-musl/release/deps/libopenssl_sys-89c6410693b927d6.rlib" "/home/rust/src/target/x86_64-unknown-linux-musl/release/deps/liblibc-6265db6daf6f0d94.rlib" "/home/rust/src/target/x86_64-unknown-linux-musl/release/deps/liblazy_static-5cac84b776fcd98b.rlib" "/home/rust/src/target/x86_64-unknown-linux-musl/release/deps/libforeign_types-23f459ebafab2c61.rlib" "/home/rust/src/target/x86_64-unknown-linux-musl/release/deps/libforeign_types_shared-1eba4aeaa81c6d19.rlib" "/home/rust/src/target/x86_64-unknown-linux-musl/release/deps/libdiesel-c89a5a6bebad19a9.rlib" "/home/rust/src/target/x86_64-unknown-linux-musl/release/deps/liblibsqlite3_sys-818909750b3afa36.rlib" "/home/rust/src/target/x86_64-unknown-linux-musl/release/deps/libpq_sys-dc85b10baeb00fc3.rlib" "/home/rust/src/target/x86_64-unknown-linux-musl/release/deps/libbyteorder-9272cb6794a9382c.rlib" "/home/rust/src/target/x86_64-unknown-linux-musl/release/deps/libbitflags-b8224b03590c6c21.rlib" "/home/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd-af9362ed5d81a840.rlib" "/home/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libpanic_unwind-4d55a38564aae54a.rlib" "/home/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libbacktrace_sys-f8521075e248b627.rlib" "/home/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libunwind-7c91ffdc8da860d3.rlib" "/home/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_demangle-0ad27b9879d551d3.rlib" "/home/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/liblibc-588f18eae3ea58be.rlib" "/home/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/liballoc-4ebf5caee903d98f.rlib" "/home/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_std_workspace_core-8895b32baedb08c6.rlib" "/home/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libcore-6a9d233d01acc350.rlib" "/home/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libcompiler_builtins-851bb3b5f6c4db49.rlib" "-Wl,-Bdynamic" "-lpq" "-static" "/home/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/crtn.o"
  = note: /usr/local/musl/lib/libpq.a(fe-connect.o): In function `connectFailureMessage':
          fe-connect.c:(.text+0xa12): undefined reference to `strlcpy'
          /usr/local/musl/lib/libpq.a(fe-connect.o): In function `internal_cancel':
          fe-connect.c:(.text+0xca9): undefined reference to `htonl'
          fe-connect.c:(.text+0xcb7): undefined reference to `htonl'
          fe-connect.c:(.text+0xcc4): undefined reference to `htonl'
          fe-connect.c:(.text+0xcd1): undefined reference to `htonl'
          fe-connect.c:(.text+0xd6e): undefined reference to `strlcpy'
          fe-connect.c:(.text+0xd9e): undefined reference to `strncat'
          fe-connect.c:(.text+0xdde): undefined reference to `strlcpy'
          fe-connect.c:(.text+0xdfa): undefined reference to `strlcpy'
          fe-connect.c:(.text+0xe26): undefined reference to `strncat'
          /usr/local/musl/lib/libpq.a(fe-connect.o): In function `PQcancel':
          fe-connect.c:(.text+0x1462): undefined reference to `strlcpy'
          /usr/local/musl/lib/libpq.a(fe-connect.o): In function `PQrequestCancel':
          fe-connect.c:(.text+0x14f0): undefined reference to `strlcpy'
          /usr/local/musl/lib/libpq.a(fe-connect.o): In function `PQsetClientEncoding':
          fe-connect.c:(.text+0x1a71): undefined reference to `sprintf'
          /usr/local/musl/lib/libpq.a(fe-connect.o): In function `pqGetHomeDirectory':
          fe-connect.c:(.text+0x1c81): undefined reference to `strlcpy'
          /usr/local/musl/lib/libpq.a(fe-connect.o): In function `parseServiceInfo':
          fe-connect.c:(.text+0x1d1e): undefined reference to `strlcpy'
          /usr/local/musl/lib/libpq.a(fe-connect.o): In function `getPgPassFilename':
          fe-connect.c:(.text+0x2c11): undefined reference to `strlcpy'
          /usr/local/musl/lib/libpq.a(fe-connect.o): In function `PasswordFromFile':
          fe-connect.c:(.text+0x2d1c): undefined reference to `feof'
          /usr/local/musl/lib/libpq.a(fe-connect.o): In function `PQconnectPoll':
          fe-connect.c:(.text+0x3969): undefined reference to `htonl'
          /usr/local/musl/lib/libpq.a(fe-connect.o): In function `defaultNoticeProcessor':
          fe-connect.c:(.text+0xee): undefined reference to `fputs'
          /usr/local/musl/lib/libpq.a(fe-exec.o): In function `pqInternalNotice':
          fe-exec.c:(.text+0x1256): undefined reference to `sprintf'
          /usr/local/musl/lib/libpq.a(fe-exec.o): In function `pqSaveParameterStatus':
          fe-exec.c:(.text+0x1964): undefined reference to `sscanf'
          /usr/local/musl/lib/libpq.a(fe-exec.o): In function `PQoidStatus':
          fe-exec.c:(.text+0x3a11): undefined reference to `strspn'
          /usr/local/musl/lib/libpq.a(fe-misc.o): In function `pqGetnchar':
          fe-misc.c:(.text+0x3ac): undefined reference to `fputc'
          fe-misc.c:(.text+0x3c6): undefined reference to `fputc'
          /usr/local/musl/lib/libpq.a(fe-misc.o): In function `pqSkipnchar':
          fe-misc.c:(.text+0x454): undefined reference to `fputc'
          fe-misc.c:(.text+0x46f): undefined reference to `fputc'
          /usr/local/musl/lib/libpq.a(fe-misc.o): In function `pqGetInt':
          fe-misc.c:(.text+0x4ec): undefined reference to `ntohl'
          fe-misc.c:(.text+0x58a): undefined reference to `ntohs'
          /usr/local/musl/lib/libpq.a(fe-misc.o): In function `pqPutnchar':
          fe-misc.c:(.text+0x7dc): undefined reference to `fputc'
          fe-misc.c:(.text+0x7f6): undefined reference to `fputc'
          /usr/local/musl/lib/libpq.a(fe-misc.o): In function `pqPutInt':
          fe-misc.c:(.text+0x881): undefined reference to `htonl'
          /usr/local/musl/lib/libpq.a(fe-misc.o): In function `pqPutMsgEnd':
          fe-misc.c:(.text+0xf9d): undefined reference to `htonl'
          /usr/local/musl/lib/libpq.a(fe-protocol2.o): In function `pqSetenvPoll':
          fe-protocol2.c:(.text+0xa59): undefined reference to `sprintf'
          fe-protocol2.c:(.text+0xb90): undefined reference to `sprintf'
          fe-protocol2.c:(.text+0xbb0): undefined reference to `sprintf'
          /usr/local/musl/lib/libpq.a(fe-protocol2.o): In function `pqParseInput2':
          fe-protocol2.c:(.text+0xde8): undefined reference to `strlcpy'
          /usr/local/musl/lib/libpq.a(fe-protocol2.o): In function `pqBuildStartupPacket2':
          fe-protocol2.c:(.text+0x1bad): undefined reference to `htonl'
          /usr/local/musl/lib/libpq.a(fe-protocol3.o): In function `build_startup_packet':
          fe-protocol3.c:(.text+0x4b3): undefined reference to `htonl'
          /usr/local/musl/lib/libpq.a(fe-protocol3.o): In function `pqGetErrorNotice3':
          fe-protocol3.c:(.text+0x11f7): undefined reference to `strlcpy'
          /usr/local/musl/lib/libpq.a(fe-protocol3.o): In function `pqParseInput3':
          fe-protocol3.c:(.text+0x19a8): undefined reference to `strlcpy'
          /usr/local/musl/lib/libpq.a(fe-secure.o): In function `pq_block_sigpipe':
          fe-secure.c:(.text+0x19c): undefined reference to `sigaddset'
          fe-secure.c:(.text+0x1c6): undefined reference to `sigismember'
          fe-secure.c:(.text+0x20c): undefined reference to `sigpending'
          fe-secure.c:(.text+0x21f): undefined reference to `sigismember'
          /usr/local/musl/lib/libpq.a(fe-secure.o): In function `pq_reset_sigpipe':
          fe-secure.c:(.text+0x288): undefined reference to `sigpending'
          fe-secure.c:(.text+0x2d1): undefined reference to `sigismember'
          fe-secure.c:(.text+0x2f2): undefined reference to `sigaddset'
          fe-secure.c:(.text+0x2ff): undefined reference to `sigwait'
          /usr/local/musl/lib/libpq.a(chklocale.o): In function `pg_get_encoding_from_locale':
          chklocale.c:(.text+0x50): undefined reference to `setlocale'
          chklocale.c:(.text+0x77): undefined reference to `setlocale'
          chklocale.c:(.text+0x8a): undefined reference to `nl_langinfo'
          chklocale.c:(.text+0xa7): undefined reference to `setlocale'
          chklocale.c:(.text+0x115): undefined reference to `setlocale'
          chklocale.c:(.text+0x159): undefined reference to `nl_langinfo'
          chklocale.c:(.text+0x1ba): undefined reference to `fputc'
          /usr/local/musl/lib/libpq.a(inet_net_ntop.o): In function `inet_net_ntop':
          inet_net_ntop.c:(.text+0xd3): undefined reference to `sprintf'
          inet_net_ntop.c:(.text+0x10b): undefined reference to `sprintf'
          inet_net_ntop.c:(.text+0x324): undefined reference to `sprintf'
          inet_net_ntop.c:(.text+0x3c4): undefined reference to `sprintf'
          inet_net_ntop.c:(.text+0x41b): undefined reference to `sprintf'
          /usr/local/musl/lib/libpq.a(ip.o): In function `pg_getnameinfo_all':
          ip.c:(.text+0x281): undefined reference to `getnameinfo'
          ip.c:(.text+0x2a7): undefined reference to `strlcpy'
          ip.c:(.text+0x2be): undefined reference to `strlcpy'
          /usr/local/musl/lib/libpq.a(ip.o): In function `pg_sockaddr_cidr_mask':
          ip.c:(.text+0x46f): undefined reference to `htonl'
          /usr/local/musl/lib/libpq.a(ip.o): In function `pg_foreach_ifaddr':
          ip.c:(.text+0x5ce): undefined reference to `getifaddrs'
          ip.c:(.text+0x65e): undefined reference to `freeifaddrs'
          /usr/local/musl/lib/libpq.a(fe-secure-openssl.o): In function `SSLerrmessage':
          fe-secure-openssl.c:(.text+0x38): undefined reference to `ERR_reason_error_string'
          fe-secure-openssl.c:(.text+0x4d): undefined reference to `strlcpy'
          /usr/local/musl/lib/libpq.a(fe-secure-openssl.o): In function `initialize_SSL':
          fe-secure-openssl.c:(.text+0x122): undefined reference to `SSLv23_method'
          fe-secure-openssl.c:(.text+0x12a): undefined reference to `SSL_CTX_new'
          fe-secure-openssl.c:(.text+0x14a): undefined reference to `SSL_CTX_ctrl'
          fe-secure-openssl.c:(.text+0x15e): undefined reference to `SSL_CTX_ctrl'
          fe-secure-openssl.c:(.text+0x1c8): undefined reference to `SSL_new'
          fe-secure-openssl.c:(.text+0x1e5): undefined reference to `SSL_set_ex_data'
          fe-secure-openssl.c:(.text+0x209): undefined reference to `BIO_new'
          fe-secure-openssl.c:(.text+0x22d): undefined reference to `SSL_set_bio'
          fe-secure-openssl.c:(.text+0x244): undefined reference to `BIO_int_ctrl'
          fe-secure-openssl.c:(.text+0x253): undefined reference to `SSL_CTX_free'
          fe-secure-openssl.c:(.text+0x2bc): undefined reference to `ENGINE_by_id'
          fe-secure-openssl.c:(.text+0x2d4): undefined reference to `ENGINE_init'
          fe-secure-openssl.c:(.text+0x2ef): undefined reference to `ENGINE_load_private_key'
          fe-secure-openssl.c:(.text+0x307): undefined reference to `SSL_use_PrivateKey'
          fe-secure-openssl.c:(.text+0x405): undefined reference to `ERR_put_error'
          fe-secure-openssl.c:(.text+0x40a): undefined reference to `ERR_get_error'
          fe-secure-openssl.c:(.text+0x44e): undefined reference to `SSL_CTX_free'
          fe-secure-openssl.c:(.text+0x471): undefined reference to `strlcpy'
          fe-secure-openssl.c:(.text+0x4e9): undefined reference to `strlcpy'
          fe-secure-openssl.c:(.text+0x5b1): undefined reference to `SSL_check_private_key'
          fe-secure-openssl.c:(.text+0x5bf): undefined reference to `ERR_get_error'
          fe-secure-openssl.c:(.text+0x619): undefined reference to `SSL_CTX_load_verify_locations'
          fe-secure-openssl.c:(.text+0x62a): undefined reference to `SSL_CTX_get_cert_store'
          fe-secure-openssl.c:(.text+0x661): undefined reference to `ERR_clear_error'
          fe-secure-openssl.c:(.text+0x6a9): undefined reference to `ERR_get_error'
          fe-secure-openssl.c:(.text+0x6fc): undefined reference to `SSL_set_verify'
          fe-secure-openssl.c:(.text+0x715): undefined reference to `SSL_CTX_use_certificate_chain_file'
          fe-secure-openssl.c:(.text+0x723): undefined reference to `ERR_get_error'
          fe-secure-openssl.c:(.text+0x7b4): undefined reference to `SSL_ctrl'
          fe-secure-openssl.c:(.text+0x834): undefined reference to `SSL_use_PrivateKey_file'
          fe-secure-openssl.c:(.text+0x842): undefined reference to `ERR_get_error'
          fe-secure-openssl.c:(.text+0x8a1): undefined reference to `BIO_s_socket'
          fe-secure-openssl.c:(.text+0x954): undefined reference to `strlcpy'
          fe-secure-openssl.c:(.text+0x969): undefined reference to `strlcpy'
          fe-secure-openssl.c:(.text+0x984): undefined reference to `X509_STORE_load_locations'
          fe-secure-openssl.c:(.text+0x99a): undefined reference to `X509_STORE_set_flags'
          fe-secure-openssl.c:(.text+0x9d1): undefined reference to `ERR_get_error'
          fe-secure-openssl.c:(.text+0xa1a): undefined reference to `ENGINE_finish'
          fe-secure-openssl.c:(.text+0xa26): undefined reference to `ENGINE_free'
          fe-secure-openssl.c:(.text+0xa75): undefined reference to `ERR_get_error'
          fe-secure-openssl.c:(.text+0xa9e): undefined reference to `ERR_get_error'
          fe-secure-openssl.c:(.text+0xb08): undefined reference to `ERR_get_error'
          fe-secure-openssl.c:(.text+0xb6d): undefined reference to `ERR_get_error'
          /usr/local/musl/lib/libpq.a(fe-secure-openssl.o): In function `verify_peer_name_matches_certificate_name':
          fe-secure-openssl.c:(.text+0xbc5): undefined reference to `ASN1_STRING_data'
          fe-secure-openssl.c:(.text+0xbd0): undefined reference to `ASN1_STRING_length'
          /usr/local/musl/lib/libpq.a(fe-secure-openssl.o): In function `my_sock_write':
          fe-secure-openssl.c:(.text+0xdb1): undefined reference to `BIO_clear_flags'
          fe-secure-openssl.c:(.text+0xde2): undefined reference to `BIO_set_flags'
          /usr/local/musl/lib/libpq.a(fe-secure-openssl.o): In function `my_sock_read':
          fe-secure-openssl.c:(.text+0xe11): undefined reference to `BIO_clear_flags'
          fe-secure-openssl.c:(.text+0xe42): undefined reference to `BIO_set_flags'
          /usr/local/musl/lib/libpq.a(fe-secure-openssl.o): In function `pgtls_read_pending':
          fe-secure-openssl.c:(.text+0xeec): undefined reference to `SSL_pending'
          /usr/local/musl/lib/libpq.a(fe-secure-openssl.o): In function `pgtls_read':
          fe-secure-openssl.c:(.text+0xf4a): undefined reference to `ERR_clear_error'
          fe-secure-openssl.c:(.text+0xf5d): undefined reference to `SSL_read'
          fe-secure-openssl.c:(.text+0xf6e): undefined reference to `SSL_get_error'
          fe-secure-openssl.c:(.text+0xfa1): undefined reference to `ERR_get_error'
          /usr/local/musl/lib/libpq.a(fe-secure-openssl.o): In function `pgtls_write':
          fe-secure-openssl.c:(.text+0x11b8): undefined reference to `ERR_clear_error'
          fe-secure-openssl.c:(.text+0x11ca): undefined reference to `SSL_write'
          fe-secure-openssl.c:(.text+0x11db): undefined reference to `SSL_get_error'
          fe-secure-openssl.c:(.text+0x1211): undefined reference to `ERR_get_error'
          /usr/local/musl/lib/libpq.a(fe-secure-openssl.o): In function `pgtls_init':
          fe-secure-openssl.c:(.text+0x1461): undefined reference to `CRYPTO_get_id_callback'
          fe-secure-openssl.c:(.text+0x146f): undefined reference to `CRYPTO_get_locking_callback'
          fe-secure-openssl.c:(.text+0x1480): undefined reference to `CRYPTO_set_locking_callback'
          fe-secure-openssl.c:(.text+0x1493): undefined reference to `OPENSSL_config'
          fe-secure-openssl.c:(.text+0x1498): undefined reference to `SSL_library_init'
          fe-secure-openssl.c:(.text+0x149d): undefined reference to `SSL_load_error_strings'
          fe-secure-openssl.c:(.text+0x14b1): undefined reference to `CRYPTO_num_locks'
          fe-secure-openssl.c:(.text+0x14dc): undefined reference to `CRYPTO_num_locks'
          fe-secure-openssl.c:(.text+0x153a): undefined reference to `CRYPTO_set_id_callback'
          /usr/local/musl/lib/libpq.a(fe-secure-openssl.o): In function `pgtls_close':
          fe-secure-openssl.c:(.text+0x1568): undefined reference to `SSL_shutdown'
          fe-secure-openssl.c:(.text+0x1579): undefined reference to `SSL_free'
          fe-secure-openssl.c:(.text+0x159c): undefined reference to `X509_free'
          fe-secure-openssl.c:(.text+0x15b8): undefined reference to `ENGINE_finish'
          fe-secure-openssl.c:(.text+0x15c4): undefined reference to `ENGINE_free'
          fe-secure-openssl.c:(.text+0x1631): undefined reference to `CRYPTO_get_locking_callback'
          fe-secure-openssl.c:(.text+0x1642): undefined reference to `CRYPTO_get_id_callback'
          fe-secure-openssl.c:(.text+0x1655): undefined reference to `CRYPTO_set_id_callback'
          fe-secure-openssl.c:(.text+0x165e): undefined reference to `CRYPTO_set_locking_callback'
          /usr/local/musl/lib/libpq.a(fe-secure-openssl.o): In function `pgtls_open_client':
          fe-secure-openssl.c:(.text+0x16a6): undefined reference to `ERR_clear_error'
          fe-secure-openssl.c:(.text+0x16b2): undefined reference to `SSL_connect'
          fe-secure-openssl.c:(.text+0x16c8): undefined reference to `SSL_get_peer_certificate'
          fe-secure-openssl.c:(.text+0x1773): undefined reference to `SSL_get_error'
          fe-secure-openssl.c:(.text+0x177b): undefined reference to `ERR_get_error'
          fe-secure-openssl.c:(.text+0x183d): undefined reference to `X509_get_ext_d2i'
          fe-secure-openssl.c:(.text+0x1851): undefined reference to `sk_num'
          fe-secure-openssl.c:(.text+0x188c): undefined reference to `sk_value'
          fe-secure-openssl.c:(.text+0x18ed): undefined reference to `sk_free'
          fe-secure-openssl.c:(.text+0x1931): undefined reference to `ERR_get_error'
          fe-secure-openssl.c:(.text+0x19cc): undefined reference to `sk_free'
          fe-secure-openssl.c:(.text+0x1a2d): undefined reference to `sk_free'
          fe-secure-openssl.c:(.text+0x1a40): undefined reference to `X509_get_subject_name'
          fe-secure-openssl.c:(.text+0x1a5e): undefined reference to `X509_NAME_get_index_by_NID'
          fe-secure-openssl.c:(.text+0x1a7a): undefined reference to `X509_NAME_get_entry'
          fe-secure-openssl.c:(.text+0x1a82): undefined reference to `X509_NAME_ENTRY_get_data'
          fe-secure-openssl.c:(.text+0x1b6d): undefined reference to `X509_get_subject_name'
          fe-secure-openssl.c:(.text+0x1b85): undefined reference to `X509_NAME_get_index_by_NID'
          /usr/local/musl/lib/libpq.a(fe-secure-openssl.o): In function `PQsslAttribute':
          fe-secure-openssl.c:(.text+0x1ce3): undefined reference to `SSL_get_version'
          fe-secure-openssl.c:(.text+0x1d04): undefined reference to `SSL_get_current_cipher'
          fe-secure-openssl.c:(.text+0x1d11): undefined reference to `SSL_CIPHER_get_bits'
          fe-secure-openssl.c:(.text+0x1d44): undefined reference to `SSL_get_current_compression'
          fe-secure-openssl.c:(.text+0x1d64): undefined reference to `SSL_get_current_cipher'
          fe-secure-openssl.c:(.text+0x1d6c): undefined reference to `SSL_CIPHER_get_name'
          /usr/local/musl/lib/libpq.a(fe-secure-openssl.o): In function `pq_threadidcallback':
          fe-secure-openssl.c:(.text+0xd81): undefined reference to `pthread_self'
          collect2: error: ld returned 1 exit status
          

error: aborting due to previous error

error: Could not compile `using-diesel`.
emk commented

Thank you! I've confirmed this bug still exists after all known workarounds are applied. I'll take a shot at it tomorrow.

emk commented

OK, I've spent the last several hours updating everything to the latest dependencies, and I can still reproduce this bug.

Here's a few things I've observed so far:

1. All the link errors involve libpq_sys linking to OpenSSL

...at least as far as I can tell. Here's a sample:

  = note: /home/rust/src/target/x86_64-unknown-linux-musl/release/deps/libpq_sys-3a6911426f910838.rlib(fe-secure-openssl.o): In function `SSLerrmessage':
          fe-secure-openssl.c:(.text+0x39): undefined reference to `ERR_reason_error_string'

This is interesting because libpq actually tries to link to openssl at the C level, but not (necessarily?) at the Rust level. I need to investigate this.

2. The example links to OpenSSL before libpq-sys

This:

/home/rust/src/target/x86_64-unknown-linux-musl/release/deps/libopenssl_sys-4783752d3593d472.rlib

...appears before:

"/home/rust/src/target/x86_64-unknown-linux-musl/release/deps/libpq_sys-3a6911426f910838.rlib"

IIRC correctly, this means that libpq won't be able to access libopenssl, because symbols in a library can only be looked up in libraries that come after.

3. In the past, we've fixed similar problems by adding extern crate openssl

This suggests that libpq isn't correctly managing to link to OpenSSL by itself.

4. I'm successfully using rust-musl-builder for a number of other projects

...and some of those projects have been updated or created very recently. So at least some of the time, this does work.

Hypothesis

Taken together, this suggests that that problem might be that libpq isn't correctly declaring a dependency on libopenssl

Things to try:

  • Can I run the link command manually, reordering libopenssl-sys, and get it to work?
  • What does the build.rs script for libpq do?
  • Is there any thing in the libpq-sys bug tracker that looks relevant?
  • Have any of the other "static Rust" images fixed a similar issue lately?
emk commented

OK, so I have verified that:

  • Linking using-diesel in debug mode Just Works.
  • I can get using-diesel to link in release mode if I reorder the libraries we're linking against.

So this sounds like a case of libpq not correctly pulling in its dependencies, as hypothesized. On to the next step...

emk commented

libpq's build.rs is here: https://github.com/sgrif/pq-sys/blob/master/build.rs

It doesn't do anything in particular to ensure that OpenSSL, etc., get linked in. And none of the bugs in the bug tracker look relevant.

So now I want to look at the other, similar Rust images that statically link libpq, and see if anybody else has an existing fix for this.

emk commented

As mentioned in #64, it may be possible to force correct linking using:

extern crate openssl;

#[macro_use]
extern crate diesel;
emk commented

Other cross builders:

  • muslrust has a bug that looks suspiciously similar: clux/muslrust#49
  • rusl-musl-cross doesn't appear to have any Diesel-related examples or Diesel-related bugs, so I can't tell whether they've ever encountered or fixed this problem.

So there's no obvious, existing solution in any other Rust static builders.

Next steps:

  • Publish a note describing the workaround.
  • Publish my updated branch (with Ubuntu 18.04 and OpenSSL 1.1.1) as experimental and experimental-2019-04-12.
  • File an issue against pq-sys describing what's we've found, so that we discuss a possible upstream solution to remove the need for this workaround.
emk commented

Issue filed upstream: sgrif/pq-sys#25

iddm commented

Would you mind notifying watchers of this issue when the problem is solved? I am really concerned.

emk commented

@vityafx Please try the workaround mentioned above:

// Order matters!
extern crate openssl;
#[macro_use]
extern crate diesel;

This should work for most current versions of Rust.

iddm commented

It worked for me but I think importing openssl crate when I don't need it is a bit weird, especially breaking the order of the imports.

The deliberately ordered extern crate workaround worked for me on one project, but didn't on another. After a couple hours of disbelief, I shrugged my shoulders and just ran cargo update, which was apparently all I needed to do. I'm not sure which crate was the offensive one, but included in the bumps were openssl 0.10.21 -> 0.10.22, and openssl-sys 0.9.44 -> 0.9.46.

Not sure who needs to hear this, but just in case anyone else gets stuck... give cargo update a shot.

emk commented

We're going to need somebody to submit a PR for sgrif/pq-sys#25. I'm extremely busy on another project right now and won't be able to tackle this for a couple of weeks. Please feel free to ping me at the end of July or early August.

iddm commented

Can I use this hack still on the rust 2018 edition?

iddm commented

I have asked the question about rust 2018 because it does not work in it. The hack with extern crate order. cargo update also does not help.

UPD: It worked again suddenly. I don't know why.

iddm commented
  = note: /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libpq_sys-f2ec40b7c53867fb.rlib(fe-connect.o): In function `parseServiceFile':
          (.text+0xbd1): undefined reference to `ldap_init'
          (.text+0xbf1): undefined reference to `ldap_set_option'
          (.text+0xc05): undefined reference to `ldap_simple_bind'
          (.text+0xc39): undefined reference to `ldap_result'
          (.text+0xc57): undefined reference to `ldap_msgfree'
          (.text+0xc76): undefined reference to `ldap_set_option'
          (.text+0xcb4): undefined reference to `ldap_search_st'
          (.text+0xcda): undefined reference to `ldap_msgfree'
          (.text+0xce9): undefined reference to `ldap_err2string'
          (.text+0xd14): undefined reference to `ldap_unbind'
          (.text+0x1001): undefined reference to `ldap_unbind'
          (.text+0x101c): undefined reference to `ldap_count_entries'
          (.text+0x1055): undefined reference to `ldap_msgfree'
          (.text+0x105d): undefined reference to `ldap_unbind'
          (.text+0x1093): undefined reference to `ldap_first_entry'
          (.text+0x10b8): undefined reference to `ldap_get_values_len'
          (.text+0x10e1): undefined reference to `ldap_msgfree'
          (.text+0x11ac): undefined reference to `ldap_value_free_len'
          (.text+0x11b7): undefined reference to `ldap_unbind'
          (.text+0x124d): undefined reference to `ldap_msgfree'
          (.text+0x125d): undefined reference to `ldap_unbind'
          (.text+0x1287): undefined reference to `ldap_value_free_len'
          (.text+0x128f): undefined reference to `ldap_unbind'
          /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libpq_sys-f2ec40b7c53867fb.rlib(fe-connect.o): In function `default_threadlock':
          (.text+0x1a79): undefined reference to `__fprintf_chk'
          /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libpq_sys-f2ec40b7c53867fb.rlib(fe-connect.o): In function `pqDropConnection':
          (.text+0x208b): undefined reference to `gss_delete_sec_context'
          (.text+0x20a5): undefined reference to `gss_release_name'
          /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libpq_sys-f2ec40b7c53867fb.rlib(fe-connect.o): In function `PQconnectPoll':
          (.text+0x28dc): undefined reference to `__snprintf_chk'
          (.text+0x2955): undefined reference to `__snprintf_chk'
          /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libpq_sys-f2ec40b7c53867fb.rlib(fe-connect.o): In function `PQsetClientEncoding':
          (.text+0x48fb): undefined reference to `__sprintf_chk'
          /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libpq_sys-f2ec40b7c53867fb.rlib(fe-connect.o): In function `parseServiceInfo':
          (.text+0x4c8a): undefined reference to `__snprintf_chk'
          (.text+0x4d15): undefined reference to `__snprintf_chk'
          /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libpq_sys-f2ec40b7c53867fb.rlib(fe-connect.o): In function `connectOptions2':
          (.text+0x6468): undefined reference to `__snprintf_chk'
          (.text+0x67a0): undefined reference to `__fprintf_chk'
          /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libpq_sys-f2ec40b7c53867fb.rlib(fe-exec.o): In function `pqInternalNotice':
          (.text+0x128f): undefined reference to `__vsnprintf_chk'
          (.text+0x1379): undefined reference to `__sprintf_chk'
          /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libpq_sys-f2ec40b7c53867fb.rlib(fe-exec.o): In function `PQcopyResult':
          (.text+0x1677): undefined reference to `__strcpy_chk'
          /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libpq_sys-f2ec40b7c53867fb.rlib(fe-exec.o): In function `pqSaveParameterStatus':
          (.text+0x18e8): undefined reference to `__fprintf_chk'
          /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libpq_sys-f2ec40b7c53867fb.rlib(fe-exec.o): In function `PQoidStatus':
          (.text+0x3c86): undefined reference to `__memcpy_chk'
          /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libpq_sys-f2ec40b7c53867fb.rlib(fe-misc.o): In function `pqGets_internal':
          (.text+0xc7): undefined reference to `__fprintf_chk'
          /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libpq_sys-f2ec40b7c53867fb.rlib(fe-misc.o): In function `pqGetc':
          (.text+0x19b): undefined reference to `__fprintf_chk'
          /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libpq_sys-f2ec40b7c53867fb.rlib(fe-misc.o): In function `pqGetnchar':
          (.text+0x242): undefined reference to `__fprintf_chk'
          /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libpq_sys-f2ec40b7c53867fb.rlib(fe-misc.o): In function `pqSkipnchar':
          (.text+0x2ee): undefined reference to `__fprintf_chk'
          /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libpq_sys-f2ec40b7c53867fb.rlib(fe-misc.o): In function `pqGetInt':
          (.text+0x3da): undefined reference to `__fprintf_chk'
          /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libpq_sys-f2ec40b7c53867fb.rlib(fe-misc.o):(.text+0x619): more undefined references to `__fprintf_chk' follow
          /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libpq_sys-f2ec40b7c53867fb.rlib(fe-protocol2.o): In function `pqSetenvPoll':
          (.text+0xb24): undefined reference to `__sprintf_chk'
          (.text+0xc4a): undefined reference to `__sprintf_chk'
          (.text+0xcd2): undefined reference to `__sprintf_chk'
          /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libpq_sys-f2ec40b7c53867fb.rlib(pqexpbuffer.o): In function `appendPQExpBufferVA':
          (.text+0x265): undefined reference to `__vsnprintf_chk'
          /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libpq_sys-f2ec40b7c53867fb.rlib(chklocale.o): In function `pg_get_encoding_from_locale':
          (.text+0x1ff): undefined reference to `__fprintf_chk'
          /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libpq_sys-f2ec40b7c53867fb.rlib(inet_net_ntop.o): In function `inet_net_ntop':
          (.text+0xdc): undefined reference to `__sprintf_chk'
          (.text+0x2d2): undefined reference to `__sprintf_chk'
          (.text+0x337): undefined reference to `__sprintf_chk'
          (.text+0x3b8): undefined reference to `__sprintf_chk'
          (.text+0x478): undefined reference to `__sprintf_chk'
          /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libpq_sys-f2ec40b7c53867fb.rlib(inet_net_ntop.o):(.text+0x4b7): more undefined references to `__sprintf_chk' follow
          /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libpq_sys-f2ec40b7c53867fb.rlib(ip.o): In function `pg_getaddrinfo_all':
          (.text+0x170): undefined reference to `__strcpy_chk'
          /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libpq_sys-f2ec40b7c53867fb.rlib(fe-secure-openssl.o): In function `SSLerrmessage':
          (.text+0x84): undefined reference to `__snprintf_chk'
          (.text+0xb7): undefined reference to `__snprintf_chk'
          /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libpq_sys-f2ec40b7c53867fb.rlib(fe-secure-openssl.o): In function `initialize_SSL':
          (.text+0x4de): undefined reference to `__snprintf_chk'
          (.text+0x5ee): undefined reference to `__snprintf_chk'
          (.text+0x6b6): undefined reference to `__snprintf_chk'
          /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libpq_sys-f2ec40b7c53867fb.rlib(fe-secure-openssl.o):(.text+0x963): more undefined references to `__snprintf_chk' follow
          /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libpq_sys-f2ec40b7c53867fb.rlib(fe-auth.o): In function `pg_GSS_error_int':
          (.text+0x5b): undefined reference to `gss_display_status'
          (.text+0x7e): undefined reference to `gss_release_buffer'
          /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libpq_sys-f2ec40b7c53867fb.rlib(fe-auth.o): In function `pg_GSS_continue':
          (.text+0x15b): undefined reference to `gss_init_sec_context'
          (.text+0x188): undefined reference to `gss_release_buffer'
          (.text+0x1eb): undefined reference to `gss_release_buffer'
          (.text+0x270): undefined reference to `gss_release_name'
          (.text+0x28b): undefined reference to `gss_delete_sec_context'
          (.text+0x2a3): undefined reference to `gss_release_name'
          /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libpq_sys-f2ec40b7c53867fb.rlib(fe-auth.o): In function `pg_fe_sendauth':
          (.text+0x531): undefined reference to `__snprintf_chk'
          (.text+0x545): undefined reference to `GSS_C_NT_HOSTBASED_SERVICE'
          (.text+0x55c): undefined reference to `gss_import_name'
          /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libpq_sys-f2ec40b7c53867fb.rlib(fe-auth.o): In function `PQencryptPasswordConn':
          (.text+0xf34): undefined reference to `__memcpy_chk'
          /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libpq_sys-f2ec40b7c53867fb.rlib(fe-auth-scram.o): In function `pg_fe_scram_exchange':
          (.text+0x5c6): undefined reference to `__snprintf_chk'
          /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libpq_sys-f2ec40b7c53867fb.rlib(scram-common.o): In function `scram_build_verifier':
          (.text+0x5a4): undefined reference to `__sprintf_chk'
          collect2: error: ld returned 1 exit status


error: aborting due to previous error

This thing does not let me sleep normally.

emk commented

I haven't seen any new reports of this error in a while, so maybe the upstream fixes all went through. If you're still seeing problems on the most recent versions of everything, please feel free to reopen this issue.

Thank you to everybody who has found workarounds or fixes for this issue!

Just a note that if you have multiple binaries in your project you need to put the extern crate declarations at the top of all of them.

I'm still having this issue and no combination of any of the suggestions I've found work. Are there any new suggestions?

Edit: actually nevermind - I forgot I had a main.rs and a lib.rs which it imports (there are multiple binaries, though I'm only building one). It's working with the proper ordering of the extern crate statements. So thanks for the help!

This bug could be related to rust-lang/rust#61328 (which has bitten me multiple times). It seems to be something to do with the order in which linker inputs are declared - the above workaround presumably changes the declaration order of linker libs which somehow fixes it.