aptos-core icon indicating copy to clipboard operation
aptos-core copied to clipboard

[compiler-v2] Disassembler doesn't work with source map constructed by the compiler

Open wrwg opened this issue 11 months ago • 6 comments

The source map generation introduced in #12534 works fine with the prover but crashes with the disassembler. The problem can be reproduced by searching for the bug number in model.rs, disassemble function.

wrwg avatar Mar 14 '24 23:03 wrwg

Does this bug appear in aptos move disassemble? If so it is urgent.

wrwg avatar Mar 21 '24 20:03 wrwg

I'm not sure if this appears in aptos move disassemble but if we try to run move-cli tests with MOVE_COMPILER_V2=true we hit this failure. So it's likely we'll see the same problem in Aptos. This at least needs more investigation.

brmataptos avatar Apr 12 '24 23:04 brmataptos

@wrwg Do you recall where/how you saw this bug?

brmataptos avatar Apr 14 '24 04:04 brmataptos

I'm not sure if the problem I just found and fixed is the one which Wolfgang mentioned originally, as I see an error with disassembly which occurs either with the "dummy" source map

        let smap = SourceMap::dummy_from_view(&view, self.env.to_ir_loc(&self.get_loc()))
            .expect("source map");

or the local source map:

        let smap = self.data.source_map.as_ref().expect("source map").clone();

When I run UB=1 MOVE_COMPILER_V2=true cargo test -p move-cli I see problem with disassemblies in various tests, for example third_party/move/tools/move-cli/tests/build_tests/build_with_warnings/args.exp which yields an error instead of a disassembly with compiler-v2:

Error: Unable to get type for local at index 0

The problem is that FunctionGenerator::temp_to_local (in move-compiler-v2/src/file_format_generator/function_generator.rs) is used to allocate both parameters and locals, but as a side-effect it calls self.gen.source_map.add_local_mapping(...), which should only be called for locals, as parameters are recorded elsewhere. Adding a flag to temp_to_local() to change the behavior in the case where it is used to allocate parameters fixes the problem.

I have a fix I will can clean up and send out after I finish some other issues. Or you can try cherry-picking it from my work-in-progress branch https://github.com/aptos-labs/aptos-core/tree/brm-issue-11146-step3. (Note that branch has some other problems with publishing deps in tests, which I'm still working out.)

brmataptos avatar Apr 14 '24 06:04 brmataptos

Btw, if we could publish some more precise instructions for replicating the original issue that would be good.

brmataptos avatar Apr 14 '24 06:04 brmataptos

@wrwg please check whether this fixes the original problem you saw.

brmataptos avatar May 04 '24 23:05 brmataptos

We need to test whether aptos move disassemble works, if so, we are good.

wrwg avatar May 23 '24 20:05 wrwg

It looks like aptos move disassemble works on hundreds of .mv files (built e2e-move-tests with MOVE_COMPILER_V2=true).

So I think this is fixed.

brmataptos avatar May 23 '24 23:05 brmataptos

Fixed.

brmataptos avatar May 23 '24 23:05 brmataptos