[PATCH,i386] Don't use errno when freestanding (was: config/i386/xmmintrin.h: Only #include if __STDC_HOSTED__)

2019-08-18 Thread Gerald Pfeifer
On Sat, 9 Dec 2017, Jakub Jelinek wrote:
>> Some users on FreeBSD noticed a problem when trying to use GCC to
>> build things in a standalone environment that manifests itself as
>> 
>> /usr/local/lib/gcc/x86_64-unknown-freebsd11.0/6.3.0/include/xmmintrin.h:34 
>> from
>> /usr/local/lib/gcc/x86_64-unknown-freebsd11.0/6.3.0/include/immintrin.h:29 
>> from
>> /workspace/src/sys/crypto/aesni/intel_sha256.c:62 
>> In function '_mm_malloc':
>> /usr/local/lib/gcc/x86_64-unknown-freebsd11.0/6.3.0/include/mm_malloc.h:39: 
>> error: 'errno' undeclared (first use in this function)
>> 
>> It turns out the clang version of xmmintrin.h does not include mm_malloc.h 
>> if !__STDC_HOSTED__ whereas ours unconditionally does so.
> 
> Wouldn't it be better to just ifdef out parts of gmm_malloc.h (pmm_malloc.h
> should be ok)?

Very good point, Jakub.  Thank you!  

Somehow I thought I had submitted this updated patch, but apparently 
not so. :-(  (This has been on my autotester for ages.)

Okay?  And if so, okay for GCC 9 after a while?

Gerald


2019-08-18  Gerald Pfeifer  
 
* config/i386/gmm_malloc.h: Only include errno.h and use errno
if __STDC_HOSTED__.
 
Index: config/i386/gmm_malloc.h
===
--- config/i386/gmm_malloc.h(revision 274618)
+++ config/i386/gmm_malloc.h(working copy)
@@ -25,7 +25,9 @@
 #define _MM_MALLOC_H_INCLUDED
 
 #include 
+#if __STDC_HOSTED__
 #include 
+#endif
 
 static __inline__ void * 
 _mm_malloc (size_t __size, size_t __align)
@@ -36,7 +38,9 @@ _mm_malloc (size_t __size, size_t __align)
   /* Error if align is not a power of two.  */
   if (__align & (__align - 1))
 {
+#if __STDC_HOSTED__
   errno = EINVAL;
+#endif
   return ((void *) 0);
 }
 


Re: [PATCH,i386] Don't use errno when freestanding (was: config/i386/xmmintrin.h: Only #include if __STDC_HOSTED__)

2019-08-19 Thread Jeff Law
On 8/18/19 10:29 AM, Gerald Pfeifer wrote:
> On Sat, 9 Dec 2017, Jakub Jelinek wrote:
>>> Some users on FreeBSD noticed a problem when trying to use GCC to
>>> build things in a standalone environment that manifests itself as
>>>
>>> /usr/local/lib/gcc/x86_64-unknown-freebsd11.0/6.3.0/include/xmmintrin.h:34 
>>> from
>>> /usr/local/lib/gcc/x86_64-unknown-freebsd11.0/6.3.0/include/immintrin.h:29 
>>> from
>>> /workspace/src/sys/crypto/aesni/intel_sha256.c:62 
>>> In function '_mm_malloc':
>>> /usr/local/lib/gcc/x86_64-unknown-freebsd11.0/6.3.0/include/mm_malloc.h:39: 
>>> error: 'errno' undeclared (first use in this function)
>>>
>>> It turns out the clang version of xmmintrin.h does not include mm_malloc.h 
>>> if !__STDC_HOSTED__ whereas ours unconditionally does so.
>>
>> Wouldn't it be better to just ifdef out parts of gmm_malloc.h (pmm_malloc.h
>> should be ok)?
> 
> Very good point, Jakub.  Thank you!  
> 
> Somehow I thought I had submitted this updated patch, but apparently 
> not so. :-(  (This has been on my autotester for ages.)
> 
> Okay?  And if so, okay for GCC 9 after a while?
> 
> Gerald
> 
> 
> 2019-08-18  Gerald Pfeifer  
>  
>   * config/i386/gmm_malloc.h: Only include errno.h and use errno
>   if __STDC_HOSTED__.
OK.
jeff