This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

PATCH: Support --enable-threads configuration with libjava for FreeBSD


OK, now that all the required GC patches are in for FreeBSD, I will
re-attack the libjava configuration.  This minimal patch allows the
--enable-threads configuration (our system-default) to bootstrap for
FreeBSD and produce decent `make check' results.  Bootstrapped on both
i386-unknown-freebsd4.3 and i386-unknown-freebsd5.0 (with the soon to
be system-default --enable-libgcj ;-).

Native configuration is i386-unknown-freebsd5.0

		=== libjava tests ===


Running target unix
FAIL: final_method run
FAIL: register run
FAIL: Divide_1 execution from source compiled test [x4]
FAIL: Float_1 -O execution from source compiled test [x2]
FAIL: Invoke_1 execution from source compiled test [x4]
FAIL: PR218 execution from source compiled test [x4]
FAIL: Thread_Wait_2 execution from source compiled test
FAIL: err2 execution from bytecode->native test
FAIL: err6 -O execution from bytecode->native test
FAIL: err9 -O execution from source compiled test [x2]
FAIL: instinit2 execution from source compiled test
XPASS: stringconst output from bytecode->native test [x2]
FAIL: stringconst2 execution from source compiled test [x2]
FAIL: KeepInline -O execution from source compiled test

		=== libjava Summary ===

# of expected passes            1842
# of unexpected failures        25
# of unexpected successes       2
# of expected failures          16
# of untested testcases         41

Commentary: Taking all the feedback produced from my past runs at the
problem, I am going to somewhat punt for the moment.  The open issue
was that under FreeBSD 4 (and before) you can't just add libraries to
a link spec.  The only official way to get threaded system libraries
is to use a switch (-pthread) which replaces a library (-lc) with
another (-lc_r).  It appears that switch must be present on the
command line, not within a link spec.  I have never been able to
produce a "contained patch" to make this work as it probably should.
Thus, under FreeBSD 4, we pass the buck to the user.  Some say that
this means we need to be multilib'd.  History says otherwise; we have
threaded libraries for C++ and objc without needing to be multilib'd.
At least in this minimal version of the port configuration patch, we
now explain to the user how this port is different when they link
without the required switch.  To wit:

; cat Hello.java 
class Hello {public static void main (String[] arg) {return;};}
; /usr/local/beta-gcc/bin/gcj --main\=Hello Hello.java
gcj: Under this configuration, the user must provide -pthread when linking.
; /usr/local/beta-gcc/bin/gcj --main\=Hello -pthread Hello.java
; a.out

For FreeBSD 5, it works like other modern UNIX, we add a library
instead of replace a library to enable threading support.  The current
libjava configuration structure directly allows for this.  Since this
is the future and better matches the direction taken by the rest of
the world, I can't see wasting any more time getting the old model to
work.

Current FreeBSD 5 (prerelease) has gethostbyaddr_r available for
linkage but no prototype in netdb.h.  I have added a general,
commented configuration-time workaround.  If that part of the
configuration patch is rejected, I would still like permission to
apply all other parts which do not affect other ports.  In the case of
selective rejection, I would also like to learn a better way to
address the problem I found with this port.  Other than looking at
source (which I can easily do for this port), I don't know how to
invent the right prototype.  Even if I do it for FreeBSD, how do we
know it is right for all other systems.

Permission to apply to the gcc mainline?

2001-10-16  Loren J. Rittle  <ljrittle@acm.org>

	* configure.in (case $THREADS): Add *-*-freebsd* configuration.
	(HAVE_GETHOSTBYADDR_R): Create a valid, non-optimal
	configuration when gethostbyaddr_r exists yet no prototype
	exists in netdb.h.
	* configure: Rebuilt.
	* posix-threads.cc (INTR): Reuse path for LINUX_THREADS
	with FREEBSD_THREADS.  However, comment different reason.

Index: configure.in
===================================================================
RCS file: /cvs/gcc/egcs/libjava/configure.in,v
retrieving revision 1.100
diff -c -r1.100 configure.in
*** configure.in	2001/10/11 15:52:39	1.100
--- configure.in	2001/10/23 06:35:36
***************
*** 333,338 ****
--- 333,359 ----
       *-*-cygwin*)
  	# Don't set THREADLIBS here.  Cygwin doesn't have -lpthread.
  	;;
+ changequote(<<,>>)   
+      *-*-freebsd[1234]*)
+ changequote([,])   
+ 	# Before FreeBSD 5, it didn't have -lpthread (or any library which
+ 	# merely adds pthread_* functions) but it does have a -pthread switch
+ 	# which is required at link-time to select -lc_r *instead* of -lc.
+ 	THREADLIBS=-pthread
+ 	# Don't set THREADSPEC here as might be expected since -pthread is
+ 	# not processed when found within a spec file, it must come from
+ 	# the command line.  For now, the user must provide the -pthread
+ 	# switch to link code compiled with gcj.  In future, consider adding
+ 	# support for weak references to pthread_* functions ala gthr.h API.
+ 	THREADSPEC='%{!pthread: %eUnder this configuration, the user must provide -pthread when linking.}'
+ 	;;
+      *-*-freebsd*)
+ 	# FreeBSD 5 implements a model much closer to other modern UNIX
+ 	# which support threads.  However, it still does not support
+ 	# -lpthread.
+ 	THREADLIBS=-pthread
+ 	THREADSPEC=-lc_r
+ 	;;
       *)
  	THREADLIBS=-lpthread
  	THREADSPEC=-lpthread
***************
*** 479,491 ****
       fi
     ])
  
     AC_CHECK_FUNCS(gethostbyaddr_r, [
       AC_DEFINE(HAVE_GETHOSTBYADDR_R)
       # There are two different kinds of gethostbyaddr_r.
       # We look for the one that returns `int'.
       # Hopefully this check is robust enough.
       AC_EGREP_HEADER(int.*gethostbyaddr_r, netdb.h, [
!        AC_DEFINE(GETHOSTBYADDR_R_RETURNS_INT)])])
  
     AC_CHECK_FUNCS(gethostname, [
       AC_DEFINE(HAVE_GETHOSTNAME)
--- 500,518 ----
       fi
     ])
  
