threads / patch / 38514

patchgit-compat-util: do not step on MAC_OS_X_VERSION_MIN_REQUIRED

Subject: [PATCH] git-compat-util: do not step on MAC_OS_X_VERSION_MIN_REQUIRED

## tl;dr

6 messages between Feb 6, 2015 and Feb 6, 2015. Diffs are folded; open one to read it.

replies: 5people: 3as markdown or json

Kyle J. McKay· Feb 6, 2015, 09:35 UTC · lore

MAC_OS_X_VERSION_MIN_REQUIRED may be defined by the builder to a specific version in order to produce compatible binaries for a particular system. Blindly defining it to MAC_OS_X_VERSION_10_6 is bad.

Additionally MAC_OS_X_VERSION_10_6 will not be defined on older systems and should AvailabilityMacros.h be included on such as system an error will result. However, using the explicit value of 1060 (which is what MAC_OS_X_VERSION_10_6 is defined to) does not solve the problem.

The changes that introduced stepping on MAC_OS_X_VERSION_MIN were made in b195aa00 (git-compat-util: suppress unavoidable Apple-specific deprecation warnings) to avoid deprecation warnings.

Instead of blindly setting MAC_OS_X_VERSION_MIN to 1060 change the definition of DEPRECATED_ATTRIBUTE to empty to avoid the warnings. This preserves any MAC_OS_X_VERSION_MIN_REQUIRED setting while avoiding the warnings as intended by b195aa00.

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
---
 git-compat-util.h | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
Show changes to git-compat-util.h +6 −4
diff --git a/git-compat-util.h b/git-compat-util.h
index eb9b0ff3..0efd32c4 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -212,12 +212,15 @@ extern char *gitbasename(char *);
 #endif
 
 #ifndef NO_OPENSSL
+#ifdef __APPLE__
 #define __AVAILABILITY_MACROS_USES_AVAILABILITY 0
-#define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_6
+#include <AvailabilityMacros.h>
+#undef DEPRECATED_ATTRIBUTE
+#define DEPRECATED_ATTRIBUTE
+#undef __AVAILABILITY_MACROS_USES_AVAILABILITY
+#endif
 #include <openssl/ssl.h>
 #include <openssl/err.h>
-#undef MAC_OS_X_VERSION_MIN_REQUIRED
-#undef __AVAILABILITY_MACROS_USES_AVAILABILITY
 #ifdef NO_HMAC_CTX_CLEANUP
 #define HMAC_CTX_cleanup HMAC_cleanup
 #endif
--
Eric Sunshine· Feb 6, 2015, 10:00 UTC · re: Kyle J. McKay · lore

Re: [PATCH] git-compat-util: do not step on MAC_OS_X_VERSION_MIN_REQUIRED

On Fri, Feb 6, 2015 at 4:35 AM, Kyle J. McKay <mackyle@gmail.com> wrote:
Show 22 quoted lines
> MAC_OS_X_VERSION_MIN_REQUIRED may be defined by the builder to a
> specific version in order to produce compatible binaries for a
> particular system.  Blindly defining it to MAC_OS_X_VERSION_10_6
> is bad.
>
> Additionally MAC_OS_X_VERSION_10_6 will not be defined on older
> systems and should AvailabilityMacros.h be included on such as
> system an error will result.  However, using the explicit value
> of 1060 (which is what MAC_OS_X_VERSION_10_6 is defined to) does
> not solve the problem.
>
> The changes that introduced stepping on MAC_OS_X_VERSION_MIN were
> made in b195aa00 (git-compat-util: suppress unavoidable
> Apple-specific deprecation warnings) to avoid deprecation
> warnings.
>
> Instead of blindly setting MAC_OS_X_VERSION_MIN to 1060 change
> the definition of DEPRECATED_ATTRIBUTE to empty to avoid the
> warnings.  This preserves any MAC_OS_X_VERSION_MIN_REQUIRED
> setting while avoiding the warnings as intended by b195aa00.
>
> Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
Tested on 10.10.2 (Yosemite) and 10.5.8 (Snow Leopard).
Reviewed-by: Eric Sunshine <sunshine@sunshineco.com>
More below...
Show 24 quoted lines
> ---
>  git-compat-util.h | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/git-compat-util.h b/git-compat-util.h
> index eb9b0ff3..0efd32c4 100644
> --- a/git-compat-util.h
> +++ b/git-compat-util.h
> @@ -212,12 +212,15 @@ extern char *gitbasename(char *);
>  #endif
>
>  #ifndef NO_OPENSSL
> +#ifdef __APPLE__
>  #define __AVAILABILITY_MACROS_USES_AVAILABILITY 0
> -#define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_6
> +#include <AvailabilityMacros.h>
> +#undef DEPRECATED_ATTRIBUTE
> +#define DEPRECATED_ATTRIBUTE
> +#undef __AVAILABILITY_MACROS_USES_AVAILABILITY
> +#endif
>  #include <openssl/ssl.h>
>  #include <openssl/err.h>
> -#undef MAC_OS_X_VERSION_MIN_REQUIRED
> -#undef __AVAILABILITY_MACROS_USES_AVAILABILITY

