sudo-project / sudo

Utility to execute a command as another user
https://www.sudo.ws
Other
1.17k stars 214 forks source link

configure.ac: fix openssl static build #244

Closed ffontaine closed 1 year ago

ffontaine commented 1 year ago

Do not use AX_APPEND_FLAG as it will break static builds by removing duplicates such as -lz or -latomic which are needed by -lssl and -lcrypto. This will fix the following build failure with sparc which needs -latomic:

Checking for X509_STORE_CTX_get0_cert
configure:21215: /home/thomas/autobuild/instance-3/output-1/host/bin/sparc-buildroot-linux-uclibc-gcc -o conftest -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -Os -g0  -static -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -DZLIB_CONST  -static conftest.c   -L/home/thomas/autobuild/instance-3/output-1/host/bin/../sparc-buildroot-linux-uclibc/sysroot/usr/lib -lssl -lz -pthread -latomic -lcrypto >&5
/home/thomas/autobuild/instance-3/output-1/host/lib/gcc/sparc-buildroot-linux-uclibc/10.4.0/../../../../sparc-buildroot-linux-uclibc/bin/ld: /home/thomas/autobuild/instance-3/output-1/host/bin/../sparc-buildroot-linux-uclibc/sysroot/usr/lib/libcrypto.a(x509cset.o): in function `X509_CRL_up_ref':
x509cset.c:(.text+0x108): undefined reference to `__atomic_fetch_add_4'

[...]

In file included from ./hostcheck.c:38:
../../include/sudo_compat.h:342:41: error: conflicting types for 'ASN1_STRING_data'
  342 | #  define ASN1_STRING_get0_data(x)      ASN1_STRING_data(x)
      |                                         ^~~~~~~~~~~~~~~~

Fixes:

millert commented 1 year ago

@ffontaine Can you share the output of pkg-config --static --libs openssl and pkg-config --libs openssl on that machine? Is the problem that -latomic is listed after both -lssl and -lcrypto?

ffontaine commented 1 year ago

Here is the output:

 output/host/bin/pkg-config --static --libs openssl
-Loutput/host/bin/../sparc-buildroot-linux-uclibc/sysroot/usr/lib -lssl -Loutput/host/bin/../sparc-buildroot-linux-uclibc/sysroot/usr/lib -lz -pthread -latomic -lcrypto -lz -pthread -latomic

The issue is indeed that -latomic is listed after both -lssland -lcrypto. But the issue is not only related to -latomic. There is the same issue with -lz and -pthread. As you know, when building statically all the dependencies should be listed in the correct order.

millert commented 1 year ago

Yes, it is unfortunate that the dependencies aren't just listed once at the end.