Because i have -march=native in my CFLAGS, GHC's RTS will be built with instructions which are not available on older CPU's. This seems like intended behaviour but this causes my build of GHC to be incapable of producing binaries compatible with all amd64 CPU's because this RTS is usually statically linked with those binaries. A compiler incapable of producing generic amd64 binaries really limits it's usefulness. From reading the ebuild this seems like a conscious choice. So i believe this should definately be documented in some way because this will probably not be obvious to everyone. Maybe provide a USE flag to toggle this behaviour?
Portage 2.3.6 (python 3.4.5-final-0, default/linux/amd64/13.0/systemd, gcc-5.4.0, glibc-2.23-r4, 4.11.12-ck x86_64) ================================================================= System Settings ================================================================= System uname: Linux-4.11.12-ck-x86_64-Intel-R-_Core-TM-_i7-4820K_CPU_@_3.70GHz-with-gentoo-2.3 KiB Mem: 7060376 total, 428688 free KiB Swap: 7340028 total, 7340028 free Timestamp of repository gentoo: Sun, 10 Sep 2017 09:00:01 +0000 sh bash 4.3_p48-r1 ld GNU ld (Gentoo 2.28.1 p1.0) 2.28.1 ccache version 3.2.4 [enabled] app-shells/bash: 4.3_p48-r1::gentoo dev-lang/perl: 5.24.1-r2::gentoo dev-lang/python: 2.7.12::gentoo, 3.4.5::gentoo dev-util/ccache: 3.2.4::gentoo dev-util/cmake: 3.7.2::gentoo dev-util/pkgconfig: 0.28-r2::gentoo sys-apps/baselayout: 2.3::gentoo sys-apps/openrc: 0.28::gentoo sys-apps/sandbox: 2.10-r3::gentoo sys-devel/autoconf: 2.69::gentoo sys-devel/automake: 1.11.6-r1::gentoo, 1.15-r2::gentoo sys-devel/binutils: 2.28.1::gentoo sys-devel/gcc: 5.4.0-r3::gentoo sys-devel/gcc-config: 1.7.3::gentoo sys-devel/libtool: 2.4.6-r3::gentoo sys-devel/make: 4.2.1::gentoo sys-kernel/linux-headers: 4.4::gentoo (virtual/os-headers) sys-libs/glibc: 2.23-r4::gentoo Repositories: gentoo location: /usr/portage sync-type: rsync sync-uri: rsync://rsync.gentoo.org/gentoo-portage priority: -1000 neomutt location: /usr/local/portage/neomutt masters: gentoo Installed sets: @steam ACCEPT_KEYWORDS="amd64" ACCEPT_LICENSE="* -@EULA" CBUILD="x86_64-pc-linux-gnu" CFLAGS="-O2 -pipe -march=native" CHOST="x86_64-pc-linux-gnu" CONFIG_PROTECT="/etc /usr/share/gnupg/qualified.txt" CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /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" DISTDIR="/usr/portage/distfiles" FCFLAGS="-O2 -pipe" FEATURES="assume-digests binpkg-logs ccache config-protect-if-modified distlocks ebuild-locks fixlafiles merge-sync news parallel-fetch preserve-libs protect-owned sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr" FFLAGS="-O2 -pipe" GENTOO_MIRRORS="http://distfiles.gentoo.org" LANG="en_US.UTF-8" LDFLAGS="-Wl,-O1 -Wl,--as-needed" MAKEOPTS="-j8" PKGDIR="/usr/portage/packages" PORTAGE_CONFIGROOT="/" PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git" PORTAGE_TMPDIR="/var/tmp" USE="X acl amd64 berkdb bzip2 cairo cli cracklib crypt cxx dri encode evdev flac fontconfig fortran gdbm glamor gtkstyle iconv icu ipv6 jpeg jpeg2k libnotify lzma mmx modules multilib ncurses nls nptl ogg openal opencl opengl openmp pam pcre png pulseaudio readline sdl seccomp session sqlite sse sse2 ssl systemd tcpd theora truetype udev unicode v4l vdpau vim-syntax vorbis x264 xattr xcb xft xvid zlib zsh-completion" ABI_X86="64" 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" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd 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 author" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_X86="aes mmx mmxext sse sse2 sse3 sse4_1 sse4_2 ssse3 f16c" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock isync itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf skytraq superstar2 timing tsip tripmate tnt ublox ubx" INPUT_DEVICES="evdev" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php5-6" POSTGRES_TARGETS="postgres9_5" PYTHON_SINGLE_TARGET="python3_4" PYTHON_TARGETS="python2_7 python3_4" RUBY_TARGETS="ruby22" USERLAND="GNU" VIDEO_CARDS="amdgpu radeonsi radeon r200" 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: CC, CPPFLAGS, CTARGET, CXX, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LC_ALL, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS ================================================================= Package Settings ================================================================= dev-lang/ghc-8.0.2::gentoo was built with the following: USE="doc gmp profile -binary -ghcbootstrap -ghcmakebinary" ABI_X86="(64)" CFLAGS="-O2 -pipe -march=native -march=native -march=native" LDFLAGS="-Wl,-O1 -Wl,--as-needed -Wl,-O1 -Wl,--as-needed"
There is no difference if it's RTS or any other library with .c files. Normally gentoo binaries are linked dynamically against RTS.
(In reply to Sergei Trofimovich from comment #2) > There is no difference if it's RTS or any other library with .c files. > Normally gentoo binaries are linked dynamically against RTS. Sure, and i guess this is a matter of opinion. But i use GHC to build static binaries for deployment on different systems, which is the default for haskell binaries. You usually don't expect a compiler to produce incompatible binaries by default so i feel that this information should be conveyed to the user somehow. So i thought adding a USE flag would be a good idea. In any case, i'll add it to the wiki.
(In reply to Michiel Derhaeg from comment #3) > (In reply to Sergei Trofimovich from comment #2) > > There is no difference if it's RTS or any other library with .c files. > > Normally gentoo binaries are linked dynamically against RTS. > > Sure, and i guess this is a matter of opinion. But i use GHC to build static > binaries for deployment on different systems, which is the default for > haskell binaries. You usually don't expect a compiler to produce > incompatible binaries by default so i feel that this information should be > conveyed to the user somehow. So i thought adding a USE flag would be a good > idea. In any case, i'll add it to the wiki. Ke pointed out my comment above does not make much sense. I agree there is a few angles to look at it. Maybe if we understand a few things about your use case we can amend something. I'll try elaborate a bit and then ask a few questions: A few points: 1. (WRT -march-native): yes, system built with -march-native has CPU instructions that might not run on older systems. I'd like to point out there is a few places where libc or gcc itself "statically links" things from your system into shared libs and binaries. For example /usr/lib64/libc_nonshared.a /usr/lib64/gcc/x86_64-pc-linux-gnu/7.2.0/libgcc.a Being short those files are harder to break with -march=native but technically nothing stops it. 2. You are correct that ghc makes things harder by linking in host's RTS and other haskell libraries (written in haskell or C). I'd like to point out that even core haskell libraries (some exampels are bytestring and text) have C code. That C code gets compiled with -march=native (unless you do special effort). 3. Normally gentoo links dynamic libraries with a caveat of being very fragile: shared libraries encode ABI hash of their dependencies. Those change every time when external interface changes (function gets added or removed from import or inlinning information is changed). Though it's easy to convince an ebuld to build static binary: CABAL_EXTRA_CONFIGURE_FLAGS=--disable-executable-dynamic emerge -1 xmonad That means you (or gentoo ebuilds) already need to keep quite a few pieces yourself once you plan to build redistributable binaries. I don't think GHC is the only package that needs adoption. Normally I would recommend having a chroot with required CFLAGS/LDFLAGS/tool-versions unless you are very careful. Question time: 1. (haskell-unrelated) When you build on host's glibc-2.25 do you plan binaries to run on glibc-2.24? 2. (ghc-related) When you build ghc and static binary on a system that supports timerfd_create() syscall do you plan to run such binaries on systems without that syscall present? 3. In light of view above (ghc and core libraries using C code) how do you see your USE flag function to be?
1) Probably not, but that's just software, i can change that. Libc tends to be quite portable so it's never actually an issue in practice. I can easily link against a generic amd64 libc. 2) The same point as 1 3) I don't expect gentoo haskell packages to work on other systems, so that C code in haskell packages are built -march=native is to be expected. This USE flag would not put these CFLAGS in build.mk and just use the default, which it mostly does now anyway. This is largely an issue with the expectations i have of a compiler. If I do `gcc somecode.c`, i expect it to emit generic amd64 code unless i tell it no to. Therefore if i do `ghc SomeCode.hs`, i expect the same. Distributing static haskell binaries does seem commonplace, so i believe this isn't some edge case. This is my opinion but if these expectations are unrealistic for a system built with -march=native, i understand.
Yeah, today these expectations don't hold. You would have to override CFLAGS for dev-lang/ghc via package.env or similar method to build more generic RTS. Maybe one day ghc will allow for easier way to build multiple flavours of RTS and we'll revisit it.