configure: Check for -no_weak_imports in ldflags on macOS

Message ID 20170306211521.82176-1-martin@martin.st
State Committed
Commit 81bffae368f331b6cd386a814f225a58e3f32f40
Headers show

Commit Message

Martin Storsjö March 6, 2017, 9:15 p.m.
From: Luca Barbato <lu_zero@gentoo.org>

Recent versions of macOS provide more posix API (in particular,
clock_gettime) than previous versions and recent Apple toolchains
provide all that API, even when targeting older releases without
said API. Disallow linking to functions which might not be available
at runtime.

To actually have an effect, either add
--extra-cflags="-mmacosx-version-min=10.11" (or any other version
prior to 10.12) or set MACOSX_DEPLOYMENT_TARGET=10.11 when running
configure.

As a workaround for libav versions without this fix, one can
also add --extra-cflags="-mmacosx-version-min=10.11
-Werror=partial-availability" while running configure.

The -no_weak_imports flag is new in Xcode 8; in Xcode 7 it is not
supported. This is not an issue since Xcode 7 only ships with the
10.11 macOS SDK, which lacks clock_gettime.

Bug-Id: 1033

CC: libav-stable@libav.org
---
 configure | 1 +
 1 file changed, 1 insertion(+)

Comments

Luca Barbato March 6, 2017, 9:20 p.m. | #1
On 06/03/2017 22:15, Martin Storsjö wrote:
> From: Luca Barbato <lu_zero@gentoo.org>
> 
> Recent versions of macOS provide more posix API (in particular,
> clock_gettime) than previous versions and recent Apple toolchains
> provide all that API, even when targeting older releases without
> said API. Disallow linking to functions which might not be available
> at runtime.
> 
> To actually have an effect, either add
> --extra-cflags="-mmacosx-version-min=10.11" (or any other version
> prior to 10.12) or set MACOSX_DEPLOYMENT_TARGET=10.11 when running
> configure.
> 
> As a workaround for libav versions without this fix, one can
> also add --extra-cflags="-mmacosx-version-min=10.11
> -Werror=partial-availability" while running configure.
> 
> The -no_weak_imports flag is new in Xcode 8; in Xcode 7 it is not
> supported. This is not an issue since Xcode 7 only ships with the
> 10.11 macOS SDK, which lacks clock_gettime.
> 
> Bug-Id: 1033
> 
> CC: libav-stable@libav.org
> ---
>  configure | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/configure b/configure
> index cdeae9a..170585a 100755
> --- a/configure
> +++ b/configure
> @@ -3944,6 +3944,7 @@ case $target_os in
>          SHFLAGS='-dynamiclib -Wl,-single_module -Wl,-install_name,$(SHLIBDIR)/$(SLIBNAME_WITH_MAJOR),-current_version,$(LIBVERSION),-compatibility_version,$(LIBMAJOR)'
>          enabled x86_32 && append SHFLAGS -Wl,-read_only_relocs,suppress
>          add_ldflags -Wl,-dynamic,-search_paths_first
> +        check_ldflags -Wl,-no_weak_imports
>          SLIBSUF=".dylib"
>          SLIBNAME_WITH_VERSION='$(SLIBPREF)$(NAME).$(LIBVERSION)$(SLIBSUF)'
>          SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(NAME).$(LIBMAJOR)$(SLIBSUF)'
> 

Looks good :) Thank you a lot for testing and amending!

lu
Sean McGovern March 6, 2017, 9:35 p.m. | #2
Hi Martin,


On Mar 6, 2017 16:15, "Martin Storsjö" <martin@martin.st> wrote:

From: Luca Barbato <lu_zero@gentoo.org>

Recent versions of macOS provide more posix API (in particular,
clock_gettime) than previous versions and recent Apple toolchains
provide all that API, even when targeting older releases without
said API. Disallow linking to functions which might not be available
at runtime.



Diego-nit: POSIX is an acronym, please capitalize.

Otherwise OK.

-- Sean McG.

Patch

diff --git a/configure b/configure
index cdeae9a..170585a 100755
--- a/configure
+++ b/configure
@@ -3944,6 +3944,7 @@  case $target_os in
         SHFLAGS='-dynamiclib -Wl,-single_module -Wl,-install_name,$(SHLIBDIR)/$(SLIBNAME_WITH_MAJOR),-current_version,$(LIBVERSION),-compatibility_version,$(LIBMAJOR)'
         enabled x86_32 && append SHFLAGS -Wl,-read_only_relocs,suppress
         add_ldflags -Wl,-dynamic,-search_paths_first
+        check_ldflags -Wl,-no_weak_imports
         SLIBSUF=".dylib"
         SLIBNAME_WITH_VERSION='$(SLIBPREF)$(NAME).$(LIBVERSION)$(SLIBSUF)'
         SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(NAME).$(LIBMAJOR)$(SLIBSUF)'