diff mbox

Fix gdb 7.12 C++ compilation on Solaris

Message ID yddk2d5yf2v.fsf@CeBiTec.Uni-Bielefeld.DE
State New
Headers show

Commit Message

Rainer Orth Oct. 18, 2016, 1:14 p.m. UTC
Hi Pedro,

> On 10/14/2016 03:45 PM, Rainer Orth wrote:

>> gdb 7.12 doesn't compile as C++ (tried with g++ 4.9) on Solaris (tried

>> 10 and 12, sparc and x86).  The following patch (relative to the 7.12

>> release, though I expect most if not all issues to be present on trunk,

>> too) fixes this.

>> 

>> Only a few of the changes bear explanation:

>> 

>> * Initially, compilation failed whereever defs.h. was included:

>> 

>> In file included from /vol/src/gnu/gdb/gdb-7.12/gdb/gdb.c:19:0:

>> /vol/src/gnu/gdb/gdb-7.12/gdb/defs.h:630:33: error: 'double atof(const char*)' conflicts with a previous declaration

>>  extern double atof (const char *); /* X3.159-1989  4.10.1.1 */

>>                                  ^

>> In file included from /usr/include/stdlib.h:17:0,

>>                  from build-gnulib/import/stdlib.h:36,

>>                  from /vol/src/gnu/gdb/gdb-7.12/gdb/common/common-defs.h:32,

>>                  from /vol/src/gnu/gdb/gdb-7.12/gdb/defs.h:28,

>>                  from /vol/src/gnu/gdb/gdb-7.12/gdb/gdb.c:19:

>> /vol/gcc-4.9/lib/gcc/i386-pc-solaris2.10/4.9.0/include-fixed/iso/stdlib_iso.h:119:15: note: previous declaration 'double std::atof(const char*)'

>>  extern double atof(const char *);

>>                ^

>> 

>>   This is due to this gem in gdb/defs.h which seems to have been present

>>   like forever:

>> 

>> #ifndef atof

>> extern double atof (const char *);	/* X3.159-1989  4.10.1.1 */

>> #endif

>> 

>>   In the Solaris headers, the appropriate functions are in namespace std,

>>   thus the conflict.  I've wrapped the defs.h declaration in !__cplusplus

>>   to avoid this; perhaps it can go completely instead.

>

> master dropped support for building with a C compiler, it's C++-only.

> So for master, just delete the thing.

>

> On both branches, please delete the whole comment above as well:

>

>  /* Global functions from other, non-gdb GNU thingies.

>     Libiberty thingies are no longer declared here.  We include libiberty.h

>     above, instead.  */

>

>  /* From other system libraries */

>

> as it no longer makes any sense afterwards.


done in the attached revised patch.

>> * All the casts are necessary to appease g++ and should be pretty

>>   obvious.

>> 

>> * The sol-thread.c changes are here to handle

>> 

>> /vol/src/gnu/gdb/gdb-7.12/gdb/sol-thread.c: In function 'void _initialize_sol_thread()':

>> /vol/src/gnu/gdb/gdb-7.12/gdb/sol-thread.c:1252:36: error: invalid conversion from 'void*' to 'void (*)(int)' [-fpermissive]

