Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 629410 - dev-libs/libgcrypt fails to compile with clang -O2, requesting -O0
Summary: dev-libs/libgcrypt fails to compile with clang -O2, requesting -O0
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Kristian Fiskerstrand (RETIRED)
URL: https://dev.gnupg.org/T3293
Whiteboard:
Keywords: UPSTREAM
: 640468 (view as bug list)
Depends on:
Blocks: systemwide-clang
  Show dependency tree
 
Reported: 2017-08-31 01:35 UTC by Pengcheng Xu
Modified: 2022-04-16 19:35 UTC (History)
7 users (show)

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


Attachments
build.log ffor libgcrypt (file_629410.txt,119.00 KB, text/plain)
2017-08-31 01:35 UTC, Pengcheng Xu
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Pengcheng Xu 2017-08-31 01:35:11 UTC
Created attachment 491126 [details]
build.log ffor libgcrypt

I'm using the default -O2. With GCC the package builds fine, but not with clang. If I set CFLAGS="-O0 -pipe" in /etc/portage/env explicitly for this package it builds successfully with clang.

The build.log is attached.

emerge --info:

Portage 2.3.8 (python 3.4.6-final-0, default/bsd/fbsd/amd64/10.3/clang, gcc-6.4.0, freebsd-lib-10.3-r3, 10.3-r6-Gentoo amd64)
=================================================================
System uname: FreeBSD-10.3-r6-Gentoo-amd64-64bit-ELF
KiB Mem:     8363612 total
KiB Swap:    2097048 total
Timestamp of repository gentoo: Wed, 30 Aug 2017 00:45:01 +0000
Head commit of repository gentoo: d4a2826f6f31e20096e82cfc94db96b24f483526
sh sh
ld GNU ld (Gentoo 2.27 p1.1) 2.27
app-shells/bash:         4.4_p12::gentoo
dev-lang/perl:           5.24.2::gentoo
dev-lang/python:         2.7.13::gentoo, 3.4.6::gentoo
dev-util/cmake:          3.9.1::gentoo
dev-util/pkgconfig:      0.29.2::gentoo
sys-apps/baselayout:     2.4.1-r1::gentoo
sys-apps/openrc:         0.29::gentoo
sys-devel/autoconf:      2.69-r4::gentoo
sys-devel/automake:      1.9.6-r3::gentoo, 1.13.4-r1::gentoo, 1.15.1-r1::gentoo
sys-devel/binutils:      2.27-r1::gentoo
sys-devel/gcc:           6.4.0::gentoo
sys-devel/gcc-config:    1.8-r1::gentoo
sys-devel/libtool:       2.4.6-r4::gentoo
sys-devel/make:          4.2.1-r1::gentoo
sys-freebsd/freebsd-lib: 10.3-r3::gentoo (virtual/os-headers)
Repositories:

gentoo
    location: /usr/portage
    sync-type: rsync
    sync-uri: rsync://rsync.gentoo.org/gentoo-portage
    priority: -1000

localrepo
    location: /usr/local/portage
    masters: gentoo

