The embodiment of the invention discloses a binary code optimization method and
system, an electronic device, a medium and a program product, based on a function
call graph and
basic block control flow graphs,
topological sorting is carried out on each
basic block control flow graph, the code execution sequence is optimized,
branch prediction errors are reduced, instruction
rewriting is carried out based on the
topological sorting result, and the efficiency is improved. By means of the method, accurate
rewriting of key instructions can be achieved according to the characteristics of a specific
system architecture (such as an ARM64 architecture), the accuracy of address calculation is guaranteed, function inline expansion (namely target function calling) is selectively conducted in the inline expansion process through strict
context management, the function calling overhead is reduced, and the function calling efficiency is improved. And finally, recoding the code of which the inline expansion is completed to generate a final optimized target binary code, so that multiple means such as inline, code
layout and instruction-level optimization are comprehensively utilized to realize a deep optimization effect on the binary code on the premise of keeping
semantics strictly unchanged.