>>    if (!(p_##X = dlsym (dlhandle, #X))) \

>>                                     ^

>> /vol/src/gnu/gdb/gdb-7.12/gdb/sol-thread.c:1255:3: note: in expansion of macro 'resolve'

>>    resolve (td_log);

>>    ^

>> 

>>   and are modeled after linux-thread-db.c (try_thread_db_load_1).

>> 

>> The patch allowed both 32 and 64-bit C++ builds on sparc-sun-solaris2.10

>> and i386-pc-solaris2.10 to complete.  The resulting binary hasn't seen

>> more than a smoke test (invoke it on itself, b main, run) yet.

>> 

>> Ok for mainline and 7.12 branch?

>

> Yes, with the tweak above on master.  But, the process for getting


Thanks.  When investigating the failure to detect -static-libstdc++
support (more below), I found two more issues which only show up with
-Werror:

/vol/src/gnu/gdb/gdb/local/gdb/procfs.c: In function 'ssd* proc_get_LDT_entry(procinfo*, int)':
/vol/src/gnu/gdb/gdb/local/gdb/procfs.c:2487:19: error: variable 'old_chain' set but not used [-Werror=unused-but-set-variable]
   struct cleanup *old_chain = NULL;
                   ^

Unless I'm mistaken, you need to run do_cleanups on every return from
the function.

Afterwards, I ran a 32-bit compilation, which (after adding
--disable-largefile to avoid

In file included from /usr/include/sys/procfs.h:28:0,
                 from /vol/src/gnu/gdb/gdb/local/gdb/i386-sol2-nat.c:23:
/usr/include/sys/old_procfs.h:39:2: error: #error "Cannot use procfs in the large file compilation environment"
 #error "Cannot use procfs in the large file compilation environment"
  ^

and two more instances) revealed

/vol/src/gnu/gdb/gdb/local/gdb/top.c: In function 'void gdb_safe_append_history()':
/vol/src/gnu/gdb/gdb/local/gdb/top.c:1170:59: error: format '%d' expects argument of type 'int', but argument 3 has type 'pid_t {aka long int}' [-Werror=format=]
     = xstrprintf ("%s-gdb%d~", history_filename, getpid ());
                                                           ^

Fixed by casting pid_t to long and printing it as such.

Still ok for mainline?

> fixes into the branch involves filing a PR.  The reason is that the

> PR's subject is later used to help create the release announcement

> (manually).  So please file a bug ("gdb 7.12 doesn't build on Solaris"

> or some such, and paste an example build error log).


Done now (PR build/20712).

>> Besides, when I compiled with g++ 4.9 installed into a non-default

>> location, gdb wouldn't run initially since libstdc++.so.6 and

>> libgcc_s.so.1 weren't found.  Maybe it would be good to handle this as

>> gcc does and just link with -static-libstdc++ -static-libgcc?

>

> That's already included in the link line for me on GNU/Linux.

> Maybe it's host-specific?  I've wondered before about why don't

> we use rpath instead though.


This turned out to be (sort of) pilot error: since I'd started with
building a 64-bit gdb with a 32-bit-default gcc, I had to configure with
CFLAGS='-g -O2 -m64' and now added CXXFLAGS='$(CFLAGS)'.  However, this
didn't work as intended, but passed a literal "$(CFLAGS)" to C++
compilations, breaking/confusing several configure tests like the one
for -static-libstdc++ or the -Werror one.  Once I duplicated the
necessary options in CXXFLAGS, everything went fine and libstdc++ was
linked statically as expected.

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University


2016-10-14  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	* defs.h: Remove obsolete comment
	(atof): Remove.
	* procfs.c (do_destroy_procinfo_cleanup): Add cast.
	(sysset_t_alloc): Likewise.
	(proc_set_traced_sysentry): Likewise.
	(proc_set_traced_sysexit): Likewise.
	[!PIOCLSTATUS && NEW_PROC_API] (do_closedir_cleanup): Likewise.
	(proc_get_LDT_entry): Initiate cleanups before returns.
	(procfs_wait): Use GDB_SIGNAL_0.
	(procfs_corefile_thread_callback): Add cast.
	* sol-thread.c (td_log_ftype, td_ta_new_ftype, td_ta_delete_ftype)
	(td_init_ftype, td_ta_get_ph_ftype, td_ta_get_nthreads_ftype)
	(td_ta_tsd_iter_ftype, td_ta_thr_iter_ftype)
	(td_thr_validate_ftype, td_thr_tsd_ftype, td_thr_get_info_ftype)
	(td_thr_getfpregs_ftype, td_thr_getxregsize_ftype)
	(td_thr_getxregs_ftype, td_thr_sigsetmask_ftype)
	(td_thr_setprio_ftype, td_thr_setsigpending_ftype)
	(td_thr_setfpregs_ftype, td_thr_setxregs_ftype)
	(td_ta_map_id2thr_ftype, td_ta_map_lwp2thr_ftype)
	(td_thr_getgregs_ftype, td_thr_setgregs_ftype): New typedefs.
	(p_td_log, p_td_ta_new, p_td_ta_delete, p_td_init, p_td_ta_get_ph)
	(p_td_ta_get_nthreads, p_td_ta_tsd_iter, p_td_ta_thr_iter)
	(p_td_thr_validate, p_td_thr_tsd, p_td_thr_get_info)
	(p_td_thr_getfpregs, p_td_thr_getxregsize, p_td_thr_getxregs)
	(p_td_thr_sigsetmask, p_td_thr_setprio, p_td_thr_setsigpending)
	(p_td_thr_setfpregs, p_td_thr_setxregs, p_td_ta_map_id2thr)
	(p_td_ta_map_lwp2thr, p_td_thr_getgregs, p_td_thr_setgregs): Use them.
	(ps_pdread): Add cast.
	(ps_ptread): Likewise.
	(resolve): Likewise.
	* top.c (gdb_safe_append_history): Print pid_t as long.

Comments

Pedro Alves Oct. 18, 2016, 2:28 p.m. UTC | #1
On 10/18/2016 02:14 PM, Rainer Orth wrote:

>> Yes, with the tweak above on master.  But, the process for getting

> 

> Thanks.  When investigating the failure to detect -static-libstdc++

> support (more below), I found two more issues which only show up with

> -Werror:

> 

> /vol/src/gnu/gdb/gdb/local/gdb/procfs.c: In function 'ssd* proc_get_LDT_entry(procinfo*, int)':

> /vol/src/gnu/gdb/gdb/local/gdb/procfs.c:2487:19: error: variable 'old_chain' set but not used [-Werror=unused-but-set-variable]

>    struct cleanup *old_chain = NULL;

>                    ^

> 

> Unless I'm mistaken, you need to run do_cleanups on every return from

> the function.


You're right.  

> 

> Afterwards, I ran a 32-bit compilation, which (after adding

> --disable-largefile to avoid

> 

> In file included from /usr/include/sys/procfs.h:28:0,

>                  from /vol/src/gnu/gdb/gdb/local/gdb/i386-sol2-nat.c:23:

> /usr/include/sys/old_procfs.h:39:2: error: #error "Cannot use procfs in the large file compilation environment"

>  #error "Cannot use procfs in the large file compilation environment"

>   ^

> 


BTW, the gdb/procfs.c file is long overdue for an overall face
lift...  All the !NEW_PROC_API code should be dead, AFAIK.  Despite
the comments at the top, the file is no longer used for any
target other than Solaris:

 $ grep -rn "[^-]procfs\.o" gdb/config/
 gdb/config/sparc/sol2.mh:5:     procfs.o proc-api.o proc-events.o proc-flags.o proc-why.o
 gdb/config/i386/sol2-64.mh:3:   procfs.o proc-api.o proc-events.o proc-flags.o proc-why.o
 gdb/config/i386/i386sol2.mh:3:  procfs.o proc-api.o proc-events.o proc-flags.o proc-why.o

The other Unix ports mentioned are all gone.

But I'm surprised that your Solaris build is including some
"old_procfs.h" though.  I thought that any non-ancient Solaris
version would be going through NEW_PROC_API too. 

Doesn't this bit in gdb/configure.ac pick NEW_PROC_API for you
in 32-bit mode? :

# Detect which type of /proc is in use, such as for Solaris.

if test "${target}" = "${host}"; then
  case "${host}" in
  *-*-sysv4.2* | *-*-sysv5* )
      AC_DEFINE(NEW_PROC_API, 1,
      [Define if you want to use new multi-fd /proc interface.])
      ;;
  *-*-solaris2.[[6789]] | *-*-solaris2.1[[0-9]]*)
      AC_DEFINE(NEW_PROC_API, 1,
      [Define if you want to use new multi-fd /proc interface.])
      ;;
  mips-sgi-irix5*)
      # Work around <sys/proc.h> needing _KMEMUSER problem on IRIX 5.
      AC_DEFINE([_KMEMUSER], 1,
      [Define to 1 so <sys/proc.h> gets a definition of anon_hdl.  Works
       around a <sys/proc.h> problem on IRIX 5.])
      ;;
  esac