ACCEPT_KEYWORDS="amd64-fbsd ~amd64-fbsd"
ACCEPT_LICENSE="* -@EULA"
CBUILD="x86_64-gentoo-freebsd10.3"
CFLAGS="-O2 -pipe"
CHOST="x86_64-gentoo-freebsd10.3"
CONFIG_PROTECT="/boot/device.hints /etc"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/terminfo"
CXXFLAGS="-O2 -pipe"
DISTDIR="/usr/portage/distfiles"
FCFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-logs chflags config-protect-if-modified distlocks ebuild-locks fixlafiles merge-sync multilib-strict news parallel-fetch preserve-libs protect-owned sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersync"
FFLAGS="-O2 -pipe"
GENTOO_MIRRORS="https://mirrors.tuna.tsinghua.edu.cn/gentoo"
INSTALL_MASK="/usr/lib/systemd"
LDFLAGS=""
MAKEOPTS="-j4"
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="acl amd64-fbsd berkdb bindist cracklib crypt cxx dri gdbm iconv ipv6 modules multilib ncurses nls oss pam pcre readline ssl tcpd unicode xattr zlib" ABI_X86="64" 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="mmx mmxext sse sse2" ELIBC="FreeBSD" 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="keyboard mouse" KERNEL="FreeBSD" 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="BSD" VIDEO_CARDS="apm ark chips cirrus cyrix dummy i128 intel mach64 mga nv r128 radeon rendition s3 s3virge savage siliconmotion sis tga trident tseng fbdev" 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, LANG, LC_ALL, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 1 Kristian Fiskerstrand (RETIRED) gentoo-dev 2017-09-01 07:14:32 UTC
(In reply to i from comment #0)
> Created attachment 491126 [details]
> build.log ffor libgcrypt
> 
> I'm using the default -O2. With GCC the package builds fine, but not with
> clang. If I set CFLAGS="-O0 -pipe" in /etc/portage/env explicitly for this
> package it builds successfully with clang.

On first look this seems like an issue that should be resolved with upstream on https://dev.gnupg.org . 

Libgcrypt uses a gcc pragma that clang doesn't know to force O0
/var/tmp/portage/dev-libs/libgcrypt-1.8.1/work/libgcrypt-1.8.1/random/jitterentropy-base.c:53:13: warning: unknown pragma ignored [-Wunknown-pragmas]
#pragma GCC optimize ("O0")

and then asserts 
/var/tmp/portage/dev-libs/libgcrypt-1.8.1/work/libgcrypt-1.8.1/random/jitterentropy-base.c:60:4: error: "The CPU Jitter random number generator must not be compiled with optimizations. See documentation. Use the compiler switch -O0 for compiling jitterentropy-base.c."
  #error "The CPU Jitter random number generator must not be compiled with optimizations. See documentation. Use the compiler switch -O0 for compiling jitterentropy-base.c."
   ^
1 warning and 1 error generated.

So the behavior is exactly as upstream intends when trying to use -02 for this snippet of code.
Comment 2 Kristian Fiskerstrand (RETIRED) gentoo-dev 2017-09-01 07:54:08 UTC
(In reply to Kristian Fiskerstrand from comment #1)
> (In reply to i from comment #0)
> > Created attachment 491126 [details]
> > build.log ffor libgcrypt
> > 
> > I'm using the default -O2. With GCC the package builds fine, but not with
> > clang. If I set CFLAGS="-O0 -pipe" in /etc/portage/env explicitly for this
> > package it builds successfully with clang.
> 
> On first look this seems like an issue that should be resolved with upstream
> on https://dev.gnupg.org . 
> 
> Libgcrypt uses a gcc pragma that clang doesn't know to force O0
> /var/tmp/portage/dev-libs/libgcrypt-1.8.1/work/libgcrypt-1.8.1/random/
> jitterentropy-base.c:53:13: warning: unknown pragma ignored
> [-Wunknown-pragmas]
> #pragma GCC optimize ("O0")

fwiw, a viable alternative to using this pragma for clang might be the optnone function attribute, iirc gcc's equivalent is optimize( 0 ) since 4.4 if wanting consistency. Would in any case require a fallback to the pragma behavior for older gcc versions.

But downstream is not the place to do this, as messing with the rng is scary enough and validation of the output is necessary.
Comment 3 Kristian Fiskerstrand (RETIRED) gentoo-dev 2017-09-01 08:33:29 UTC
This issue is already reported upstream at https://dev.gnupg.org/T3293
Comment 4 Fabian Groffen gentoo-dev 2017-12-18 07:28:02 UTC
and this https://dev.gnupg.org/T1431
Comment 5 Fabian Groffen gentoo-dev 2017-12-18 07:28:35 UTC
*** Bug 640468 has been marked as a duplicate of this bug. ***
Comment 6 Fabian Groffen gentoo-dev 2017-12-18 07:31:05 UTC
-fhenious-gnu-extensions doesn't work, so how about a
  tc-is-clang && replace-flags -O* -O0
for the time being in src_configure?  This works for me.
Comment 7 Fabian Groffen gentoo-dev 2017-12-18 07:31:56 UTC
(cc-ing relevant teams)
Comment 8 Kristian Fiskerstrand (RETIRED) gentoo-dev 2017-12-18 20:56:42 UTC
(In reply to Fabian Groffen from comment #6)
> -fhenious-gnu-extensions doesn't work, so how about a
>   tc-is-clang && replace-flags -O* -O0
> for the time being in src_configure?  This works for me.

Why not provide a patch upstream with the necessary changes to make it work with clang c.f comment 2?
Comment 9 Fabian Groffen gentoo-dev 2017-12-19 07:57:22 UTC
I have nothing against that, but as I don't have time to look into that (I have no idea what needs to be done, this is just a clumpsy workaround that unbreaks this package, which is a good and cheap tradeoff between user seeing a package that doesn't compile and user not getting as much optimisation he/she asked for.
Comment 10 Vladimir Smirnov (RETIRED) gentoo-dev 2018-01-12 09:55:15 UTC
Upstream supports an option '--enable-O-flag-mangling', configure-time. The only thing it do - it disables '-O*' (just seds it out) for sensitive places (rng, cipher), but it's explicitly disabled in our ebuild.
Comment 11 Kristian Fiskerstrand (RETIRED) gentoo-dev 2018-01-13 13:00:44 UTC
(In reply to Vladimir Smirnov from comment #10)
> Upstream supports an option '--enable-O-flag-mangling', configure-time. The
> only thing it do - it disables '-O*' (just seds it out) for sensitive places
> (rng, cipher), but it's explicitly disabled in our ebuild.

That idea I like :) I've added a use-flag for it instead of hardcoding the disable in 1.8.2-r1
Comment 12 Larry the Git Cow gentoo-dev 2018-01-13 13:01:12 UTC
The bug has been referenced in the following commit(s):

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

commit 09bbba541c60d161e6c164312372cddb9d04f6c7
Author:     Kristian Fiskerstrand <k_f@gentoo.org>
AuthorDate: 2018-01-13 12:58:54 +0000
Commit:     Kristian Fiskerstrand <k_f@gentoo.org>
CommitDate: 2018-01-13 12:59:46 +0000

    dev-libs/libgcrypt: Add use-flag for o-flag-mangling
    
    Bug: https://bugs.gentoo.org/629410
    
    Package-Manager: Portage-2.3.13, Repoman-2.3.3

 dev-libs/libgcrypt/libgcrypt-1.8.2-r1.ebuild | 77 ++++++++++++++++++++++++++++
 dev-libs/libgcrypt/metadata.xml              |  3 ++
 2 files changed, 80 insertions(+)}
Comment 13 Guilherme Amadio gentoo-dev 2018-03-13 16:41:48 UTC
(In reply to Larry the Git Cow from comment #12)
> The bug has been referenced in the following commit(s):
> 
> https://gitweb.gentoo.org/repo/gentoo.git/commit/
> ?id=09bbba541c60d161e6c164312372cddb9d04f6c7
> 
> commit 09bbba541c60d161e6c164312372cddb9d04f6c7
> Author:     Kristian Fiskerstrand <k_f@gentoo.org>
> AuthorDate: 2018-01-13 12:58:54 +0000
> Commit:     Kristian Fiskerstrand <k_f@gentoo.org>
> CommitDate: 2018-01-13 12:59:46 +0000
> 
>     dev-libs/libgcrypt: Add use-flag for o-flag-mangling
>     
>     Bug: https://bugs.gentoo.org/629410
>     
>     Package-Manager: Portage-2.3.13, Repoman-2.3.3
> 
>  dev-libs/libgcrypt/libgcrypt-1.8.2-r1.ebuild | 77
> ++++++++++++++++++++++++++++
>  dev-libs/libgcrypt/metadata.xml              |  3 ++
>  2 files changed, 80 insertions(+)}

@grobian, can you sync prefix, please? On Darwin I still only see 1.8.1. Maybe dropping the prefix version would be enough.
Comment 14 Larry the Git Cow gentoo-dev 2018-03-13 19:33:13 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=4d94d5305bd45ff7d8524603500aef9918b52ca8

commit 4d94d5305bd45ff7d8524603500aef9918b52ca8
Author:     Fabian Groffen <grobian@gentoo.org>
AuthorDate: 2018-03-13 19:31:57 +0000
Commit:     Fabian Groffen <grobian@gentoo.org>
CommitDate: 2018-03-13 19:31:57 +0000

    dev-libs/libgcrypt: sync, bug #629410
    
    Bug: https://bugs.gentoo.org/629410
    Package-Manager: Portage-2.3.18-prefix, Repoman-2.3.6

 dev-libs/libgcrypt/Manifest                  | 22 +------
 dev-libs/libgcrypt/libgcrypt-1.8.2-r2.ebuild | 86 ++++++++++++++++++++++++++++
 dev-libs/libgcrypt/metadata.xml              | 11 ++--
 3 files changed, 95 insertions(+), 24 deletions(-)}
Comment 15 Guilherme Amadio gentoo-dev 2018-03-13 21:16:06 UTC
Thanks! Works for me on prefix standalone (Linux) and on High Sierra. Closing.
Comment 16 Larry the Git Cow gentoo-dev 2018-04-11 22:47:40 UTC
The bug has been referenced in the following commit(s):

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

commit 0821fda75de8ca5548e1b9f5f055c96047f14e6f
Author:     Yuta Satoh <nigoro.dev@gmail.com>
AuthorDate: 2018-04-01 12:32:33 +0000
Commit:     Patrice Clement <monsieurp@gentoo.org>
CommitDate: 2018-04-11 22:47:19 +0000

    profiles/arch/amd64-fbsd/clang/package.use.force: add dev-libs/libgcrypt.
    
    If CC=clang, it requires the o-flag-munging flag to pass a compile phase.
    
    Bug: https://bugs.gentoo.org/629410
    Closes: https://github.com/gentoo/gentoo/pull/7766

 profiles/arch/amd64-fbsd/clang/package.use.force | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)}
