Bug 220937

Summary: security/libgcrypt: warning: unknown pragma "#pragma GCC optimize" ignored => compile failure
Product: Ports & Packages Reporter: O. Hartmann <ohartmann>
Component: Individual Port(s)Assignee: Carlos J. Puga Medina <cpm>
Status: Closed FIXED    
Severity: Affects Many People CC: chris, ohartmann, thciobanu
Priority: --- Flags: cpm: maintainer-feedback+
Version: Latest   
Hardware: Any   
OS: Any   
URL: https://dev.gnupg.org/T3293
Attachments:
Description Flags
patch cpm: maintainer-approval+

Description O. Hartmann 2017-07-23 09:09:38 UTC
The recent update of port security/libgcrypt to version 1.8.0 reveals an error on 12-CURRENT using LLVM 4.0.0 and LLVM 5.0.0 (no LLVM LLD used!):


[...]
libtool: compile:  cc -DHAVE_CONFIG_H -I. -I.. -I../src -I../src -I/usr/local/include -O0 -pipe -O3 -fstack-protector -fno-strict-aliasing -std=gnu89 -fvisibility=hidden -Wall -c ./rndjent.c  -fPIC -DPIC -o .libs/rndjent.o
In file included from ./rndjent.c:86:
./jitterentropy-base.c:53:13: warning: unknown pragma ignored [-Wunknown-pragmas]
#pragma GCC optimize ("O0")
            ^
./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.
*** [rndjent.lo] Error code 1

make[4]: stopped in /usr/ports/security/libgcrypt/work/libgcrypt-1.8.0/random
--- random-system.lo ---
Comment 1 Carlos J. Puga Medina freebsd_committer freebsd_triage 2017-07-23 09:29:02 UTC
I'll take a look.

Thanks for reporting!
Comment 2 Carlos J. Puga Medina freebsd_committer freebsd_triage 2017-07-23 10:27:15 UTC
Please, try the following patch

--- random/jitterentropy-base.c.orig    2017-07-23 10:26:06 UTC
+++ random/jitterentropy-base.c
@@ -51,6 +51,7 @@
 
 #undef _FORTIFY_SOURCE
 #pragma GCC optimize ("O0")
+#pragma clang optimize off
 
 #include "jitterentropy.h"
