View Issue Details

IDProjectCategoryView StatusLast Update
0003836Talerwallet (WebExtension)public2019-12-26 21:37
ReporterMarcello Stanisci Assigned ToChristian Grothoff  
PriorityurgentSeveritymajorReproducibilityalways
Status closedResolutionfixed 
Platformemscripten1.33.2 + libgcrypt1.19 
Product Versiongit (master) 
Target Version0.0Fixed in Version0.0 
Summary0003836: unresolved symbol in libgcrypt
DescriptionWhen compiling and running the two tests in wallet_button/emscripten/hello_world/,
nodejs complains about the symbol _gcry_hwf_detect_x86 being unresolved.

The unresolved symbol (_gcry_hwf_detect_x86) is defined in src/hwf-x86.c
but it's not compiled in because we don't configure for 'normal' x86.
For some reason, a define called HAVE_CPU_ARCH_X86 gets set to 1, so in
src/hwfeatures.c a call to the undefined symbol does occur.


A stacktrace from nodejs follows:
 
 
 missing function: _gcry_hwf_detect_x86A stacktrace from nodejs follows:
 
 
 missing function: _gcry_hwf_detect_x86
 -1
 -1
 
 /home/marcello/Downloads/emscriptest/fancy.js:90
       throw ex;
             ^
 abort(-1) at Error
     at jsStackTrace (/home/marcello/Downloads/emscriptest/fancy.js:1165:13)
     at stackTrace (/home/marcello/Downloads/emscriptest/fancy.js:1182:22)
     at abort (/home/marcello/Downloads/emscriptest/fancy.js:204912:44)
     at __gcry_hwf_detect_x86 (/home/marcello/Downloads/emscriptest/fancy.js:7116:65)
     at __gcry_detect_hw_features (/home/marcello/Downloads/emscriptest/fancy.js:18882:8)
     at _global_init (/home/marcello/Downloads/emscriptest/fancy.js:12628:2)
     at __gcry_check_version (/home/marcello/Downloads/emscriptest/fancy.js:11014:2)
     at _gcry_check_version (/home/marcello/Downloads/emscriptest/fancy.js:10166:8)
     at _GNUNET_CRYPTO_random_init (/home/marcello/Downloads/emscriptest/fancy.js:10056:8)
     at asm._GNUNET_CRYPTO_random_init (/home/marcello/Downloads/emscriptest/fancy.js:202963:40)
TagsNo tags attached.
Attached Files
hwf-fix.diff (2,746 bytes)   
diff --git a/configure.ac b/configure.ac
index 0f16175..b472020 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2201,11 +2201,12 @@ AC_DEFINE_UNQUOTED(LIBGCRYPT_KDFS, "$tmp",
 # Note that all possible modules must also be listed in
 # src/Makefile.am (EXTRA_libgcrypt_la_SOURCES).
 #
-GCRYPT_HWF_MODULES=
+HAVE_X86=0
+HAVE_ARM=0
 case "$mpi_cpu_arch" in
      x86)
         AC_DEFINE(HAVE_CPU_ARCH_X86, 1,   [Defined for the x86 platforms])
-        GCRYPT_HWF_MODULES="hwf-x86.lo"
+        HAVE_X86=1
         ;;
      alpha)
         AC_DEFINE(HAVE_CPU_ARCH_ALPHA, 1, [Defined for Alpha platforms])
@@ -2224,10 +2225,11 @@ case "$mpi_cpu_arch" in
         ;;
      arm)
         AC_DEFINE(HAVE_CPU_ARCH_ARM, 1,   [Defined for ARM platforms])
-        GCRYPT_HWF_MODULES="hwf-arm.lo"
+        HAVE_ARM=1
         ;;
 esac
-AC_SUBST([GCRYPT_HWF_MODULES])
+AM_CONDITIONAL(HAVE_X86, test "$HAVE_X86" = "1")
+AM_CONDITIONAL(HAVE_ARM, test "$HAVE_ARM" = "1")
 
 
 #
