Unused -mno-fused-madd clang warnings on OS X

Issue #46 resolved
Daniel Neuhäuser
created an issue

When running the tests on OS X 10.8 with the system CPython, every test that compiles C code with -Werror fails.

The reason for this is that distutils uses the same compiler flags that have been used to compile the interpreter, specifically these are:

>>> from distutils.sysconfig import get_config_var
>>> get_config_var("PY_CFLAGS")
'-fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g  -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -I. -IInclude -I./Include -pipe -DPy_BUILD_CORE -arch i386 -arch x86_64'

One of those -mno-fused-madd is unsupported by clang, which clang warns about (clang: error: argument unused during compilation: '-mno-fused-madd') leading to the observed test failures.

One possible solution to this problem is to pass -Qunused-arguments as extra_compile_args to silence the warning. A better one would probably to make distutils not pass -mno-fused-madd to clang but I haven't been able to find a documented way to do that.

Comments (13)

  1. Armin Rigo

    That's an OS/X 10.8-with-clang-only problem; of course I'm interested in solutions that don't break elsewhere. So how would you suggest that we detect whether we must pass -Qunused-arguments or not?

  2. Daniel Neuhäuser reporter

    tl;dr: sys.platform == 'darwin' and map(int, os.uname()[2].split('.')) >= [11, 0, 0]

    clang has been the default compiler on OS X since 10.7, I think it is therefore fair to assume that if we run on OS X and the version is >= 10.7, the compiler is clang.

    Checking that we are running on OS X is trivial, the OS version can be identified by calling sw_vers -ProductVersion which we probably want to avoid, it can be read from /System/Library/CoreServices/SystemVersion.plist using plistlib which I think is a more elegant or it can be inferred from the Kernel version which is accessible with os.uname()[2] and maps directly to the OS version, so 11.0.0 is 10.7, this seems to be the least expensive method and therefore the one I would go with.

  3. Glyph

    But there's still a warning, so, I don't think the issue is actually fixed. Is this a problem with the way CPython on OS X is built? Or something about its distutils configuration?

  4. Lucian Brănescu-Mihăilă

    The lastest Clang update for OS X as part of Command line developer tools has made all unknown argument warnings into errors; in the future, it won't even be possible to turn them into warnings.

    clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]
    clang: note: this will be a hard error (cannot be downgraded to a warning) in the future

    This is a problem for lots of packages, not just cffi. I'm not sure what the solution is.

    My clang version:

    Apple LLVM version 5.1 (clang-503.0.38) (based on LLVM 3.4svn)
    Target: x86_64-apple-darwin13.1.0
    Thread model: posix
  5. Marc-Antoine Parent

    Not pretty. Since this breaks most compilation on Mac, I have edited away the argument in /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_sysconfigdata.py (and renewed the .pyc, .pyo files.) I wonder if it's possible to pass to distutils an argument filter function that could edit the flags?

  6. Armin Rigo

    It seems to be a general issue of distutils; I bet you get the very same error building any C extension module with setup.py. My guess would be that you need to recompile CPython with the same clang (and if the system distributes both this recent clang and a CPython that wasn't compiled with it, then it's a bug in the system). At any rate it seems there is little that can be done from cffi's setup.py.

  7. Log in to comment