I assumed I could compile simple programs, since I had done so quite recently, 
but apparently not.  After some more digging I discovered that the issue was a 
misconfigured emscripten install — I had multiple copies of the portable SDK 
around, and was trying to use one of them with the other activated.  I can now 
build, and run the following:

#include<gc.h>
#include <stdio.h>

int main() {
    GC_INIT();
    printf("Successfully init'ed GC\n");
    for (int i = 0; i < 100; i++) {
        void* v = GC_malloc(1024*1024*1);
    }
    GC_gcollect();
    printf("Successfully alloc'ed a lot of memory, and forced collection\n");
    return 0;
}

With

emcc -I $OUTPUT/lib/libgc.dylib boehm.c -s NO_EXIT_RUNTIME=1

But now I’m stuck on a new compiler crash for the code I’m actually trying to 
compile, which uses uses variadic struct arguments, and the workaround 
suggested 
here<http://kripken.github.io/emscripten-site/docs/getting_started/FAQ.html#why-do-i-get-error-cannot-compile-this-aggregate-va-arg-expression-yet-and-it-says-compiler-frontend-failed-to-generate-llvm-bitcode-halting-afterwards>
 yields:

$ emcc -I $OUTPUT/include/ $OUTPUT/lib/libgc.dylib boehm.c -s NO_EXIT_RUNTIME=1
boehm.c:11:25: error: cannot compile this aggregate va_arg expression yet
        printf("%d\n", (va_arg(ap, t)).f);
                        ^~~~~~~~~~~~~
.../emsdk/emscripten/1.25.0/system/include/libc/stdarg.h:15:25: note:
      expanded from macro 'va_arg'
#define va_arg(v,l)     __builtin_va_arg(v,l)
                        ^~~~~~~~~~~~~~~~~~~~~
1 error generated.
ERROR    root: compiler frontend failed to generate LLVM bitcode, halting
$ EMCC_LLVM_TARGET=i386-pc-linux-gnu emcc -I $OUTPUT/include/ 
$OUTPUT/lib/libgc.dylib boehm.c -s NO_EXIT_RUNTIME=1
Exception in thread Thread-3:
Traceback (most recent call last):
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py",
 line 808, in __bootstrap_inner
    self.run()
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py",
 line 761, in run
    self.__target(*self.__args, **self.__kwargs)
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/pool.py",
 line 376, in _handle_results
    task = get()
TypeError: ('__init__() takes at least 3 arguments (1 given)', <class 
'subprocess.CalledProcessError'>, ())

^\Quit: 3
$

I have to use ^\ to kill it, or I just get a long stack trace from a keyboard 
interrupt

The test code to produce the error above is:

#include<gc.h>
#include <stdio.h>
#include<stdarg.h>

typedef struct { int f; } t;

void many_ts(int count, ...) {
    va_list ap;
    int i = 0;
    for (i = 0; i < count; i++) {
        printf("%d\n", (va_arg(ap, t)).f);
    }
}

int main() {
    GC_INIT();
    printf("Successfully init'ed GC\n");
    for (int i = 0; i < 100; i++) {
        void* v = GC_malloc(1024*1024*1);
    }
    GC_gcollect();
    printf("Successfully alloc'ed a lot of memory, and forced collection\n");
    return 0;
}

I also tried without the GC code and libraries, and the same crash occurs:

#include <stdio.h>
#include<stdarg.h>

typedef struct { int f; } t;

void many_ts(int count, ...) {
    va_list ap;
    int i = 0;
    for (i = 0; i < count; i++) {
        printf("%d\n", (va_arg(ap, t)).f);
    }
}

int main() {
    printf("hello\n");
    return 0;
}

for
$ EMCC_LLVM_TARGET=i386-pc-linux-gnu emcc testhello.c -s NO_EXIT_RUNTIME=1

Is there another known workaround for structs as variadic arguments?  Or do I 
need to rewrite the code to pass non-aggregates to the variadic functions?

Thanks,
Colin


From: Alon Zakai <[email protected]<mailto:[email protected]>>
Reply-To: 
"[email protected]<mailto:[email protected]>"
 
<[email protected]<mailto:[email protected]>>
Date: Thursday, November 6, 2014 at 4:49 PM
To: 
"[email protected]<mailto:[email protected]>"
 
<[email protected]<mailto:[email protected]>>
Subject: Re: Trouble with emscripten support in official Boehm GC?

Is this Boehm specific? Can you build a trivial hello world?

- Alon


