python / python/cpython

On macOS, Configure script assumes that "gcc" is an alias for "clang", even if it really is GCC

Open
#96,249 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

build type-bug
Dominant language
Python
Stars
77.2k
Forks
36k
PR merge metrics
PR metrics pending

Description

Your environment

  • MacOS 12.4

Bug report

Apologies if this is a known "wontfix" issue, I didn't see it mentioned in a search of past issues.

The configure.ac script assumes that gcc is actually clang on MacOS and uses Clang's -fprofile-instr-generate flag for PGO instead of GCC's -fprofile-generate, leading to build failure when PGO is turned on.

Steps to reproduce on MacOS:

sudo port install gcc
# or `brew install gcc`, same result

CC='/opt/local/bin/gcc-mp-12' pyenv install --verbose 3.10.6

Outcome:

...
gcc-mp-12: error: unrecognized command-line option '-fprofile-instr-generate'; did you mean '-fprofile-generate'?
...

The problem is found here: https://github.com/python/cpython/blob/3.10/configure.ac#L1491-L1514

case $CC in
  *clang*)
    # Any changes made here should be reflected in the GCC+Darwin case below
    ...
    ;;
  *gcc*)
    case $ac_sys_system in
      Darwin*)
        PGO_PROF_GEN_FLAG="-fprofile-instr-generate"
        PGO_PROF_USE_FLAG="-fprofile-instr-use=code.profclangd"

MacOS (perhaps annoyingly) ships with gcc as an alias for clang, so the configure script sensibly assumes that gcc is actually clang and sets its options accordingly.

However, that isn't always a correct assumption!

Possible solutions:

  1. Check for the presence of Apple clang in the $CC --version output.
  2. Check that the absolute path of $CC is /usr/bin/gcc.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in configure.ac around lines 1491–1514 and reproduce with CC='/opt/local/bin/gcc-mp-12' pyenv install --verbose 3.10.6 on macOS. Compare the compiler identification with the Darwin PGO flags selected there. Done means real GCC uses -fprofile-generate while Apple Clang continues to use its existing flags, without breaking the configure path.

Written by the indexing model from the issue text.

Assessment

Tech stack
shell
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.