Changes between Version 2 and Version 3 of WimplicitFunctionDeclaration


Ignore:
Timestamp:
Jan 24, 2022, 7:30:25 AM (2 years ago)
Author:
JDLH (Jim DeLaHunt)
Comment:

Extensive additional content, in several section headers.

Legend:

Unmodified
Added
Removed
Modified
  • WimplicitFunctionDeclaration

    v2 v3  
    11= WimplicitFunctionDeclaration =
    22
    3 WimplicitFunctionDeclaration is wiki shorthand for a particular error message, "Warning: Configuration logfiles contain indications of -Wimplicit-function-declaration; check that features were not accidentally disabled", sometimes seen in the configuration log of a port.  This page explains what you as a MacPorts user should understand about this message, and what helpful steps you can take.  It also explains to port maintainers, and the adventurer who wants to diagnose the problem behind the warning, the reason why the message appears, and how to pursue the problem to the upstream developers.
    4 
    5 TODO: write more page content. This is just an initial stub.
    6 
    7 Email "[https://lists.macports.org/pipermail/macports-users/2021-May/049998.html Re: Warning: -Wimplicit-function-declaration]" from Ryan Schmidt to the MacPorts Users list on Thu May 20 06:05:07 UTC 2021:
     3WimplicitFunctionDeclaration is wiki shorthand for a particular warning message, "Warning: Configuration logfiles contain indications of -Wimplicit-function-declaration; check that features were not accidentally disabled", which MacPorts sometimes displays when configuring a port.  This page explains what you as a MacPorts user should understand about this message, and what helpful steps you can take.  It also explains to port maintainers, and the adventurer who wants to diagnose the problem behind the warning, the reason why the message appears, and how to pursue the problem to the upstream developers.
     4
     5[[PageOutline]]
     6
     7== The warning ==
     8
     9Here is what MacPorts prints to Terminal when building the **freeciv-common** port. Certain parts of this port's code causes MacPorts to issue the warning message.
     10
     11{{{
     12% sudo port build freeciv-common
     13--->  Computing dependencies for freeciv-common
     14--->  Fetching distfiles for freeciv-common
     15--->  Verifying checksums for freeciv-common
     16--->  Extracting freeciv-common
     17--->  Configuring freeciv-common
     18Warning: Configuration logfiles contain indications of -Wimplicit-function-declaration; check that features were not accidentally disabled:
     19  strcmp: found in freeciv-2.6.6/config.log
     20  exit: found in freeciv-2.6.6/config.log
     21  at_quick_exit: found in freeciv-2.6.6/config.log
     22--->  Building freeciv-common
     23%
     24}}}
     25
     26MacPorts displays the same warning message, "Warning: Configuration logfiles contain indications of -Wimplicit-function-declaration; check that features were not accidentally disabled", for every port. The following lines summarise each separate indication which MacPorts found. Each indication is of a separate place in the source code which might be using a function name as an "implicit function declaration". The indication gives the function name. It is a clue for investigating the situation. The "implicit function declaration" could potentially cause the port to configure incorrectly, especially on Apple Silicon Macs, or on macOS Big Sur or newer versions.
     27
     28In this example, there are three indications. They are related to the functions "strcmp", "exit", and "at_quick_exit".
     29
     30The message "found in freeciv-2.6.6/config.log" gives the final part of the path to the log file which contains the message. This log file is in the port's work directory, which only exists while the port is being built and prepared for installation. Once installation is complete, MacPorts deletes the work directory and the log file. The command `port work `''portname'' tells MacPorts to print out the path to the work directory. Thus, to open the log file in editor, you can use a command combining `port work` and the final part of the path:
     31
     32{{{
     33% edit $(port work freeciv-common)/freeciv-2.6.6/config.log
     34}}}
     35
     36In the `config.log`, search for each function name mentioned in the configuration output. This might look like (with line breaks added for legibility):
     37
     38{{{
     39configure:25690: checking for C11 at_quick_exit()
     40configure:25713: /usr/bin/clang -o conftest -pipe -Os -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk -arch x86_64
     41-I/opt/local/include -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk -Werror -Wall -Wpointer-arith -Wcast-align
     42-Wno-tautological-compare -L/opt/local/lib -Wl,-headerpad_max_install_names -Wl,-syslibroot,/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk
     43-arch x86_64 conftest.c  -liconv >&5
     44conftest.c:99:2: error: implicit declaration of function 'at_quick_exit' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
     45 at_quick_exit(func);
     46 ^
     471 error generated.
     48configure:25713: $? = 1
     49configure: failed program was:
     50| /* confdefs.h */
     51| …[lines omitted for brevity]…
     52| /* end confdefs.h.  */
     53| #include <stdlib.h>
     54| static void func(void)
     55| {}
     56|
     57| int
     58| main (void)
     59| {
     60|  at_quick_exit(func);
     61|   ;
     62|   return 0;
     63| }
     64configure:25723: result: no
     65}}}
     66
     67Note: if MacPorts has deleted the work directory, the `port work` gives no output, and the `edit` command above will fail.
     68
     69See the [#Diagnosis] section below for how to pursue the clues in the logs further.
     70
     71== Respond by filing MacPorts ticket(s) ==
     72
     73The -Wimplicit-function-declaration warning could be a serious bug in a port. It is worth reporting such problems. This lets other users of the same port know that the problem is recognised, and it lets port maintainers (and you, if you want) diagnose the problem further, and report it to the upstream developers of the port's source code. So, please consider filing a MacPorts ticket about the problems.
     74
     75You have a choice of filing a a separate MacPorts ticket for each indication in the message, or a single ticket for all the indications. Each indication is evidence of a separate problem, which might get fixed or languish independent of the others. But, someone who works on one problem might well work on the others at the same time. And filing a single ticket is less work than filing multiple. Choosing to file a single ticket for all the indications is perfectly fine.
     76
     77Follow the instructions for [https://guide.macports.org/#project.tickets filing a MacPorts ticket]. Be sure to check for existing tickets on this port about the -Wimplicit-function-declaration warnings. There is no point in filing a redundant report.
     78
     79== What it means ==
     80
     81MacPorts started generating this message in [https://lists.macports.org/pipermail/macports-users/2021-May/049980.html MacPorts 2.7.0, released in May 2021].
     82
     83Clemens Lang announced the functionality in an announcement to the MacPorts Dev email list in a message, ''[https://lists.macports.org/pipermail/macports-dev/2020-November/042647.html port maintainers: please test check for implicit decls]'' on Tue Nov 24 22:15:53 UTC 2020:
     84   This will become a significant problem with the release of Big Sur, since Apple has made -Wimplicit-function-declaration an error by default due to details of the calling convention on Apple Silicon.
     85
     86   The problem this warning is designed to catch is as follows:
     87
     88   1. A configure check tests for presence and usability of a function, but does not include a header declaring the function.
     89   2. The configure check fails due to -Wimplicit-function-declaration, but would succeed otherwise.
     90   3. The configure script disables certain functionality based on this incorrect result, and software compiles differently than it used to.
     91
     92Ryan Schmidt's [https://lists.macports.org/pipermail/macports-dev/2020-November/042648.html reply to that thread] has a lot more detail. Please read it. It is not easy to summarise it here.
     93
     94Ryan Schmidt explained it to the MacPorts Users list in a message, "[https://lists.macports.org/pipermail/macports-users/2021-May/049998.html Re: Warning: -Wimplicit-function-declaration]" on Thu May 20 06:05:07 UTC 2021:
    895    Sometimes programs are written to use functions before declaring them. This has not been correct ever since the introduction of the 1999 version of the C standard decades ago, but because it was allowed by the earlier 1989 C standard many C99 compilers still allowed this with a warning. But it can cause programs to crash or behave incorrectly on ARM processors, therefore to avoid problems on Apple Silicon Macs, the version of clang in included with Xcode 12 and later considers this to be an error. This causes some ports to fail to build. Worse, many configure tests have this problem, but when they fail, it doesn't cause configure to immediately fail and tell you that; instead, configure just makes wrong determinations about your system. In the best case, the build still succeeds and works fine. Or, the build fails with a bizarre error later. Or the build succeeds but is wrong.
    996   
     
    1198
    1299    If many programs check for functions which we know are not ever present on certain versions of macOS, then we can mark that in a central location rather than individually in each affected port.
     100
     101The -Wimplicit-function-declaration warning does not cause the problem. The underlying code, together with the behaviour of Xcode 12 and ARM processors, causes the problem. And the problem might be silent in some cases. The message just makes the problem visible. It is sometimes possible to work around such problems by having the port patch the underlying code at the MacPorts stage. It is far better to have the upstream developers change their code so that it works with Xcode 12 and on ARM processers, along with all the other compilers and processors where it needs to work.
     102
     103Thus, in the long term, the most helpful response to this message is enough diagnosis to make useful bug report, then filing that bug report with the upstream developers.
     104
     105== Diagnosis ==
     106
     107In ''[#Thewarning The warning]'' section above, there was an excerpt from a `config.log` file with one of the indications reported in the -Wimplicit-function-declaration warning. Here are the first few lines again (with line breaks added for legibility):
     108
     109{{{
     110configure:25690: checking for C11 at_quick_exit()
     111configure:25713: /usr/bin/clang -o conftest -pipe -Os -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk -arch x86_64
     112-I/opt/local/include -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk -Werror -Wall -Wpointer-arith -Wcast-align
     113-Wno-tautological-compare -L/opt/local/lib -Wl,-headerpad_max_install_names -Wl,-syslibroot,/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk
     114-arch x86_64 conftest.c  -liconv >&5
     115conftest.c:99:2: error: implicit declaration of function 'at_quick_exit' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
     116 at_quick_exit(func);
     117 ^
     1181 error generated.
     119configure:25713: $? = 1
     120configure: failed program was:
     121| /* confdefs.h */
     122| …[lines omitted for brevity]…
     123| /* end confdefs.h.  */
     124| #include <stdlib.h>
     125| static void func(void)
     126| {}
     127|
     128| int
     129| main (void)
     130| {
     131|  at_quick_exit(func);
     132|   ;
     133|   return 0;
     134| }
     135configure:25723: result: no
     136}}}
     137
     138The notation `configure:25690` refers to line 25690 of file `configure` in the work directory. `configure` is a shell script generated by the [https://www.gnu.org/software/autoconf/ GNU Autoconf tool]. For this project, those lines looked like:
     139
     140{{{
     141  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for C11 at_quick_exit()" >&5
     142printf %s "checking for C11 at_quick_exit()... " >&6; }
     143if test ${ac_cv_c11_at_quick_exit+y}
     144then :
     145  printf %s "(cached) " >&6
     146else $as_nop
     147
     148                        fc_save_CPPFLAGS="$CPPFLAGS"
     149    CPPFLAGS="$CPPFLAGS -Werror $EXTRA_DEBUG_CFLAGS"
     150    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
     151/* end confdefs.h.  */
     152#include <stdlib.h>
     153static void func(void)
     154{}
     155
     156int
     157main (void)
     158{
     159 at_quick_exit(func);
     160  ;
     161  return 0;
     162}
     163_ACEOF
     164if ac_fn_c_try_link "$LINENO"
     165then :
     166  ac_cv_c11_at_quick_exit=yes
     167else $as_nop
     168  ac_cv_c11_at_quick_exit=no
     169fi
     170rm -f core conftest.err conftest.$ac_objext conftest.beam \
     171    conftest$ac_exeext conftest.$ac_ext
     172    CPPFLAGS="$fc_save_CPPFLAGS"
     173fi
     174{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c11_at_quick_exit" >&5
     175printf "%s\n" "$ac_cv_c11_at_quick_exit" >&6; }
     176  if test "x${ac_cv_c11_at_quick_exit}" = "xyes" ; then
     177
     178printf "%s\n" "#define HAVE_AT_QUICK_EXIT 1" >>confdefs.h
     179
     180  fi
     181}}}
     182 
     183So, the implicit function declaration appears to be in line 25708 of `configure`: `at_quick_exit(func);` .
     184
     185Autoconf generates the `configure` file as a result of performing an auto-configuration, driven by script files. `configure.ac` is an often-used name for the script file which drives Autoconf as it generates `configure`. Looking in `configure.ac` in the work directory, we see no mention of `at_quick_exit(func);`.
     186
     187Searching the entire code base for the distinctive string `at_quick_exit`, we discover another file, `m4/c11.m4`, with this code:
     188
     189{{{
     190AC_DEFUN([FC_C11_AT_QUICK_EXIT],
     191[
     192  AC_CACHE_CHECK([for C11 at_quick_exit()], [ac_cv_c11_at_quick_exit], [
     193    dnl Add -Werror to detect cases where the header does not declare
     194    dnl at_quick_exit() but linking still work. This situation can happen
     195    dnl when the header is strict about the fact that at_quick_exit() is
     196    dnl a C11 feature and the compiler is not in C11 mode.
     197    dnl $EXTRA_DEBUG_CFLAGS contains -Wmissing-declarations if it's supported.
     198    fc_save_CPPFLAGS="$CPPFLAGS"
     199    CPPFLAGS="$CPPFLAGS -Werror $EXTRA_DEBUG_CFLAGS"
     200    AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>
     201static void func(void)
     202{}
     203]], [[ at_quick_exit(func); ]])],
     204[ac_cv_c11_at_quick_exit=yes], [ac_cv_c11_at_quick_exit=no])
     205    CPPFLAGS="$fc_save_CPPFLAGS"])
     206  if test "x${ac_cv_c11_at_quick_exit}" = "xyes" ; then
     207    AC_DEFINE([HAVE_AT_QUICK_EXIT], [1], [C11 at_quick_exit() available])
     208  fi
     209])
     210}}}
     211
     212The file extension, .m4, indicates it is a GNU M4 script. GNU Autoconf is built using M4. It is likely that the upstream developers wrote this code. It includes the specific expression, `[[ at_quick_exit(func); ]]`, which seems to have triggered the warning. The square brackets surrounding it are Autoconf syntax. It seems like this code might be a useful place to point to in a bug report filed with the upstream developers about the implicit declaration problem.
     213
     214This code, and its counterpart in `configure`, are a good place to examine closely for incorrect behaviour. Does the configuration come to the wrong conclusion about the capabilities of the compiler? If so, that is exactly the "features were… accidentally disabled" risk which the original warning was bringing to your attention.
     215
     216== Respond by filing upstream bug reports ==
     217
     218If you can, please report these indications to the upstream developers. It is far better to have the upstream developers change their code so that it works with Xcode 12 and on ARM processers, along with all the other compilers and processors where it needs to work.
     219
     220Thus, in the long term, the most helpful response to this message is enough diagnosis to make useful bug report, then filing that bug report with the upstream developers.
     221
     222The details of how to do this differ for each port. The Portfile for the port will probably have a link to the upstream project's website. That website may well have instructions about how best to file bug reports with that project.
     223
     224== See also ==
     225
     226Here are some links to other information related to the -Wimplicit-function-declaration warning.
     227
     228=== Macports-users email threads ===
     229
     230The following are some of the email threads about the -Wimplicit-function-declaration warning on the macports-users email list. Some of these threads have further insight about the problem and how to respond.
     231
     232  * ''[https://lists.macports.org/pipermail/macports-users/2021-May/049994.html Warning: -Wimplicit-function-declaration]'', started Thu May 20 00:21:10 UTC 2021.
     233  * ''[https://lists.macports.org/pipermail/macports-users/2021-June/050074.html Warning: Configuration logfiles contain indications of -Wimplicit-function-declaration]'', started Tue Jun 8 09:27:29 UTC 2021.
     234  * ''[https://lists.macports.org/pipermail/macports-users/2021-October/050351.html Notes & warning after update.]'', started Mon Oct 11 17:53:54 UTC 2021.
     235
     236=== GNU Automake tools ===
     237
     238One kind of source code which triggers -Wimplicit-function-declaration warning is configuration code generated with, or by, GNU Autoconf. We have not discovered any information which says that Autoconf is incompatible with Xcode 12 and ARM processors. However, the way a project uses the Autoconf, where the project's configuration test code triggers the warning, may make it appear that Autoconf is the problem. Here are links to the project websites for these tools. You can find more documentation on them there.
     239
     240  * [https://www.gnu.org/software/automake/automake.html GNU Automake] project: https://www.gnu.org/software/automake/automake.html
     241  * [https://www.gnu.org/software/autoconf/ GNU Autoconf] project: https://www.gnu.org/software/autoconf/
     242  * [https://www.gnu.org/software/m4/m4.html GNU M4] project: https://www.gnu.org/software/m4/m4.html
     243