diff --git a/src/Makefile.am b/src/Makefile.am
index cd0d354..ddf3536 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -61,10 +61,15 @@ libgcrypt_la_SOURCES = \
 	stdmem.c stdmem.h secmem.c secmem.h \
 	mpi.h missing-string.c fips.c \
 	hmac256.c hmac256.h context.c context.h \
-	ec-context.h
-
-EXTRA_libgcrypt_la_SOURCES = hwf-x86.c hwf-arm.c
-gcrypt_hwf_modules = @GCRYPT_HWF_MODULES@
+	ec-context.h $(GCRYPT_HWF_MODULES)
+if HAVE_ARM
+libgcrypt_la_SOURCES += \
+  hwf-arm.c
+endif
+if HAVE_X86
+libgcrypt_la_SOURCES += \
+  hwf-x86.c
+endif
 
 
 if HAVE_W32_SYSTEM
@@ -111,14 +116,12 @@ libgcrypt_la_LDFLAGS = $(no_undefined) $(export_symbols) $(extra_ltoptions) \
 	$(libgcrypt_version_script_cmd) -version-info \
 	@LIBGCRYPT_LT_CURRENT@:@LIBGCRYPT_LT_REVISION@:@LIBGCRYPT_LT_AGE@
 libgcrypt_la_DEPENDENCIES = \
-         $(gcrypt_hwf_modules) \
 	../cipher/libcipher.la \
 	../random/librandom.la \
 	../mpi/libmpi.la \
 	../compat/libcompat.la \
 	$(srcdir)/libgcrypt.vers $(gcrypt_deps)
 libgcrypt_la_LIBADD = $(gcrypt_res) \
-        $(gcrypt_hwf_modules) \
 	../cipher/libcipher.la \
 	../random/librandom.la \
 	../mpi/libmpi.la \
diff --git a/src/hwf-x86.c b/src/hwf-x86.c
index 399952c..a9a4c5f 100644
--- a/src/hwf-x86.c
+++ b/src/hwf-x86.c
@@ -28,9 +28,7 @@
 #include "g10lib.h"
 #include "hwf-common.h"
 
-#if !defined (__i386__) && !defined (__x86_64__)
-# error Module build for wrong CPU.
-#endif
+#if defined (__i386__) || defined (__x86_64__)
 
 /* We use the next macro to decide whether we can test for certain
    features.  */
@@ -308,3 +306,15 @@ _gcry_hwf_detect_x86 (void)
   return 0;
 #endif
 }
+
+
+#else
+/* __i386__ and __x86_64__ not defined, likely x86-emscripten */
+
+unsigned int
+_gcry_hwf_detect_x86 (void)
+{
+  return 0;
+}
+
+#endif
hwf-fix.diff (2,746 bytes)   
stack_trace (1,215 bytes)   
/home/marcello/wallet/wallet_button/emscripten/hello_world/fancy.js:90
      throw ex;
            ^
Assertion failed: !"sizeof lock obj", at: posix-lock.c,119,get_lock_object at Error
    at jsStackTrace (/home/marcello/wallet/wallet_button/emscripten/hello_world/fancy.js:1165:13)
    at stackTrace (/home/marcello/wallet/wallet_button/emscripten/hello_world/fancy.js:1182:22)
    at ___assert_fail (/home/marcello/wallet/wallet_button/emscripten/hello_world/fancy.js:5568:210)
    at _get_lock_object (/home/marcello/wallet/wallet_button/emscripten/hello_world/fancy.js:187371:3)
    at __gpgrt_lock_lock (/home/marcello/wallet/wallet_button/emscripten/hello_world/fancy.js:187282:8)
    at _gpgrt_lock_lock (/home/marcello/wallet/wallet_button/emscripten/hello_world/fancy.js:187218:8)
    at _lock_pool2655 (/home/marcello/wallet/wallet_button/emscripten/hello_world/fancy.js:182211:8)
    at _initialize (/home/marcello/wallet/wallet_button/emscripten/hello_world/fancy.js:182166:2)
    at __gcry_rngcsprng_initialize (/home/marcello/wallet/wallet_button/emscripten/hello_world/fancy.js:181782:3)
    at __gcry_random_initialize (/home/marcello/wallet/wallet_button/emscripten/hello_world/fancy.js:121435:5)