DEPRECATED_ATTRIBUTE is a fairly generic name. Do we want to be extra careful and #undef it here to avoid potential unintended interactions with other #includes (Apple or not)?

    #ifdef __APPLE__
    #undef DEPRECATED_ATTRIBUTE
    #endif
On the other hand, we've already mucked with it, so #undef may be superfluous.
>  #ifdef NO_HMAC_CTX_CLEANUP
>  #define HMAC_CTX_cleanup HMAC_cleanup
>  #endif
> --
Kyle J. McKay· Feb 6, 2015, 19:47 UTC · re: Eric Sunshine · lore

Re: [PATCH] git-compat-util: do not step on MAC_OS_X_VERSION_MIN_REQUIRED

On Feb 6, 2015, at 02:00, Eric Sunshine wrote:
Show 19 quoted lines
> On Fri, Feb 6, 2015 at 4:35 AM, Kyle J. McKay <mackyle@gmail.com>  
> wrote:
>> #ifndef NO_OPENSSL
>> +#ifdef __APPLE__
>> #define __AVAILABILITY_MACROS_USES_AVAILABILITY 0
>> -#define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_6
>> +#include <AvailabilityMacros.h>
>> +#undef DEPRECATED_ATTRIBUTE
>> +#define DEPRECATED_ATTRIBUTE
>> +#undef __AVAILABILITY_MACROS_USES_AVAILABILITY
>> +#endif
>> #include <openssl/ssl.h>
>> #include <openssl/err.h>
>> -#undef MAC_OS_X_VERSION_MIN_REQUIRED
>> -#undef __AVAILABILITY_MACROS_USES_AVAILABILITY
>
> DEPRECATED_ATTRIBUTE is a fairly generic name. Do we want to be extra
> careful and #undef it here to avoid potential unintended interactions
> with other #includes (Apple or not)?

The new patch only mucks with it when we have #ifdef __APPLE__ and pretty much any apple code is going to end up including the availability stuff sooner or later which manipulates DEPRECATED_ATTRIBUTE. Essentially that makes "DEPRECATED_ATTRIBUTE" a reserved macro name on __APPLE__.

>
>    #ifdef __APPLE__
>    #undef DEPRECATED_ATTRIBUTE
>    #endif

If we do that, won't the compiler then helpfully supply a "0" when the macro is used? Or is that only when an undefined macro is used inside an #if or #elif ?

That would break all later declarations that use it.
> On the other hand, we've already mucked with it, so #undef may be  
> superfluous.

Actually I just tested it. If we #undef it we could end up producing these:

   error: syntax error before ‘DEPRECATED_ATTRIBUTE’

So I think it needs to stay #define'd to nothing to be safe in case anything later on ends up including stuff that uses it. The worst that happens is you don't see some deprecation warnings that you otherwise would. It won't make any functions available that shouldn't be or make unavailable functions that should be.

-Kyle
Junio C Hamano· Feb 6, 2015, 20:05 UTC · re: Kyle J. McKay · lore

Re: [PATCH] git-compat-util: do not step on MAC_OS_X_VERSION_MIN_REQUIRED

"Kyle J. McKay" <mackyle@gmail.com> writes:
Show 7 quoted lines
> Actually I just tested it.  If we #undef it we could end up producing  
> these:
>
>    error: syntax error before DEPRECATED_ATTRIBUTE
>
> So I think it needs to stay #define'd to nothing to be safe in case  
> anything later on ends up including stuff that uses it.

Doesn't the fact that your test failed indicates that it is not jsut "to be safe in case" but is required for correctness?

The first hit for "MAC_OS_X_VERSION_MIN_REQUIRED" was this:
  https://opensource.apple.com/source/CarbonHeaders/CarbonHeaders-18.1/AvailabilityMacros.h