fi

It'd be great to find someone motivated to clean this all up.  :-)
At least to make sure that the 32-bit and 64-bit compilations
take the same paths in the backend...

FYI, AFAIK, no GDB maintainer cares for/tests on Solaris
routinely nowadays.

> and two more instances) revealed

> 

> /vol/src/gnu/gdb/gdb/local/gdb/top.c: In function 'void gdb_safe_append_history()':

> /vol/src/gnu/gdb/gdb/local/gdb/top.c:1170:59: error: format '%d' expects argument of type 'int', but argument 3 has type 'pid_t {aka long int}' [-Werror=format=]

>      = xstrprintf ("%s-gdb%d~", history_filename, getpid ());

>                                                            ^

> 

> Fixed by casting pid_t to long and printing it as such.

> 

> Still ok for mainline?


Still OK.

Thanks,
Pedro Alves
Rainer Orth Oct. 19, 2016, 11:53 a.m. UTC | #2
Hi Pedro,

>> Afterwards, I ran a 32-bit compilation, which (after adding

>> --disable-largefile to avoid

>> 

>> In file included from /usr/include/sys/procfs.h:28:0,

>>                  from /vol/src/gnu/gdb/gdb/local/gdb/i386-sol2-nat.c:23:

>> /usr/include/sys/old_procfs.h:39:2: error: #error "Cannot use procfs in the large file compilation environment"

>>  #error "Cannot use procfs in the large file compilation environment"

>>   ^

>> 

>

> BTW, the gdb/procfs.c file is long overdue for an overall face

> lift...  All the !NEW_PROC_API code should be dead, AFAIK.  Despite

> the comments at the top, the file is no longer used for any

> target other than Solaris:

>

>  $ grep -rn "[^-]procfs\.o" gdb/config/

>  gdb/config/sparc/sol2.mh:5:     procfs.o proc-api.o proc-events.o proc-flags.o proc-why.o

>  gdb/config/i386/sol2-64.mh:3:   procfs.o proc-api.o proc-events.o proc-flags.o proc-why.o

>  gdb/config/i386/i386sol2.mh:3:  procfs.o proc-api.o proc-events.o proc-flags.o proc-why.o

>

> The other Unix ports mentioned are all gone.

>

> But I'm surprised that your Solaris build is including some

> "old_procfs.h" though.  I thought that any non-ancient Solaris

> version would be going through NEW_PROC_API too. 


No wonder: i386-sol2-nat.c unconditionally includes <sys/procfs.h>,
which has this:

/*
 * This definition is temporary.  Structured proc is the preferred API,
 * and the older ioctl-based interface will be removed in a future version
 * of Solaris.  Until then, by default, including <sys/procfs.h> will
 * provide the older ioctl-based /proc definitions.  To get the structured
 * /proc definitions, either include <procfs.h> or define _STRUCTURED_PROC
 * to be 1 before including <sys/procfs.h>.
 */
#ifndef _STRUCTURED_PROC
#define _STRUCTURED_PROC        0
#endif

#if !defined(_KERNEL) && _STRUCTURED_PROC == 0

#include <sys/old_procfs.h>

The Solaris code simply should include <procfs.h> everywhere.

> Doesn't this bit in gdb/configure.ac pick NEW_PROC_API for you

> in 32-bit mode? :

>

> # Detect which type of /proc is in use, such as for Solaris.

>

> if test "${target}" = "${host}"; then

>   case "${host}" in

>   *-*-sysv4.2* | *-*-sysv5* )

