OpenJDK fails to build with GCC when the #include<time.h> inside zip.cpp comes from a non-sysroot path

Florian Weimer fweimer at redhat.com
Thu Nov 29 12:01:42 UTC 2018


* David Holmes:

> This should really be being discussed on core-libs-dev.

Okay, moving the conversation.

>> diff -r 70a423caee44 src/share/native/com/sun/java/util/jar/pack/zip.cpp
>> --- a/src/share/native/com/sun/java/util/jar/pack/zip.cpp	Tue Oct 09 08:33:33 2018 +0100
>> +++ b/src/share/native/com/sun/java/util/jar/pack/zip.cpp	Wed Nov 28 22:13:12 2018 -0500
>> @@ -415,9 +415,7 @@
>>       ((uLong)h << 11) | ((uLong)m << 5) | ((uLong)s >> 1);
>>   }
>>   -#ifdef _REENTRANT // solaris
>> -extern "C" struct tm *gmtime_r(const time_t *, struct tm *);
>> -#else
>> +#if !defined(_REENTRANT) // linux
>>   #define gmtime_r(t, s) gmtime(t)
>>   #endif
>>   /*
>
> Under the theme "two wrongs don't make a right" the use of _REENTRANT
> here is totally inappropriate AFAICS. It seems to be a misguided
> attempt at determining whether we need the thread-safe gmtime_r or not
> - and the answer to that should always be yes IMHO.
>
> We define _REENTRANT for:
> - linux
> - gcc
> - xlc
>
> So the original code will define:
>
> extern "C" struct tm *gmtime_r(const time_t *, struct tm *);
>
> for linux (and AIX with xlc?) but not Solaris, OS X or Windows.
>
> But Solaris has gmtime_r anyway. So the existing code seems a really
> convoluted hack. AFAICS we have gmtime_r everywhere but Windows (where
> gmtime is already thread-safe). So it seems to me that all we should
> need here is:
>
> -#ifdef _REENTRANT // solaris
> -extern "C" struct tm *gmtime_r(const time_t *, struct tm *);
> -#else
> +#ifdef _MSC_VER // Windows
>  #define gmtime_r(t, s) gmtime(t)
>  #endif

That looks much cleaner.

Thanks,
Florian


More information about the core-libs-dev mailing list