Comment 17 Larry the Git Cow gentoo-dev 2022-04-16 19:35:10 UTC
The bug has been referenced in the following commit(s):

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

commit eadc4f710b6783d509cb6d9b2b5b475069e16391
Author:     Mike Gilbert <floppym@gentoo.org>
AuthorDate: 2022-04-16 19:32:25 +0000
Commit:     Mike Gilbert <floppym@gentoo.org>
CommitDate: 2022-04-16 19:34:26 +0000

    dev-libs/libgcrypt: always enable O-flag-munging
    
    Exposing this as a USE flag is mostly pointless, and results in silly
    bug reports from users who disable it by accident.
    
    Users can disable it using EXTRA_ECONF if so desired.
    
    Bug: https://bugs.gentoo.org/629410
    Bug: https://bugs.gentoo.org/707330
    Closes: https://bugs.gentoo.org/838472
    Signed-off-by: Mike Gilbert <floppym@gentoo.org>

 dev-libs/libgcrypt/libgcrypt-1.10.1.ebuild   | 3 +--
 dev-libs/libgcrypt/libgcrypt-1.8.8.ebuild    | 5 ++---
 dev-libs/libgcrypt/libgcrypt-1.8.9.ebuild    | 3 +--
 dev-libs/libgcrypt/libgcrypt-1.9.4-r1.ebuild | 3 +--
 dev-libs/libgcrypt/metadata.xml              | 1 -
 5 files changed, 5 insertions(+), 10 deletions(-)