Skip to content

Instantly share code, notes, and snippets.

=================================================================
==2342311==ERROR: AddressSanitizer: heap-use-after-free on address 0x6030004541e4 at pc 0x7ff218ebce95 bp 0x7ff1fe2bc850 sp 0x7ff1fe2bc848
READ of size 4 at 0x6030004541e4 thread T6
#0 0x7ff218ebce94 in wasm::Type::isTuple() const (/bin/../lib/libbinaryen.so+0x125e0e94)
#1 0x7ff218fa852b in wasm::TypeBuilder::build() (/bin/../lib/libbinaryen.so+0x126cc52b)
#2 0x7ff218fbda5f in wasm::Type::getLeastUpperBound(wasm::Type, wasm::Type) (/bin/../lib/libbinaryen.so+0x126e1a5f)
#3 0x7ff2186f5006 in wasm::If::finalize() (/bin/../lib/libbinaryen.so+0x11e19006)
#4 0x56004b397f60 in wasm::Walker<wasm::ReFinalize, wasm::OverriddenVisitor<wasm::ReFinalize, void> >::walk(wasm::Expression*&) (/bin/wasm-opt+0xce3f60)
#5 0x7ff2178918ed in wasm::RemoveUnusedBrs::doWalkFunction(wasm::Function*) (/bin/../lib/libbinaryen.so+0x10fb58ed)
#6 0x7ff2178973ec in wasm::WalkerPass<wasm::PostWalker<wasm::RemoveUnusedBrs, wasm::Visitor<wasm::Remove
#include "a.h"
void a() {
data = 42;
}
commit 972d6299672f4508c805af5efd886bb87b0a22fe
Author: Alon Zakai <[email protected]>
Date: Tue Apr 5 16:50:33 2022 -0700
wip
diff --git a/src/passes/ConstantFieldPropagation.cpp b/src/passes/ConstantFieldPropagation.cpp
index e4e01dc0e..76f64535c 100644
--- a/src/passes/ConstantFieldPropagation.cpp
+++ b/src/passes/ConstantFieldPropagation.cpp

Emscripten as a linker for Zig and C

This shows how to build a nontrivial program using Zig+Emscripten or C+Emscripten. In both cases Emscripten is only used as a linker, that is the frontend is either zig or clang.

"Nontrivial" here means the program uses interesting Emscripten features:

  • Asyncify
  • Full GLES3 support
  • GLFW3 support
/*
* Copyright 2011 The Emscripten Authors. All rights reserved.
* Emscripten is available under two separate licenses, the MIT license and the
* University of Illinois/NCSA Open Source License. Both these licenses can be
* found in the LICENSE file.
*/
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
//
// Build with
//
// -pthread -s PROXY_TO_PTHREAD -s EXIT_RUNTIME
//
#include <stdlib.h>
#include <emscripten.h>
#include <emscripten/threading.h>
# 1 "tests/core/test_atomic_cxx.cpp"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 355 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "tests/core/test_atomic_cxx.cpp" 2
# 13 "tests/core/test_atomic_cxx.cpp"
# 1 "/home/azakai/Dev/emscripten/cache/sysroot/include/c++/v1/atomic" 1 3
# 577 "/home/azakai/Dev/emscripten/cache/sysroot/include/c++/v1/atomic" 3
@kripken
kripken / .gitignore
Last active July 9, 2021 19:58
Interface Types IOI
*.wasm
temp
@kripken
kripken / README.markdown
Last active May 23, 2021 17:36
Building binaryen with zig cc

Building binaryen with zig cc

  1. Add zigcc, zigc++ scripts because cmake doens't accept a compiler with spaces in the name like "zig cc".
  2. The zigcc/zigc++ scripts can also add a target for cross-compiling as shown here.
  3. Disable threads (perhaps cmake cross-compiling needs to be set up?).
  4. Use a static build (otherwise cmake emits a .so - again, do we need cmake cross-compiling here?).
  5. ninja stalls on the final links: it just hangs. To solve that, run ninja wasm-opt and so forth manually, as a specific build target works.
extern "C" int foo();
int main() {
foo();
}