Skip Menu |
 

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"); }
Show quoted text
> conftest.c:25:15: error: implicit declaration of function 'unlink' is
invalid in C99 [-Werror,-Wimplicit-function-declaration]

Was this configure run done with CPPFLAGS=-Werror or similar?

If not, what version of clang was this?

(There seem to be other, more immediate problems with configuring with -Werror in the compiler flags, such as TRY_WARN_CC_FLAG_1 failing in AC_TRY_COMPILE([], 1;, ...) because "1;" generates an unused value warning.  So probably something else is going on.)
Additional notes:

* The compiler line doesn't include -Werror in the options, but the error message does, which is weird.
* Using godbolt.org, recent versions of the test program don't seem to give an error on the test program by default.
* The presence of -fno-common in the compiler options suggests macOS (aclocal.m4 line 589).
* If I explicitly configure with CFLAGS=-Werror, lots of tests go wrong.  TRY_WARN_CC_FLAG_1 errors out entirely (fixable by changing "1;" to ";" in the AC_TRY_COMPILE program arguments), Tcl isn't found, functions like vsprintf and strdup aren't found, etc..
* A search of the autoconf bug list suggests that making configure work with CFLAGS=-Werror is not a design goal.

It's conceivable that Apple has modified clang to error out on implicit-function-declaration by default, and that the diagnostic includes Werror due to the nature of the local modification.  If so, there may be two other tests giving incorrect results.  My (Linux) config.log reports an implicit declaration warning for Tcl_CreateInterp in the tcl tests and for printf in the in6addr_any test.  AC_CHECK_FUNC doesn't seem to generate implicit declaration warnings all the time because it sticks a "char fnname ();" in the body, but is does generate "conflicting types for built-in function" warnings when the function being tested for has a compiler builtin.
 
Date: Fri, 31 Jul 2020 09:51:11 -0700
From: "Misty De Meo" <mistydemeo@gmail.com>
To: rt@krbdev.mit.edu
Subject: Re: [krbdev.mit.edu #8928] [PATCH] Constructor/destructor configure check fails on certain compilers
On Mon, Jul 27, 2020 at 9:51 AM Greg Hudson via RT <rt@krbdev.mit.edu> wrote:
Show quoted text
>
> > conftest.c:25:15: error: implicit declaration of function 'unlink' is
> invalid in C99 [-Werror,-Wimplicit-function-declaration]
>
> Was this configure run done with CPPFLAGS=-Werror or similar?
>
> If not, what version of clang was this?

This is Apple's clang 12, which now sets this by default. I didn't
explicitly pass these flags; they are now set implicitly.
You can find information about that in the Xcode beta release notes:
https://developer.apple.com/documentation/xcode-release-notes/xcode-12-beta-release-notes/

Show quoted text
>
> (There seem to be other, more immediate problems with configuring with -Werror
> in the compiler flags, such as TRY_WARN_CC_FLAG_1 failing in AC_TRY_COMPILE([],
> 1;, ...) because "1;" generates an unused value warning. So probably something
> else is going on.)
>
>
Thanks for the additional information.  That kind of compiler change is hostile to autoconf, whose developers (looking over conversations on their mailing list over many years) do not feel that they can avoid warnings across all compilers in its code snippets.  There does appear to be some effort in the autoconf core macros to avoid implicit function declaration warnings, but of course custom tests can fail, as in this case.

I have identified three tests that produce the wrong answer with -Werror=implicit-function-declarations: this one, the test for Tcl, and the test for in6addr_any.  I will work on a patch for all three.
 
Subject: git commit
From: ghudson@mit.edu

Fix three configure tests for Xcode 12

Xcode 12 will change its clang to have
-Werror=implicit-function-declaration by default. Fix three autoconf
tests which generate this warning due to missing include declarations.
Reported by Misty De Meo.

https://github.com/krb5/krb5/commit/a037a7694b841f7cab6eb47bd877c6710a2de8fb
Author: Greg Hudson <ghudson@mit.edu>
Commit: a037a7694b841f7cab6eb47bd877c6710a2de8fb
Branch: master
src/aclocal.m4 | 7 ++++---
src/configure.ac | 1 +
2 files changed, 5 insertions(+), 3 deletions(-)