macOS version detection broken in configure

Carlo Cabrera carlo.cabrera at me.com
Wed Oct 20 16:59:49 UTC 2021


The configure script mistakenly recognises macOS 11 (Big Sur) as an old version
of macOS, thereby choosing the linker flags `-flat_namespace` and `-undefined suppress`.

We want to avoid `-flat_namespace` as this can cause name collisions for users
of the library. [1]

This can be fixed by patching libtool.m4 [2] and regenerating configure.

The problem lies in this snippet from `configure`:

    case $host_os in
    rhapsody* | darwin1.[012])
      _lt_dar_allow_undefined='$wl-undefined ${wl}suppress' ;;
    darwin1.*)
      _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined ${wl}suppress' ;;
    darwin*) # darwin 5.x on
      # if running on 10.5 or later, the deployment target defaults
      # to the OS version, if on x86, and 10.4, the deployment
      # target defaults to 10.4. Don't you love it?
      case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in
	10.0,*86*-darwin8*|10.0,*-darwin[91]*)
	  _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;;
	10.[012][,.]*)
	  _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined ${wl}suppress' ;;
	10.*)
	  _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;;
      esac

To check, we can use `otool -hV` or a newish version of `file` on
`libgmp.10.dylib`:

    ❯ otool -hV .libs/libgmp.10.dylib
    .libs/libgmp.10.dylib:
    Mach header
          magic  cputype cpusubtype  caps    filetype ncmds sizeofcmds      flags
    MH_MAGIC_64   X86_64        ALL  0x00       DYLIB    14       1616 DYLDLINK NO_REEXPORTED_DYLIBS
    ❯ file .libs/libgmp.10.dylib
    .libs/libgmp.10.dylib: Mach-O 64-bit x86_64 dynamically linked shared library, flags:<|DYLDLINK|NO_REEXPORTED_DYLIBS>

A library built with the correct linker options (`-undefined dynamic_lookup`)
should produce this output (built on macOS 10.15):

    ❯ otool -hV lib/libgmp.10.dylib
    lib/libgmp.10.dylib:
    Mach header
          magic  cputype cpusubtype  caps    filetype ncmds sizeofcmds      flags
    MH_MAGIC_64   X86_64        ALL  0x00       DYLIB    14       1632   NOUNDEFS DYLDLINK TWOLEVEL NO_REEXPORTED_DYLIBS
    ❯ file lib/libgmp.10.dylib
    lib/libgmp.10.dylib: Mach-O 64-bit x86_64 dynamically linked shared library, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|NO_REEXPORTED_DYLIBS>

In particular, `TWOLEVEL` appears in the flags for the library built on Catalina
but not on Big Sur. Checking the output of `make` also shows that `libtool`
invokes `clang` with the `-flat_namespace` flag.

Here is the information requested in your bug reporting manual:

configure options: none
configure output: see attached `configure_output.txt`
compiler: Apple clang version 13.0.0 (clang-1300.0.29.3)
uname -a: Darwin hermes.lan 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:21 PDT 2021; root:xnu-7195.141.6~3/RELEASE_X86_64 x86_64 i386 MacBookAir9,1 Darwin
config.guess: nehalem-apple-darwin20.6.0
configfsf.guess: x86_64-apple-darwin20.6.0
config.log: attached

[1] http://mirror.informatimago.com/next/developer.apple.com/releasenotes/DeveloperTools/TwoLevelNamespaces.html#intro
[2] https://lists.gnu.org/archive/html/libtool-patches/2020-06/msg00001.html

-------------- next part --------------
A non-text attachment was scrubbed...
Name: config.log.tar.gz
Type: application/x-gzip
Size: 50346 bytes
Desc: not available
URL: <https://gmplib.org/list-archives/gmp-bugs/attachments/20211021/60dae535/attachment-0001.bin>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: configure_output.txt
URL: <https://gmplib.org/list-archives/gmp-bugs/attachments/20211021/60dae535/attachment-0001.txt>


More information about the gmp-bugs mailing list