Bug 12116 - AIX 6.1 declares getthrds() in <procinfo.h>
Summary: AIX 6.1 declares getthrds() in <procinfo.h>
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: build (show other bugs)
Version: 7.2
: P2 normal
Target Milestone: ---
Assignee: Joel Brobecker
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-13 13:43 UTC by Michael Haubenwallner
Modified: 2012-12-06 05:07 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2011-03-15 18:05:07


Attachments
proposed fix (1.41 KB, patch)
2011-03-15 18:05 UTC, Joel Brobecker
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Haubenwallner 2010-10-13 13:43:45 UTC
Compiling gdb-7.0.1 (with gcc) on AIX 6.1 gives this compiler error:

powerpc-ibm-aix6.1.0.0-gcc    -I. -I. -I./common -I./config -DLOCALEDIR="\"/gentoo/prefix/usr/share/locale\"" -DHAVE_CONFIG_H -I./../include/opcode -I./../readline/.. -I../bfd -I./../bfd -I./../include -I../libdecnumber -I./../libdecnumber  -I./gnulib -Ignulib  -DMI_OUT=1 -DTUI=1  -Wall -Wdeclaration-after-statement -Wpointer-arith -Wformat-nonliteral -Wno-pointer-sign -Wno-unused -Wno-switch -Wno-char-subscripts  -c -o aix-thread.o -MT aix-thread.o -MMD -MP -MF .deps/aix-thread.Tpo aix-thread.c
aix-thread.c: In function 'get_signaled_thread':
aix-thread.c:652: error: conflicting types for 'getthrds'
/usr/include/procinfo.h:921: error: previous declaration of 'getthrds' was here

This would be a simple patch for current cvs-HEAD of gdb/aix-thread.c:
+#ifndef _AIX61
  /* getthrds(3) isn't prototyped in any AIX 4.3.3 #include file.  */
  extern int getthrds (pid_t, struct thrdsinfo64 *, 
                       int, pthdb_tid_t *, int);
+#endif

This same error has been reported on the mailing list already: while reported for AIX 6.1, Harald's patch does check for _AIX51 too:
http://lists.gnu.org/archive/html/bug-gdb/2010-02/msg00009.html
However, my AIX 5.3 here (TL8, with patches up to early 2010 IIRC) still does not declare getthrds().
So it might even make sense to add a configure check for declaration of getthrds(), because I've already seen IBM backporting declarations from AIX 6.1 to AIX 5.3 (flock() as the single example).

Thank you!
Comment 1 Bruno Haible 2011-03-13 13:11:50 UTC
Still present in gdb 7.2:

On AIX 6.1:

gcc -D_ALL_SOURCE -g -O2   -I. -I. -I./common -I./config -DLOCALEDIR="\"/home/haible/prefix-aix61/share/locale\"" -DHAVE_CONFIG_H -I./../include/opcode -I./../opcodes/.. -I./../readline/.. -I../bfd -I./../bfd -I./../include -I../libdecnumber -I./../libdecnumber -I./../intl -I./gnulib -Ignulib  -DMI_OUT=1 -DTUI=1 -Wall -D_ALL_SOURCE  -Wall -Wdeclaration-after-statement -Wpointer-arith -Wformat-nonliteral -Wno-pointer-sign -Wno-unused -Wunused-value -Wunused-function -Wno-switch -Wno-char-subscripts  -c -o aix-thread.o -MT aix-thread.o -MMD -MP -MF .deps/aix-thread.Tpo aix-thread.c
aix-thread.c: In function 'get_signaled_thread':
aix-thread.c:652: error: conflicting types for 'getthrds'
/usr/include/procinfo.h:908: error: previous declaration of 'getthrds' was here
gmake[2]: *** [aix-thread.o] Error 1

And on AIX 7.1:

gcc -D_ALL_SOURCE -g -O2   -I. -I. -I./common -I./config -DLOCALEDIR="\"/home/haible/prefix-aix71/share/locale\"" -DHAVE_CONFIG_H -I./../include/opcode -I./../opcodes/.. -I./../readline/.. -I../bfd -I./../bfd -I./../include -I../libdecnumber -I./../libdecnumber -I./../intl -I./gnulib -Ignulib  -DMI_OUT=1 -DTUI=1 -Wall -D_ALL_SOURCE  -Wall -Wdeclaration-after-statement -Wpointer-arith -Wformat-nonliteral -Wno-pointer-sign -Wno-unused -Wunused-value -Wunused-function -Wno-switch -Wno-char-subscripts  -c -o aix-thread.o -MT aix-thread.o -MMD -MP -MF .deps/aix-thread.Tpo aix-thread.c
aix-thread.c: In function 'get_signaled_thread':
aix-thread.c:652: error: conflicting types for 'getthrds'
/usr/include/procinfo.h:1025: error: previous declaration of 'getthrds' was here
gmake[2]: *** [aix-thread.o] Error 1
Comment 2 Joel Brobecker 2011-03-15 18:05:07 UTC
Created attachment 5311 [details]
proposed fix
Comment 3 Joel Brobecker 2011-03-15 18:06:23 UTC
Can you please try the attached patch? It was tested on AIX 5.3 where getthrds is not defined, but I do not have access to AIX 6.x.
Comment 4 Michael Haubenwallner 2011-03-15 20:29:24 UTC
Looks good, have tried this patch with some gdb-7.0 on AIX 6.1:

