Skip to content

The configure script incorrectly detects crypt() when it doesn't exist #123917

@madscientist

Description

@madscientist

Bug report

Bug description:

I'm trying to build Python in a very limited sysroot, with limited functionality. In particular, there is no crypt library in this restricted system.

Unfortunately, Python configure detects that there IS a crypt() and then the build fails:

$ /data/src/python3/Python-3.12.6/configure 'CFLAGS=-march=haswell -mtune=intel -O2 -fPIC -static-libgcc' 'LDFLAGS=-L/data/src/build/x86_64-linux/sysroot/rl84/lib64 -L/data/src/build/x86_64-linux/sysroot/rl84/usr/lib64' --prefix=/data/src/python3/Linux-Release-make/dist --enable-static --without-readline --with-openssl=/data/src/openssl/Linux-Release-make-maximal/dist
  ...
checking for crypt.h... no
 ...
checking for libxcrypt >= 3.1.1... no
checking for library containing crypt_r... no
checking for crypt or crypt_r... yes
  ...
checking for stdlib extension module _crypt... yes
  ...
[ERROR] _crypt failed to import: /data/src/python3/Linux-Release-make/bld.python3/build/lib.linux-x86_64-3.12/_crypt.cpython-312-x86_64-linux-gnu.so: undefined symbol: crypt
  ...
/bin/install -c -m 755 Modules/_crypt.cpython-312-x86_64-linux-gnu.so /data/src/python3/Linux-Release-make/dist/lib/python3.12/lib-dynload/_crypt.cpython-312-x86_64-linux-gnu.so
/bin/install: cannot stat 'Modules/_crypt.cpython-312-x86_64-linux-gnu.so': No such file or directory
make: *** [Makefile:2079: sharedinstall] Error 1

I believe the problem is that this test is insufficient (from configure.ac):

    AC_LINK_IFELSE([AC_LANG_PROGRAM([
        #ifdef HAVE_CRYPT_H
          #include <crypt.h>
        #endif
        #include <unistd.h>
      ], [
        #ifdef HAVE_CRYPT_R
          void *x = crypt_r;
        #else
          void *x = crypt;
        #endif
      ])
    ], [ac_cv_crypt_crypt=yes], [ac_cv_crypt_crypt=no])

If you compile and link the above with CFLAGS=-O2 then the assignment will be optimized away. I think you can force it by changing the test like this:

    AC_LINK_IFELSE([AC_LANG_PROGRAM([
        #ifdef HAVE_CRYPT_H
          #include <crypt.h>
        #endif
        #include <unistd.h>
        volatile void *x;
      ], [
        #ifdef HAVE_CRYPT_R
          x = crypt_r;
        #else
          x = crypt;
        #endif
      ])
    ], [ac_cv_crypt_crypt=yes], [ac_cv_crypt_crypt=no])

If I do this then the link fails as expected even with -O2.

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixesbuildThe 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