>       AC_DEFINE(NEW_PROC_API, 1,

>       [Define if you want to use new multi-fd /proc interface.])

>       ;;

>   *-*-solaris2.[[6789]] | *-*-solaris2.1[[0-9]]*)

>       AC_DEFINE(NEW_PROC_API, 1,

>       [Define if you want to use new multi-fd /proc interface.])

>       ;;

>   mips-sgi-irix5*)

>       # Work around <sys/proc.h> needing _KMEMUSER problem on IRIX 5.

>       AC_DEFINE([_KMEMUSER], 1,

>       [Define to 1 so <sys/proc.h> gets a definition of anon_hdl.  Works

>        around a <sys/proc.h> problem on IRIX 5.])

>       ;;

>   esac

> fi


It did as it should.

> It'd be great to find someone motivated to clean this all up.  :-)

> At least to make sure that the 32-bit and 64-bit compilations

> take the same paths in the backend...


Certainly: I initially encountered this in gcc when boehm-gc still used
the ioctl-based procfs which is finally gone in Solaris 12:

	https://gcc.gnu.org/ml/gcc-patches/2015-08/msg01591.html

Given that the structured one became available with Solaris 2.6 back in
1997, there's no need at all to deal with the old ioctl interface
anywhere.

Besides, given that GCC 4.9 was the last version to support Solaris 9,
one might consider deprecating/removing anything before Solaris 10 in
gdb, too.

I'll see if I can find some spare cycles to clean procfs.c and friends
up: there are tons of opportunities with anything but Solaris gone as
clients of that file and a couple related ones.

> FYI, AFAIK, no GDB maintainer cares for/tests on Solaris

> routinely nowadays.


Neither do I: just whenever a new gdb or binutils release arrives, I
give them a try.  I'm way behind even on Solaris/gcc maintenance, so I
fear there's not much I can do about gdb on that front.  However,
there's a couple of Solaris patches for gdb 7.11 here:

	https://java.net/projects/solaris-userland/sources/gate/show/components/gdb/patches?rev=7127

Perhaps the authors can be motivated to contribute them upstream as they
obviously intended ;-)

>> Still ok for mainline?

>

> Still OK.


Thanks.  I'll commit as soon as I've sorted some problem with hg-git
out: plain git is completely unusable for me.

What about the 7.12 branch backport with the PR now filed?

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University
Pedro Alves Oct. 19, 2016, 12:19 p.m. UTC | #3
On 10/19/2016 12:53 PM, Rainer Orth wrote:

> Besides, given that GCC 4.9 was the last version to support Solaris 9,

> one might consider deprecating/removing anything before Solaris 10 in

> gdb, too.


That's be fine with me, but then again, I don't really use
Solaris at all.  :-)

> 

> I'll see if I can find some spare cycles to clean procfs.c and friends

> up: there are tons of opportunities with anything but Solaris gone as

> clients of that file and a couple related ones.

> 

>> FYI, AFAIK, no GDB maintainer cares for/tests on Solaris

>> routinely nowadays.

> 

> Neither do I: just whenever a new gdb or binutils release arrives, I

> give them a try.  I'm way behind even on Solaris/gcc maintenance, so I

