Page MenuHome GnuPG

libgcrypt: warning: unknown pragma "#pragma GCC optimize" ignored => compile failure with LLVM 5.0
Closed, ResolvedPublic

Description

Libgcrypt 1.8.0 reveals an error on FreeBSD 12-CURRENT using 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 ---

Event Timeline

cpm set External Link to https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=220937.Jul 23 2017, 9:37 PM
werner added projects: libgcrypt, clang.

The warning is just a warning, so no problem. The pragma even indicates the compiler for which it is intended.

I wonder how the -O3 slipped into the compiler command. Afaics this might be due to an -O2 or so in the original command line. Do you use extra CFLAGS? Anyway, the sed script can be improved. Fix pushed.

Workaround would be

configure --disable-jent-support

The fixed sed expression still does not work correctly; it misses the plain "-O" form of the option. As per gcc docs, -O is the same as -O1, and clang accepts it (and the build falls over with it) even though it does not document it at all.

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

Why isn't the sed expression simply 's/-O\([1-9s]*|fast\)/-O0/g' ? The specter of compatibility raising its head?

cpm claimed this task.

It's solved!

Thanks, Werner

No, it's not. It still misses "-O" entirely.