Skip to content

undefined reference to 'fmaf' on Ubuntu 18.04 #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bagder opened this issue Sep 13, 2021 · 7 comments · Fixed by #213
Closed

undefined reference to 'fmaf' on Ubuntu 18.04 #133

bagder opened this issue Sep 13, 2021 · 7 comments · Fixed by #213

Comments

@bagder
Copy link
Contributor

bagder commented Sep 13, 2021

The CI builds that verify curl+rustls has started to fail on Ubuntu 18.04 and I can reproduce in a manual build as well on Ubuntu 18.04.I'm not sure exactly when this problem started but it feels like within the last few weeks. (I've tried work-arounds to get it working again in curl/curl#7701 but so far it has failed)

This reproduces on master as well as v0.7.1 and v0.7.2.

It does not reproduce on my Debian Linux unstable.

The steps to reproduce:

cd $HOME
git clone https://github.com/rustls/rustls-ffi.git
curl https://sh.rustup.rs -sSf | sh -s -- -y
source $HOME/.cargo/env
cargo install cbindgen
cd $HOME/rustls-ffi
make
make DESTDIR=$HOME/crust install

# now build curl to use this rustls
cd $HOME
git clone https://github.com/curl/curl.git
cd curl
./buildconf
./configure --with-rustls=$HOME/crust

That configure script tries use the function rustls_connection_read when linking with crustls.a - but fails since it lacks the symbols fmafand fma. Here's a piece of the resulting config.log:

configure:26660: checking for rustls_connection_read in -lcrustls
configure:26682: gcc -o conftest -Werror-implicit-function-declaration -g -O0 -pedantic -Wall -W -Wpointer-arith -Wwrite-strings -Wunused -Wshadow -Winline -Wnested-externs -Wmissing-declarations -Wmissing-prototypes -Wno-long-long -Wbad-function-cast -Wfloat-equal -Wno-multichar -Wsign-compare -Wundef -Wno-format-nonliteral -Wendif-labels -Wstrict-prototypes -Wdeclaration-after-statement -Wold-style-definition -Wstrict-aliasing=3 -Wcast-align -Wtype-limits -Wold-style-declaration -Wmissing-parameter-type -Wempty-body -Wclobbered -Wignored-qualifiers -Wconversion -Wno-sign-conversion -Wvla -ftree-vrp -Wdouble-promotion -Wformat=2 -Warray-bounds=2 -Wshift-negative-value -Wshift-overflow=2 -Wnull-dereference -fdelete-null-pointer-checks -Wduplicated-cond -Wunused-const-variable -Wduplicated-branches -Wrestrict -Walloc-zero -Wformat-overflow=2 -Wformat-truncation=2 -Wimplicit-fallthrough=4 -Wno-system-headers    -I/home/zuul/crust/include -lm   -L/home/zuul/crust/lib conftest.c -lcrustls -lpthread -ldl -lzstd  -lbrotlidec   >&5
conftest.c:46:1: warning: function declaration isn't a prototype [-Wstrict-prototypes]
 char rustls_connection_read ();
 ^~~~
/home/zuul/crust/lib/libcrustls.a(std-008055cc7d873802.std.cf1c8f7e-cgu.0.rcgu.o): In function `std::f32::<impl f32>::lerp':
/rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b//library/std/src/f32.rs:914: undefined reference to `fmaf'
/home/zuul/crust/lib/libcrustls.a(std-008055cc7d873802.std.cf1c8f7e-cgu.0.rcgu.o): In function `std::f64::<impl f64>::lerp':
/rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b//library/std/src/f64.rs:916: undefined reference to `fma'
collect2: error: ld returned 1 exit status
configure:26682: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "curl"
| #define PACKAGE_TARNAME "curl"
| #define PACKAGE_VERSION "-"
| #define PACKAGE_STRING "curl -"
| #define PACKAGE_BUGREPORT "a suitable curl mailing list: https://curl.se/mail/"
| #define PACKAGE_URL ""
| #define DEBUGBUILD 1
| #define CURLDEBUG 1
| #define PACKAGE "curl"
| #define VERSION "-"
| #define OS "x86_64-pc-linux-gnu"
| #define STDC_HEADERS 1
| #define HAVE_SYS_TYPES_H 1
| #define HAVE_SYS_STAT_H 1
| #define HAVE_STDLIB_H 1
| #define HAVE_STRING_H 1
| #define HAVE_MEMORY_H 1
| #define HAVE_STRINGS_H 1
| #define HAVE_INTTYPES_H 1
| #define HAVE_STDINT_H 1
| #define HAVE_UNISTD_H 1
| #define HAVE_DLFCN_H 1
| #define LT_OBJDIR ".libs/"
| #define HAVE_LDAP_SSL 1
| #define HAVE_SYS_TYPES_H 1
| #define HAVE_SYS_TIME_H 1
| #define HAVE_CLOCK_GETTIME_MONOTONIC 1
| #define HAVE_LIBBROTLIDEC 1
| #define HAVE_BROTLI_DECODE_H 1
| #define HAVE_BROTLI 1
| #define HAVE_LIBZSTD 1
| #define HAVE_ZSTD_H 1
| #define HAVE_ZSTD 1
| #define CURL_DISABLE_LDAP 1
| #define CURL_DISABLE_LDAPS 1
| #define ENABLE_IPV6 1
| #define HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID 1
| #define HAVE_WRITABLE_ARGV 1
| /* end confdefs.h.  */
| 
| 
| #ifdef __cplusplus
| extern "C"
| #endif
| char rustls_connection_read ();
| int main (void)
| {
| return rustls_connection_read ();
|  ;
|  return 0;
| }
configure:26691: result: no
configure:26706: error: --with-rustls was specified but could not find rustls.
@bagder
Copy link
Contributor Author

