Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 411681 - sys-devel/gcc-4.5.3-r2 libstdc++ handling of realtime funcs
Summary: sys-devel/gcc-4.5.3-r2 libstdc++ handling of realtime funcs
Status: VERIFIED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: Normal minor (vote)
Assignee: Gentoo Toolchain Maintainers
URL: https://bugs.archlinux.org/task/27838
Whiteboard:
Keywords:
: 444038 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-04-12 05:47 UTC by Christopher Head
Modified: 2018-04-29 15:31 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christopher Head 2012-04-12 05:47:03 UTC
Some functions, e.g. in C++11's <thread> header (sleep_for, sleep_until, and yield) are only defined conditionally, based on the presence of macros like _GLIBCXX_USE_SCHED_YIELD and _GLIBCXX_USE_NANOSLEEP. _GLIBCXX_USE_NANOSLEEP, at least, is missing in the installed files! According to the URL I posted describing the same bug for Arch, individual programs shouldn't enable these defines; rather, GCC should be built with configure options to turn these functions on. Could sys-devel/gcc enable these configure options so these functions are available?

Reproducible: Always

Steps to Reproduce:
emerge sys-devel/gcc and try to build a program that uses e.g. std::this_thread::sleep_for()
Actual Results:  
The program should compile.

Expected Results:  
The function sleep_for() is undefined.

$ emerge --info sys-devel/gcc
Portage 2.1.10.49 (default/linux/amd64/10.0, gcc-4.5.3, glibc-2.13-r4, 3.2.12-gentoo x86_64)
=================================================================
                         System Settings
=================================================================
System uname: Linux-3.2.12-gentoo-x86_64-Intel-R-_Core-TM-_i7_CPU_Q_720_@_1.60GHz-with-gentoo-2.0.3
Timestamp of tree: Fri, 06 Apr 2012 20:15:02 +0000
app-shells/bash:          4.2_p20
dev-java/java-config:     2.1.11-r3
dev-lang/python:          2.7.2-r3, 3.2.2
dev-util/cmake:           2.8.6-r4
dev-util/pkgconfig:       0.26
sys-apps/baselayout:      2.0.3
sys-apps/openrc:          0.9.8.4
sys-apps/sandbox:         2.5
sys-devel/autoconf:       2.13, 2.68
sys-devel/automake:       1.11.1
sys-devel/binutils:       2.21.1-r1
sys-devel/gcc:            4.5.3-r2
sys-devel/gcc-config:     1.5-r2
sys-devel/libtool:        2.4-r1
sys-devel/make:           3.82-r1
sys-kernel/linux-headers: 3.1 (virtual/os-headers)
sys-libs/glibc:           2.13-r4
Repositories: gentoo kruskal-local sunrise hawk777
ACCEPT_KEYWORDS="amd64"
ACCEPT_LICENSE="* -@EULA AdobeFlash-10.3 dlj-1.1 google-talkplugin Oracle-BCLA-JavaSE skype-eula"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-O2 -pipe -march=native -fomit-frame-pointer"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/gnupg/qualified.txt /var/lib/hsqldb"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/env.d/java/ /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /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=native -fomit-frame-pointer"
DISTDIR="/var/cache/distfiles"
EMERGE_DEFAULT_OPTS="--jobs 3 --load-average 8 --with-bdeps y"
FEATURES="assume-digests binpkg-logs distlocks ebuild-locks fixlafiles news parallel-fetch protect-owned sandbox sfperms sign strict unknown-features-warn unmerge-logs unmerge-orphans userfetch xattr"
FFLAGS=""
GENTOO_MIRRORS="ftp://gentoo.arcticnetwork.ca/pub/gentoo ftp://mirror.csclub.uwaterloo.ca/gentoo-distfiles http://gentoo.osuosl.org/"
LANG="en_CA.UTF-8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
LINGUAS="en en_CA"
MAKEOPTS="--jobs 8 --load-average 8"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_EXTRA_OPTS="--exclude ChangeLog --delete-excluded"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/usr/local/portage /var/lib/layman/sunrise /home/chead/portage"
SYNC="rsync://rsync.ca.gentoo.org/gentoo-portage"
USE="X a52 aac acpi aio alsa amd64 archive bluetooth bzip2 cairo caps cdda cddb cdinstall cdio cli css cups custom-optimization cxx dbus dillo double-precision dri dvd faac faad fat ffmpeg fftw flac fontconfig fortran gcrypt gif gimp glade glibc-omitfp gmp gnutls gtk hou hpn iconv idn imap ios java java6 jce joystick jpeg laptop libnotify libsamplerate mbox mikmod mmx modules mp3 mpeg multilib multiuser ncurses nls nntp nowin nptl nptlonly ntfs ntp offensive ogg opengl openmp pam pdf plotutils png pppd readline scanner sdl session sou spell sse sse2 startup-notification stream svg symlink sysfs taglib theora thunar tiff timidity truetype unicode usb vdpau videos vim-syntax vorbis xattr xft xinerama xorg xscreensaver xulrunner xv xvid xvmc zlib" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" 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 cgi cgid 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" CALLIGRA_FEATURES="kexi words flow plan sheets stage tables krita karbon braindump" CAMERAS="ptp2" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ubx" INPUT_DEVICES="evdev synaptics" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LINGUAS="en en_CA" PHP_TARGETS="php5-3" QEMU_SOFTMMU_TARGETS="i386 x86_64" RUBY_TARGETS="ruby18" SANE_BACKENDS="plustek" USERLAND="GNU" VIDEO_CARDS="nvidia" XFCE_PLUGINS="logout menu" 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, INSTALL_MASK, LC_ALL, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, USE_PYTHON

