-
Notifications
You must be signed in to change notification settings - Fork 989
Rewrite the RTLIL parser for efficiency #5339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
You should also run the Glasgow tests since they exercise a bigger class of netlists. |
FYI currently failing with memory leak in
rtlil_frontend.cc:823 Something to do with modifying the input file istream within the worker? Compare cxxrtl_backend.cc:
|
I don't know how much we care about behaviour on malformed input, but with a fuzzer I found the following:
With previous |
I ran the Glasgow tests with
I hope I did that right... |
2346efd
to
8144604
Compare
Fixed. |
Fixed. |
8144604
to
e14adfd
Compare
I ran the AFL++ fuzzer for 300 CPU-hours and found one issue: it's trivially easy to crash the parser on with OOM on a tiny input by writing a constant like |
…already know the string length
… avoid refcount churn
Without this check it's trivially easy to crash Yosys with a tiny RTLIL input by specifying a constant with very large width. Fuzz testers love hitting this over and over again.
e14adfd
to
f9d9d1a
Compare
Yeah I saw the same in my fuzzing runs - didn't mention it because it's not a change in behaviour and I doubt it would actually affect fuzzer effectiveness because from a coverage perspective it looks roughly the same whether it crashes or raises an error for afl++, it just means the testcase gets binned as a crash. I'm happy to see a limit on the max size, there was discussion of this in the past as #3460 but it was never merged (the author stopped working on Yosys as much around then). |
Good point. |
Sounds good to me, thank you! |
What are the reasons/motivation for this change?
See https://yosyshq.discourse.group/t/faster-rtlil-parser for context. The current parser is not very C++ friendly, is hard to debug because of the Flex/Bison dependency, and does a lot of unnecessary copying.
Explain how this is achieved.
By rewriting it into a handwritten recursive-descent parser it becomes more maintainable and 2.5x faster.
I ran the Amaranth tests and they pass.