Skip to content

configure fails to detect fchdir() using CFLAGS="-Werror -Wall" #75929

Closed

Description

@dilyanpalauzov
BPO 31748
Nosy @vstinner
PRs
  • bpo-31748: configure Werror #3949
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2017-10-10.17:05:50.570>
    labels = ['type-feature', '3.7', 'build']
    title = 'configure fails to detect fchdir() using CFLAGS="-Werror -Wall"'
    updated_at = <Date 2017-10-11.09:30:09.481>
    user = 'https://bugs.python.org/dilyanpalauzov'

    bugs.python.org fields:

    activity = <Date 2017-10-11.09:30:09.481>
    actor = 'vstinner'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Build']
    creation = <Date 2017-10-10.17:05:50.570>
    creator = 'dilyan.palauzov'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 31748
    keywords = ['patch']
    message_count = 9.0
    messages = ['304059', '304073', '304075', '304077', '304080', '304081', '304082', '304121', '304123']
    nosy_count = 2.0
    nosy_names = ['vstinner', 'dilyan.palauzov']
    pr_nums = ['3949']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue31748'
    versions = ['Python 2.7', 'Python 3.6', 'Python 3.7']

    Linked PRs

    Activity

    1. dilyanpalauzov commented on Oct 10, 2017

      dilyanpalauzovmannequin
      MannequinAuthor

      These are needed only sometimes.

      diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
      --- a/Modules/posixmodule.c
      +++ b/Modules/posixmodule.c
      @@ -1466,6 +1466,7 @@ path_error2(path_t *path, path_t *path2)
       
       /* POSIX generic methods */
       
      +#if defined(HAVE_FSYNC) || defined(HAVE_FDATASYNC) || defined(HAVE_FCHDIR)
       static int
       fildes_converter(PyObject *o, void *p)
       {
      @@ -1495,6 +1496,7 @@ posix_fildes_fd(int fd, int (*func)(int))
               return (!async_err) ? posix_error() : NULL;
           Py_RETURN_NONE;
       }
      +#endif
       
       
       #ifdef MS_WINDOWS
    2. vstinner commented on Oct 10, 2017

      @vstinner
      Member

      Hi Дилян Палаузов,

      These are needed only sometimes.

      Would you mind to elaborate, please?

      Which platform doesn't have os.fchdir(), os.fsync() nor os.fdatasync()?

    3. dilyanpalauzov commented on Oct 10, 2017

      dilyanpalauzovmannequin
      MannequinAuthor

      Having 'CFLAGS="-pipe -Werror -Wall -Wextra -O3 -fno-fat-lto-objects -flto" CXXFLAGS="-pipe -Wall -Wextra -O3 -fno-fat-lto-objects -flto" LDFLAGS="-Wl,-O1,-s -flto=12" ' in config.site and running "./configure" with gcc8 prints:

      checking for fchdir... no
      checking for fsync... no
      checking for fdatasync... no

      and config.log has:

      configure:11440: checking for fchdir
      configure:11453: gcc -c -pipe -Werror -Wall -Wextra -O3 -fno-fat-lto-objects -flto  conftest.c >&5
      conftest.c: In function 'main':
      conftest.c:250:7: error: unused variable 'x' [-Werror=unused-variable]
       void *x=fchdir
             ^
      cc1: all warnings being treated as errors
      configure:11453: $? = 1
      configure: failed program was:
      | /* confdefs.h */
      ...
      | #define HAVE_DIRFD 1
      | /* end confdefs.h.  */
      | #include <unistd.h>
      | int
      | main ()
      | {
      | void *x=fchdir
      |   ;
      |   return 0;
      | }
      configure:11460: result: no
    4. vstinner commented on Oct 10, 2017

      @vstinner
      Member

      Ok. My next question is: what is your operating system? What is your operating system version?

    5. dilyanpalauzov commented on Oct 10, 2017

      dilyanpalauzovmannequin
      MannequinAuthor

      If I remove -Werror from CFLAGS ./configure prints:

      checking for fchdir... yes
      checking for fsync... yes
      checking for fdatasync... yes

      so it is irrelevant what the OS is.

    6. vstinner commented on Oct 10, 2017

      @vstinner
      Member

      I can reproduce the issue on Fedora 26:

      haypo@selma$ ./configure CFLAGS="-Werror -Wall" 2>&1|tee log
      haypo@selma$ grep fchdir log
      checking for fchdir... no

      The problem is not posixmodule.c. The problem is configure which emits a compiler warning.

      configure.ac contains:
      ---

      AC_MSG_CHECKING(for fchdir)
      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <unistd.h>]], [[void *x=fchdir]])],
        [AC_DEFINE(HAVE_FCHDIR, 1, Define if you have the 'fchdir' function.)
         AC_MSG_RESULT(yes)],
        [AC_MSG_RESULT(no)
      ])

      Extract of config.log, without the long confdefs.h part:
      ---

      configure:11258: checking for fchdir
      configure:11271: gcc -c -Werror -Wall -Wextra  conftest.c >&5
      conftest.c: In function 'main':
      conftest.c:256:7: error: unused variable 'x' [-Werror=unused-variable]
       void *x=fchdir
             ^
      cc1: all warnings being treated as errors
      configure:11271: $? = 1
      configure: failed program was:
      | /* confdefs.h */
      | (...)
      | /* end confdefs.h.  */
      | #include <unistd.h>
      | int
      | main ()
      | {
      | void *x=fchdir
      |   ;
      |   return 0;
      | }
      configure:11278: result: no

    7. changed the title [-]Modules/posixmodule.c: skip compiling jka4NaPmmQ37 and posix_fildes_fd[/-] [+]configure fails to detect fchdir() using CFLAGS="-Werror -Wall"[/+] on Oct 10, 2017
    8. vstinner commented on Oct 10, 2017

      @vstinner
      Member

      Python 2.7 is also affected by the issue.

    9. added and removed on Oct 10, 2017
    10. dilyanpalauzov commented on Oct 11, 2017

      dilyanpalauzovmannequin
      MannequinAuthor

      The patch puts in "Misc/NEWS.d/next/Core and Builtins/2017-10-11-10-42-02.bpo-31748.oaEZcq.rst":

      +Support configure with -Wall by avoiding unused variables.

      but likely means "-Werror" (or both)

      Different people generate ./configure different ways. Some insert runstatedir in configure, others don't. E.g. on 14 April 2017 runstatedir was added to configure, on 9 June it was removed from configure, on 29 June it was added to configure. It needs to be clarified once forever, whether runstatedir belongs to configure or not and then everybody has to stick to this, in order to avoid useless changes in the version control.

    11. vstinner commented on Oct 11, 2017

      @vstinner
      Member

      "Different people generate ./configure different ways. Some insert runstatedir in configure, others don't. E.g. on 14 April 2017 runstatedir was added to configure, on 9 June it was removed from configure, on 29 June it was added to configure. It needs to be clarified once forever, whether runstatedir belongs to configure or not and then everybody has to stick to this, in order to avoid useless changes in the version control."

      For practical reasons, we decided to include the generated file configure in Git. You are right that not all developers use the same autoconf version, and so that the generated file includes or not the runstatedir change. I don't know how to fix this issue. If you consider that it's a bug and should be fixed, please open a new dedicated issue, since it's unrelated to your fchdir + -Werror bug.

    12. transferred this issue fromon Apr 10, 2022
    13. added
      type-bugAn unexpected behavior, bug, or error
      and removed
      type-featureA feature request or enhancement
      on Jul 3, 2026
    14. vasiliyk commented on Oct 23, 2026

      @vasiliyk
      Contributor

      Still reproducible on 3.16.0a1+dev (Apple clang 21, GCC 14).

      The PY_CHECK_FUNC macro uses expression void *x=$1 to check for name declaration.
      It has side effects: an unused variable and a function pointer to void* conversion that isn't valid ISO C. With CFLAGS="-Werror -Wall", ~40 checks (num is different per platform) report no for functions that exist (including fchdir).

      We can change the expression to (void)$1, the idiom AC_CHECK_DECL uses. It still fails to compile when the name isn't declared but it doesn't have those effects, so those ~40 false negatives go away.

      With the change configure under -Werror -Wall still gets other ~15 cpython checks wrong + autoconf's own AC_CHECK_FUNCS.

      Do we want to make the change anyway?

    15. vstinner commented on Nov 4, 2026

      @vstinner
      Member

      Do we want to make the change anyway?

      Using (void)$1 sounds correct to me. Go ahead and propose a PR. You can cc me if you want a review.

    16. added a commit that references this issue on Nov 4, 2026
    17. added 2 commits that reference this issue on Nov 5, 2026
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.7 (EOL)end of lifebuildThe build process and cross-buildtype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions