A rule-based learning binary translation method for virtualization

Automatically obtain the translation rules of the binary translation system through a rule-based learning method, combining constraint equivalent and lightweight dynamic verification technology, the problem of low execution efficiency and high-quality rules being screened out in the existing technology is solved, and efficient and flexible binary translation is achieved.

CN113885883BActive Publication Date: 2025-04-01FUDAN UNIVERSITY +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202010625228.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-07-01
Publication Date
2025-04-01
Estimated Expiration
2040-07-01

AI Technical Summary

Technical Problem

The existing binary translation system has inefficient execution and high additional overhead due to the complexity and opacity of manually constructing translation rules, and the strict equivalence verification process leads to the screening of high-quality translation rules.

Method used

Using a rule-based learning method, the final translation rules are automatically obtained through the translation learning model that completes translation training in advance, and using constraint equivalent and lightweight dynamic verification technology to obtain more high-quality translation rules, and virtual constraint contacts and virtual jump contacts are introduced during the translation process to improve translation efficiency.

Benefits of technology

It improves the execution efficiency of the binary translation system, saves unnecessary overhead, and improves coverage and translation performance while ensuring the performance of translation rules.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113885883B_ABST
    Figure CN113885883B_ABST
Patent Text Reader

Abstract

The present invention provides a binary translation method based on rule learning for virtualization. The present invention belongs to the field of system virtualization. Specifically, by completing pre-translation training based on the code to be translated and the target code for the translation learning model, it can be used to automatically obtain translation rules and accelerate the speed of the dynamic binary translation system. The present invention proposes a binary translation method based on rule learning for virtualization. Constraints are added to the translation rules through an automatic learning process, and lightweight verification is used during the dynamic translation process to ensure that the translation method with constraints is used correctly. Compared with traditional dynamic binary translation tools, the present invention reduces the workload of developers and effectively improves performance. At the same time, compared with the original dynamic binary translation method based on learning, the learning efficiency and the performance of actual translation are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of system virtualization, and in particular relates to a binary translation method based on rule learning and oriented to virtualization. Background Art

[0002] Dynamic binary translation technology is an important technology in system virtualization. It is a method that instantly translates the binary code of the source instruction set architecture into the binary code of the target instruction set architecture. The binary code compiled by the source instruction set architecture can be directly run on another instruction set architecture without any conversion.

[0003] For a binary translation system, an important indicator is the execution efficiency of the target binary code generated by the translation, which is particularly critical in cross-platform virtualization. Through binary translation, for example, an ARM instruction architecture virtual machine can be virtualized on an x86 instruction architecture platform to run ARM applications. However, common binary translation systems build translation rules by developers manually writing them. However, due to the complexity and opacity of modern instruction set architecture design, it is a great challenge for developers to manually build high-quality translation rules. Manually building translation rules and intermediate representation translation methods will bring a lot of additional execution overhead, resulting in extremely low execution efficiency and large additional overhead for most current binary translation systems.

[0004] In order to improve the quality of translation rules and reduce the large amount of programming work caused by manually writing translation rules, Wenwen Wang et al. proposed a new binary translation system that generates translation rules through automatic learning. The binary translation system first optimizes and compiles a source code using the compilers of the source instruction set architecture and the target instruction set architecture, and then obtains candidate translation rules by establishing a correspondence between the binary codes compiled on the two architectures. Finally, the correctness of the candidate translation rules is verified, thereby automatically constructing the correct translation rules. However, the correctness verification link of the original learning process is very strict. The correctness verification can only pass if and only if all instructions of the source binary code and the target binary code are strictly one-to-one corresponding, and the translation rule is considered to be a legal translation rule. On the surface, this strict equivalence verification is very necessary and effective. However, this strict equivalence relationship and strict equivalence verification process are an excessive requirement in some cases, which will cause many high-quality translation rules to be screened out during the verification process because they cannot pass the strict equivalence verification. Summary of the invention

