Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 30 Dec 2015 01:09:47 +1100 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Dmitry Chagin <dchagin@freebsd.org>
Cc:        Bruce Evans <brde@optusnet.com.au>,  Konstantin Belousov <kostikbel@gmail.com>, Ian Lepore <ian@freebsd.org>,  src-committers <src-committers@freebsd.org>,  "svn-src-all@freebsd.org" <svn-src-all@freebsd.org>,  "svn-src-head@freebsd.org" <svn-src-head@freebsd.org>
Subject:   Re: svn commit: r292777 - in head: lib/libc/sys sys/kern
Message-ID:  <20151229235754.T3714@besplex.bde.org>
In-Reply-To: <CAC0jpUAC0s%2Bkr_a6v-kwTeDodQQ7KQqvxTieXFUDvCVMOHww0w@mail.gmail.com>
References:  <CAC0jpUAC0s%2Bkr_a6v-kwTeDodQQ7KQqvxTieXFUDvCVMOHww0w@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 29 Dec 2015, Dmitry Chagin wrote:

> So, my point was:
> a)  for a long time we have broken settimeofday() which does not allow us
> to set the system time before the Epoch

We still have a broken settimeofday that doesn't allow us to set the system
time to the Epoch in the Western hemisphere if the clock is on local time,
and doesn't allow as to set the system time to a year > 9999.  More precise=
ly
it does allow us to set these and usually panics on x86 before completing.

> b) as you already mentioned POSIX doesn't require times before the Epoch =
to
> work

In fact, the representation of times is undefined for times before the
Epoch in general.

The specification of clock_settime() is interesting.  At least in an
old POSIX-2001 draft, It is required to set to the specified time and is
not limited to the current time, whatever that is.  It is only required
to work for CLOCK_REALTIME.  It is required to fail if the specified
time is outside of the "legal range" for the clock id.  "legal range"
is bad wording and is unspecified.

> =D1=81) Linux does not allows negative seconds also

Old (~2004) versions of Linux seem to have less error checking for i386
settimeofday() FreeBSD then, so they seem to allow it.  The implementation
seems to be:
- copy the requested value to the kernel software time without much error
   checking.  Don't touch the hardware yet
- update the RTC every 11 minutes if the clock is externally synchronized.

So with 64-bit time_t anyone could easily set the time to year +-292g, or
just to year +-10k.  The AT RTC cannot represent this, and it is difficult
to make it try since it is difficult to find external servers running that
far off the current time.  With 32-bit time_t the range is 1906-2037.
Linux seems to have no range checking for the conversion to BCD, but it
doesn't panic because the BCD macros are expressions.  These macros of
course don't work for arbitrary inputs.  They just convert valid but
unusual years to garbage.  Before that, negative times are converted to
garbage using a type pun: set_rtc_mmss(xtime.tv_sec) starts with a time_t,
but the function takes an unsigned long.  So 1 second before the Epoch
becomes year +584g.  The usual divisions by 60 are used to reduce the
type-punned time.  Since it is unsigned, these now give garbage in-range
values.

> d) we have settimeofsay(2) that consistent with POSIX and in my
> understanding phrase "The time is expressed in seconds and microseconds
> since midnight (0 hour), January 1, 1970." is a strict definition, which
> prohibits time before the Epoch

TImes before the Epoch give undefined behaviour, so they are allowed to
work.  They are even allowed to work better than times after the Epoch,
since they can have any representation and are not require to be missing
support for leap seconds.

> I do not understand why we should have our own (separate from the rest
> world) behavior.

It would be good to not have such broken bounds checkng as the rest of
the world.

Updating the AT RTC synchronously in settimeofday() is already more
significantly different than limiting the range of accepted times.  One
reason that Linux updates asynchronously is that a correct synchronous
update (which FreeBSD doesn't do) requires waiting for a second or two.
The asynchronous update gives the usual problems handling errors --
even if the interrupt handler detected representation errors, it wouldn't
be able to return them to settimeofday().  So errors of a measly 292g
years go unreported.

Bruce
From owner-svn-src-head@freebsd.org  Tue Dec 29 15:23:04 2015
Return-Path: <owner-svn-src-head@freebsd.org>
Delivered-To: svn-src-head@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id CB024A555A8;
 Tue, 29 Dec 2015 15:23:04 +0000 (UTC) (envelope-from ian@FreeBSD.org)
Received: from repo.freebsd.org (repo.freebsd.org
 [IPv6:2610:1c1:1:6068::e6a:0])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id 9BC34118A;
 Tue, 29 Dec 2015 15:23:04 +0000 (UTC) (envelope-from ian@FreeBSD.org)
Received: from repo.freebsd.org ([127.0.1.37])
 by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tBTFN3QH074515;
 Tue, 29 Dec 2015 15:23:03 GMT (envelope-from ian@FreeBSD.org)
Received: (from ian@localhost)
 by repo.freebsd.org (8.15.2/8.15.2/Submit) id tBTFN3og074514;
 Tue, 29 Dec 2015 15:23:03 GMT (envelope-from ian@FreeBSD.org)
Message-Id: <201512291523.tBTFN3og074514@repo.freebsd.org>
X-Authentication-Warning: repo.freebsd.org: ian set sender to ian@FreeBSD.org
 using -f
From: Ian Lepore <ian@FreeBSD.org>
Date: Tue, 29 Dec 2015 15:23:03 +0000 (UTC)
To: src-committers@freebsd.org, svn-src-all@freebsd.org,
 svn-src-head@freebsd.org
Subject: svn commit: r292870 - head/contrib/binutils/bfd
X-SVN-Group: head
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-BeenThere: svn-src-head@freebsd.org
X-Mailman-Version: 2.1.20
Precedence: list
List-Id: SVN commit messages for the src tree for head/-current
 <svn-src-head.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/svn-src-head>,
 <mailto:svn-src-head-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/svn-src-head/>;
List-Post: <mailto:svn-src-head@freebsd.org>
List-Help: <mailto:svn-src-head-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/svn-src-head>,
 <mailto:svn-src-head-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Tue, 29 Dec 2015 15:23:04 -0000

Author: ian
Date: Tue Dec 29 15:23:03 2015
New Revision: 292870
URL: https://svnweb.freebsd.org/changeset/base/292870

Log:
  Correct the code for sign-extending a 16 bit value.  As near as I can tell
  this is effectively a no-op -- the addend term in MOVT/MOVW relocations
  always seems to be zero.  But this is correct and the old code wasn't.

Modified:
  head/contrib/binutils/bfd/elf32-arm.c

Modified: head/contrib/binutils/bfd/elf32-arm.c
==============================================================================
--- head/contrib/binutils/bfd/elf32-arm.c	Tue Dec 29 12:38:04 2015	(r292869)
+++ head/contrib/binutils/bfd/elf32-arm.c	Tue Dec 29 15:23:03 2015	(r292870)
@@ -5800,7 +5800,7 @@ elf32_arm_final_link_relocate (reloc_how
 	if (globals->use_rel)
 	  {
 	    addend = ((insn >> 4) & 0xf000) | (insn & 0xfff);
-	    signed_addend = (addend ^ 0x10000) - 0x10000;
+	    signed_addend = (addend ^ 0x8000) - 0x8000;
 	  }
 
 	value += signed_addend;



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