From owner-freebsd-current@FreeBSD.ORG Wed Sep 24 09:03:32 2003 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 36C1D16A4B3; Wed, 24 Sep 2003 09:03:32 -0700 (PDT) Received: from salmon.maths.tcd.ie (salmon.maths.tcd.ie [134.226.81.11]) by mx1.FreeBSD.org (Postfix) with SMTP id 1CB3243FEC; Wed, 24 Sep 2003 09:03:30 -0700 (PDT) (envelope-from iedowse@maths.tcd.ie) Received: from walton.maths.tcd.ie by salmon.maths.tcd.ie with SMTP id ; 24 Sep 2003 17:03:28 +0100 (BST) To: deischen@freebsd.org In-Reply-To: Your message of "Wed, 24 Sep 2003 11:01:01 EDT." Date: Wed, 24 Sep 2003 17:03:28 +0100 From: Ian Dowse Message-ID: <200309241703.aa94887@salmon.maths.tcd.ie> cc: Doug Barton cc: Freebsd Current Subject: Re: Fixing -pthreads (Re: ports and -current) X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Sep 2003 16:03:32 -0000 In message , Daniel Eischen writes: >On Wed, 24 Sep 2003, Scott Long wrote: >> PTHREAD_LIBS is a great tool for the /usr/ports mechanism, but doesn't >> mean anything outside of that. > >That just meant it makes it easier to maintain ports so that >they are PTHREAD_LIBS compliant (they would break when linked). >I know it has no bearing on 3rd party stuff. Just to throw one further approach out on the table, below is a patch that makes gcc read from a file to determine what library to associate with the -pthread flag. It's a hack of course, and probably neither correct or optimal. If you want to make -pthread mean libkse, create an /etc/pthread.libs that looks like: -lc_r: -lkse -lc_r_p: -lkse_p I haven't been following the discussion in any detail - this is just another possibility that is worth mentioning as it could retain compatibility for users that want -pthread to mean use the default thread library. Ian Index: gcc.c =================================================================== RCS file: /dump/FreeBSD-CVS/src/contrib/gcc/gcc.c,v retrieving revision 1.36 diff -u -r1.36 gcc.c --- gcc.c 11 Jul 2003 04:45:39 -0000 1.36 +++ gcc.c 24 Sep 2003 15:37:14 -0000 @@ -331,6 +331,7 @@ static const char *if_exists_spec_function PARAMS ((int, const char **)); static const char *if_exists_else_spec_function PARAMS ((int, const char **)); +static const char *thread_lib_override_spec_function PARAMS ((int, const char **)); /* The Specs Language @@ -1440,6 +1441,7 @@ { { "if-exists", if_exists_spec_function }, { "if-exists-else", if_exists_else_spec_function }, + { "thread-lib-override", thread_lib_override_spec_function }, { 0, 0 } }; @@ -7335,4 +7337,46 @@ return argv[0]; return argv[1]; +} + +/* thread-lib-override built-in spec function. + + Override a thread library according to /etc/pthread.libs */ + +static const char * +thread_lib_override_spec_function (argc, argv) + int argc; + const char **argv; +{ + static char buf[256]; + FILE *fp; + int n; + + /* Must have exactly one argument. */ + if (argc != 1) + return NULL; + + fp = fopen ("/etc/pthread.libs", "r"); + if (fp == NULL) + return argv[0]; + + while (fgets (buf, sizeof(buf), fp) != NULL) + { + n = strlen (buf); + while (n > 0 && buf[n - 1] == '\n') + buf[--n] = '\0'; + if (buf[0] == '#' || buf[0] == '\0') + continue; + n = strlen (argv[0]); + if (strncmp (buf, argv[0], n) != 0 || n >= sizeof (buf) || buf[n] != ':') + continue; + n++; + while (buf[n] != '\0' && isspace ((unsigned char)buf[n])) + n++; + fclose (fp); + + return &buf[n]; + } + fclose (fp); + return argv[0]; } Index: config/freebsd-spec.h =================================================================== RCS file: /dump/FreeBSD-CVS/src/contrib/gcc/config/freebsd-spec.h,v retrieving revision 1.14 diff -u -r1.14 freebsd-spec.h --- config/freebsd-spec.h 21 Sep 2003 07:59:16 -0000 1.14 +++ config/freebsd-spec.h 24 Sep 2003 15:38:11 -0000 @@ -160,8 +160,8 @@ #if __FreeBSD_version >= 500016 #define FBSD_LIB_SPEC " \ %{!shared: \ - %{!pg: %{pthread:-lc_r} -lc} \ - %{pg: %{pthread:-lc_r_p} -lc_p} \ + %{!pg: %{pthread:%:thread-lib-override(-lc_r)} -lc} \ + %{pg: %{pthread:%:thread-lib-override(-lc_r_p)} -lc_p} \ }" #else #define FBSD_LIB_SPEC " \