> fear there's not much I can do about gdb on that front.  However,

> there's a couple of Solaris patches for gdb 7.11 here:

> 

> 	https://java.net/projects/solaris-userland/sources/gate/show/components/gdb/patches?rev=7127

> 

> Perhaps the authors can be motivated to contribute them upstream as they

> obviously intended ;-)


Indeed.  (That page is not opening for me, server seems slow, can't see
what the patches are about.)


> 

>>> Still ok for mainline?

>>

>> Still OK.

> 

> Thanks.  I'll commit as soon as I've sorted some problem with hg-git

> out: plain git is completely unusable for me.

> 


Thanks.

(FYI, we don't just put the ChangeLog entry in the commit log
like gcc does.  If you include the description of the problem as you
had in the email in the git commit log, that'd be great.)

> What about the 7.12 branch backport with the PR now filed?


You just need to cherry pick the fix to the gdb-7.12-branch branch
and push it.  Just leave the atof call in place under !__cplusplus
in the branch version, like you had in the original version, in case
that was really necessary on some host.

Thanks,
Pedro Alves
Rainer Orth Oct. 25, 2016, 2:18 p.m. UTC | #4
Hi Pedro,

> On 10/19/2016 12:53 PM, Rainer Orth wrote:

>

>> Besides, given that GCC 4.9 was the last version to support Solaris 9,

>> one might consider deprecating/removing anything before Solaris 10 in

>> gdb, too.

>

> That's be fine with me, but then again, I don't really use

> Solaris at all.  :-)


ok, I'll go ahead with this assumption then: should there really exist
any Solaris 8 or 9 users out in the wild, the can stay with gdb 7.12 if
they must...

>> I'll see if I can find some spare cycles to clean procfs.c and friends

>> up: there are tons of opportunities with anything but Solaris gone as

>> clients of that file and a couple related ones.

>> 

>>> FYI, AFAIK, no GDB maintainer cares for/tests on Solaris

>>> routinely nowadays.


I've no made a first cut at stripping procfs.c and friends of
non-Solaris support: the files shrink nicely from that :-)  Will need
proper testing (this time with full testsuite runs) on Solaris 10-12,
sparc and x86, 32 and 64-bit before posting, though.

>> Neither do I: just whenever a new gdb or binutils release arrives, I

>> give them a try.  I'm way behind even on Solaris/gcc maintenance, so I

>> fear there's not much I can do about gdb on that front.  However,

>> there's a couple of Solaris patches for gdb 7.11 here:

>> 

>> 	https://java.net/projects/solaris-userland/sources/gate/show/components/gdb/patches?rev=7127

>> 

>> Perhaps the authors can be motivated to contribute them upstream as they

>> obviously intended ;-)

>

> Indeed.  (That page is not opening for me, server seems slow, can't see

> what the patches are about.)


