http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47571

--- Comment #30 from dave at hiauly1 dot hia.nrc.ca 2011-03-09 00:10:22 UTC ---
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47571
> 
> --- Comment #29 from Janne Blomqvist <jb at gcc dot gnu.org> 2011-03-08 
> 22:38:49 UTC ---
> (In reply to comment #28)
> > (In reply to comment #26)
> > > Tru64 UNIX doesn't support weak undefined symbols, which seems to be
> > > what weakrefs are.
> > 
> > Hmm, I think it is going to be difficult. What we want to have:
> > 
> > a) If libc has clock_gettime, use it unconditionally
> > b) If librt has clock_gettime and weak refs are supported, use it if
> >    available
> > c) If librt has it, but no weak refs are supported, don't use it.
> > d) If it not available at all, don't use it.
> 
> Yes, sounds like a good plan.
> 
> > (b) and (d) work; also (a) works - albeit with a warning. Now one needs to
> > support (c).
> 
> Indeed; the patch was developed based on the understanding that only Linux has
> clock_gettime in librt, and Linux supports weakrefs, so (c) does not need to 
> be
> considered. Oh well.
> 
> > I think the best would be to set (effectively) HAVE_CLOCK_GETTIME
> > to false.
> > 
> > One possibility would be to replace:
> > 
> > #ifdef HAVE_CLOCK_GETTIME
> > #  ifdef SUPPORTS_WEAK
> >      ...
> > #  else
> > 
> > by
> > 
> > #if define(HAVE_CLOCK_GETTIME) && define(SUPPORTS_WEAK)
> > 
> > That would exclude platforms, where libc supports clock_gettime but which do
> > not have weak refs. Another possibility is a link-time check which does not
> > work well for some cross-compilations.
> > 
> > What do you think?
> 
> I think the easiest way would be to change the test in configure.ac where we
> check for clock_gettime in librt, so that we set, say, 
> HAVE_CLOCK_GETTIME_LIBRT
> instead of HAVE_CLOCK_GETTIME, thus allowing us to distinguish whether the
> function a) exists at all b) is in libc or librt.

I think it is unnecessary to check whether clock_gettime is in librt
as we don't want libgfortran to depend on librt in general.  This reduces
the accuracy when weak references are not supported and clock_gettime
is only in librt.  The case where weak references are supported and
clock_gettime isn't available at all seems remote.

If weak references are supported, always define weak_gettime as
__attribute__((__weakref__("clock_gettime"))).  Probably, the extra
overhead of the runtime check is acceptable.

If weak references are not supported and clock_gettime is in libc,
define weak_gettime as we currently do:

static inline int weak_gettime (clockid_t clk_id, struct timespec *res)
{
  return clock_gettime (clk_id, res);
}

Condition the code that uses weak_gettime on either having clock_gettime
in libc or weak references.  This could be tweaked to eliminate the `if'
when clock_gettime is in libc.

Dave

Reply via email to