stack_trace (1,215 bytes)   
llvm-nm.libgcrypt (106,478 bytes)
gpgrt_lock.diff (389 bytes)   
diff --git a/src/posix-lock.c b/src/posix-lock.c
index 89be944..29f0f76 100644
--- a/src/posix-lock.c
+++ b/src/posix-lock.c
@@ -116,8 +116,8 @@ get_lock_object (gpgrt_lock_t *lockhd)
     }
   if (sizeof (gpgrt_lock_t) < sizeof (_gpgrt_lock_t))
     {
-      assert (!"sizeof lock obj");
-      abort ();
+     /* assert (!"sizeof lock obj");
+      abort (); */
     }
 
   return lock;
gpgrt_lock.diff (389 bytes)   

Relationships

related to 0003839 closedMarcello Stanisci Update Sphinx API/Documentation with instructions on how to build the final .xpi 

Activities

Christian Grothoff

2015-06-11 21:16

manager   ~0009265

The problem is that the build includes the hwf-x86.lo from the earlier gcc-build, and then emscripten just ignores the ".lo" (it ignores all libraries and treats the .lo as a normal "dynamic" library):

/bin/bash ../libtool --tag=CC --mode=link /home/grothoff/ems/emsdk_portable/emscripten/master/emcc -I/tmp/taler/include -fvisibility=hidden -Wall -Wl,--version-script=./libgcrypt.vers -version-info 21:0:1 -o libgcrypt.la -rpath /tmp/taler/lib libgcrypt_la-visibility.lo libgcrypt_la-misc.lo libgcrypt_la-global.lo libgcrypt_la-sexp.lo libgcrypt_la-hwfeatures.lo libgcrypt_la-stdmem.lo libgcrypt_la-secmem.lo libgcrypt_la-missing-string.lo libgcrypt_la-fips.lo libgcrypt_la-hmac256.lo libgcrypt_la-context.lo hwf-x86.lo ../cipher/libcipher.la ../random/librandom.la ../mpi/libmpi.la ../compat/libcompat.la -L/tmp/taler/lib -lgpg-error

A possible fix would seem to change the build system to not rely on some ".lo"-hack but to add the .c to the source set. I'll test that.

Christian Grothoff

2015-06-11 21:29

manager   ~0009266

I've uploaded hwf-fix.diff which (for me) would seem to fix the issue by:

1) instructing the build system to add hwf-x86.c to the SOURCES set (instead of adding hwf-x86.lo to the dependencies), thereby forcing it to be re-build when we switch the host.