+    # FIXME: libjava source code expects to find a prototype for
+    # gethostbyaddr_r in netdb.h.  The outer check ensures that
+    # HAVE_GETHOSTBYADDR_R will not be defined if the prototype fails
+    # to exist where expected.  (The root issue: AC_CHECK_FUNCS assumes C
+    # linkage check is enough, yet C++ code requires proper prototypes.)
+    AC_EGREP_HEADER(gethostbyaddr_r, netdb.h, [
     AC_CHECK_FUNCS(gethostbyaddr_r, [
       AC_DEFINE(HAVE_GETHOSTBYADDR_R)
       # There are two different kinds of gethostbyaddr_r.
       # We look for the one that returns `int'.
       # Hopefully this check is robust enough.
       AC_EGREP_HEADER(int.*gethostbyaddr_r, netdb.h, [
!        AC_DEFINE(GETHOSTBYADDR_R_RETURNS_INT)])])])
  
     AC_CHECK_FUNCS(gethostname, [
       AC_DEFINE(HAVE_GETHOSTNAME)
Index: posix-threads.cc
===================================================================
RCS file: /cvs/gcc/egcs/libjava/posix-threads.cc,v
retrieving revision 1.28
diff -c -r1.28 posix-threads.cc
*** posix-threads.cc	2001/09/21 04:23:31	1.28
--- posix-threads.cc	2001/10/23 06:35:36
***************
*** 55,62 ****
  static int non_daemon_count;
  
  // The signal to use when interrupting a thread.
! #ifdef LINUX_THREADS
    // LinuxThreads (prior to glibc 2.1) usurps both SIGUSR1 and SIGUSR2.
  #  define INTR SIGHUP
  #else /* LINUX_THREADS */
  #  define INTR SIGUSR2
--- 55,63 ----
  static int non_daemon_count;
  
  // The signal to use when interrupting a thread.
! #if defined(LINUX_THREADS) || defined(FREEBSD_THREADS)
    // LinuxThreads (prior to glibc 2.1) usurps both SIGUSR1 and SIGUSR2.
+   // GC on FreeBSD uses both SIGUSR1 and SIGUSR2.
  #  define INTR SIGHUP
  #else /* LINUX_THREADS */
  #  define INTR SIGUSR2


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]