Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Commit

Permalink
Patch generator to support AOT VM mode
Browse files Browse the repository at this point in the history
- Ahead-of-time compilation mode(AOT mode)

```sh
deps/ckb-binary-patcher/target/release/ckb-binary-patcher --remove-a -i build/generator -o build/generator.aot
instruction at 149118(content 04e6a7af) is replace by nop
```
  • Loading branch information
Flouse committed Dec 17, 2021
1 parent 6c117e7 commit 5f8f43e
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 282 deletions.
39 changes: 36 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,17 @@ CFLAGS_MBEDTLS := -Ideps/mbedtls/include
CFLAGS_EVMONE := -Ideps/evmone/lib/evmone -Ideps/evmone/include -Ideps/evmone/evmc/include
CFLAGS_SMT := -Ideps/godwoken-scripts/c/deps/sparse-merkle-tree/c
CFLAGS_GODWOKEN := -Ideps/godwoken-scripts/c
CFLAGS := -O3 -Ic/ripemd160 $(CFLAGS_CKB_STD) $(CFLAGS_EVMONE) $(CFLAGS_INTX) $(CFLAGS_BN128) $(CFLAGS_ETHASH) $(CFLAGS_CRYPTO_ALGORITHMS) $(CFLAGS_MBEDTLS) $(CFLAGS_SMT) $(CFLAGS_GODWOKEN) $(CFLAGS_SECP) -Wall -g -fdata-sections -ffunction-sections
CFLAGS := -O3 -Ic/ripemd160 $(CFLAGS_CKB_STD) $(CFLAGS_EVMONE) $(CFLAGS_INTX) $(CFLAGS_BN128) $(CFLAGS_ETHASH) $(CFLAGS_CRYPTO_ALGORITHMS) $(CFLAGS_MBEDTLS) $(CFLAGS_SMT) $(CFLAGS_GODWOKEN) $(CFLAGS_SECP)
CXXFLAGS := $(CFLAGS) -std=c++1z
LDFLAGS := -Wl,--gc-sections
# -Wl,<args> Pass the comma separated arguments in args to the linker(GNU linker)
# --gc-sections
# This will perform a garbage collection of code and data never referenced.
# together with -ffunction-sections and -fdata-sections
# -static
# On systems that support dynamic linking, this pre-
# vents linking with the shared libraries. On other
# systems, this option has no effect.
LDFLAGS := -Wl,-static -Wl,--gc-sections -fdata-sections -ffunction-sections -Wall

SECP256K1_SRC := $(SECP_DIR)/src/ecmult_static_pre_context.h

Expand All @@ -47,6 +55,7 @@ all: build/test_contracts build/test_rlp build/generator build/validator build/g
all-via-docker: generate-protocol
mkdir -p build
docker run --rm -v `pwd`:/code ${BUILDER_DOCKER} bash -c "cd /code && make"
make patch-generator
log-version-via-docker: generate-protocol
mkdir -p build
docker run --rm -v `pwd`:/code ${BUILDER_DOCKER} bash -c "cd /code && make build/generator_log && make build/validator_log"
Expand All @@ -55,7 +64,31 @@ clean-via-docker:
mkdir -p build
docker run --rm -v `pwd`:/code ${BUILDER_DOCKER} bash -c "cd /code && make clean"

dist: clean-via-docker all-via-docker
dist: clean-via-docker all-via-docker patch-generator patch-generator_log

CKB_BIN_PATCHER := deps/ckb-binary-patcher/target/release/ckb-binary-patcher
build/ckb-binary-patcher:
cd deps && [ -d "ckb-binary-patcher" ] \
|| git clone --depth=1 https://github.com/nervosnetwork/ckb-binary-patcher.git
[ -f ${CKB_BIN_PATCHER} ] \
|| (cd deps/ckb-binary-patcher \
&& git fetch https://github.com/XuJiandong/ckb-binary-patcher 57144f122e55ee1610779b307d3935918b28167e \
&& git checkout FETCH_HEAD \
&& cargo build --release)
patch-generator: build/ckb-binary-patcher
${CKB_BIN_PATCHER} --remove-a -i build/generator -o build/generator.aot
mv build/generator build/generator.asm
cp build/generator.aot build/generator
patch-generator_log: build/ckb-binary-patcher
${CKB_BIN_PATCHER} --remove-a -i build/generator_log -o build/generator_log.aot
mv build/generator_log build/generator_log.asm
cp build/generator_log.aot build/generator_log
# patch-validator: build/ckb-binary-patcher
# ${CKB_BIN_PATCHER} --remove-a -i build/validator -o build/validator.aot
# patch-validator_log: build/ckb-binary-patcher
# ${CKB_BIN_PATCHER} --remove-a -i build/validator_log -o build/validator_log.aot
# patch-test_contracts: build/ckb-binary-patcher
# ${CKB_BIN_PATCHER} --remove-a -i build/test_contracts -o build/test_contracts.aot

build/generator: c/generator.c $(GENERATOR_DEPS)
cd $(SECP_DIR) && (git apply workaround-fix-g++-linking.patch || true) && cd - # apply patch
Expand Down
4 changes: 2 additions & 2 deletions devtools/ci/integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ if [ -d "$GODWOKEN_DIR" ]
then
echo "godwoken project already exists"
else
git clone --depth=66 -b master https://github.com/nervosnetwork/godwoken.git $GODWOKEN_DIR
git clone --depth=100 -b generator-ahead-of-time-compilation https://github.com/flouse/godwoken.git $GODWOKEN_DIR
fi
cd $GODWOKEN_DIR
git checkout 81508486047d14e75b870de628f2fd4bf48fdad3 # Commit on Nov 22, 2021
git checkout a6405ad140f96f1d7914e18b66c1249a9a4632d6 # Commit on Thu Dec 9 07:10:43 2021 +0000
git submodule update --init --recursive --depth=1

cd $PROJECT_ROOT
Expand Down
Loading

0 comments on commit 5f8f43e

Please sign in to comment.