2) fixing hwf-x86.c so that it compiles (emscripten claims to be x86, but doesn't set __x86__ or __x86_64__).

Christian Grothoff

2015-06-11 21:30

manager   ~0009267

Marcello: please confirm this works.

Werner: please review the patch if it is acceptable for libgcrypt.

dd9jn

2015-06-11 22:56

reporter   ~0009268

What is libgcrypt 1.19? If you took it from git master how do you got this version number?

dd9jn

2015-06-11 23:01

reporter   ~0009269

BTW, the CPU architecture is determined by mpi/config.links and thus by the cpu-vendor-os triplet. What's it in your case?

Christian Grothoff

2015-06-11 23:20

manager   ~0009270

We use --host=i386-emscripten-linux-gnu

Marcello Stanisci

2015-06-12 14:27

reporter   ~0009275

Yes, I was actually referring to libgcrypt 1.7 (commit a36ee7501f68ad7ebcfe31f9659430b9d2c3ddd1).

Unfortunately I get another error, you find attached both its output from nodejs ('stack_trace'), and the output from 'llvm-nm'
('llvm-nm.libgcrypt').
which shows the symbols belonging to libgcrypt.a (compiled in LLVM).

Assuming that hwf-fix.diff is under libgcrypt/, to apply the patch and run the test I do:

cd libgcrypt/
git apply hwf-fix.diff
./autogen.sh
./myconf-libgcrypt.sh

# then I recompile gnunet with ./myconf-libgnunetutil-taler_wallet.sh
# finally I rebuild the 'fancy.c' test in wallet_button/emscripten/hello_world/

Christian Grothoff

2015-06-12 14:36

manager   ~0009276

That's a run-time error, right - like when you run the resulting binary in a browser?

Marcello Stanisci

2015-06-12 14:50

reporter   ~0009277

If by 'binary' you mean the final HTML containing the JavaScript, I get just a black canvas when I compile the test with 'emcc ... -o fancy.html' and open it with Firefox.

Marcello Stanisci

2015-06-14 18:24

reporter   ~0009278

The runtime error should occur because emscripten uses his own system libraries,
among which there is pthread.h (and bits/alltypes.h) that in our case makes the condition:

if (sizeof (gpgrt_lock_t) < sizeof (_gpgrt_lock_t))

evaluate to true, thereby aborting the execution.
See function 'get_lock_object' at libgpg-error/src/posix-lock.c.

The attached diff, that is nothing but commenting out the call to 'abort()', makes the
execution of the mentioned tests completing fine; however, let's discuss for a wiser
solution!

dd9jn

2015-06-15 09:03

reporter   ~0009279

From my understanding you are targeting the wrong platform. emscripten does not target x86 but asm.js which is should be neither x86 nor arm. An older version of Libgcrypt was build by the emscripten project and according to a comment about NaCl they are targeting a CPU named le32 (little endian 32 bit). This makes a lot of sense to me because these properties are not specific to a certain platform.

Regarding the Mutex support: If you don't have threads that does not make sense at all. I suggest to first draw a plan on how to use Libgcrypt or GnuPG with asm.js before trying to solve problems based on other hacks.

Christian Grothoff

2015-06-15 10:00

manager   ~0009280

Ok, using "--host=asmjs-unknown-emscripten" seems to be what people suggest sometimes, I think that's better than calling the CPU "le32".

The use of 'x86' seems to be a hack used by people that don't want to modify configure(.ac) to properly support the platform, so not something we should propagate unnecessarily.

So what if we added explicit support for an 'emscripten' OS that doesn't have threads, and a CPU arch 'asmjs' that then obviously doesn't have cpuid()? Would that be fine with you, Werner? (Btw, I still think my patch should be considered, as it cleans up a hack in the build system with what I would view as a cleaner solution for conditionally compiling in some C sources.)

dd9jn

2015-06-15 10:40

reporter   ~0009281

Adding support for asm.js would be useful. We need to figure out some properties of that CPU, for example endianess and bit sizes.

dd9jn

2015-06-15 10:41

reporter   ~0009282

BTW, the 1.19 version number seems to be from libgpg-error.

I just push a change to libgpg-error which should now properly handle
--disable-threads. It is a different ABI, though.

dd9jn

2015-06-15 10:42

reporter   ~0009283

Oh weel, bit size is easy: Usually this is 1 :-)
I meant word sizes.

Christian Grothoff

2015-06-15 10:57

manager   ~0009284

$ emcc -Wall -Wextra -std=c11 sizeof.c -o sizeof.js
$ iojs sizeof.js
sizeof (char) = 1, alignof (char) == 1
sizeof (short) = 2, alignof (short) == 2
sizeof (int) = 4, alignof (int) == 4
sizeof (long) = 4, alignof (long) == 4
sizeof (long long) = 8, alignof (long long) == 8
sizeof (float) = 4, alignof (float) == 4
sizeof (double) = 8, alignof (double) == 8
sizeof (long double) = 8, alignof (long double) == 8
sizeof (size_t) = 4, alignof (size_t) == 4
sizeof (ptrdiff_t) = 4, alignof (ptrdiff_t) == 4
sizeof (wchar_t) = 4, alignof (wchar_t) == 4
sizeof (wint_t) = 4, alignof (wint_t) == 4
sizeof (div_t) = 8, alignof (div_t) == 4
sizeof (fpos_t) = 16, alignof (fpos_t) == 8
sizeof (time_t) = 4, alignof (time_t) == 4
sizeof (clock_t) = 4, alignof (clock_t) == 4
sizeof (struct tm) = 44, alignof (struct tm) == 4
sizeof (va_list) = 16, alignof (va_list) == 4
sizeof (mbstate_t) = 8, alignof (mbstate_t) == 4
sizeof (jmp_buf) = 156, alignof (jmp_buf) == 4
sizeof (struct lconv) = 56, alignof (struct lconv) == 4
sizeof (bool) = 1, alignof (bool) == 1
sizeof (intmax_t) = 8, alignof (intmax_t) == 8
sizeof (uintptr_t) = 4, alignof (uintptr_t) == 4
sizeof (float complex) = 8, alignof (float complex) == 4
sizeof (double complex) = 16, alignof (double complex) == 8
sizeof (long double complex) = 16, alignof (long double complex) == 8
sizeof (fenv_t) = 32, alignof (fenv_t) == 4
sizeof (fexcept_t) = 2, alignof (fexcept_t) == 2