=================================================================
                        Package Settings
=================================================================

sys-devel/gcc-4.5.3-r2 was built with the following:
USE="cxx doc fortran gtk (multilib) nls nptl openmp (-altivec) -bootstrap -build (-fixed-point) -gcj -graphite (-hardened) (-libssp) -lto -mudflap -multislot -nocxx -nopie -nossp -objc -objc++ -objc-gc -test -vanilla"
CFLAGS="-march=native -O2 -pipe -O2"
CXXFLAGS="-march=native -O2 -pipe -O2"
Comment 1 SpanKY gentoo-dev 2012-04-12 16:00:21 UTC
i don't think that description is entirely accurate.  the libstdc++ code tries to detect the funcs, but in the C library, so they fail (as they're actually in the realtime library).  we would need the flag:
 --enable-libstdcxx-time=rt

however, as the upstream documentation explains, that isn't a good default:
  Note that the latter is not always desirable because, in glibc, for example,
  in turn it triggers the linking of libpthread too, which activates locking,
  a large overhead for single-thread programs.

thus i'm inclined to leave it as is.  if you want to use these funcs in your own code, you must:
 - define _GLIBCXX_USE_NANOSLEEP/etc...
 - link with -lrt

simply defining + compiling is not sufficient
Comment 2 SpanKY gentoo-dev 2012-10-20 02:38:44 UTC
upstream glibc is moving clock_* funcs to -lc.  that means gcc should automatically find & enable this functionality once you've installed that.
Comment 3 SpanKY gentoo-dev 2012-11-20 16:29:21 UTC
*** Bug 444038 has been marked as a duplicate of this bug. ***
Comment 4 Sven Eden 2012-11-20 16:41:30 UTC
All that has to be done is to configure with --enable-libstdcxx-time.

I have tested it just today and wanted to post my findings that everything works well after configuring gcc with this additional switch in bug 444038 - but that has been marked as a duplicate of this one.

Please see the answer from Jonathen Wakely here:
http://stackoverflow.com/questions/12523122/what-is-glibcxx-use-nanosleep-all-about

Quote:
---
The reason it's not enabled by configure is that the checks for it don't even run unless you use the --enable-libstdcxx-time option (documented in the Configuration chapter of the libstdc++ manual, not the GCC configure docs)
---

Configuration chapter: http://gcc.gnu.org/onlinedocs/libstdc++/manual/configure.html
Comment 5 Sven Eden 2012-11-20 16:47:21 UTC
(Sorry, I hit some weird key-combo that submitted!)

Quote from the online configuration manual.

---
--enable-libstdcxx-time

    This is an abbreviated form of '--enable-libstdcxx-time=yes'(described next). 
--enable-libstdcxx-time=OPTION

    Enables link-type checks for the availability of the clock_gettime clocks, used in the implementation of [time.clock], and of the nanosleep and sched_yield functions, used in the implementation of [thread.thread.this] of the 2011 ISO C++ standard. The choice OPTION=yes checks for the availability of the facilities in libc and libposix4. In case of need the latter is also linked to libstdc++ as part of the build process. OPTION=rt also searches (and, in case, links) librt. Note that the latter is not always desirable because, in glibc, for example, in turn it triggers the linking of libpthread too, which activates locking, a large overhead for single-thread programs. OPTION=no skips the tests completely. The default is OPTION=no. 
---

The important part is the last sentence: The default is to _skip_ the tests entirely.
Comment 6 SpanKY gentoo-dev 2012-12-24 04:20:48 UTC
(In reply to comment #4)

i've verified that passing that flag enables support on a glibc-2.17 system and does not have any averse affects on older glibc systems -- i.e. nothing changes

http://sources.gentoo.org/eclass/toolchain.eclass?r1=1.560&r2=1.561
Comment 7 Larry the Git Cow gentoo-dev 2018-04-29 15:31:41 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=e4da4705a51d46236f3e9a0d2c850455b7d9772c

commit e4da4705a51d46236f3e9a0d2c850455b7d9772c
Author:     Sergei Trofimovich <slyfox@gentoo.org>
AuthorDate: 2018-04-29 15:26:25 +0000
Commit:     Sergei Trofimovich <slyfox@gentoo.org>
CommitDate: 2018-04-29 15:31:31 +0000

    eclass/toolchain.eclass: disable libstdcxx-time for bare metal
    
    Historically Gentoo unconditionally sets --enable-libstdcxx-time=yes
    to avoid --enable-libstdcxx-time=rt on linux targets, bug #411681
    
    Unfortunately this conflicts with arm-none-eabi and other
    bare-metal targets that don't provide enough plumbing
    to support for POSIX timers.
    
    This change ogerrides our default to --disable-libstdcxx-time
    on *-elf and *-eabi targets.
    
    Tested as:
      $ crossdev --stage4 arm-none-eabi
    
    Reported-by: scheer@wsoptics.de
    Reported-by: Thomas Schneider
    Bug: https://bugs.gentoo.org/411681
    Bug: https://bugs.gentoo.org/589672
    Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>

 eclass/toolchain.eclass | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)}