[0005] In order to solve the above problems, a virtualization-oriented rule-based learning binary translation method is provided, and the present invention adopts the following technical solutions: a data preparation step, obtaining multiple lines of binary code to be translated; a code translation step, inputting the code to be translated into a translation learning model that has completed translation training in advance, and the translation learning model obtains the target code corresponding to the code to be translated through the final translation rule; wherein the specific steps of translation training for the translation learning model include: a training data set construction step, in which the translation learning model uses the training code to be translated and the training target code obtained by compiling the source code based on the same multiple lines of source code and by two different compilation methods as the training data set; a range construction step, dividing the multiple lines of source code into multiple parts in sequence based on a predetermined source code line number rule, and dividing the training data set into corresponding multiple ranges to be processed based on the corresponding relationship between the source code in each part and the training code to be translated and the training target code; a current state acquisition step, dividing the multiple ranges to be processed into the training target code; and a current state acquisition step. The first to-be-processed range is taken as the current range, and the binary code in the current range is parsed by binary instructions to obtain the current translation rule; an intermediate state setting step is to set the current range as the intermediate range, and the current rule is set as the intermediate rule; a state updating step is to sequentially obtain a to-be-processed range after the intermediate range from multiple to-be-processed ranges as the new current range, and the binary code in the new current range is parsed by binary instructions to obtain a new current translation rule; a rule judgment step is to enter the intermediate state acquisition step until the similarity between the current translation rule and the temporarily stored translation rule reaches a preset value; a translation rule execution step is to take the current rule as the translation rule, and use the translation rule to translate the training to-be-translated code in the data set line by line to obtain the to-be-verified target code; a training completion judgment step is to judge that each line of the to-be-verified target code is completely consistent with the corresponding training target code, then the translation rule is taken as the final translation rule of the translation learning model, and the translation learning model is output as the completed preset translation learning model.

[0006] The virtualization-oriented rule-based learning binary translation method provided by the present invention may also have such a technical feature, wherein, in the training completion step, if the target code to be verified obtained in a certain row is partially consistent with the corresponding training target code, a constraint condition is introduced, and a virtual constraint contact corresponding to the constraint condition is generated based on the target code to be verified obtained in a certain row and the training code to be translated in this row, and the target code to be verified obtained by the training code to be translated through the constraint condition and the translation rule is completely consistent with the corresponding training target code. When the final translation rule triggers a virtual constraint contact during the translation process, the final translation rule and the constraint condition are used together as the translation rule to translate a row of binary code containing the virtual constraint contact.

[0007] A virtualization-oriented rule-learning-based binary translation method provided by the present invention may also have such a technical feature, wherein, in a line where the training completion step exists under special circumstances, if the target code to be verified is completely inconsistent with the corresponding training target code, a virtual jump contact is generated, and when the final translation rule triggers the virtual jump contact during the translation process, the final translation rule does not translate a line of binary code containing the virtual jump contact, and jumps to the next line of the binary code, and translates the next line of binary code based on the final translation rule.

[0008] The virtualization-oriented rule-learning-based binary translation method provided by the present invention may also have such a technical feature, wherein the predetermined source code line number rule is based on an arithmetic progression, with one line as the common difference and the first term as one line, dividing multiple lines of source code into multiple parts in sequence according to the number of lines.

[0009] Function and Effect of the Invention

[0010] According to a virtualization-oriented rule-learning-based binary translation method of the present invention, since the translation learning model can automatically obtain the final translation rules through pre-training, compared with the traditional translation system in which the translation rules are constructed by developers manually writing, it saves labor costs, improves the execution efficiency of the binary translation system, and saves unnecessary expenses. Furthermore, since the training data set is divided into multiple more flexible current ranges based on the source code line number rule in the process of automatically obtaining the final translation rules, the learning process has more opportunities to obtain translation rules. The present invention introduces a preset pre-value to iteratively train the translation learning model so that the final translation rules obtained by the translation learning model guarantee performance while improving coverage. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] Figure 1 is a workflow diagram of a virtualization-oriented rule-learning-based binary translation method in practical application in this embodiment; and

[0012] Figure 2 Flowchart of translation training performed by the translation learning model in the embodiment. DETAILED DESCRIPTION

