Skip to content

In a package build environment, cc accepts the -mpopcnt flag despite it being unsupported, unless -c is also passed #21112

@gridbugs

Description

@gridbugs

brew doctor output

Your system is ready to brew.

Verification

  • I ran brew update twice and am still able to reproduce my issue.
  • My "brew doctor output" above says Your system is ready to brew or a definitely unrelated Tier message.
  • This issue's title and/or description do not reference a single formula e.g. brew install wget. If they do, open an issue at https://github.com/Homebrew/homebrew-core/issues/new/choose instead.

brew config output

HOMEBREW_VERSION: 5.0.2-56-g07a983c
ORIGIN: https://github.com/Homebrew/brew
HEAD: 07a983c338fe0df4409d75c04318c81f654805a4
Last commit: 13 hours ago
Branch: main
Core tap HEAD: a574a7831cb5a4543cabb1a86d8cc1fafe9ab552
Core tap last commit: 16 minutes ago
Core tap JSON: 19 Nov 06:40 UTC
Core cask tap JSON: 19 Nov 06:41 UTC
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_DOWNLOAD_CONCURRENCY: 16
HOMEBREW_EDITOR: nvim
HOMEBREW_FORBID_PACKAGES_FROM_PATHS: set
HOMEBREW_MAKE_JOBS: 8
HOMEBREW_SORBET_RUNTIME: set
Homebrew Ruby: 3.4.7 => /opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.4.7/bin/ruby
CPU: octa-core 64-bit arm_blizzard_avalanche
Clang: 17.0.0 build 1700
Git: 2.50.1 => /Library/Developer/CommandLineTools/usr/bin/git
Curl: 8.7.1 => /usr/bin/curl
macOS: 15.6-arm64
CLT: 26.0.0.0.1.1757719676
Xcode: N/A
Rosetta 2: false

What were you trying to do (and why)?

I want to use a command like cc test.c -mpopcnt to check for C compiler support for the -mpopcnt flag, however the command succeeds even when the compiler does not support the flag.

Context:

In a build script for the base ocaml package, support for the -mpopcnt C compiler flag is tested by compiling a test program passing the flag. The code is here.

The command which tests compiler support for -mpopcnt is:

cc baseconf.c -mpopcnt -o /dev/null

This works as expected when building the package directly (outside of homebrew), where the command above fails with the error:

clang: error: unsupported option '-mpopcnt' for target 'arm64-apple-darwin24.6.0'

I'm trying to build this package as part of a larger project (vpnkit) in a homebrew formula.

What happened (include all command output)?

The command cc baseconf.c -mpopcnt -o /dev/null gives no error and exits with 0. This leads the build script to incorrectly believe that -mpopcnt is supported by the C compiler. Later in the build it attempts to compile C code with cc -c -mpopcnt ..., which fails with the error:

clang: error: unsupported option '-mpopcnt' for target 'arm64-apple-darwin24.6.0'

What did you expect to happen?

I expected the command cc baseconf.c -mpopcnt -o /dev/null to fail with the error:

clang: error: unsupported option '-mpopcnt' for target 'arm64-apple-darwin24.6.0'

That's how the command behaves outside of a homebrew build environment, and that's how the command behaves inside a homebrew environment if -c is also passed

Step-by-step reproduction instructions (by running brew commands)

$ brew sh
$ echo 'int main(){return 0;}' > a.c
$ cc -mpopcnt a.c   # no error
$ cc -mpopcnt -c a.c
clang: error: unsupported option '-mpopcnt' for target 'arm64-apple-darwin24.6.0'


Repeating the above sequence of commands without first entering a homebrew environment leads to both `cc` commands to fail with the error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions