public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH,FIXINCLUDES] AIX stdlib.h #define malloc
@ 2016-06-09 17:25 David Edelsohn
  2016-06-09 17:29 ` Jeff Law
  2016-06-12 21:04 ` Bruce Korb
  0 siblings, 2 replies; 5+ messages in thread
From: David Edelsohn @ 2016-06-09 17:25 UTC (permalink / raw)
  To: GCC Patches, Bruce Korb

AIX has added variants of malloc, realloc, calloc and valloc with
greater compatibility with Linux semantics, especially for NULL
addresses.  The variants are declared in stdlib.h and use #define to
override the normal definition if _LINUX_SOURCE_COMPAT is defined,
e.g.,

#define malloc __linux_malloc
#define calloc __linux_calloc
#define realloc __linux_realloc
#define valloc __linux_valloc

libstdc++-v3 cstdlib specifically undefines a number of stdlib.h macros, e.g.,

// Get rid of those macros defined in <stdlib.h> in lieu of real functions.
...
#undef malloc
#undef realloc

C++ applications on AIX, especially users of BOOST that include
cstdlib, encounter unexpected behavior when the definition of malloc
changes from the expected / requested version.

The following patch updates fixincludes to correct the AIX stdlib.h
header by converting the #define to GCC asm aliases.  I created a
separate fix for each definition because the order is not guaranteed.

Bootstrapped on powerpc-ibm-aix7.1.0.0.  This fixes a recent node.js
build failure on AIX due to additional dependence on BOOST.

Okay for trunk, GCC 6 and GCC 5?

Thanks, David

* inclhack.def (aix_stdlib_malloc): New fix.
(aix_stdlib_realloc): New fix.
(aix_stdlib_calloc): New fix.
(aix_stdlib_valloc): New fix.
* fixincl.x: Regenerate.
* test/base/stdlib.h [AIX_STDLIB_MALLOC]: New test.
[AIX_STDLIB_REALLOC]: New test.
[AIX_STDLIB_CALLOC]: New test.
[AIX_STDLIB_VALLOC]: New test.

Index: inclhack.def
===================================================================
--- inclhack.def        (revision 237258)
+++ inclhack.def        (working copy)
@@ -911,7 +911,49 @@
     test_text = "#ifdef __cplusplus\n}\n\n#ifdef ferror";
 };

+/*
+ * stdlib.h on AIX uses #define on malloc and friends.
+ */
+fix = {
+    hackname  = aix_stdlib_malloc;
+    mach      = "*-*-aix*";
+    files     = stdlib.h;
+    select    = "#define[ \t]+malloc[ \t]+__linux_malloc";
+    c_fix     = format;
+    c_fix_arg = "extern void malloc(size_t) __asm__(\"__linux_malloc\");";
+    test_text = "#define malloc __linux_malloc";
+};

