Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
use strip dead code (ew) to resolve the memory usage issue
Browse files Browse the repository at this point in the history
  • Loading branch information
addisoncrump committed Jun 14, 2023
1 parent 122439e commit 9859a50
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
16 changes: 10 additions & 6 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,18 @@ path = "fuzz_targets/rome_format_tsx.rs"
name = "rome_format_typescript"
path = "fuzz_targets/rome_format_typescript.rs"

# enabling debug seems to cause a massive use of RAM (>12GB)
[profile.release]
opt-level = 2
debug = true
opt-level = 3
#debug = true
debug = false

[profile.dev]
opt-level = 2
debug = true
opt-level = 3
#debug = true
debug = false

[profile.test]
opt-level = 2
debug = true
opt-level = 3
#debug = true
debug = false
13 changes: 10 additions & 3 deletions fuzz/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ without it (very unlikely for the fuzzer to generate valid python code from "thi
Once you have initialised the fuzzers, you can then execute any fuzzer with:

```bash
cargo fuzz run -s none name_of_fuzzer -- -timeout=1
cargo fuzz run --strip-dead-code -s none name_of_fuzzer -- -timeout=1
```

**Users using Apple M1 devices must use a nightly compiler and omit the `-s none` portion of this
Expand All @@ -40,7 +40,7 @@ triggered with a smaller input.
`cargo-fuzz` supports this out of the box with:

```bash
cargo fuzz tmin -s none name_of_fuzzer artifacts/name_of_fuzzer/crash-...
cargo fuzz tmin --strip-dead-code -s none name_of_fuzzer artifacts/name_of_fuzzer/crash-...
```

From here, you will need to analyse the input and potentially the behaviour of the program.
Expand Down Expand Up @@ -116,4 +116,11 @@ preservation property of formatting.
Of particular note: these fuzzers may have false negative results if e.g. two tokens are turned into
one token and the reformatting result is the same.
Unfortunately, we can't necessarily control for this because the formatter may reorganise the
sequence of tokens.
sequence of tokens.

## Errata

Unfortunately, `--strip-dead-code` is necessary to build the target with a suitable amount of
memory.
This seems to be caused by some issue in LLVM, but I haven't been able to spend the time to
investigate this fully yet.
4 changes: 2 additions & 2 deletions fuzz/init-fuzzer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if [ ! -d corpus/rome_format_all ]; then
cp -r "../../../crates/rome_js_parser/test_data" .
find . -name \*.rast -delete
cd -
cargo fuzz cmin --features rome_all -s none rome_format_all
cargo fuzz cmin --strip-dead-code --features rome_all -s none rome_format_all
fi

if [ ! -d corpus/rome_format_json ]; then
Expand All @@ -33,7 +33,7 @@ if [ ! -d corpus/rome_format_json ]; then
cp -r "../../../crates/rome_json_parser/tests/json_test_suite" .
find . -name \*.rast -delete
cd -
cargo fuzz cmin -s none rome_format_json
cargo fuzz cmin --strip-dead-code -s none rome_format_json
fi

echo "Done! You are ready to fuzz."
4 changes: 2 additions & 2 deletions fuzz/reinit-fuzzer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ cd corpus/rome_format_all
cp -r "../../../crates/rome_js_parser/test_data" .
find . -name \*.rast -delete
cd -
cargo fuzz cmin --features rome_all -s none rome_format_all
cargo fuzz cmin --strip-dead-code --features rome_all -s none rome_format_all

mkdir -p corpus/rome_format_json
cd corpus/rome_format_json
cp -r "../../../crates/rome_json_parser/tests/json_test_suite" .
find . -name \*.rast -delete
cd -
cargo fuzz cmin -s none rome_format_json
cargo fuzz cmin --strip-dead-code -s none rome_format_json

echo "Done! You are ready to fuzz."

0 comments on commit 9859a50

Please sign in to comment.