rabbitmq / horus

Erlang library to create standalone modules from anonymous functions
https://rabbitmq.github.io/horus/
Apache License 2.0
27 stars 1 forks source link

Use a custom disassembler based on `beam_disasm` #1

Open the-mikedavis opened 1 year ago

the-mikedavis commented 1 year ago

Is your feature request related to a problem? Please describe.

Horus currently uses the beam_disasm module from the compiler application in Erlang/OTP to disassemble (convert BEAM chunks into instructions). beam_disasm had some bugs involving mistranslated instructions (for example https://github.com/erlang/otp/pull/6447) which are papered over by Horus (for example see pass1_process_instructions/3). These mistranslations are fixed upstream but we must wait until Erlang/OTP 26 to take full advantage of the upstream fixes and drop compatibility code in Horus.

Also, beam_disasm in Erlang/OTP 26 cannot decode modules compiled with the Erlang/OTP 25 compiler. Erlang/OTP 26 introduced a new format for the Type BEAM chunk and also dropped all code for serializing and deserializing the version 1 type chunk from Erlang/OTP 25. This could happen again to this particular chunk or to any other BEAM chunk. A custom disassembler could support multiple BEAM chunk versions.

Describe the solution you'd like

Horus could implement a custom disassembler based on beam_disasm. This would allow us to fix the mistranslations in-tree and drop the compatibility code now. We could also support multiple BEAM chunk versions and have fine control over which Erlang/OTP versions are supported.

The downside to a custom disassembler is that it's more work to maintain. beam_disasm in Erlang/OTP provides a good guide but sometimes has bugs as mentioned. This part of Horus would need some work for every Erlang/OTP major release that introduces new instructions or changes the format of BEAM chunks. (Every major release since Erlang/OTP 20 has added new instructions.)

Describe alternatives you've considered

We could restrict the versions recommended for running Rabbit releases that include Horus and Khepri (see https://www.rabbitmq.com/which-erlang.html) to work around the version compatibility problem. The compatibility code for mistranslations could stay in-tree until Horus depends on Erlang/OTP 26 as a minimum.

Additional context

No response

the-mikedavis commented 1 year ago

The incompatibility between the OTP 25 compiler and OTP 26 beam_disasm was resolved and should be included in OTP 26.0: https://github.com/erlang/otp/pull/7044