java.net can be dog slow at times ;-(  The easiest and quickest way to
get at the stuff is probably to

$ hg clone https://hg.java.net/hg/solaris-userland~gate/

The patches are in components/gdb/patches.  I've looked over them and
there are four groups of changes:

* handle NT_LWPSTATUS notes in core files.

* predefine SOLARIS for target specific code

* Solaris support in features

* Solaris support in syscalls

For the last two, however, I see no initialize_tdesc_* or
set_xml_syscall_file_name calls to make use of them.  Very strange...

>>>> Still ok for mainline?

>>>

>>> Still OK.

>> 

>> Thanks.  I'll commit as soon as I've sorted some problem with hg-git

>> out: plain git is completely unusable for me.

>> 

>

> Thanks.

>

> (FYI, we don't just put the ChangeLog entry in the commit log

> like gcc does.  If you include the description of the problem as you

> had in the email in the git commit log, that'd be great.)


I see.  I've now committed the patch after another round of testing on
i386-pc-solaris2.10 (both 32 and 64-bit).

>> What about the 7.12 branch backport with the PR now filed?

>

> You just need to cherry pick the fix to the gdb-7.12-branch branch

> and push it.  Just leave the atof call in place under !__cplusplus

> in the branch version, like you had in the original version, in case

> that was really necessary on some host.


Did so as well.

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University
diff mbox

Patch

diff --git a/gdb/defs.h b/gdb/defs.h
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -612,16 +612,6 @@  enum gdb_osabi
   GDB_OSABI_INVALID		/* keep this last */
 };
 
-/* Global functions from other, non-gdb GNU thingies.
-   Libiberty thingies are no longer declared here.  We include libiberty.h
-   above, instead.  */
-
-/* From other system libraries */
-
-#ifndef atof
-extern double atof (const char *);	/* X3.159-1989  4.10.1.1 */
-#endif
-
 /* Enumerate the requirements a symbol has in order to be evaluated.
    These are listed in order of "strength" -- a later entry subsumes
    earlier ones.  This fine-grained distinction is important because
diff --git a/gdb/procfs.c b/gdb/procfs.c
--- a/gdb/procfs.c
+++ b/gdb/procfs.c
@@ -791,7 +791,7 @@  destroy_procinfo (procinfo *pi)
 static void
 do_destroy_procinfo_cleanup (void *pi)
 {
-  destroy_procinfo (pi);
+  destroy_procinfo ((procinfo *) pi);
 }
 
 enum { NOKILL, KILL };
@@ -845,7 +845,7 @@  sysset_t_alloc (procinfo * pi)
   sysset_t *ret;
   int size = sysset_t_size (pi);
 
-  ret = xmalloc (size);
+  ret = (sysset_t *) xmalloc (size);
 #ifdef DYNAMIC_SYSCALLS
   ret->pr_size = ((pi->num_syscalls + (8 * sizeof (uint64_t) - 1))
 		  / (8 * sizeof (uint64_t)));
@@ -1675,7 +1675,7 @@  proc_set_traced_sysentry (procinfo *pi, 
 		  - sizeof (sysset_t)
 		  + sysset_t_size (pi);
 
-    argp = xmalloc (argp_size);
+    argp = (struct gdb_proc_ctl_pcsentry *) xmalloc (argp_size);
 
     argp->cmd = PCSENTRY;
     memcpy (&argp->sysset, sysset, sysset_t_size (pi));
@@ -1720,7 +1720,7 @@  proc_set_traced_sysexit (procinfo *pi, s
 		  - sizeof (sysset_t)
 		  + sysset_t_size (pi);
 
-    argp = xmalloc (argp_size);
+    argp = (struct gdb_proc_ctl_pcsexit *) xmalloc (argp_size);
 
     argp->cmd = PCSEXIT;
     memcpy (&argp->sysset, sysset, sysset_t_size (pi));
@@ -2512,9 +2512,13 @@  proc_get_LDT_entry (procinfo *pi, int ke
 	break;	/* end of table */
       /* If key matches, return this entry.  */
       if (ldt_entry->sel == key)
-	return ldt_entry;
+	{
+	  do_cleanups (old_chain);
+	  return ldt_entry;
+	}
     }
   /* Loop ended, match not found.  */
+  do_cleanups (old_chain);
   return NULL;
 #else
   int nldt, i;
@@ -2756,7 +2760,7 @@  proc_update_threads (procinfo *pi)
 static void
 do_closedir_cleanup (void *dir)
 {
-  closedir (dir);
+  closedir ((DIR *) dir);
 }
 
 static int
@@ -3836,7 +3840,7 @@  wait_again:
 		      add_thread (temp_ptid);
 
 		    status->kind = TARGET_WAITKIND_STOPPED;
-		    status->value.sig = 0;
+		    status->value.sig = GDB_SIGNAL_0;
 		    return retval;
 		  }
 #endif