which marks quite a many macros to that value. I do not know what changes they make to openssl/*.h (which is included just after the above header is included, but I would imagine that is where the AVAILABLE_MAC_OS_X_VERSION_XXX_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_VERSION_YYY macros are checked and annoying warnings that are being squelched by the previous change are given?

Kyle J. McKay· Feb 6, 2015, 20:43 UTC · re: Junio C Hamano · lore

Re: [PATCH] git-compat-util: do not step on MAC_OS_X_VERSION_MIN_REQUIRED

On Feb 6, 2015, at 12:05, Junio C Hamano wrote:
Show 23 quoted lines
> "Kyle J. McKay" <mackyle@gmail.com> writes:
>
>> Actually I just tested it.  If we #undef it we could end up producing
>> these:
>>
>>   error: syntax error before DEPRECATED_ATTRIBUTE
>>
>> So I think it needs to stay #define'd to nothing to be safe in case
>> anything later on ends up including stuff that uses it.
>
> Doesn't the fact that your test failed indicates that it is not jsut
> "to be safe in case" but is required for correctness?
>
> The first hit for "MAC_OS_X_VERSION_MIN_REQUIRED" was this:
>
>  https://opensource.apple.com/source/CarbonHeaders/CarbonHeaders-18.1/AvailabilityMacros.h
>
> which marks quite a many macros to that value.  I do not know what
> changes they make to openssl/*.h (which is included just after the
> above header is included, but I would imagine that is where the
> AVAILABLE_MAC_OS_X_VERSION_XXX_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_VERSION_YYY
> macros are checked and annoying warnings that are being squelched by
> the previous change are given?
Yes.

Although Eric didn't specify exactly where when he suggested adding this:

On Feb 6, 2015, at 02:00, Eric Sunshine wrote:
>    #ifdef __APPLE__
>    #undef DEPRECATED_ATTRIBUTE
>    #endif

I took the suggestion to be after the openssl/*.h headers are included which would avoid the error of having DEPRECATED_ATTRIBUTE be #undef'd for them. But, even math.h can end up including AvailabilityMacros.h, so I think #undef'ing DEPRECATED_ATTRIBUTE after the openssl/*.h headers are included would be unsafe in general. While we might happen to get away with that today, if say compat/apple-common- crypto.h changes in the future (or for that matter any sequence of includes in other files or any headers in the Apple SDK) we could start seeing the error.

TLDR; yeah, DEPRECATED_ATTRIBUTE needs to remain defined to nothing.
-Kyle
Eric Sunshine· Feb 6, 2015, 22:01 UTC · re: Kyle J. McKay · lore

Re: [PATCH] git-compat-util: do not step on MAC_OS_X_VERSION_MIN_REQUIRED

On Fri, Feb 6, 2015 at 3:43 PM, Kyle J. McKay <mackyle@gmail.com> wrote:
Show 35 quoted lines
> On Feb 6, 2015, at 12:05, Junio C Hamano wrote:
>> "Kyle J. McKay" <mackyle@gmail.com> writes:
>>> So I think it needs to stay #define'd to nothing to be safe in case
>>> anything later on ends up including stuff that uses it.
>>
>> Doesn't the fact that your test failed indicates that it is not jsut
>> "to be safe in case" but is required for correctness?
>>
>> [...] I do not know what
>> changes they make to openssl/*.h (which is included just after the
>> above header is included, but I would imagine that is where the
>> AVAILABLE_MAC_OS_X_VERSION_XXX_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_VERSION_YYY
>> macros are checked and annoying warnings that are being squelched by
>> the previous change are given?
>
> Yes.
>
> Although Eric didn't specify exactly where when he suggested adding this:
>
> On Feb 6, 2015, at 02:00, Eric Sunshine wrote:
>>
>>    #ifdef __APPLE__
>>    #undef DEPRECATED_ATTRIBUTE
>>    #endif
>
> I took the suggestion to be after the openssl/*.h headers are included which
> would avoid the error of having DEPRECATED_ATTRIBUTE be #undef'd for them.
> But, even math.h can end up including AvailabilityMacros.h, so I think
> #undef'ing DEPRECATED_ATTRIBUTE after the openssl/*.h headers are included
> would be unsafe in general.  While we might happen to get away with that
> today, if say compat/apple-common-crypto.h changes in the future (or for
> that matter any sequence of includes in other files or any headers in the
> Apple SDK) we could start seeing the error.
>
> TLDR; yeah, DEPRECATED_ATTRIBUTE needs to remain defined to nothing.

I agree with this analysis. An alternative would be to revert b195aa00 (and not apply this patch), but then we risk having legitimate Git-related compilation warnings lost in the noise of the useless Apple deprecation warnings. Given the glacial pace at which Apple headers changes, and considering the rapid pace of change in Git, it still seems the lesser evil to suppress the useless warnings Apple thrust upon us when they deprecated OpenSSL in its entirety without providing replacements. It's unfortunate that the DEPRECATED_ATTRIBUTE #define will bleed beyond the OpenSSL #includes and potentially allow us to miss some future Apple deprecations, however, given the shortcomings of b195aa00, the proposed patch seems to be the best we can do.

← back to recent threads