[0013] In order to make the technical means, creative features, objectives and effects achieved by the present invention easy to understand, the following is a detailed description of a virtualization-oriented rule-learning-based binary translation method of the present invention in conjunction with embodiments and drawings.

[0014] The method of the present invention mainly utilizes the constraint equivalence method and lightweight dynamic verification to ensure the acquisition of more high-quality translation rules, and utilizes these translation rules to correctly implement dynamic binary translation, thereby improving the execution efficiency of the target binary code on the corresponding target virtualization platform. The following is a specific implementation of the virtualization-oriented rule-based learning binary translation method of the present invention in conjunction with an embodiment.

[0015] <Example>

[0016] The present embodiment adopts the dynamic binary translation system QEMU system, adopts the binary code under the ARM architecture as the code to be translated, and adopts the binary code under the X86 architecture as the target code. The learning framework of the constraint condition is implemented using python. The verification stage is implemented based on a symbolic execution tool FuzzBALL. In the dynamic translation process, the Tiny code generator (TCG) in QEMU is used to support the situation where the automatically learned translation rules cannot be translated, and is used to help translate the predicted instructions.

[0017] A virtualization-oriented rule-learning-based binary translation method in this embodiment inputs the data to be processed (in this embodiment, multiple lines of binary code under the RAM framework) to a translation learning model that has completed training based on the relationship between the code to be processed and the target code architecture. The translation learning model obtains the required target code through the final translation rules (in this embodiment, multiple lines of binary code under the X86 framework with the same semantics as the multiple lines of binary code under the input RAM framework).

[0018] Figure 1 This is a workflow diagram of a virtualization-oriented rule-learning-based binary translation method in practical application in this embodiment.

[0019] like Figure 1 As shown, the actual application process of a virtualization-oriented rule-based learning binary translation method in this embodiment is as follows:

[0020] Step S1, data preparation step, directly obtains multiple lines of binary code to be translated according to specific work requirements, or compiles a multi-line source code into multiple lines of binary code to be translated through a compiler, and then enters step S2.

[0021] In this embodiment, the code to be translated is a plurality of lines of binary code in a RAM architecture pre-downloaded from a network database.

[0022] Step S2, code translation step, inputs the code to be translated into a translation learning model that has completed translation training in advance, and the translation learning model obtains the target code under the X86 framework corresponding to the code to be translated through the final translation rules, and then enters the end state.

[0023] The trained translation learning model in this embodiment can complete the conversion of all binary codes from the RAM framework to the X86 framework, and then in a working environment where the RAM framework is restricted, the expected work can be completed by translating the binary code under the RAM framework into the binary code under the X86 framework.

[0024] Figure 2 Flowchart of translation training performed by the translation learning model in the embodiment.

[0025] like Figure 2 As shown in the figure, the translation learning model needs to undergo the following training steps before application:

[0026] Step U1 is a step of constructing a training data set. The translation learning model obtains training codes to be translated and training target codes compiled from the network database based on the same multi-line source code by two different compilation methods as training data sets, and then enters step U2.

[0027] In this embodiment, the two different compilation modes are RAM compilation mode and X86 compilation mode. The binary code obtained by RAM compilation is used as the training code to be translated, and the binary code obtained by X86 compilation is used as the training target code.

[0028] Step U2, the range construction step, divides the multiple lines of source code obtained in step U1 into multiple parts in sequence based on the predetermined source code line number rule, and takes the training code to be translated and the training target code corresponding to the same part as a range to be processed, thereby dividing the training data set into multiple ranges to be processed, and then enters step U3.

[0029] In this embodiment, the source code line number rule is specifically as follows: based on an arithmetic progression, multiple lines of source code are divided into multiple parts in sequence according to the number of lines, with one line as the common difference and the first term as one line, that is, the first line of source code in the multiple lines of source code is taken as the first part, the second line of source code and the third line of source code in the multiple lines of source code are taken as the second part, and so on, the multiple lines of source code are divided into multiple parts.

[0030] Step U3, current state acquisition step, takes the first to-be-processed range among the multiple to-be-processed ranges as the current range, and obtains the current translation rule through binary instruction parsing of the binary code in the current range, and then enters step U4.