+fix = {
+    hackname  = aix_stdlib_realloc;
+    mach      = "*-*-aix*";
+    files     = stdlib.h;
+    select    = "#define[ \t]+realloc[ \t]+__linux_realloc";
+    c_fix     = format;
+    c_fix_arg = "extern void realloc(void *, size_t)
__asm__(\"__linux_realloc\");";
+    test_text = "#define realloc __linux_realloc";
+};
+
+fix = {
+    hackname  = aix_stdlib_calloc;
+    mach      = "*-*-aix*";
+    files     = stdlib.h;
+    select    = "#define[ \t]+calloc[ \t]+__linux_calloc";
+    c_fix     = format;
+    c_fix_arg = "extern void calloc(size_t, size_t)
__asm__(\"__linux_calloc\");";
+    test_text = "#define calloc __linux_calloc";
+};
+
+fix = {
+    hackname  = aix_stdlib_valloc;
+    mach      = "*-*-aix*";
+    files     = stdlib.h;
+    select    = "#define[ \t]+valloc[ \t]+__linux_valloc";
+    c_fix     = format;
+    c_fix_arg = "extern void valloc(size_t) __asm__(\"__linux_valloc\");";
+    test_text = "#define valloc __linux_valloc";
+};
+
 /*
  * stdlib.h on AIX 4.3 declares strtof() with a non-const first argument.
  */

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH,FIXINCLUDES] AIX stdlib.h #define malloc
  2016-06-09 17:25 [PATCH,FIXINCLUDES] AIX stdlib.h #define malloc David Edelsohn
@ 2016-06-09 17:29 ` Jeff Law
       [not found]   ` <CAKRnqN+kq4LEqtSFdcXQOh0XH-SN1L7sXXnjM05YCAt3v9-iFA@mail.gmail.com>
  2016-06-12 21:04 ` Bruce Korb
  1 sibling, 1 reply; 5+ messages in thread
From: Jeff Law @ 2016-06-09 17:29 UTC (permalink / raw)
  To: David Edelsohn, GCC Patches, Bruce Korb

On 06/09/2016 11:25 AM, David Edelsohn wrote:
> AIX has added variants of malloc, realloc, calloc and valloc with
> greater compatibility with Linux semantics, especially for NULL
> addresses.  The variants are declared in stdlib.h and use #define to
> override the normal definition if _LINUX_SOURCE_COMPAT is defined,
> e.g.,
>
> #define malloc __linux_malloc
> #define calloc __linux_calloc
> #define realloc __linux_realloc
> #define valloc __linux_valloc
>
> libstdc++-v3 cstdlib specifically undefines a number of stdlib.h macros, e.g.,
>
> // Get rid of those macros defined in <stdlib.h> in lieu of real functions.
> ...
> #undef malloc
> #undef realloc
>
> C++ applications on AIX, especially users of BOOST that include
> cstdlib, encounter unexpected behavior when the definition of malloc
> changes from the expected / requested version.
>
> The following patch updates fixincludes to correct the AIX stdlib.h
> header by converting the #define to GCC asm aliases.  I created a
> separate fix for each definition because the order is not guaranteed.
>
> Bootstrapped on powerpc-ibm-aix7.1.0.0.  This fixes a recent node.js
> build failure on AIX due to additional dependence on BOOST.
>
> Okay for trunk, GCC 6 and GCC 5?
>
> Thanks, David
>
> * inclhack.def (aix_stdlib_malloc): New fix.
> (aix_stdlib_realloc): New fix.
> (aix_stdlib_calloc): New fix.
> (aix_stdlib_valloc): New fix.
> * fixincl.x: Regenerate.
> * test/base/stdlib.h [AIX_STDLIB_MALLOC]: New test.
> [AIX_STDLIB_REALLOC]: New test.
> [AIX_STDLIB_CALLOC]: New test.
> [AIX_STDLIB_VALLOC]: New test.
Wow, fixincludes....    I'm not even sure if Bruce is around anymore...

GIven these are conditional on mach= *-*-aix*, I think you can 
self-approve them.

jeff

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH,FIXINCLUDES] AIX stdlib.h #define malloc
       [not found]   ` <CAKRnqN+kq4LEqtSFdcXQOh0XH-SN1L7sXXnjM05YCAt3v9-iFA@mail.gmail.com>
@ 2016-06-09 17:49     ` David Edelsohn
       [not found]       ` <CAKRnqNKZd_rA8JuPaQ9W-FOCvi88aWKru4WiWwi8X_-yE67SNw@mail.gmail.com>
  0 siblings, 1 reply; 5+ messages in thread
From: David Edelsohn @ 2016-06-09 17:49 UTC (permalink / raw)
  To: Bruce Korb; +Cc: Jeff Law, GCC Patches

Hi, Bruce!

I thought about a regex, but the aliases require a full function
signature and the original, narrow context does not provide a function
signature.  If it was just alias XXXalloc as __linux_XXXalloc, it
would be more straight forward.  If there's a convenient way to add
the other information, I'm eager to learn.

Thanks, David

On Thu, Jun 9, 2016 at 1:44 PM, Bruce Korb <bkorb@gnu.org> wrote:
> He's retired, but he ain't dead.
> I think these could be accomplished with a single fix.
> Please try a regex expression in the selection and utilize the selection in
> the replacement.
> I'll look at it when I have time (give me a few days)
>
> On Thu, Jun 9, 2016 at 10:29 AM, Jeff Law <law@redhat.com> wrote:
>>
>> On 06/09/2016 11:25 AM, David Edelsohn wrote:
>>>
>>> AIX has added variants of malloc, realloc, calloc and valloc with
>>> greater compatibility with Linux semantics, especially for NULL
>>> addresses.  The variants are declared in stdlib.h and use #define to
>>> override the normal definition if _LINUX_SOURCE_COMPAT is defined,
>>> e.g.,
>>>
>>> #define malloc __linux_malloc
>>> #define calloc __linux_calloc
>>> #define realloc __linux_realloc
>>> #define valloc __linux_valloc
>>>
>>> libstdc++-v3 cstdlib specifically undefines a number of stdlib.h macros,
>>> e.g.,
>>>
>>> // Get rid of those macros defined in <stdlib.h> in lieu of real
>>> functions.
>>> ...
>>> #undef malloc
>>> #undef realloc
>>>
>>> C++ applications on AIX, especially users of BOOST that include
>>> cstdlib, encounter unexpected behavior when the definition of malloc
>>> changes from the expected / requested version.
>>>
>>> The following patch updates fixincludes to correct the AIX stdlib.h
>>> header by converting the #define to GCC asm aliases.  I created a
>>> separate fix for each definition because the order is not guaranteed.
>>>
>>> Bootstrapped on powerpc-ibm-aix7.1.0.0.  This fixes a recent node.js
>>> build failure on AIX due to additional dependence on BOOST.
>>>
>>> Okay for trunk, GCC 6 and GCC 5?
>>>
>>> Thanks, David
>>>
>>> * inclhack.def (aix_stdlib_malloc): New fix.
>>> (aix_stdlib_realloc): New fix.
>>> (aix_stdlib_calloc): New fix.
>>> (aix_stdlib_valloc): New fix.
>>> * fixincl.x: Regenerate.
>>> * test/base/stdlib.h [AIX_STDLIB_MALLOC]: New test.
>>> [AIX_STDLIB_REALLOC]: New test.
>>> [AIX_STDLIB_CALLOC]: New test.
>>> [AIX_STDLIB_VALLOC]: New test.
>>
>> Wow, fixincludes....    I'm not even sure if Bruce is around anymore...
>>
>> GIven these are conditional on mach= *-*-aix*, I think you can
>> self-approve them.
>>
>> jeff
>>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH,FIXINCLUDES] AIX stdlib.h #define malloc
       [not found]       ` <CAKRnqNKZd_rA8JuPaQ9W-FOCvi88aWKru4WiWwi8X_-yE67SNw@mail.gmail.com>
@ 2016-06-09 22:21         ` David Edelsohn
  0 siblings, 0 replies; 5+ messages in thread
From: David Edelsohn @ 2016-06-09 22:21 UTC (permalink / raw)
  To: Bruce Korb; +Cc: Jeff Law, GCC Patches

Bruce,

The current AIX stdlib.h header file uses #define.  This is exactly
what I am trying to remove with the fixincludes patch.

#define malloc __linux_malloc

needs to be replaced with

extern void *malloc(size_t) __asm__("__linux_malloc");

and so forth.

Thanks, David

On Thu, Jun 9, 2016 at 5:18 PM, Bruce Korb <bkorb@gnu.org> wrote:
> It ought to work:
>
> $ for f in m re c v ; do printf '#define %salloc __linux_%salloc\n' $f $f
>> done > foo.h
> $ grep -E '[ \t](m|re|c|v)alloc +__linux_\1alloc' foo.h
> #define malloc __linux_malloc
> #define realloc __linux_realloc
> #define calloc __linux_calloc
> #define valloc __linux_valloc
>
> and your "%1" is then "m" or "re" or "c" or "v".
> I can't test right now tho.
>
> On Thu, Jun 9, 2016 at 10:49 AM, David Edelsohn <dje.gcc@gmail.com> wrote:
>>
>> Hi, Bruce!
>>
>> I thought about a regex, but the aliases require a full function
>> signature and the original, narrow context does not provide a function
>> signature.  If it was just alias XXXalloc as __linux_XXXalloc, it
>> would be more straight forward.  If there's a convenient way to add
>> the other information, I'm eager to learn.
>>
>> Thanks, David
>>
>> On Thu, Jun 9, 2016 at 1:44 PM, Bruce Korb <bkorb@gnu.org> wrote:
>> > He's retired, but he ain't dead.
>> > I think these could be accomplished with a single fix.
>> > Please try a regex expression in the selection and utilize the selection
>> > in
>> > the replacement.
>> > I'll look at it when I have time (give me a few days)
>> >
>> > On Thu, Jun 9, 2016 at 10:29 AM, Jeff Law <law@redhat.com> wrote:
>> >>
>> >> On 06/09/2016 11:25 AM, David Edelsohn wrote:
>> >>>
>> >>> AIX has added variants of malloc, realloc, calloc and valloc with
>> >>> greater compatibility with Linux semantics, especially for NULL
>> >>> addresses.  The variants are declared in stdlib.h and use #define to
>> >>> override the normal definition if _LINUX_SOURCE_COMPAT is defined,
>> >>> e.g.,
>> >>>
>> >>> #define malloc __linux_malloc
>> >>> #define calloc __linux_calloc
>> >>> #define realloc __linux_realloc
>> >>> #define valloc __linux_valloc
>> >>>
>> >>> libstdc++-v3 cstdlib specifically undefines a number of stdlib.h
>> >>> macros,
>> >>> e.g.,
>> >>>
>> >>> // Get rid of those macros defined in <stdlib.h> in lieu of real
>> >>> functions.
>> >>> ...
>> >>> #undef malloc
>> >>> #undef realloc
>> >>>
>> >>> C++ applications on AIX, especially users of BOOST that include
>> >>> cstdlib, encounter unexpected behavior when the definition of malloc
>> >>> changes from the expected / requested version.
>> >>>
>> >>> The following patch updates fixincludes to correct the AIX stdlib.h
>> >>> header by converting the #define to GCC asm aliases.  I created a
>> >>> separate fix for each definition because the order is not guaranteed.
>> >>>
>> >>> Bootstrapped on powerpc-ibm-aix7.1.0.0.  This fixes a recent node.js
>> >>> build failure on AIX due to additional dependence on BOOST.
>> >>>
>> >>> Okay for trunk, GCC 6 and GCC 5?
>> >>>
>> >>> Thanks, David
>> >>>
>> >>> * inclhack.def (aix_stdlib_malloc): New fix.
>> >>> (aix_stdlib_realloc): New fix.
>> >>> (aix_stdlib_calloc): New fix.
>> >>> (aix_stdlib_valloc): New fix.
>> >>> * fixincl.x: Regenerate.
>> >>> * test/base/stdlib.h [AIX_STDLIB_MALLOC]: New test.
>> >>> [AIX_STDLIB_REALLOC]: New test.
>> >>> [AIX_STDLIB_CALLOC]: New test.
>> >>> [AIX_STDLIB_VALLOC]: New test.
>> >>
>> >> Wow, fixincludes....    I'm not even sure if Bruce is around anymore...
>> >>
>> >> GIven these are conditional on mach= *-*-aix*, I think you can
>> >> self-approve them.
>> >>
>> >> jeff
>> >>
>> >
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH,FIXINCLUDES] AIX stdlib.h #define malloc
  2016-06-09 17:25 [PATCH,FIXINCLUDES] AIX stdlib.h #define malloc David Edelsohn
  2016-06-09 17:29 ` Jeff Law
@ 2016-06-12 21:04 ` Bruce Korb
  1 sibling, 0 replies; 5+ messages in thread
From: Bruce Korb @ 2016-06-12 21:04 UTC (permalink / raw)
  To: David Edelsohn; +Cc: GCC Patches

BTW, OK by me :)  Now that I'm retired, it is starting to look like
less time for this stuff... ;)

On Thu, Jun 9, 2016 at 10:25 AM, David Edelsohn <dje.gcc@gmail.com> wrote:

> Index: inclhack.def
> ===================================================================
> --- inclhack.def        (revision 237258)
> +++ inclhack.def        (working copy)

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-06-12 21:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-09 17:25 [PATCH,FIXINCLUDES] AIX stdlib.h #define malloc David Edelsohn
2016-06-09 17:29 ` Jeff Law
     [not found]   ` <CAKRnqN+kq4LEqtSFdcXQOh0XH-SN1L7sXXnjM05YCAt3v9-iFA@mail.gmail.com>
2016-06-09 17:49     ` David Edelsohn
     [not found]       ` <CAKRnqNKZd_rA8JuPaQ9W-FOCvi88aWKru4WiWwi8X_-yE67SNw@mail.gmail.com>
2016-06-09 22:21         ` David Edelsohn
2016-06-12 21:04 ` Bruce Korb

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).