Message ID | 55354CC3.6070103@arm.com |
---|---|
State | New |
Headers | show |
On 20/04/15 20:00, Szabolcs Nagy wrote: > The posix_memalign declaration is incompatible with musl for C++, > because of the exception specification. It also pollutes the > namespace and lacks protection against a potential macro definition > that is allowed by POSIX. The fix avoids source level namespace > pollution but retains the dependency on the posix_memalign extern > libc symbol. > > The fix is ugly, but it is not possible to correctly redeclare a > libc function in a public gcc header for C++. > ping (now with maintainers in cc) > > gcc/Changelog: > > 2015-04-16 Szabolcs Nagy <szabolcs.nagy@arm.com> > > * config/i386/pmm_malloc.h (posix_memalign): Renamed to ... > (__gcc_posix_memalign): This. Use posix_memalign as extern > symbol only. >
On Fri, May 15, 2015 at 2:34 PM, Szabolcs Nagy <szabolcs.nagy@arm.com> wrote: > On 20/04/15 20:00, Szabolcs Nagy wrote: >> The posix_memalign declaration is incompatible with musl for C++, >> because of the exception specification. It also pollutes the >> namespace and lacks protection against a potential macro definition >> that is allowed by POSIX. The fix avoids source level namespace >> pollution but retains the dependency on the posix_memalign extern >> libc symbol. >> >> The fix is ugly, but it is not possible to correctly redeclare a >> libc function in a public gcc header for C++. >> > > ping > > (now with maintainers in cc) > >> >> gcc/Changelog: >> >> 2015-04-16 Szabolcs Nagy <szabolcs.nagy@arm.com> >> >> * config/i386/pmm_malloc.h (posix_memalign): Renamed to ... >> (__gcc_posix_memalign): This. Use posix_memalign as extern >> symbol only. This changes Intel's header - adding relevant people to OK the change. Uros.
On Mon, Apr 20, 2015 at 12:00 PM, Szabolcs Nagy <szabolcs.nagy@arm.com> wrote: > The posix_memalign declaration is incompatible with musl for C++, > because of the exception specification. It also pollutes the > namespace and lacks protection against a potential macro definition > that is allowed by POSIX. The fix avoids source level namespace > pollution but retains the dependency on the posix_memalign extern > libc symbol. > > The fix is ugly, but it is not possible to correctly redeclare a > libc function in a public gcc header for C++. > > > gcc/Changelog: > > 2015-04-16 Szabolcs Nagy <szabolcs.nagy@arm.com> > > * config/i386/pmm_malloc.h (posix_memalign): Renamed to ... > (__gcc_posix_memalign): This. Use posix_memalign as extern > symbol only. What does this try to achieve? Do you have a testcase which fails before and passes with this patch?
On 15/05/15 16:05, H.J. Lu wrote: > On Mon, Apr 20, 2015 at 12:00 PM, Szabolcs Nagy <szabolcs.nagy@arm.com> wrote: >> The posix_memalign declaration is incompatible with musl for C++, >> because of the exception specification. It also pollutes the >> namespace and lacks protection against a potential macro definition >> that is allowed by POSIX. The fix avoids source level namespace >> pollution but retains the dependency on the posix_memalign extern >> libc symbol. >> >> The fix is ugly, but it is not possible to correctly redeclare a >> libc function in a public gcc header for C++. >> >> >> gcc/Changelog: >> >> 2015-04-16 Szabolcs Nagy <szabolcs.nagy@arm.com> >> >> * config/i386/pmm_malloc.h (posix_memalign): Renamed to ... >> (__gcc_posix_memalign): This. Use posix_memalign as extern >> symbol only. > > What does this try to achieve? Do you have a testcase which > fails before and passes with this patch? if posix_memalign is defined in stdlib.h according to posix then the exception specifier used in mm_malloc.h is incompatible: $ echo "#include <mm_malloc.h>" | ./x86_64-linux-musl-g++ -pedantic -c -xc++ -D_POSIX_C_SOURCE=200809L - In file included from <stdin>:1:0: /data/cross/x86_64-linux-musl/lib/gcc/x86_64-linux-musl/6.0.0/include/mm_malloc.h:34:64: error: declaration of 'int posix_memalign(void**, size_t, size_t) throw ()' has a different exception specifier extern "C" int posix_memalign (void **, size_t, size_t) throw () ^ In file included from /data/cross/x86_64-linux-musl/lib/gcc/x86_64-linux-musl/6.0.0/include/mm_malloc.h:27:0, from <stdin>:1: /data/cross/x86_64-linux-musl/x86_64-linux-musl/include/stdlib.h:98:5: error: from previous declaration 'int posix_memalign(void**, size_t, size_t)' int posix_memalign (void **, size_t, size_t); ^ however it seems without -pedantic there is no error anymore, the code is accepted even in standard conforming mode. (it used to be an error that could not be silenced). this means the patch is no longer critical for musl support.
On Fri, May 15, 2015 at 9:09 AM, Szabolcs Nagy <szabolcs.nagy@arm.com> wrote: > > > On 15/05/15 16:05, H.J. Lu wrote: >> On Mon, Apr 20, 2015 at 12:00 PM, Szabolcs Nagy <szabolcs.nagy@arm.com> wrote: >>> The posix_memalign declaration is incompatible with musl for C++, >>> because of the exception specification. It also pollutes the >>> namespace and lacks protection against a potential macro definition >>> that is allowed by POSIX. The fix avoids source level namespace >>> pollution but retains the dependency on the posix_memalign extern >>> libc symbol. >>> >>> The fix is ugly, but it is not possible to correctly redeclare a >>> libc function in a public gcc header for C++. >>> >>> >>> gcc/Changelog: >>> >>> 2015-04-16 Szabolcs Nagy <szabolcs.nagy@arm.com> >>> >>> * config/i386/pmm_malloc.h (posix_memalign): Renamed to ... >>> (__gcc_posix_memalign): This. Use posix_memalign as extern >>> symbol only. >> >> What does this try to achieve? Do you have a testcase which >> fails before and passes with this patch? > > if posix_memalign is defined in stdlib.h according to posix then > the exception specifier used in mm_malloc.h is incompatible: > > $ echo "#include <mm_malloc.h>" | ./x86_64-linux-musl-g++ -pedantic -c -xc++ -D_POSIX_C_SOURCE=200809L - > In file included from <stdin>:1:0: > /data/cross/x86_64-linux-musl/lib/gcc/x86_64-linux-musl/6.0.0/include/mm_malloc.h:34:64: error: declaration of 'int posix_memalign(void**, size_t, > size_t) throw ()' has a different exception specifier > extern "C" int posix_memalign (void **, size_t, size_t) throw () > ^ > In file included from /data/cross/x86_64-linux-musl/lib/gcc/x86_64-linux-musl/6.0.0/include/mm_malloc.h:27:0, > from <stdin>:1: > /data/cross/x86_64-linux-musl/x86_64-linux-musl/include/stdlib.h:98:5: error: from previous declaration 'int posix_memalign(void**, size_t, size_t)' > int posix_memalign (void **, size_t, size_t); > ^ > > however it seems without -pedantic there is no error anymore, > the code is accepted even in standard conforming mode. > (it used to be an error that could not be silenced). > > this means the patch is no longer critical for musl support. > 2 more comments: 1. You need a tecase, independent of MUSL. 2. Please replace __gcc_posix_memalign with _mm_posix_memalign.
diff --git a/gcc/config/i386/pmm_malloc.h b/gcc/config/i386/pmm_malloc.h index 901001b..321fcd3 100644 --- a/gcc/config/i386/pmm_malloc.h +++ b/gcc/config/i386/pmm_malloc.h @@ -27,12 +27,13 @@ #include <stdlib.h> /* We can't depend on <stdlib.h> since the prototype of posix_memalign - may not be visible. */ + may not be visible and we can't pollute the namespace either. */ #ifndef __cplusplus -extern int posix_memalign (void **, size_t, size_t); +extern int __gcc_posix_memalign (void **, size_t, size_t) #else -extern "C" int posix_memalign (void **, size_t, size_t) throw (); +extern "C" int __gcc_posix_memalign (void **, size_t, size_t) throw () #endif +__asm__("posix_memalign"); static __inline void * _mm_malloc (size_t size, size_t alignment) @@ -42,7 +43,7 @@ _mm_malloc (size_t size, size_t alignment) return malloc (size); if (alignment == 2 || (sizeof (void *) == 8 && alignment == 4)) alignment = sizeof (void *); - if (posix_memalign (&ptr, alignment, size) == 0) + if (__gcc_posix_memalign (&ptr, alignment, size) == 0) return ptr; else return NULL;