Skip to content

Commit

Permalink
wasm: Update to llvm 10 build tools
Browse files Browse the repository at this point in the history
As part of this update we needed to change the memory grow builtins.
The version we used were removed in https://reviews.llvm.org/D56645
after (apparently) having been deprecated for some time. The newer
versions match up with more recent versions of the WASM spec (see
WebAssembly/spec#627 for more context).

The WebAssembly/wabt version is also updated to the latest release to
correct build issues with the older one and llvm 10.

Upgrading should prevent a deadlock we saw periodically in the CI
while building the OPA wasm binaries.

Signed-off-by: Patrick East <east.patrick@gmail.com>
  • Loading branch information
patrick-east committed Jul 9, 2020
1 parent abccfe3 commit 32201de
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion internal/compiler/wasm/opa/opa.go

Large diffs are not rendered by default.

Binary file modified internal/compiler/wasm/opa/opa.wasm
Binary file not shown.
24 changes: 12 additions & 12 deletions wasm/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM ubuntu:18.04

RUN apt-get update && apt-get install -y curl git build-essential
RUN apt-get update && apt-get install -y curl git build-essential python

RUN bash -c 'echo -ne "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic main\ndeb-src http://apt.llvm.org/bionic/ llvm-toolchain-bionic main" > /etc/apt/sources.list.d/llvm.list'

Expand All @@ -9,22 +9,22 @@ RUN curl -L https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
RUN apt-get update && \
apt-get install -y \
cmake \
clang-8 \
lld-8
clang-10 \
lld-10

ENV CC=clang-8
ENV CXX=clang-8
ENV LLD=wasm-ld-8
ENV AR=llvm-ar-8
ENV RANLIB=llvm-ranlib-8
ENV CC=clang-10
ENV CXX=clang-10
ENV LLD=wasm-ld-10
ENV AR=llvm-ar-10
ENV RANLIB=llvm-ranlib-10

RUN ln -s /usr/bin/clang-8 /usr/bin/clang && \
ln -s /usr/bin/clang++-8 /usr/bin/clang++ && \
ln -s /usr/bin/clang-cpp-8 /usr/bin/clang-cpp
RUN ln -s /usr/bin/clang-10 /usr/bin/clang && \
ln -s /usr/bin/clang++-10 /usr/bin/clang++ && \
ln -s /usr/bin/clang-cpp-10 /usr/bin/clang-cpp

RUN git clone https://github.com/WebAssembly/wabt && \
cd wabt && \
git checkout 1.0.5 && \
git checkout 1.0.17 && \
git submodule update --init && \
make

Expand Down
6 changes: 3 additions & 3 deletions wasm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ DOCKER_FLAGS := --rm
endif

WASM_BUILDER_REPOSITORY := openpolicyagent/opa-wasm-builder
WASM_BUILDER_VERSION := 1.0
WASM_BUILDER_VERSION := 1.1
WASM_BUILDER_IMAGE := $(WASM_BUILDER_REPOSITORY):$(WASM_BUILDER_VERSION)
WASM_OBJ_DIR := _obj

Expand Down Expand Up @@ -79,7 +79,7 @@ $(TEST_OBJS): $(WASM_OBJ_DIR)/tests/%.wasm: tests/%.c
$(CC) $(CFLAGS) -I src -c -o $@ $<

$(WASM_OBJ_DIR)/opa.wasm: $(OBJS) $(LIB_OBJS) $(LIB_MPDEC_OBJS)
wasm-ld-8 \
wasm-ld-10 \
--allow-undefined-file=src/undefined.symbols \
--import-memory \
--no-entry \
Expand All @@ -89,7 +89,7 @@ $(WASM_OBJ_DIR)/opa.wasm: $(OBJS) $(LIB_OBJS) $(LIB_MPDEC_OBJS)

$(WASM_OBJ_DIR)/opa-test.wasm: $(OBJS) $(LIB_OBJS) $(LIB_MPDEC_OBJS) $(TEST_OBJS)
@cat src/undefined.symbols tests/undefined.symbols > _obj/undefined.symbols
@wasm-ld-8 \
@wasm-ld-10 \
--allow-undefined-file=_obj/undefined.symbols \
--import-memory \
--no-entry \
Expand Down
4 changes: 2 additions & 2 deletions wasm/src/malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static void init(void)
if (!initialized)
{
heap_ptr = (unsigned int)&__heap_base;
heap_top = __builtin_wasm_grow_memory(0) * WASM_PAGE_SIZE;
heap_top = __builtin_wasm_memory_grow(0, 0) * WASM_PAGE_SIZE;
init_free();
initialized = 1;
}
Expand Down Expand Up @@ -145,7 +145,7 @@ void *opa_malloc(size_t size)
if (heap_ptr >= heap_top)
{
unsigned int pages = (block_size / WASM_PAGE_SIZE) + 1;
__builtin_wasm_grow_memory(pages);
__builtin_wasm_memory_grow(0, pages);
heap_top += (pages * WASM_PAGE_SIZE);
}

Expand Down

0 comments on commit 32201de

Please sign in to comment.