Page MenuHome GnuPG

libgcrypt-1.10.3 build failure on x86 with -Og
Testing, NormalPublic

Description

Originally reported downstream in Gentoo at https://bugs.gentoo.org/915060 when building libgcrypt-1.10.{2,3} with -Og on x86.

$ ./configure --host=i686-pc-linux-gnu CFLAGS="-Og" CC="gcc -m32"
[...]
$ make
make[2]: Entering directory '/tmp/libgcrypt/libgcrypt-1.10.3/mpi'
/bin/sh ../libtool  --tag=CC   --mode=compile gcc -m32 -DHAVE_CONFIG_H -I. -I..  -I../src -I../src   -Og -fvisibility=hidden -fno-delete-null-pointer-checks -Wall -MT ec-nist.lo -MD -MP -MF .deps/ec-nist.Tpo -c -o ec-nist.lo ec-nist.c
libtool: compile:  gcc -m32 -DHAVE_CONFIG_H -I. -I.. -I../src -I../src -Og -fvisibility=hidden -fno-delete-null-pointer-checks -Wall -MT ec-nist.lo -MD -MP -MF .deps/ec-nist.Tpo -c ec-nist.c  -fPIC -DPIC -o .libs/ec-nist.o
In file included from ec-nist.c:34:
ec-nist.c: In function '_gcry_mpi_ec_nist256_mod':
ec-inline.h:701:3: error: 'asm' operand has impossible constraints or there are not enough registers
  701 |   __asm__ ("subl %11, %3\n" \
      |   ^~~~~~~
ec-inline.h:894:9: note: in expansion of macro 'SUB4_LIMB32'
  894 |         SUB4_LIMB32(A1.hi, A1.lo, A0.hi, A0.lo, \
      |         ^~~~~~~~~~~
ec-inline.h:1009:5: note: in expansion of macro 'SUB2_LIMB64'
 1009 |     SUB2_LIMB64(A4, A3, B4, B3, C4, C3); \
      |     ^~~~~~~~~~~
ec-nist.c:474:3: note: in expansion of macro 'SUB5_LIMB64'
  474 |   SUB5_LIMB64 (s[4], s[3], s[2], s[1], s[0],
      |   ^~~~~~~~~~~
make[2]: *** [Makefile:658: ec-nist.lo] Error 1
make[2]: Leaving directory '/tmp/libgcrypt/libgcrypt-1.10.3/mpi'

Details

Event Timeline

Thank you for your report.

It is understandable. Register pressure is too high in the expressions, so, it requires higher optimization level.

Given the situation where there is no good way for source code to know the optimization level, things that we could do here is:

  • Adding detection of __OPTIMIZE__ macro in the #if/#endif
    • this could work well when it is compiled without -O, or with -O0

But it doesn't work with -O, -O1 or -Og,

Attached patch should workaround the issue:

@jukivili Thanks a lot. Please push the change to 1.10 branch and master.

gniibe changed the task status from Open to Testing.Dec 19 2023, 12:44 AM

It looks that this is a bit more problematic case than I thought. Now building i386 with "-O2 -fsanitize=undefined" flags fails. I need to think little bit more how to handle this.

Fix for i386 assembly pushed to master and 1.10 branch.