@@ -4567,7 +4571,7 @@  procfs_create_inferior (struct target_op
       if (path == NULL)
 	path = "/bin:/usr/bin";
 
-      tryname = alloca (strlen (path) + strlen (shell_file) + 2);
+      tryname = (char *) alloca (strlen (path) + strlen (shell_file) + 2);
       for (p = path; p != NULL; p = p1 ? p1 + 1: NULL)
 	{
 	  p1 = strchr (p, ':');
@@ -5367,7 +5371,8 @@  struct procfs_corefile_thread_data {
 static int
 procfs_corefile_thread_callback (procinfo *pi, procinfo *thread, void *data)
 {
-  struct procfs_corefile_thread_data *args = data;
+  struct procfs_corefile_thread_data *args
+    = (struct procfs_corefile_thread_data *) data;
 
   if (pi != NULL)
     {
diff --git a/gdb/sol-thread.c b/gdb/sol-thread.c
--- a/gdb/sol-thread.c
+++ b/gdb/sol-thread.c
@@ -98,56 +98,82 @@  static void init_sol_thread_ops (void);
 /* Default definitions: These must be defined in tm.h if they are to
    be shared with a process module such as procfs.  */
 
+/* Types of the libthread_db functions.  */
+
+typedef void (td_log_ftype)(const int on_off);
+typedef td_err_e (td_ta_new_ftype)(const struct ps_prochandle *ph_p,
+				   td_thragent_t **ta_pp);
+typedef td_err_e (td_ta_delete_ftype)(td_thragent_t *ta_p);
+typedef td_err_e (td_init_ftype)(void);
+typedef td_err_e (td_ta_get_ph_ftype)(const td_thragent_t *ta_p,
+				      struct ps_prochandle **ph_pp);
+typedef td_err_e (td_ta_get_nthreads_ftype)(const td_thragent_t *ta_p,
+					    int *nthread_p);
+typedef td_err_e (td_ta_tsd_iter_ftype)(const td_thragent_t *ta_p,
+					td_key_iter_f *cb, void *cbdata_p);
+typedef td_err_e (td_ta_thr_iter_ftype)(const td_thragent_t *ta_p,
+					td_thr_iter_f *cb, void *cbdata_p,
+					td_thr_state_e state, int ti_pri,
+					sigset_t *ti_sigmask_p,
+					unsigned ti_user_flags);
+typedef td_err_e (td_thr_validate_ftype)(const td_thrhandle_t *th_p);
+typedef td_err_e (td_thr_tsd_ftype)(const td_thrhandle_t * th_p,
+				    const thread_key_t key, void **data_pp);
+typedef td_err_e (td_thr_get_info_ftype)(const td_thrhandle_t *th_p,
+					 td_thrinfo_t *ti_p);
+typedef td_err_e (td_thr_getfpregs_ftype)(const td_thrhandle_t *th_p,
+					  prfpregset_t *fpregset);
+typedef td_err_e (td_thr_getxregsize_ftype)(const td_thrhandle_t *th_p,
+					    int *xregsize);
+typedef td_err_e (td_thr_getxregs_ftype)(const td_thrhandle_t *th_p,
+					 const caddr_t xregset);
+typedef td_err_e (td_thr_sigsetmask_ftype)(const td_thrhandle_t *th_p,
+					   const sigset_t ti_sigmask);
+typedef td_err_e (td_thr_setprio_ftype)(const td_thrhandle_t *th_p,
+					const int ti_pri);
+typedef td_err_e (td_thr_setsigpending_ftype)(const td_thrhandle_t *th_p,
+					      const uchar_t ti_pending_flag,
+					      const sigset_t ti_pending);
+typedef td_err_e (td_thr_setfpregs_ftype)(const td_thrhandle_t *th_p,
+					  const prfpregset_t *fpregset);
+typedef td_err_e (td_thr_setxregs_ftype)(const td_thrhandle_t *th_p,
+					 const caddr_t xregset);
+typedef td_err_e (td_ta_map_id2thr_ftype)(const td_thragent_t *ta_p,
+					  thread_t tid,
+					  td_thrhandle_t *th_p);
+typedef td_err_e (td_ta_map_lwp2thr_ftype)(const td_thragent_t *ta_p,
+					   lwpid_t lwpid,
+					   td_thrhandle_t *th_p);
+typedef td_err_e (td_thr_getgregs_ftype)(const td_thrhandle_t *th_p,
+					 prgregset_t regset);
+typedef td_err_e (td_thr_setgregs_ftype)(const td_thrhandle_t *th_p,
+					 const prgregset_t regset);
+
 /* Pointers to routines from libthread_db resolved by dlopen().  */
 
-static void (*p_td_log)(const int on_off);
-static td_err_e (*p_td_ta_new)(const struct ps_prochandle *ph_p,
-			       td_thragent_t **ta_pp);
-static td_err_e (*p_td_ta_delete)(td_thragent_t *ta_p);
-static td_err_e (*p_td_init)(void);
-static td_err_e (*p_td_ta_get_ph)(const td_thragent_t *ta_p,
-				  struct ps_prochandle **ph_pp);
-static td_err_e (*p_td_ta_get_nthreads)(const td_thragent_t *ta_p,
-					int *nthread_p);
-static td_err_e (*p_td_ta_tsd_iter)(const td_thragent_t *ta_p,
-				    td_key_iter_f *cb, void *cbdata_p);
-static td_err_e (*p_td_ta_thr_iter)(const td_thragent_t *ta_p,
-				    td_thr_iter_f *cb, void *cbdata_p,
-				    td_thr_state_e state, int ti_pri,
-				    sigset_t *ti_sigmask_p,
-				    unsigned ti_user_flags);
-static td_err_e (*p_td_thr_validate)(const td_thrhandle_t *th_p);
-static td_err_e (*p_td_thr_tsd)(const td_thrhandle_t * th_p,
-				const thread_key_t key, void **data_pp);
-static td_err_e (*p_td_thr_get_info)(const td_thrhandle_t *th_p,
-				     td_thrinfo_t *ti_p);
-static td_err_e (*p_td_thr_getfpregs)(const td_thrhandle_t *th_p,
-				      prfpregset_t *fpregset);
-static td_err_e (*p_td_thr_getxregsize)(const td_thrhandle_t *th_p,
-					int *xregsize);
-static td_err_e (*p_td_thr_getxregs)(const td_thrhandle_t *th_p,
-				     const caddr_t xregset);
-static td_err_e (*p_td_thr_sigsetmask)(const td_thrhandle_t *th_p,
-				       const sigset_t ti_sigmask);
-static td_err_e (*p_td_thr_setprio)(const td_thrhandle_t *th_p,
-				    const int ti_pri);
-static td_err_e (*p_td_thr_setsigpending)(const td_thrhandle_t *th_p,
-					  const uchar_t ti_pending_flag,
-					  const sigset_t ti_pending);
-static td_err_e (*p_td_thr_setfpregs)(const td_thrhandle_t *th_p,
-				      const prfpregset_t *fpregset);
-static td_err_e (*p_td_thr_setxregs)(const td_thrhandle_t *th_p,
-				     const caddr_t xregset);
-static td_err_e (*p_td_ta_map_id2thr)(const td_thragent_t *ta_p,
-				      thread_t tid,
-				      td_thrhandle_t *th_p);
-static td_err_e (*p_td_ta_map_lwp2thr)(const td_thragent_t *ta_p,
-				       lwpid_t lwpid,
-				       td_thrhandle_t *th_p);
-static td_err_e (*p_td_thr_getgregs)(const td_thrhandle_t *th_p,
-				     prgregset_t regset);
-static td_err_e (*p_td_thr_setgregs)(const td_thrhandle_t *th_p,
-				     const prgregset_t regset);
+static td_log_ftype *p_td_log;
+static td_ta_new_ftype *p_td_ta_new;
+static td_ta_delete_ftype *p_td_ta_delete;
+static td_init_ftype *p_td_init;
+static td_ta_get_ph_ftype *p_td_ta_get_ph;
+static td_ta_get_nthreads_ftype *p_td_ta_get_nthreads;
+static td_ta_tsd_iter_ftype *p_td_ta_tsd_iter;
+static td_ta_thr_iter_ftype *p_td_ta_thr_iter;
+static td_thr_validate_ftype *p_td_thr_validate;
+static td_thr_tsd_ftype *p_td_thr_tsd;
+static td_thr_get_info_ftype *p_td_thr_get_info;
+static td_thr_getfpregs_ftype *p_td_thr_getfpregs;
+static td_thr_getxregsize_ftype *p_td_thr_getxregsize;
+static td_thr_getxregs_ftype *p_td_thr_getxregs;
+static td_thr_sigsetmask_ftype *p_td_thr_sigsetmask;
+static td_thr_setprio_ftype *p_td_thr_setprio;
+static td_thr_setsigpending_ftype *p_td_thr_setsigpending;
+static td_thr_setfpregs_ftype *p_td_thr_setfpregs;
+static td_thr_setxregs_ftype *p_td_thr_setxregs;
+static td_ta_map_id2thr_ftype *p_td_ta_map_id2thr;
+static td_ta_map_lwp2thr_ftype *p_td_ta_map_lwp2thr;
+static td_thr_getgregs_ftype *p_td_thr_getgregs;
+static td_thr_setgregs_ftype *p_td_thr_setgregs;
 
 
 /* Return the libthread_db error string associated with ERRCODE.  If
@@ -818,7 +844,7 @@  ps_err_e
 ps_pdread (gdb_ps_prochandle_t ph, gdb_ps_addr_t addr,
 	   gdb_ps_read_buf_t buf, gdb_ps_size_t size)
 {
-  return rw_common (0, ph, addr, buf, size);
+  return rw_common (0, ph, addr, (gdb_byte *) buf, size);
 }
 
 /* Copies SIZE bytes from debugger memory .data segment to target process.  */
@@ -836,7 +862,7 @@  ps_err_e
 ps_ptread (gdb_ps_prochandle_t ph, gdb_ps_addr_t addr,
 	   gdb_ps_read_buf_t buf, gdb_ps_size_t size)
 {
-  return rw_common (0, ph, addr, buf, size);
+  return rw_common (0, ph, addr, (gdb_byte *) buf, size);
 }
 
 /* Copies SIZE bytes from debugger memory .text segment to target process.  */
@@ -1249,7 +1275,7 @@  void
     goto die;
 
 #define resolve(X) \
-  if (!(p_##X = dlsym (dlhandle, #X))) \
+  if (!(p_##X = (X ## _ftype *) dlsym (dlhandle, #X)))	\
     goto die;
 
   resolve (td_log);
diff --git a/gdb/top.c b/gdb/top.c
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -1167,7 +1167,7 @@  gdb_safe_append_history (void)
   struct cleanup *old_chain;
 
   local_history_filename
-    = xstrprintf ("%s-gdb%d~", history_filename, getpid ());
+    = xstrprintf ("%s-gdb%ld~", history_filename, (long) getpid ());
   old_chain = make_cleanup (xfree, local_history_filename);
 
   ret = rename (history_filename, local_history_filename);