checking whether ptrace is declared... yes
checking return type of ptrace... int
checking types of arguments for ptrace... int,pid_t,int *,int,int *
checking whether getthrds is declared... yes
checking whether setpgrp takes no argument... yes
checking for sigsetjmp... yes
checking for GNU regex... no

Compilation failed without but succeeded with this patch, thank you!
Comment 5 Sourceware Commits 2011-03-17 13:19:13 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	brobecke@sourceware.org	2011-03-17 13:19:10

Modified files:
	gdb            : ChangeLog aix-thread.c config.in configure 
	                 configure.ac 

Log message:
	Add 'getthrds' declaration check in configure for AIX
	
	On newer versions of AIX (6.x and later), this function is actually
	declared in procinfo.h, thus causing a compilation warning when we
	re-declare it ourselves. This patch adds a configure check for that
	function allowing us to declare the function only if the declaration
	isn't already present in one of procinfo system header.
	
	gdb/ChangeLog:
	
	PR gdb/12116:
	* configure.ac: Add getthrds declaration check.
	* configure, config.in: Regenerate.
	* aix-thread.c (getthrds): Declare only if not already declared
	in procinfo.h.  More declaration out of get_signaled_thread to
	global scope.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/ChangeLog.diff?cvsroot=src&r1=1.12825&r2=1.12826
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/aix-thread.c.diff?cvsroot=src&r1=1.75&r2=1.76
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/config.in.diff?cvsroot=src&r1=1.124&r2=1.125
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/configure.diff?cvsroot=src&r1=1.328&r2=1.329
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/configure.ac.diff?cvsroot=src&r1=1.143&r2=1.144
Comment 6 Joel Brobecker 2011-03-17 13:23:26 UTC
Fixed.
Comment 7 Perry Smith 2011-10-24 17:37:50 UTC
FYI: This is also present in the 6.4 tree.
Comment 8 Joel Brobecker 2012-12-05 11:25:48 UTC
Does anyone still have access to AIX 6.x and would be able to send me a copy of getthrds' prototype?

I suspect that GDB is declaring it wrong, and that is why GCC reported *conflicting* prototypes. On AIX 7.1, the 4rth argument is a tid_t *,
not a pthdb_tid_t *. As a result of this, I get a warning when calling
it, because we use a variable with the wrong type. Changing the prototype
to match AIX 7.1 yields no regression on 5.3, and I can't seem to be able
to find a prototype for 5.3 anywhere on the 'net.
Comment 9 Perry Smith 2012-12-05 14:53:54 UTC
The getthrds prototypes of 6.1 and 7.1 are the same (the bottom of /usr/include/procinfo.h including the comment above the prototypes about the 2nd argument.
Comment 10 Michael Haubenwallner 2012-12-05 14:56:31 UTC
(In reply to comment #8)
> On AIX 7.1, the 4rth argument is a tid_t *, not a pthdb_tid_t *.

This is true for AIX 6.1 too - and also AIX 5.3, although the declaration in procinfo.h actually is missing on AIX 5.3:

http://publib.boulder.ibm.com/infocenter/pseries/v5r3/topic/com.ibm.aix.basetechref/doc/basetrf1/getthrds.htm
http://pic.dhe.ibm.com/infocenter/aix/v6r1/topic/com.ibm.aix.basetechref/doc/basetrf1/getthrds.htm
http://pic.dhe.ibm.com/infocenter/aix/v7r1/topic/com.ibm.aix.basetechref/doc/basetrf1/getthrds.htm

The declarations itself are this ones on both 6.1 and 7.1:
extern  int     getthrds( pid_t, void *, int,  tid_t *, int );
extern  int     getthrds64( pid_t, void *, int, tid64_t *, int );

One thing to note eventually:
In procinfo.h on both AIX 6.1 and 7.1 there is a struct thrdentry64_v2 with this comment:
/*
 * thrdentry64_v2:  Increased size thrdentry64_v2 struct.  
 *
 * thrdentry64_v2 is an increased size version of thrdentry64 that contains
 * the new thread information fields.  The getthrds64() service contains 
 * support for callers passing either a thrdentry64 or a thrdentry64_v2 
 * size structure.  
 *
 * AIX 6100 TL 4 (61H) required additional getthrds64() thread information 
 * fields.  There was not enough unused space in thrdentry64 to contain the
 * additional fields. Increasing the size of thrdentry64 to contain the 
 * additional fields causes a core file compatibility problem because 
 * struct core_dumpxx in core.h includes thrdentry64.  Programs compiled 
 * with previous versions of AIX can not correctly read AIX 6100 TL 4 
 * core files.      
 */
Comment 11 Joel Brobecker 2012-12-05 15:28:41 UTC
Awesome, thank you! I will send a patch fixing the prototype in GDB.
Comment 12 Joel Brobecker 2012-12-06 05:07:15 UTC
Patch fixing declaration and use checked in:
http://www.sourceware.org/ml/gdb-patches/2012-12/msg00099.html

Thanks again.