Christian Grothoff

2015-06-15 10:58

manager   ~0009285

And I think you already wrote that it should be little-endian.

Christian Grothoff

2015-07-12 17:41

manager   ~0009424

Fixed in 776d97c..1cfaa85: the best method was to use

--host=asmjs-local-emscripten

That fixes the i386-issue of libgcrypt and works fine for everything else as well. Updated shell scripts are in Git.

Issue History

Date Modified Username Field Change
2015-06-11 20:02 Marcello Stanisci New Issue
2015-06-11 20:02 Marcello Stanisci Status new => assigned
2015-06-11 20:02 Marcello Stanisci Assigned To => Marcello Stanisci
2015-06-11 21:16 Christian Grothoff Note Added: 0009265
2015-06-11 21:28 Christian Grothoff File Added: hwf-fix.diff
2015-06-11 21:29 Christian Grothoff Note Added: 0009266
2015-06-11 21:30 Christian Grothoff Note Added: 0009267
2015-06-11 22:56 dd9jn Note Added: 0009268
2015-06-11 23:01 dd9jn Note Added: 0009269
2015-06-11 23:20 Christian Grothoff Note Added: 0009270
2015-06-12 13:49 Marcello Stanisci Relationship added related to 0003839
2015-06-12 14:19 Marcello Stanisci File Added: stack_trace
2015-06-12 14:20 Marcello Stanisci File Added: llvm-nm.libgcrypt
2015-06-12 14:27 Marcello Stanisci Note Added: 0009275
2015-06-12 14:36 Christian Grothoff Note Added: 0009276
2015-06-12 14:50 Marcello Stanisci Note Added: 0009277
2015-06-14 18:23 Marcello Stanisci File Added: gpgrt_lock.diff
2015-06-14 18:24 Marcello Stanisci Note Added: 0009278
2015-06-15 09:03 dd9jn Note Added: 0009279
2015-06-15 10:00 Christian Grothoff Note Added: 0009280
2015-06-15 10:40 dd9jn Note Added: 0009281
2015-06-15 10:41 dd9jn Note Added: 0009282
2015-06-15 10:42 dd9jn Note Added: 0009283
2015-06-15 10:57 Christian Grothoff Note Added: 0009284
2015-06-15 10:58 Christian Grothoff Note Added: 0009285
2015-06-18 13:48 Christian Grothoff Assigned To Marcello Stanisci => Christian Grothoff
2015-06-21 10:56 Christian Grothoff Product Version => git (master)
2015-06-21 10:56 Christian Grothoff Target Version => 0.0
2015-07-09 13:03 Christian Grothoff Priority high => normal
2015-07-11 23:12 Christian Grothoff Priority normal => high
2015-07-11 23:16 Christian Grothoff Priority high => urgent
2015-07-12 17:41 Christian Grothoff Note Added: 0009424
2015-07-12 17:41 Christian Grothoff Status assigned => resolved
2015-07-12 17:41 Christian Grothoff Fixed in Version => 0.0
2015-07-12 17:41 Christian Grothoff Resolution open => fixed
2015-07-24 09:29 Christian Grothoff Status resolved => closed
2019-12-26 21:37 Florian Dold Category wallet (browser-based) => wallet (WebExtensions)
2023-04-13 20:37 Florian Dold Category wallet (WebExtensions) => wallet (WebExtension)