bagder commented Sep 13, 2021

Ok, this is solved by simply forcing the math lib to be used by configure:

LIBS=-lm ./configure --with-rustls=$HOME/crust

@bagder
Copy link
Contributor Author

bagder commented Sep 13, 2021

I propose maybe then consider this a request to have this documented somewhere.

@djc
Copy link
Member

djc commented Sep 13, 2021

So last week we had a new Rust release, 1.55. Might be that it changed how libm is used/linked? Might be interesting to force the use of Rust 1.54 with rustup to see if it fixes the problem.

@bagder
Copy link
Contributor Author

bagder commented Sep 13, 2021

That seems likely to be related, yes!

@jsha
Copy link
Collaborator

jsha commented Nov 9, 2021

I can also reproduce on ubuntu 18.04. For my own memory: on a fresh Ubuntu install I also needed to install: autoconf libtool build-essential.

I confirmed that running curl's configure from Sep 13 with rustls-ffi latest and Rust latest stable (1.56) gives the same error. Switching to Rust 1.54 fixes it. So it definitely is linked to the Rust release.

The function mentioned, lerp, was added in 1.55 as an experimental nightly-only feature: https://doc.rust-lang.org/1.55.0/std/primitive.f32.html#method.lerp.

It was removed from master 14 days ago: rust-lang/rust#86269. So within a few releases, it should be gone and the requirement for -lm will also be gone. I'll document that it's required between 1.55 and... 1.57.

I'm still a little confused about why this manifests for curl's configure script, but not rustls-ffi's make test, though.

@jsha
Copy link
Collaborator

jsha commented Nov 9, 2021

Thinking about this some more, I'd like to find a way to insulate rustls-ffi users from this sort of requirement. rustls-ffi doesn't use symbols from libm, and it doesn't use any of the stdlib functions that rely on libm. Similarly, rustls-ffi doesn't actually rely on libpthread or libdl- but linking against rustls-ffi seems to require those, because the Rust stdlib depends on them.

Speculating aloud: Is there a way to build librustls.a such that these unreachable symbols are not needed when it gets linked into a user's program? I think I need to learn more about linking.

@jsha
Copy link
Collaborator

jsha commented Nov 11, 2021

Fixed in #213. It turns out rustc has a flag that will list out all needed flags for linking against a static library that it generates. There are more than I thought!

@jsha jsha closed this as completed in #213 Nov 15, 2021
asfgit pushed a commit to apache/httpd that referenced this issue Dec 22, 2021
See rustls/rustls-ffi#133 for discussion about it.
Only 1.55, 1.56 and 1.57 should be affected.

Tested with 1.56.1 on Linux pop-os 5.15.5

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1896278 13f79535-47bb-0310-9956-ffa450edef68
asfgit pushed a commit to apache/httpd that referenced this issue Feb 14, 2022
  *) mod_tls: Fix a linkage issue with rustls when compiled
     with rust 1.55, 1.56 or 1.57. This prevents the loading
     of the module because of an undefined symbol: fmaf
     See rustls/rustls-ffi#133
     [Christophe Jaillet]




git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1898077 13f79535-47bb-0310-9956-ffa450edef68
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants