This is the mail archive of the
libffi-discuss@sourceware.org
mailing list for the libffi project.
Re: [PATCH] HPUX: fix dlmalloc build
Hello,
A bit more explanation which I meant to add:
The starting point is that 'gmake src/dlmalloc.c' fails to compile on
HP-UX, in my case it's v11.31 ia64.
It fails because of re-declaration of 'struct mallinfo', both defined in
dlmalloc.c and in /usr/include/stdlib.h:
=========================
bash-4.0# gmake src/dlmalloc.o
gcc -DHAVE_CONFIG_H -I. -I. -I./include -Iinclude -I./src -Wall -g
-fexceptions -O2 -MT src/dlmalloc.o -MD -MP -MF $depbase.Tpo -c -o
src/dlmalloc.o src/dlmalloc.c
In file included from src/dlmalloc.c:1164:
/usr/local/lib/gcc/ia64-hp-hpux11.31/4.2.3/include/stdlib.h:579: error:
redefinition of 'struct mallinfo'
gmake: *** [src/dlmalloc.o] Error 1
=========================
Now, there are two approaches to resolve this:
1. Take struct definition from /usr/include/stdlib.h: by defining
HAVE_USR_INCLUDE_MALLOC_H in src/dlmalloc.c (there's actually a detailed
comment which explains that in the file)
2. Take struct definition from dlmalloc.c: this needs defining
_STRUCT_MALLINFO to avoid re-definition. HP-UX, unlike many other OSes,
defines 'struct mallinfo' in its /usr/include/stdlib.h, if a special
constant named _STRUCT_MALLINFO is not defined.
My goal was to handle this automatically.
I can think of three options, but not sure what's the smartest way:
1. If we prefer the OS native mallinfo declaration: have autoconf add
#define HAVE_USR_INCLUDE_MALLOC_H if it's an HP that has 'struct
malloc' in its /usr/include/stdlib.h
2. If we prefer the libffi (dlmalloc.c) mallinfo decleration:
2.a. Simply add #define _STRUCT_MALLINFO inside dlmalloc.c, in the block
that declares the mallinfo struct. There's a very low risk that this
constant would affect other OSes badly and cause the problem.
2.b. Do the above only for HPUX - probably needs an autoconf change.
The previously attached patch is the #2.a. solution. I'm not familiar
with autoconf, and I'm not very sure which 'struct mallinfo'
impementation to prefer, thus I didn't implement solution #1 or #2.b.
Regards
Oren
On 12/30/2010 01:04 PM, Oren Held wrote:
> Prevent redefinition of struct mallinfo in HPUX.
> HPUX' /usr/include/stdlib.h redefines this struct, unless _STRUCT_MALLINFO is
> defined.
> ---
> src/dlmalloc.c | 3 +++
> 1 files changed, 3 insertions(+), 0 deletions(-)
>
> diff --git a/src/dlmalloc.c b/src/dlmalloc.c
> index 0fa235a..5c9f9c2 100644
> --- a/src/dlmalloc.c
> +++ b/src/dlmalloc.c
> @@ -622,6 +622,9 @@ DEFAULT_MMAP_THRESHOLD default: 256K
> #include "/usr/include/malloc.h"
> #else /* HAVE_USR_INCLUDE_MALLOC_H */
>
> +/* HP-UX's stdlib.h redefines mallinfo unless _STRUCT_MALLINFO is defined */
> +#define _STRUCT_MALLINFO
> +
> struct mallinfo {
> MALLINFO_FIELD_TYPE arena; /* non-mmapped space allocated from system */
> MALLINFO_FIELD_TYPE ordblks; /* number of free chunks */
>