diff mbox

Fix conflicting posix_memalign declaration error

Message ID CABtf2+Ruin4Z2B82PGQhUwBUvX_AohvP_KD7Z2u2A2ejHZyOig@mail.gmail.com
State New
Headers show

Commit Message

Caroline Tice Oct. 27, 2016, 8:47 p.m. UTC
The posix_memalign declaration in gcc/i386/config/pmm_malloc.h is
decorated with 'throw ()', which occasionally causes declaration
conflict errors (some header files, not part of GCC, that declare
posix_memalign, do not have the throw decoration).  An example of this
can be seen at https://github.com/android-ndk/ndk/issues/91.  It
appears that the 'throw()' decoration comes from glibc header files.
Adding ifdefs to check for __GLIBC__ before adding the 'throw()' fixed
the github problem mentioned above.

I have tested this patch by bootstrapping and by running test
testsuite with no regressions.

Is this ok to commit?

-- Caroline Tice
ctice42@gmail.com


gcc/ChangeLog:

2016-10-27  Caroline Tice  <cmtice@google.com>

        * config/i386/pmm_malloc.h (posix_memalign):  Add ifdefs to only
        decorate the declaration with 'throw()' if __GLIBC__ is defined.

Comments

Bernd Schmidt Oct. 28, 2016, 10:38 a.m. UTC | #1
On 10/27/2016 10:47 PM, Caroline Tice wrote:
>

>         * config/i386/pmm_malloc.h (posix_memalign):  Add ifdefs to only

>         decorate the declaration with 'throw()' if __GLIBC__ is defined.


I seem to recall a similar patch being submitted by Szabolcs. My 
suggestion at the time was to move _mm_malloc into libgcc so that it 
could just include the right header.


Bernd
Szabolcs Nagy Oct. 28, 2016, 10:51 a.m. UTC | #2
On 28/10/16 11:38, Bernd Schmidt wrote:
> On 10/27/2016 10:47 PM, Caroline Tice wrote:

>>

>>         * config/i386/pmm_malloc.h (posix_memalign):  Add ifdefs to only

>>         decorate the declaration with 'throw()' if __GLIBC__ is defined.

> 

> I seem to recall a similar patch being submitted by Szabolcs. My suggestion at the time was to move _mm_malloc

> into libgcc so that it could just include the right header.

> 


i stopped working on that patch because it seems
gcc-6 does not care about inconsistent exception
specification in this particular case any more
(even in strict standard conform mode) and thus
i could not provide a test case along the patch
which H.J.Lu asked for.

(i also think that hardwiring libc specific
knowledge here is wrong: glibc might change its
declaration, c++ code should not try to redeclare
standard c interfaces, which is just another
regression in the c++ language compared to c.)
diff mbox

Patch

Index: gcc/config/i386/pmm_malloc.h
===================================================================
--- gcc/config/i386/pmm_malloc.h	(revision 241483)
+++ gcc/config/i386/pmm_malloc.h	(working copy)
@@ -31,8 +31,12 @@ 
 #ifndef __cplusplus
 extern int posix_memalign (void **, size_t, size_t);
 #else
+#ifdef __GLIBC__
 extern "C" int posix_memalign (void **, size_t, size_t) throw ();
+#else
+extern "C" int posix_memalign (void **, size_t, size_t);
 #endif
+#endif
 
 static __inline void *
 _mm_malloc (size_t __size, size_t __alignment)