(Sending this a 2nd time, after I joined the list.)

For the Nettle crypto library:

If the C compiler lacks __builtin_bswap64, then Nettle may call a
function named __builtin_bswap64 and get a link error.  The problem is
that ./configure doesn't check for link errors.  I append a small diff
to switch from AC_TRY_COMPILE to AC_TRY_LINK.

OpenBSD, on some unusual hardware platforms, still uses GCC 4.2.1, which
doesn't have __builtin_bswap64.  Manphiz reported to OpenBSD that the
build of Nettle 3.5.1 failed on mips64el/longsoon hardware:
https://marc.info/?l=openbsd-ports&m=157510504817444&w=2

The error was "undefined reference to `__builtin_bswap64'".

Nettle only uses __builtin_bswap64 (in ctr.c) on little-endian hardware.
The error didn't happen when OpenBSD built Nettle with GCC 4.2.1 on
big-endian platforms, like powerpc/macppc.

In traditional C, you never needed to declare functions if their return
type was int.  C code like `whatever(11, "a string")` would implicitly
declare `int whatever();`.  Likewise, if __builtin_bswap64 isn't a
built-in, then `__builtin_bswap64(x)` in ./configure does implicitly
declare `int __builtin_bswap64();` as a function.  AC_TRY_COMPILE can
compile this function call, but AC_TRY_LINK can't link it.

OpenBSD decided to patch ./configure to do a link test:
https://cvsweb.openbsd.org/cgi-bin/cvsweb/ports/security/libnettle/patches/patch-configure?rev=1.9&content-type=text/x-cvsweb-markup

The below diff is for configure.ac in Nettle git master cdbbe64.  After
I made this change, I ran ./.bootstrap and checked the build on my
OpenBSD powerpc/macppc machine with GCC 4.2.1:

$ ../configure --disable-documentation \
> CPPFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib
$ gmake
$ gmake check

(The --disable-documentation prevents an error from makeinfo 4.8, which
seems too old.  The FLAGS find gmp in /usr/local, because OpenBSD's
compilers don't look there by default.  gmake is GNU make.)

The build got "All 99 tests passed", then "All 3 tests passed".
config.log shows that "checking for __builtin_bswap64" failed with the
"undefined reference" error.  --George

diff --git a/configure.ac b/configure.ac
index 3547cae4..7ac84f2e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -213,7 +213,7 @@ AC_C_BIGENDIAN([AC_DEFINE([WORDS_BIGENDIAN], 1)
 
 AC_CACHE_CHECK([for __builtin_bswap64],
                nettle_cv_c_builtin_bswap64,
-[AC_TRY_COMPILE([
+[AC_TRY_LINK([
 #include <stdint.h>
 ],[
 uint64_t x = 17;
_______________________________________________
nettle-bugs mailing list
[email protected]
http://lists.lysator.liu.se/mailman/listinfo/nettle-bugs

Reply via email to