bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* Make fnstcw work with emscripten
@ 2019-10-12 12:34 Diomidis Spinellis
  2019-10-13  0:21 ` Bruno Haible
  0 siblings, 1 reply; 3+ messages in thread
From: Diomidis Spinellis @ 2019-10-12 12:34 UTC (permalink / raw)
  To: bug-gnulib

When glibc is compiled with emscripten toolchain for compiling to asm.js 
and WebAssembly [1] (e.g. as part of groff), the compilation fails due 
to the inclusion of assembly code, as shown in the example below.

emcc groff.bc -o groff.html
In function vasnprintf()
void (i16*)* asm sideeffect "fnstcw $0", "=*m"
LLVM ERROR: asm() with non-empty content not supported, use EM_ASM() 
(see emscripten.h)

The following small change corrects this problem.

--- a/lib/fpucw.h  2019-10-12 15:27:25.810899880 +0300
+++ b/lib/fpucw.h 2019-10-12 14:25:30.875463263 +0300
@@ -62,7 +62,7 @@
   */

  /* Inline assembler like this works only with GNU C.  */
-#if (defined __i386__ || defined __x86_64__) && defined __GNUC__
+#if (defined __i386__ || defined __x86_64__) && defined __GNUC__ && 
!defined __EMSCRIPTEN__

  typedef unsigned short fpucw_t; /* glibc calls this fpu_control_t */


[1] https://emscripten.org/


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Make fnstcw work with emscripten
  2019-10-12 12:34 Make fnstcw work with emscripten Diomidis Spinellis
@ 2019-10-13  0:21 ` Bruno Haible
  2019-10-13  6:23   ` Diomidis Spinellis
  0 siblings, 1 reply; 3+ messages in thread
From: Bruno Haible @ 2019-10-13  0:21 UTC (permalink / raw)
  To: bug-gnulib; +Cc: Diomidis Spinellis

Hi Diomidis,

> When glibc is compiled with emscripten toolchain for compiling to asm.js 
> and WebAssembly [1] (e.g. as part of groff),

You mean gnulib, not glibc? glibc is not built when you compile groff.

> the compilation fails due 
> to the inclusion of assembly code, as shown in the example below.
> 
> emcc groff.bc -o groff.html
> In function vasnprintf()
> void (i16*)* asm sideeffect "fnstcw $0", "=*m"
> LLVM ERROR: asm() with non-empty content not supported, use EM_ASM() 
> (see emscripten.h)
> 
> The following small change corrects this problem.
> 
> --- a/lib/fpucw.h  2019-10-12 15:27:25.810899880 +0300
> +++ b/lib/fpucw.h 2019-10-12 14:25:30.875463263 +0300
> @@ -62,7 +62,7 @@
>    */
> 
>   /* Inline assembler like this works only with GNU C.  */
> -#if (defined __i386__ || defined __x86_64__) && defined __GNUC__
> +#if (defined __i386__ || defined __x86_64__) && defined __GNUC__ && 
> !defined __EMSCRIPTEN__
> 
>   typedef unsigned short fpucw_t; /* glibc calls this fpu_control_t */

This indicates that in the compilation, at this point, either the macro
__i386__ or __x86_64__ is defined as a preprocessor macro.

When you run
  $ touch empty.c; emcc -E -dM empty.c |grep '\(i386\|x86_64\)'
does is display such macro definitions?

If yes, your emcc compiler is misconfigured. For me, it does not
define __i386__ or __x86_64__; it defines __asmjs__ instead.

If not, it means that some file defines __i386__ or __x86_64__
during the compilation. But application files should not do this.
In this case, your groff.bc (or one of the files that it includes
directly or indirectly) is buggy.

Bruno



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Make fnstcw work with emscripten
  2019-10-13  0:21 ` Bruno Haible
@ 2019-10-13  6:23   ` Diomidis Spinellis
  0 siblings, 0 replies; 3+ messages in thread
From: Diomidis Spinellis @ 2019-10-13  6:23 UTC (permalink / raw)
  To: Bruno Haible, bug-gnulib

Hi Bruno,

On 13-Oct-19 3:21, Bruno Haible wrote:
>> When glibc is compiled with emscripten toolchain for compiling to asm.js
>> and WebAssembly [1] (e.g. as part of groff),
> 
> You mean gnulib, not glibc? glibc is not built when you compile groff.

Yes, I meant gnulib.

>> the compilation fails due
>> to the inclusion of assembly code, as shown in the example below.
[...]
> When you run
>    $ touch empty.c; emcc -E -dM empty.c |grep '\(i386\|x86_64\)'
> does is display such macro definitions?
> 
> If yes, your emcc compiler is misconfigured. For me, it does not
> define __i386__ or __x86_64__; it defines __asmjs__ instead.

Indeed I verified that emcc on its own defines __asmjs__, not __i386__ 
or __x86_64__.

> If not, it means that some file defines __i386__ or __x86_64__
> during the compilation. But application files should not do this.
> In this case, your groff.bc (or one of the files that it includesE
> directly or indirectly) is buggy.

By running gcc on lib/vasnprintf.c with the same flags as emcc (as shown 
with emmake make V=1) plus -E -fdirectives-only I found that groff's 
src/include/config.h defines __i386__.

#ifndef __i386__
#define __i386__ 1
#endif

Removing the definition fixes the problem.  So it's a bug of emconfigure 
or groff's autoconf.

Many thanks,

Diomidis


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-10-13  6:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-12 12:34 Make fnstcw work with emscripten Diomidis Spinellis
2019-10-13  0:21 ` Bruno Haible
2019-10-13  6:23   ` Diomidis Spinellis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).