On Thu, Nov 6, 2014 at 2:15 PM, Colin Gordon 
<[email protected]<mailto:[email protected]>> wrote:
Hi everyone,

I’ve been trying to build the trunk version of the Boehm GC using emscripten, 
which now appears to be an officially supported platform based on some of the 
change sets from the last few months (some work was upstreamed from Unity).  
Has anyone had success in doing this?  I’ve managed to produce a compiled 
library of LLVM bit code with the emscripten target triple, but attempting to 
link even a trivial program against it causes emcc to crash.

I’ve asked about this on the Boehm GC mailing list with no luck.

I modified the standard Boehm build instructions according to standard 
emscripten practice and based on the changes to the GC library itself:

autoreconf -vif
automake --add-missing
emconfigure ./configure --prefix=$OUTPUT --without-threads --disable-threads 
__EMSCRIPTEN__=1 EMSCRIPTEN=1
emmake make
make install

This produces an LLVM bitcode file in $OUTPUT/lib/libgc.dylib (OS X 10.9.5) 
which, when disassembled, appears to contain the relevant symbols, code, and 
the target triple asmjs-unknown-emscripten.  But linking even a minimal program 
against this cases emcc (from the portable SDK, I’ve tried 1.22 and 1.25) to 
fail.

Example program:

#include<gc.h>
int main() {
    GC_INIT(); // Initialize the GC allocator
    return 0;
}

Compiled via:
emcc –g –I $OUTPUT/include –L$(OUTPUT)/lib –lgc boehm.c

Produces:
fs.js:427
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^
Error: ENOENT, no such file or directory '--'
    at Object.fs.openSync (fs.js:427:18)
    at Object.fs.readFileSync (fs.js:284:15)
    at read (.../external/emsdk/emscripten/1.22.0/src/compiler.js:57:34)
    at Object.<anonymous> 
(.../external/emsdk/emscripten/1.22.0/src/compiler.js:145:29)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
Traceback (most recent call last):
  File ".../external/emsdk/emscripten/1.22.0/emscripten.py", line 1490, in 
<module>
    _main(environ=os.environ)
  File ".../external/emsdk/emscripten/1.22.0/emscripten.py", line 1478, in _main
    temp_files.run_and_clean(lambda: main(
  File ".../external/emsdk/emscripten/1.22.0/tools/tempfiles.py", line 39, in 
run_and_clean
    return func()
  File ".../external/emsdk/emscripten/1.22.0/emscripten.py", line 1486, in 
<lambda>
    DEBUG_CACHE=DEBUG_CACHE,
  File ".../external/emsdk/emscripten/1.22.0/emscripten.py", line 1373, in main
    jcache=jcache, temp_files=temp_files, DEBUG=DEBUG, DEBUG_CACHE=DEBUG_CACHE)
  File ".../external/emsdk/emscripten/1.22.0/emscripten.py", line 861, in 
emscript_fast
    cwd=path_from_root('src'), error_limit=300)
  File ".../external/emsdk/emscripten/1.22.0/tools/jsrun.py", line 43, in run_js
    raise Exception('Expected the command ' + str(command) + ' to finish with 
return code ' + str(assert_returncode) + ', but it returned with code ' + 
str(proc.returncode) + ' instead! Output: ' + str(ret)[:error_limit])
Exception: Expected the command 
['.../external/emsdk/node/0.10.18_64bit/bin/node', 
'.../external/emsdk/emscripten/1.22.0/src/compiler.js', '--', 
'/var/folders/nx/_cvrfktd5cs5h3ktk6v3z310qn9lg1/T/tmp6TBpfX.txt', ';', 'glue'] 
to finish with return code 0, but it returned with code 8 instead! Output:
Traceback (most recent call last):
  File "external/emsdk/emscripten/1.22.0/emcc", line 1642, in <module>
    final = shared.Building.emscripten(final, append_ext=False, 
extra_args=extra_args)
  File ".../external/emsdk/emscripten/1.22.0/tools/shared.py", line 1464, in 
emscripten
    assert os.path.exists(filename + '.o.js'), 'Emscripten failed to generate 
.js'
AssertionError: Emscripten failed to generate .js

A very similar stack trace showed up in another recent mail to this list 
(https://groups.google.com/forum/#!topic/emscripten-discuss/Wn6YnoHu9XQ).

Has anyone had more success than this?  Am I missing another 
emscripten-specific build tweak?

Thanks in advance,
Colin

--
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
[email protected]<mailto:[email protected]>.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
[email protected]<mailto:[email protected]>.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to