Skip to content

PHP_TEST_BUILD macro false negatives with -Werror=strict-prototypes #13727

Closed
@orlitzky

Description

@orlitzky

Description

The contents of the PHP_TEST_BUILD macro are,

AC_DEFUN([PHP_TEST_BUILD], [
  old_LIBS=$LIBS
  LIBS="$4 $LIBS"
  AC_LINK_IFELSE([AC_LANG_SOURCE([[
    $5
    char $1();
    int main(void) {
      $1();
      return 0;
    }
  ]])],[
    LIBS=$old_LIBS
    $2
  ],[
    LIBS=$old_LIBS
    $3
  ])
])

The char $1(); runs afoul of -Wstrict-prototypes, so when that warning is turned into an error via CFLAGS, it can cause the build test to fail even if the function/library it's checking for is present.

I found this accidentally while testing ext/gd with -Werror=strict-prototypes in my CFLAGS (from working on an unrelated problem):

$ ./configure --disable-all --enable-gd
...
checking for GD support... yes
checking for external libgd... no
checking for libavif... no
checking for libwebp... no
checking for libjpeg... no
checking for libXpm... no
checking for FreeType 2... no
checking whether to enable JIS-mapped Japanese font support in GD... no
checking for zlib... yes
checking for libpng... yes
configure: error: GD build test failed. Please check the config.log for details.

The generated program is,

char foobar(void) { return '\0'; }
char foobar();
int main(void) {
  foobar();
  return 0;
}

and the compiler error was,

conftest.c:225:5: error: function declaration isn't a prototype [-Werror=strict-prototypes]
  225 |     char foobar();
      |     ^~~~

For now, "don't do that" is a valid response, but in a few years we'll start seeing newer compilers enable these things by default. The result here is not too bad because the build dies, but in the worst case, features could quietly be disabled.

PHP Version

git HEAD

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions