Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 24 Sep 2003 17:03:28 +0100
From:      Ian Dowse <iedowse@maths.tcd.ie>
To:        deischen@freebsd.org
Cc:        Freebsd Current <current@freebsd.org>
Subject:   Re: Fixing -pthreads (Re: ports and -current) 
Message-ID:  <200309241703.aa94887@salmon.maths.tcd.ie>
In-Reply-To: Your message of "Wed, 24 Sep 2003 11:01:01 EDT." <Pine.GSO.4.10.10309241029001.26896-100000@pcnet5.pcnet.com> 

next in thread | previous in thread | raw e-mail | index | archive | help
In message <Pine.GSO.4.10.10309241029001.26896-100000@pcnet5.pcnet.com>, 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 "							\



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200309241703.aa94887>