Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 324445

Summary: sys-freebsd/freebsd-lib-8.0: when compiled with "-fstrict-overflow" or "-O2", mktime() dosen't handle overflowed time well.
Product: Gentoo/Alt Reporter: Naohiro Aota <naota>
Component: FreeBSDAssignee: Gentoo/BSD Team <bsd+disabled>
Status: RESOLVED FIXED    
Severity: normal    
Priority: High    
Version: unspecified   
Hardware: All   
OS: FreeBSD   
Whiteboard:
Package list:
Runtime testing required: ---

Description Naohiro Aota gentoo-dev 2010-06-17 11:34:03 UTC
dev-lang/R check if mktime() sets errno or not like this.

#include <stdlib.h>
#include <time.h>
#include <errno.h>

int main()
{
    struct tm tm;
    tm.tm_year = 3000; tm.tm_mon = 0; tm.tm_mday = 0;
    tm.tm_hour = 0; tm.tm_min = 0; tm.tm_sec = 0; tm.tm_isdst = -1;
    errno = 0;
    mktime(&tm);
    exit(errno == 0);
}

But, if sys-freebsd/freebsd-lib emerge'd with "-fstrict-overflow" (or "-O2" enable it implicitly). mktime() cannot detect the overflow and the code above doesn't finish anymore.
We should append "-fno-strict-overflow" to the ebuild.


Reproducible: Always

Steps to Reproduce:
1.CFLAGS='-fstrict-overflow' emerge =freebsd-lib-8.0
2.compile the code above and run the program.


Actual Results:  
You see such little program dosen't return even after an hour.


Expected Results:  
The program should finish immediately.



Portage 2.2_rc67 (default/bsd/fbsd/x86/8.0, gcc-4.3.4, freebsd-lib-8.0-r0, 8.0-RELEASE i386)
=================================================================
System uname: FreeBSD-8.0-RELEASE-i386-32bit-ELF
Timestamp of tree: Thu, 17 Jun 2010 11:00:01 +0000
app-shells/bash:     4.1_p7
dev-java/java-config: 2.1.9-r1
dev-lang/python:     2.5.4-r4, 2.6.5-r2, 3.1.2-r3
dev-util/cmake:      2.8.1-r2
sys-apps/baselayout: 2.0.1
sys-apps/openrc:     0.6.1-r1
sys-apps/sandbox:    1.6-r2
sys-devel/autoconf:  2.13, 2.65
sys-devel/automake:  1.9.6-r2, 1.10.3, 1.11.1
sys-devel/binutils:  2.20.1
sys-devel/gcc:       3.4.6-r2, 4.3.4, 4.4.4
sys-devel/gcc-config: 1.4.1
sys-devel/libtool:   2.2.10
virtual/os-headers:  8.0
ACCEPT_KEYWORDS="x86-fbsd ~x86-fbsd"
ACCEPT_LICENSE="* -@EULA sun-bcla-java-vm skype-eula"
CBUILD="i686-gentoo-freebsd7.1"
CFLAGS="-O2 -pipe -march=prescott --param l1-cache-size=16 --param l1-cache-line-size=64 -mtune=prescott"
CHOST="i686-gentoo-freebsd7.1"
CONFIG_PROTECT="/etc /usr/share/X11/xkb"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/env.d/java/ /etc/eselect/postgresql /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/php/apache2-php5/ext-active/ /etc/php/cgi-php5/ext-active/ /etc/php/cli-php5/ext-active/ /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo /etc/texmf/language.dat.d /etc/texmf/language.def.d /etc/texmf/updmap.d /etc/texmf/web2c"
CXXFLAGS="-O2 -pipe -march=prescott --param l1-cache-size=16 --param l1-cache-line-size=64 -mtune=prescott"
DISTDIR="/usr/portage/distfiles"
FEATURES="assume-digests chflags distlocks fixpackages news parallel-fetch preserve-libs protect-owned sandbox sfperms strict unmerge-logs unmerge-orphans userfetch"
GENTOO_MIRRORS="http://distfiles.gentoo.org"
LANG="ja_JP.UTF-8"
LC_ALL="ja_JP.UTF-8"
LDFLAGS=""
LINGUAS="ja"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/usr/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/var/lib/layman/naota /var/lib/layman/gentoo-bsd /var/lib/layman/sunrise /usr/local/portage/pc_local"
SYNC="rsync://rsync.gentoo.org/gentoo-portage"
USE="X acl acpi berkdb bzip2 cli cracklib crypt cxx dri emacs fortran gdbm gif gtk gzip-el iconv ipv6 java5 java6 jpeg mmx modules ncurses nls nptlonly openal opengl oss pam pcre perl png python readline reflection session source spell spl sse sse2 ssl svg tcpd toolkit-scroll-bars truetype unicode usb x86-fbsd xft xorg zlib" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" ELIBC="FreeBSD" INPUT_DEVICES="keyboard mouse" KERNEL="FreeBSD" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LINGUAS="ja" RUBY_TARGETS="ruby18" USERLAND="BSD" VIDEO_CARDS="intel" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account" 
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, FFLAGS, INSTALL_MASK, MAKEOPTS, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 1 Naohiro Aota gentoo-dev 2010-07-29 10:44:10 UTC
Does anyone test the C code above?
Comment 2 Javier Villavicencio (RETIRED) gentoo-dev 2010-08-02 14:05:33 UTC
Is this the same mktime check done by autotools macros? If so, I think I have seen it also fail on vanilla FreeBSD (just tested your testcase and it doesn't succeeds either). Perhaps you may wanna ask upstream about it?
Comment 3 Naohiro Aota gentoo-dev 2012-05-15 00:55:04 UTC
http://svnweb.freebsd.org/base/head/contrib/tzcode/stdtime/localtime.c?revision=226828&view=markup
1787 	increment_overflow(number, delta)

It highly depend on overflow behavior. Let's add -fno-strict-overflow to all freebsd-lib-*.ebuild.
Comment 4 Naohiro Aota gentoo-dev 2012-05-25 04:13:56 UTC
Change added to the tree.