[0031] Step U4, the intermediate state setting step, sets the current range obtained in step U3 as the intermediate range, and sets the current rule obtained in step U3 as the intermediate rule, and then enters step U5.

[0032] Step U5, a state update step, sequentially obtains a to-be-processed range after the intermediate range from multiple to-be-processed ranges as a new current range, and obtains a new current translation rule through binary instruction parsing in the binary code in the new current range, and then enters step U6.

[0033] Step U6 is a rule judgment step, which judges whether the current translation rule obtained in step U5 and the temporarily stored translation rule obtained in step U4 can reach a preset value in similarity. If not, the process proceeds to step U4; if so, the process proceeds to step U7.

[0034] In this embodiment, the preset value of the similarity is 90%, that is, when the number of candidate translation rules obtained in the larger learning scope is less than 10% of the obtained translation rules.

[0035] In this embodiment, from step U6, by making a judgment based on the preset value, the operations of step U4 and step U5 are cyclically performed, thereby further completing the iteration process of the current rule, thereby improving the accuracy of the current rule obtained.

[0036] Step U7, the translation rule execution step, takes the current rule obtained in step U5 as the translation rule, and uses the translation rule to translate the training code to be translated in the data set line by line to obtain the target code to be verified, and then enters step U8.

[0037] Step U8, the training completion judgment step, is to judge whether each line of the target code to be verified and the corresponding training target code are parsed into a usable data structure and then establish an initial match for all operands, and use the symbolic execution tool FuzzBALL to calculate the symbolic execution result. If the execution result is completely consistent, the translation rule is used as the final translation rule of the translation learning model, and the translation learning model is output as the completed preset translation learning model, entering the end state.

[0038] In this embodiment, the line-by-line translation adopted in step U7 is to translate each line of the training code to be translated into the training target code through the translation rules, thereby providing data for the symbolic execution in step U8.

[0039] In special cases, in step U8, if the execution results are partially consistent, a constraint condition is introduced, and a virtual constraint contact corresponding to the constraint condition is generated based on the target code to be verified in the processing range and the training code to be translated. The constraint condition and the translation rule are translated together to make the execution results of the processing range in U8 completely consistent. When the translation learning model triggers the virtual constraint contact during the translation process through the final translation rule, the final translation rule and the constraint condition are used as the translation rule to translate a line of binary code containing the virtual constraint contact.

[0040] In addition, in step U8, if the execution results are completely inconsistent, a virtual jump contact is generated. When the translation learning model triggers the virtual jump contact during the translation process through the final translation rule, the final translation rule does not translate a line of binary code containing the virtual jump contact, and jumps to the next line of the binary code, and translates the next line of binary code based on the final translation rule.

[0041] After the translation learning model completes the translation, the translation code in tcg is used to translate the binary code within the jumped range, and the translation result is written into the corresponding position of the target code.

[0042] In this embodiment, after the method is implemented based on the QEMU system, the performance of the code translation execution process is greatly improved. It is tested that the performance of the test program in SPEC CPU INT 2006 is improved by more than 15% on the virtual platform using the method compared with the original platform.

[0043] Example Function and Effect

[0044] According to a virtualization-oriented rule-learning-based binary translation method in this embodiment, since the translation learning model can automatically obtain the final translation rules through pre-training, compared with the traditional translation system in which the translation rules are constructed by developers manually writing, it saves labor costs, improves the execution efficiency of the binary translation system, and saves unnecessary expenses. Furthermore, since the training data set is divided into multiple more flexible current ranges based on the source code line number rule in the process of automatically obtaining the final translation rules, the learning process has more opportunities to obtain translation rules. This embodiment introduces a preset pre-value to iteratively train the translation learning model so that the final translation rules obtained by the translation learning model guarantee performance while improving coverage.

[0045] In this embodiment, the constraint equivalence (introduction of constraint conditions) method is used in the learning and verification phases to identify inequivalent parts in the translation rules, such as inconsistent numbers of registers, and mark these inequities as constraints. This greatly reduces the workload of writing translation rules and improves the actual translation performance. More high-quality translation rules can be obtained in the learning phase, improving the coverage and performance of the original method.