Comment 3 Carlos J. Puga Medina freebsd_committer freebsd_triage 2017-07-23 19:09:05 UTC
(In reply to Carlos J. Puga Medina from comment #2)

No need for a patch.

libgcrypt 1.8.0 builds fine with LLVM 5.0 (FreeBSD 12.0-CURRENT r321380)

Log: http://sprunge.us/GiKd
Comment 4 Carlos J. Puga Medina freebsd_committer freebsd_triage 2017-07-23 19:10:22 UTC
(In reply to O. Hartmann from comment #0)

(In reply to Carlos J. Puga Medina from comment #3)

It also builds fine with LLVM 4.0
Comment 5 Carlos J. Puga Medina freebsd_committer freebsd_triage 2017-07-23 19:20:44 UTC
(In reply to O. Hartmann from comment #0)

Would you mind show me the following output?

cd /usr/ports/security/libgcrypt && make -V CFLAGS
Comment 6 Christian Ullrich 2017-07-24 06:45:46 UTC
Hi, another of the "affects many people" here.

# make -V CFLAGS
-O -pipe -march=haswell  -fstack-protector -fno-strict-aliasing -std=gnu89
# fgrep CFLAGS /etc/make.conf
CFLAGS= -O -pipe

Also, no, it does not build with llvm 4.0, or at least not with clang 4.0.0 from stable/11 as of 11 days ago.

> Log: http://sprunge.us/GiKd

503 Over Quota
Comment 7 Christian Ullrich 2017-07-24 08:43:49 UTC
(In reply to Christian Ullrich from comment #6)

The machinery that libgcrypt uses to fix the optimization flags for the files they want built unoptimized is wrong:

$ echo "cc -O -O2 -foo" | sed -e 's/-O\([1-9s][1-9s]*\)/-O0/' -e 's/-Ofast/-O0/g'
cc -O -O0 -foo

IOW, it it not aware that plain "-O" exists. I have updated your gnupg bug report; perhaps they will actually fix that.
Comment 8 Carlos J. Puga Medina freebsd_committer freebsd_triage 2017-07-24 10:01:04 UTC
(In reply to Christian Ullrich from comment #6)

It is not recommended to override the CFLAGS defaults from /etc/make.conf

CFLAGS= -O -pipe

You should remove that line.
Comment 9 Carlos J. Puga Medina freebsd_committer freebsd_triage 2017-07-24 10:10:20 UTC
Again, don't muck about with CFLAGS or CPUTYPE variables. You're more likely to do harm than good. For the most part everything already uses their most "optimal" compiler flags.

-O -pipe -march=haswell
Comment 10 Carlos J. Puga Medina freebsd_committer freebsd_triage 2017-07-24 11:33:39 UTC
Created attachment 184660 [details]
patch

Add patch to disable support for the Jitter entropy collector
Comment 11 Carlos J. Puga Medina freebsd_committer freebsd_triage 2017-07-24 12:34:48 UTC
Another possible solution is to fix the command line munging for jitterbase

@@ -40,6 +43,7 @@
 post-patch:
 	@${RM} ${WRKSRC}/doc/gcrypt.info*
 	@${REINPLACE_CMD} -e 's|ALIGN (3)|ALIGN (2)|g' ${WRKSRC}/mpi/i386/*.S
+	@${REINPLACE_CMD} -e 's|-O0/'\''|-O0/g'\''|g' ${WRKSRC}/random/Makefile.am
Comment 12 O. Hartmann 2017-07-25 16:20:50 UTC
(In reply to Carlos J. Puga Medina from comment #5)
-O2 -pipe  -O3 -fstack-protector -fno-strict-aliasing -std=gnu89
Comment 13 O. Hartmann 2017-07-25 16:25:44 UTC
I see where the problem lies and reverted -O3 to -O2. Now the port comples. :-/

Thanks for taking care of.
Comment 14 thciobanu 2017-07-29 09:48:43 UTC
(In reply to Carlos J. Puga Medina from comment #11)

I came across this issue as well recently. I was able to get the port to compile by applying this patch with a small modification: I used `Makefile.*` instead of `Makefile.am`.
Comment 15 commit-hook freebsd_committer freebsd_triage 2017-08-01 12:10:33 UTC
A commit references this bug:

Author: cpm
Date: Tue Aug  1 12:10:14 UTC 2017
New revision: 447018
URL: https://svnweb.freebsd.org/changeset/ports/447018

Log:
  - Fix the command line munging for jitterbase

  PR:		220937
  Reported by:	O. Hartmann <ohartmann@walstatt.org>
  Obtained from:	https://dev.gnupg.org/rCac39522ab08fcd2483edc223334c6ab9d19e91f3
  MFH:		2017Q3 (blanket)

Changes:
  head/security/libgcrypt/Makefile
Comment 16 commit-hook freebsd_committer freebsd_triage 2017-08-01 12:22:45 UTC
A commit references this bug:

Author: cpm
Date: Tue Aug  1 12:21:46 UTC 2017
New revision: 447019
URL: https://svnweb.freebsd.org/changeset/ports/447019

Log:
  MFH: r447018

  - Fix the command line munging for jitterbase

  PR:		220937
  Reported by:	O. Hartmann <ohartmann@walstatt.org>
  Obtained from:	https://dev.gnupg.org/rCac39522ab08fcd2483edc223334c6ab9d19e91f3

  Approved by:	ports-secteam (blanket)

Changes:
_U  branches/2017Q3/
  branches/2017Q3/security/libgcrypt/Makefile