Subject: | [PATCH] Constructor/destructor configure check fails on certain compilers |
From: | "Misty De Meo" <mistydemeo@gmail.com> |
To: | krb5-bugs@mit.edu |
Date: | Sat, 18 Jul 2020 14:37:06 -0700 |
On recent versions of clang, calling functions without first having
imported their headers is an error. This causes the
constructor/destructor configure check to fail; it doesn't include any
headers, and a function it uses goes undefined. Sample error:
configure:5947: checking for constructor/destructor attribute support
configure:5975: clang -o conftest -g -O2 -fno-common
-Wl,-search_paths_first conftest.c -lresolv >&5
conftest.c:25:15: error: implicit declaration of function 'unlink' is
invalid in C99 [-Werror,-Wimplicit-function-declaration]
void foo1() { unlink("conftest.1"); }
^
Patch:
diff --git a/src/aclocal.m4 b/src/aclocal.m4
index 2394f7e..811e987 100644
--- a/src/aclocal.m4
+++ b/src/aclocal.m4
@@ -1606,7 +1606,8 @@ fi
a=no
b=no
# blindly assume we have 'unlink'...
-AC_TRY_RUN([void foo1() __attribute__((constructor));
+AC_TRY_RUN([#include <unistd.h>
+void foo1() __attribute__((constructor));
void foo1() { unlink("conftest.1"); }
void foo2() __attribute__((destructor));
void foo2() { unlink("conftest.2"); }
imported their headers is an error. This causes the
constructor/destructor configure check to fail; it doesn't include any
headers, and a function it uses goes undefined. Sample error:
configure:5947: checking for constructor/destructor attribute support
configure:5975: clang -o conftest -g -O2 -fno-common
-Wl,-search_paths_first conftest.c -lresolv >&5
conftest.c:25:15: error: implicit declaration of function 'unlink' is
invalid in C99 [-Werror,-Wimplicit-function-declaration]
void foo1() { unlink("conftest.1"); }
^
Patch:
diff --git a/src/aclocal.m4 b/src/aclocal.m4
index 2394f7e..811e987 100644
--- a/src/aclocal.m4
+++ b/src/aclocal.m4
@@ -1606,7 +1606,8 @@ fi
a=no
b=no
# blindly assume we have 'unlink'...
-AC_TRY_RUN([void foo1() __attribute__((constructor));
+AC_TRY_RUN([#include <unistd.h>
+void foo1() __attribute__((constructor));
void foo1() { unlink("conftest.1"); }
void foo2() __attribute__((destructor));
void foo2() { unlink("conftest.2"); }