[0046] In this embodiment, the binary code within the jumped range is translated using the translation code in tcg, and the translation result is written into the corresponding position of the target code. On the premise of ensuring that the translation rules are efficient and feasible, the integrity of the translation target is also guaranteed.

[0047] In this embodiment, by introducing a preset source code line number rule, the source code is divided into different parts according to different rules. The user can adjust the source code line number rule according to specific translation requirements, or the final translation rules of different translation accuracies.

[0048] The above embodiments are only used to illustrate specific implementation modes of the present invention, and the present invention is not limited to the description scope of the above embodiments.

Claims

1. A virtualization-oriented rule-based binary translation method for translating a source code generated by a compilation method into a target code generated by another compilation method, characterized in that: include: A data preparation step, obtaining multiple lines of binary code to be translated; A code translation step, inputting the code to be translated into a translation learning model that has completed translation training in advance, and the translation learning model obtains the target code corresponding to the code to be translated through a final translation rule; The specific steps of performing translation training on the translation learning model include: In the step of constructing a training data set, the translation learning model uses the training code to be translated and the training target code obtained by respectively compiling the same multi-line source code in two different compilation modes as the training data set; A step of constructing a range, dividing the multiple lines of source code into multiple parts in sequence based on a predetermined rule of the number of source code lines, and dividing the training data set into multiple corresponding ranges to be processed based on the correspondence between the source code in each part and the training code to be translated and the training target code; a current state acquisition step, taking the first to-be-processed range among the multiple to-be-processed ranges as the current range, and obtaining the current translation rule by binary instruction parsing the binary code in the current range; An intermediate state setting step, setting the current range as an intermediate range, and setting the current rule as an intermediate rule; a state updating step of sequentially obtaining a to-be-processed range after the intermediate range from the plurality of to-be-processed ranges as a new current range, and obtaining a new current translation rule by parsing the binary code in the new current range through the binary instruction; A rule judgment step, entering the intermediate state setting step until the similarity between the current translation rule and the temporarily stored translation rule reaches a preset value; A translation rule execution step, taking the current rule as the translation rule, and applying the translation rule to translate the training code to be translated in the data set line by line to obtain the target code to be verified; The training completion judgment step determines that each line of the target code to be verified is completely consistent with the corresponding training target code, then the translation rule is used as the final translation rule of the translation learning model, and the translation learning model is output as the completed preset translation learning model.

2. The virtualization-oriented rule-learning-based binary translation method according to claim 1, characterized in that: in, In the training completion step, if the target code to be verified obtained in a certain row is partially consistent with the corresponding target code for training, a constraint condition is introduced, and a virtual constraint contact corresponding to the constraint condition is generated based on the target code to be verified obtained in the certain row and the code to be translated for training in this row, The target code to be verified obtained by the training code to be translated through the constraint conditions and the translation rules is completely consistent with the corresponding training target code, When the final translation rule triggers the virtual constraint contact during the translation process, the final translation rule and the constraint condition are used together as translation rules to translate a line of binary code containing the virtual constraint contact.

3. The virtualization-oriented rule-learning-based binary translation method according to claim 1, characterized in that: in, If the target code to be verified is completely inconsistent with the corresponding target code for training in a row in the training completion step under special circumstances, a virtual jump contact is generated. When the final translation rule triggers the virtual jump contact during the translation process, the final translation rule does not translate a line of binary code containing the virtual jump contact, and jumps to the next line of the binary code, and translates the next line of binary code based on the final translation rule.

4. The virtualization-oriented rule-learning-based binary translation method according to claim 1, characterized in that: in, The predetermined rule of the number of source code lines is to divide the multiple lines of source code into the multiple parts in order according to the number of lines based on an arithmetic progression with one line as the common difference and the first term as the first line.

Citation Information

Patent Citations

  • A binary translation intermediate representation correctness test method and device based on semantic equivalence verification

    CN109634869A

  • Translation method in dynamic binary translation

    CN1746849A