1 Upstream-Status: Inappropriate [Backport]
2 From 137ed44dcdd5890433b8d0348dcd2b7624b7c3d6 Mon Sep 17 00:00:00 2001
3 From: jb <jb@138bc75d-0d04-0410-961f-82ee72b054a4>
4 Date: Mon, 18 Apr 2011 15:49:16 +0000
5 Subject: [PATCH 140/200] PR 47571 Fix weakref trickery breakage on alpha-dec-osf
7 This is a backport from mainline r172469.
9 It also removes the temporary fix from r171095.
12 git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_6-branch@172656 138bc75d-0d04-0410-961f-82ee72b054a4
14 index 395a1ea..62c3b45 100644
15 --- a/libgfortran/acinclude.m4
16 +++ b/libgfortran/acinclude.m4
17 @@ -108,7 +108,7 @@ AC_DEFUN([LIBGFOR_GTHREAD_WEAK], [
18 [Define to 1 if the target supports #pragma weak])
21 - *-*-darwin* | *-*-hpux* | *-*-cygwin* | *-*-mingw* )
22 + *-*-darwin* | *-*-hpux* | *-*-cygwin* | *-*-mingw* | alpha*-dec-osf* )
23 AC_DEFINE(GTHREAD_USE_WEAK, 0,
24 [Define to 0 if the target shouldn't use #pragma weak])
26 diff --git a/libgfortran/config.h.in b/libgfortran/config.h.in
27 index a255bdc..a99ba69 100644
28 --- a/libgfortran/config.h.in
29 +++ b/libgfortran/config.h.in
31 /* Define to 1 if you have the `clock_gettime' function. */
32 #undef HAVE_CLOCK_GETTIME
34 +/* Define to 1 if you have the `clock_gettime' function in librt. */
35 +#undef HAVE_CLOCK_GETTIME_LIBRT
37 /* libm includes clog */
40 diff --git a/libgfortran/configure b/libgfortran/configure
41 index 5a81735..ef4712a 100755
42 --- a/libgfortran/configure
43 +++ b/libgfortran/configure
44 @@ -25314,10 +25314,11 @@ $as_echo "#define HAVE_FEENABLEEXCEPT 1" >>confdefs.h
48 -# At least for glibc, clock_gettime is in librt. But don't pull that
49 -# in if it still doesn't give us the function we want.
50 -# This test is copied from libgomp, and modified to not link in -lrt
51 -# as libgfortran calls clock_gettime via a weak reference.
52 +# At least for glibc and Tru64, clock_gettime is in librt. But don't
53 +# pull that in if it still doesn't give us the function we want. This
54 +# test is copied from libgomp, and modified to not link in -lrt as
55 +# libgfortran calls clock_gettime via a weak reference if it's found
57 if test $ac_cv_func_clock_gettime = no; then
58 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for clock_gettime in -lrt" >&5
59 $as_echo_n "checking for clock_gettime in -lrt... " >&6; }
60 @@ -25360,7 +25361,7 @@ fi
61 $as_echo "$ac_cv_lib_rt_clock_gettime" >&6; }
62 if test "x$ac_cv_lib_rt_clock_gettime" = x""yes; then :
64 -$as_echo "#define HAVE_CLOCK_GETTIME 1" >>confdefs.h
65 +$as_echo "#define HAVE_CLOCK_GETTIME_LIBRT 1" >>confdefs.h
69 @@ -25698,7 +25699,7 @@ $as_echo "#define SUPPORTS_WEAK 1" >>confdefs.h
73 - *-*-darwin* | *-*-hpux* | *-*-cygwin* | *-*-mingw* )
74 + *-*-darwin* | *-*-hpux* | *-*-cygwin* | *-*-mingw* | alpha*-dec-osf* )
76 $as_echo "#define GTHREAD_USE_WEAK 0" >>confdefs.h
78 diff --git a/libgfortran/configure.ac b/libgfortran/configure.ac
79 index e265ccd..86d7161 100644
80 --- a/libgfortran/configure.ac
81 +++ b/libgfortran/configure.ac
82 @@ -491,14 +491,15 @@ LIBGFOR_CHECK_FLOAT128
83 # Check for GNU libc feenableexcept
84 AC_CHECK_LIB([m],[feenableexcept],[have_feenableexcept=yes AC_DEFINE([HAVE_FEENABLEEXCEPT],[1],[libm includes feenableexcept])])
86 -# At least for glibc, clock_gettime is in librt. But don't pull that
87 -# in if it still doesn't give us the function we want.
88 -# This test is copied from libgomp, and modified to not link in -lrt
89 -# as libgfortran calls clock_gettime via a weak reference.
90 +# At least for glibc and Tru64, clock_gettime is in librt. But don't
91 +# pull that in if it still doesn't give us the function we want. This
92 +# test is copied from libgomp, and modified to not link in -lrt as
93 +# libgfortran calls clock_gettime via a weak reference if it's found
95 if test $ac_cv_func_clock_gettime = no; then
96 AC_CHECK_LIB(rt, clock_gettime,
97 - [AC_DEFINE(HAVE_CLOCK_GETTIME, 1,
98 - [Define to 1 if you have the `clock_gettime' function.])])
99 + [AC_DEFINE(HAVE_CLOCK_GETTIME_LIBRT, 1,
100 + [Define to 1 if you have the `clock_gettime' function in librt.])])
103 # Check for SysV fpsetmask
104 diff --git a/libgfortran/intrinsics/system_clock.c b/libgfortran/intrinsics/system_clock.c
105 index adf535d..f4bac07 100644
106 --- a/libgfortran/intrinsics/system_clock.c
107 +++ b/libgfortran/intrinsics/system_clock.c
108 @@ -29,21 +29,16 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
112 -/* Tru64 UNIX doesn't support weakrefs, so the trickery below completely
113 - breaks libgfortran (PR fortran/47571). Don't use clock_gettime until a
114 - proper solution has been tested. */
115 -#if defined(__alpha__) && defined(__osf__)
116 -#undef HAVE_CLOCK_GETTIME
119 -#ifdef HAVE_CLOCK_GETTIME
120 /* POSIX states that CLOCK_REALTIME must be present if clock_gettime
121 is available, others are optional. */
122 +#if defined(HAVE_CLOCK_GETTIME) || defined(HAVE_CLOCK_GETTIME_LIBRT)
123 #ifdef CLOCK_MONOTONIC
124 #define GF_CLOCK_MONOTONIC CLOCK_MONOTONIC
126 #define GF_CLOCK_MONOTONIC CLOCK_REALTIME
130 /* Weakref trickery for clock_gettime(). On Glibc, clock_gettime()
131 requires us to link in librt, which also pulls in libpthread. In
132 @@ -57,15 +52,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
133 #define GTHREAD_USE_WEAK 1
136 -#if SUPPORTS_WEAK && GTHREAD_USE_WEAK
137 +#if SUPPORTS_WEAK && GTHREAD_USE_WEAK && defined(HAVE_CLOCK_GETTIME_LIBRT)
138 static int weak_gettime (clockid_t, struct timespec *)
139 __attribute__((__weakref__("clock_gettime")));
141 -static inline int weak_gettime (clockid_t clk_id, struct timespec *res)
143 - return clock_gettime (clk_id, res);
149 @@ -91,6 +80,13 @@ gf_gettime_mono (time_t * secs, long * nanosecs)
152 #ifdef HAVE_CLOCK_GETTIME
153 + struct timespec ts;
154 + err = clock_gettime (GF_CLOCK_MONOTONIC, &ts);
156 + *nanosecs = ts.tv_nsec;
159 +#if defined(HAVE_CLOCK_GETTIME_LIBRT) && SUPPORTS_WEAK && GTHREAD_USE_WEAK
163 @@ -103,6 +99,7 @@ gf_gettime_mono (time_t * secs, long * nanosecs)
164 err = gf_gettime (secs, nanosecs);
170 extern void system_clock_4 (GFC_INTEGER_4 *, GFC_INTEGER_4 *, GFC_INTEGER_4 *);