Automatic parallelization low-coupling dynamic binary translation tool and method

Through the automatic parallelization of low-coupling dynamic binary translation tools and the use of LLVM IR and inter-process communication, the problems of high coupling and large execution overhead in dynamic binary translation technology are solved, and more efficient code translation and execution are achieved.

CN118689489APending Publication Date: 2024-09-24NANKAI UNIV
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202410836292.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-26
Publication Date
2024-09-24

AI Technical Summary

Technical Problem

Existing dynamic binary translation technology has the problems of high coupling and high execution overhead, which leads to difficulty in development and maintenance and high running time consumption.

Method used

Using an automatically parallelized low-coupling dynamic binary translation tool, through the inter-process communication pipeline between the QEMU side and the Instrew Server side, and using LLVM IR as an intermediate language to decode, optimize and generate target platform binary files, reducing coupling And improves parallel execution capabilities.

Benefits of technology

It implements a low-coupling dynamic binary translation process, simplifies the translation and optimization process, reduces execution overhead, and improves program execution performance and flexibility.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118689489A
    Figure CN118689489A
Patent Text Reader

Abstract

The invention discloses an automatic parallelization low-coupling dynamic binary translation tool and method. The automatic parallelization low-coupling dynamic binary translation tool comprises a QEMU end, an inter-process communication pipeline, an Instream Server end and a target code cache. The QEMU end is used for loading and initializing an original architecture binary file, sending a maintained processor state and an initialization request through an inter-process communication pipeline, searching whether the original architecture binary file is translated or not, loading and executing if the original architecture binary file is translated, otherwise, searching from a target code cache, loading and executing if the target code cache is translated, and otherwise, initiating a translation request; loading and executing from the target code cache after translation is completed; the Instream Server end is used for initializing and establishing a register mapping relation, receiving a translation request, loading a corresponding code snippet according to a code address, decoding a code block, translating the code block into an intermediate language, optimizing the intermediate language, generating a target binary file and storing the target binary file into a target code cache; according to the method, low coupling of automatic parallel optimization codes is realized, and the execution overhead is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and more particularly to an automatic parallel low-coupling dynamic binary translation tool and method. Background Art

[0002] Binary translation technology refers to the cross-architecture instruction translation of binary files. It can generate binary files under a specified architecture through decoding, intermediate language representation and optimization, target platform machine code generation and other steps, thereby achieving the purpose of simulating the original program function and reverse analysis in the absence of source program.

[0003] At present, static binary technology SBT can be performed offline, but SBT often has problems with code discovery and identification of self-modifying code, which requires users to intervene in the translation process or combine it with the dynamic binary translation technology discussed next to solve it; dynamic binary translation technology DBT can well solve the problems encountered in the static binary translation technology mentioned above.

[0004] However, the existing dynamic binary translation technology has the following disadvantages:

[0005] High coupling: Existing dynamic binary translation tools often have a high degree of coupling. The front-end decoding, mid-end optimization, and back-end execution parts are often integrated together, which often leads to a ripple effect when making development improvements. This brings certain difficulties to development and maintenance: when a new system architecture or new requirements emerge, the DBT tool needs to be modified accordingly from beginning to end, which consumes a lot of time and manpower;

[0006] Execution overhead: Dynamic binary translation technology is mainly divided into translation and execution processes. During the runtime of dynamic binary translation, since it is necessary to translate and execute at the same time, and to optimize the code during the translation process, the translation and optimization time will be included in the runtime overhead. Therefore, the translation and optimization process in the dynamic binary translation process should be simplified as much as possible to reduce time consumption. Therefore, many studies focus on the optimization of the translation and optimization process, and try to make these two processes simpler and faster. However, the survey found that in programs with parallel characteristics, execution overhead actually accounts for a large part.

[0007] Therefore, how to achieve low coupling of automatic parallel optimization codes and reduce execution overhead is an urgent problem that needs to be solved by those skilled in the art. Summary of the invention

[0008] In view of this, the present invention provides an automatic parallel low-coupling dynamic binary translation tool and method to solve some of the technical problems mentioned in the background technology.

[0009] In order to achieve the above object, the present invention adopts the following technical solution:

[0010] An automatic parallelized low-coupling dynamic binary translation tool, including QEMU side, inter-process communication pipeline, Instrew Server side and target code cache;

[0011] QEMU is used to load binary files under the original architecture instruction set and initialize the program running environment. It sends the processor status and initialization request maintained by QEMU to the Instrew Server through the inter-process communication pipeline. After the initialization is completed, it searches for translated code based on the program entry address. If so, it loads and executes it. If not, it searches for the corresponding code fragment from the target code cache. If found, it loads and executes it. If not found, it uses the inter-process communication pipeline to initiate a translation request to the Instrew Server. It is also used to receive the message that the Instrew Server has completed the translation, load the code fragment stored in the ELF format from the target code cache, load it and execute it.

[0012] The Instrew Server is used to receive the processor status and initialization request maintained by QEMU, perform initialization and establish a register mapping relationship with the QEMU side. After receiving the translation request, the corresponding code fragment is loaded from the binary file loaded by the QEMU side according to the code address, and the code block to be translated is decoded, translated into an intermediate language and optimized. Finally, a binary file in the ELF format of the target platform is generated and stored in the target code cache. The translation completion message is replied to the QEMU side through the inter-process communication pipe.

[0013] Preferably, the QEMU end includes a QEMU backend, a QEMU agent and a QA API;

[0014] The QEMU backend interacts with the QEMU agent through the QA API;

[0015] The QEMU agent communicates with the Instrew Server using an inter-process communication pipe.

[0016] Preferably, the QEMU backend is used to store the translated code snippets in a continuous area in the memory after initializing the program environment, and to search whether the area contains the translated code snippets before each run. If found, the translated code snippets are loaded and executed. If not found, the translated code snippets are delivered to the QEMU agent for processing using the QA API. After the translation is completed on the Instrew Server side, the translated code snippets are loaded and executed from the cache of the QEMU backend.

[0017] QEMU agent is used to start the Instrew Server process. After the QEMU backend is initialized, it uses the pipeline to initiate an initialization request to the Instrew Server, and sends the processor state maintained by QEMU to the InstrewServer. It receives the message that the Instrew Server initialization is completed. When the translated code fragment is not found in the code cache and target code cache of the QEMU backend, it initiates a translation request and receives messages of successful and failed translation. When the translation is successful, it is responsible for loading the code fragment from the target code cache and storing it in the code cache of the QEMU backend, sending a message of the end of execution and receiving a message containing the exit status of the Instrew Server.

[0018] Preferably, the Instrew Server includes a decoding module, a Rellume module, an automatic parallel optimization module and a target code generation module;

[0019] The decoding module is used to load the corresponding code fragment from the binary file loaded by the QEMU end according to the code address after receiving the translation request, and decode it to obtain the function-like granularity code block;

[0020] The Rellume module is used to establish a mapping between the source architecture registers and the target architecture registers according to the processor state maintained by QEMU, and translate the Function-like granularity code blocks into the intermediate language LLVM IR;

[0021] Automatic parallel optimization module, which uses common LLVM Pass and custom optimization Pass to perform preliminary optimization, code refactoring and semantic recovery, obtain optimized LLVM IR, and generate multi-threaded code that can be executed in parallel for the target architecture;

[0022] The target code generation module is used to package the multi-threaded code that can be executed in parallel into an ELF binary file and store it in the target code cache.

[0023] Preferably, the automatic parallel optimization module includes an existing LLVM Pass, an IR reconstruction Pass, a GEP instruction recovery Pass, and an existing Polly Pass;

[0024] There is already an LLVM Pass for preliminary optimization of the intermediate language LLVM IR;

[0025] IR reconstruction pass is used to identify the reading and writing of temporary variables in the simulated stack operation in combination with translation rules, and then rewrite the corresponding part of the code to remove unnecessary memory dependencies while ensuring correctness;

[0026] The GEP instruction recovery pass is used to obtain the array dimensions and the sizes of each dimension based on the address calculation instructions for the code part that can be optimized in parallel, and rewrite the access to the array elements into GEP instructions;

[0027] There is already a Polly Pass for processing the rewritten code, detecting and analyzing the code parts that can be optimized in parallel, and generating multi-threaded code that can be executed in parallel based on the rewritten GEP instructions.

[0028] Preferably, the decoding module decodes to obtain a code block of Function-like granularity as follows: starting from an address that has not been translated, the machine code instructions in the binary file are translated into assembly code in sequence. When a non-direct jump or call instruction is encountered, all code blocks that have been translated into assembly code are regarded as a translation unit, i.e., a code block of Function-like granularity.

[0029] An automatic parallel low-coupling dynamic binary translation method comprises the following steps:

[0030] S1. QEMU loads the binary file under the original architecture instruction set and initializes the program running environment, and sends the processor status and initialization request maintained by QEMU to the Instrew Server through the inter-process communication pipeline;

[0031] S2. The Instrew Server receives the processor status and initialization request maintained by QEMU, performs initialization, and establishes a register mapping relationship with the QEMU side;

[0032] S3. After initialization, QEMU searches for translated code based on the program entry address. If so, it loads and executes it. If not, it searches for the corresponding code snippet from the target code cache. If found, it loads and executes it. If not found, it uses the inter-process communication pipeline to initiate a translation request to the Instrew Server.

[0033] S4. After receiving the translation request, the Instrew Server loads the corresponding code fragment from the binary file loaded by the QEMU side according to the code address, decodes the code block to be translated, translates it into an intermediate language and optimizes it, and finally generates a binary file in the ELF format of the target platform and stores it in the target code cache, and replies to the QEMU side through the inter-process communication pipe to inform it that the translation is completed;

[0034] S5.QEMU receives the message that the translation is completed from the Instrew Server, loads the code fragment stored in the ELF format from the target code cache, loads it and executes it.

[0035] Preferably, the QEMU end includes a QEMU backend, a QEMU agent and a QA API; the QEMU backend interacts with the QEMU agent through the QA API; the QEMU agent communicates with the Instrew Server end by using an inter-process communication pipe;

[0036] The QEMU backend loads the binary files under the original architecture instruction set and initializes the program running environment; after the QEMU backend is initialized, the QEMU agent uses the pipeline to initiate an initialization request to the Instrew Server, and sends the processor state maintained by QEMU to the Instrew Server for initialization; the QEMU agent receives the message that the initialization is completed from the InstrewServer, and the QEMU backend uses a continuous area in the memory to store the translated code snippets. Before each run, it searches the area for translated code snippets. If found, it loads and executes them. If not found, it uses the QA API to deliver the QEMU agent to initiate a translation request.

[0037] Preferably, the specific content of step S4 is:

[0038] S41. After receiving the translation request, the corresponding code fragment is loaded from the binary file loaded by the QEMU end according to the code address, and the code block of the class Function granularity is decoded;

[0039] S42. According to the mapping between the source architecture register and the target architecture register, the Function-like granularity code block is translated into the intermediate language LLVM IR;

[0040] S43. Use the general LLVM Pass and the custom optimization Pass to perform preliminary optimization, code refactoring, and semantic recovery to obtain the optimized LLVM IR and generate multi-threaded code that can be executed in parallel for the target architecture;

[0041] S44. Package the multi-threaded code that can be executed in parallel into an ELF binary file and store it in the target code cache.

[0042] Preferably, the specific content of step S43 is:

[0043] S431. Perform preliminary optimization on the intermediate language LLVM IR;

[0044] S432. Combining the translation rules to identify the reading and writing of temporary variables in the simulated stack operation, and then rewriting the corresponding part of the code to remove unnecessary memory dependencies while ensuring correctness;

[0045] S433. Obtain the array dimension and the size of each dimension according to the relevant instructions of address calculation for the code part that can be optimized in parallel, and rewrite the access to the array elements into GEP instructions;

[0046] S434. Process the rewritten code, detect and analyze the code parts that can be optimized in parallel, and generate multi-threaded code that can be executed in parallel based on the rewritten GEP instructions.

[0047] It can be seen from the above technical solutions that, compared with the prior art, the present invention discloses an automatic parallel low-coupling dynamic binary translation tool and method, which selects LLVM IR as the intermediate language, and combines the Instrew tool and QEMU to respectively perform the translation optimization of binary files and the execution of translated codes. This low-coupling mode enables researchers to flexibly apply optimization methods without having to consider too much the impact on other parts of DBT.

[0048] Use Instrew to directly promote machine code to LLVM IR, reducing the extra overhead of promoting machine code to TCG IR first and then to LLVM IR;

[0049] Using Instrew, optimization can be performed at the Function-like granularity. The Function-like granularity translation unit can contain more structural and semantic information, which is more conducive to the recovery of later code and structural semantics.

[0050] By using the existing LLVM Pass and the custom-implemented Pass to reconstruct the code and restore the semantic information, the Polly tool is combined to realize the automatic parallelization of the serial code, making full use of the characteristics of multi-core platform that can execute in parallel to improve program performance, greatly shortening the execution time of the program. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0052] Figure 1 A schematic diagram of the framework of an automatic parallel low-coupling dynamic binary translation tool provided by the present invention;

[0053] Figure 2 A schematic diagram of the register mapping provided by the present invention. DETAILED DESCRIPTION

[0054] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0055] The embodiment of the present invention discloses an automatic parallel low-coupling dynamic binary translation tool, such as Figure 1 , including QEMU side, inter-process communication pipe, Instrew Server side and target code cache;

[0056] QEMU is used to load binary files under the original architecture instruction set and initialize the program running environment. It sends the processor status and initialization request maintained by QEMU to the Instrew Server through the inter-process communication pipeline. After the initialization is completed, it searches for translated code based on the program entry address. If so, it loads and executes it. If not, it searches for the corresponding code fragment from the target code cache. If found, it loads and executes it. If not found, it uses the inter-process communication pipeline to initiate a translation request to the Instrew Server. It is also used to receive the message that the Instrew Server has completed the translation, load the code fragment stored in the ELF format from the target code cache, load it and execute it.

[0057] The Instrew Server is used to receive the processor status and initialization request maintained by QEMU, perform initialization and establish a register mapping relationship with the QEMU side. After receiving the translation request, the corresponding code fragment is loaded from the binary file loaded by the QEMU side according to the code address, and the code block to be translated is decoded, translated into an intermediate language and optimized. Finally, a binary file in the ELF format of the target platform is generated and stored in the target code cache. The translation completion message is replied to the QEMU side through the inter-process communication pipe.

[0058] To further implement the above technical solution, the QEMU side includes the QEMU backend, QEMU agent and QA API;

[0059] The QEMU backend interacts with the QEMU agent through the QA API;

[0060] The QEMU agent communicates with the Instrew Server using an inter-process communication pipe.

[0061] In this embodiment, the communication between the Instrew Server and the QEMU Agent is realized by two pipes (inter-process communication pipes). The message types transmitted by the pipes include: translation requests with code addresses, translation completion signals, translation failure signals, initialization signals, untranslated code blocks, etc. The QEMU backend assumes the role of the Instrew Client and communicates with the Server through the QEMU Agent using pipes.

[0062] In order to further implement the above technical solution, the QEMU backend is mainly implemented by the user mode of QEMU. After initializing the environment, QEMU will cyclically call the function (cpu-exec) for executing the code. The function parameter is the processor state CPUState maintained by the QEMU backend, which simulates the operating environment and registers of the source platform. After initializing the program environment, a continuous area in the memory is used to store the translated code fragments. Before each run, the area is searched for whether the translated code fragments are contained. If found, they are loaded and executed. If not found, the QA API is used to deliver it to the QEMU agent for processing. After the InstrewServer end completes the translation, it is loaded and executed from the cache of the QEMU backend.

[0063] QEMU agent is used to start the Instrew Server process. After the QEMU backend is initialized, it uses the pipeline to initiate an initialization request to the Instrew Server, and sends the processor state maintained by QEMU to the InstrewServer. It receives the message that the Instrew Server initialization is completed. When the translated code fragment is not found in the code cache and target code cache of the QEMU backend, it initiates a translation request and receives messages of successful and failed translation. When the translation is successful, it is responsible for loading the code fragment from the target code cache and storing it in the code cache of the QEMU backend, sending a message of the end of execution and receiving a message containing the exit status of the Instrew Server.

[0064] In this embodiment, the common feature of the dynamic binary translation tools is to maintain the processor and operating environment (stack) status of a target platform, and update it in time according to the code running results. However, there are differences in the processor states maintained by Instrew and QEMU, and a specific mapping needs to be implemented as a bridge between the two. After the initialization of the QEMU backend is completed, the QEMU Agent will use the pipeline to initiate an initialization request to the Instrew Server, and send the processor state maintained by QEMU to the Instrew Server, so that it can establish a mapping between the QEMU backend and the registers managed by Instrew based on the information; for example, the storage order of the processor structure maintained by the QEMU backend is eax, ecx, and the storage order of the structure used by the InstrewServer during translation is ecx, eax. Then, the mapping can map the reading and writing of the first variable position in the structure to the reading and writing of the second variable during the translation process, so that the code translated by the Instrew Server can run correctly on the QEMU backend.

[0065] In order to further implement the above technical solution, the Instrew Server includes a decoding module, a Rellume module, an automatic parallel optimization module and a target code generation module;

[0066] The decoding module is used to load the corresponding code fragment from the binary file loaded by the QEMU end according to the code address after receiving the translation request, and decode it to obtain the function-like granularity code block;

[0067] The Rellume module is used to establish a mapping between the source architecture registers and the target architecture registers according to the processor state maintained by QEMU, and translate the Function-like granularity code blocks into the intermediate language LLVM IR;

[0068] Automatic parallel optimization module, which uses common LLVM Pass and custom optimization Pass to perform preliminary optimization, code refactoring and semantic recovery, obtain optimized LLVM IR, and generate multi-threaded code that can be executed in parallel for the target architecture;

[0069] The target code generation module is used to package the multi-threaded code that can be executed in parallel into an ELF binary file and store it in the target code cache.

[0070] In order to further implement the above technical solutions, the automatic parallel optimization module includes the existing LLVM Pass, IR reconstruction Pass, GEP instruction recovery Pass and the existing Polly Pass;

[0071] There is already an LLVM Pass for preliminary optimization of the intermediate language LLVM IR;

[0072] IR reconstruction pass is used to identify the reading and writing of temporary variables in the simulated stack operation in combination with translation rules, and then rewrite the corresponding part of the code to remove unnecessary memory dependencies while ensuring correctness;

[0073] For example, when X86-64 is used as the target architecture, LLVM can provide the HHVM calling convention. The actual design purpose of this calling convention is to develop a calling scheme for the HipHop virtual machine, which is used for PHP and Hack. The HHVM calling convention can pass 15 parameters and return 14 values. Only two registers, r12 and rsp, of the 16 general registers in the x86 architecture are saved by the callee. Instrew applies this calling convention to speed up the rewriting process. When switching function execution, the values ​​of 12 general registers are saved in the registers provided by the target platform. When accessing related values, the registers storing the required values ​​are found through the specified register mapping, thereby converting memory access into register access, greatly reducing memory access overhead. In addition, the CPU structure pointer is passed as a parameter, and the address of the next instruction is additionally returned; another register is reserved to reduce register pressure. The register mapping is as follows Figure 2 shown.

[0074] The GEP instruction recovery pass is used to obtain the array dimensions and the sizes of each dimension based on the address calculation instructions for the code part that can be optimized in parallel, and rewrite the access to the array elements into GEP instructions;

[0075] There is already a Polly Pass for processing the rewritten code, detecting and analyzing the code parts that can be optimized in parallel, and generating multi-threaded code that can be executed in parallel based on the rewritten GEP instructions.

[0076] For example: when running an x86 binary file under the arm architecture, after the Instrew Server gets the untranslated address, it starts from this address and translates the machine code in the binary file into assembly code one by one until it encounters the ret instruction (or other non-direct jump instructions), and then it regards all the code blocks that have been translated into assembly code as a translation unit; then, the Instrew Server uses the submodule rellume to lift this translation unit into LLVM IR, and then applies a series of Passes to optimize it based on the LLVM IR. These Passes include the automatic parallel optimization part (identifying temporary variables, temporary variable recovery, GEP instruction recovery, etc.). After all Passes are run, the optimized LLVM IR can be obtained, and then the machine code of the arm architecture is generated based on this LLVM IR code block, and it is packaged into an ELF binary file and placed in the code cache, and the QEMU agent is informed of the completion of the translation.

[0077] In order to further implement the above technical solution, the process of decoding the code block of the Function-like granularity by the decoding module is as follows: starting from the address that has not been translated, the machine code instructions in the binary file are translated into assembly code in sequence. When encountering a non-direct jump or call instruction, all the code blocks that have been translated into assembly code are regarded as a translation unit, that is, a code block of the Function-like granularity.

[0078] An automatic parallel low-coupling dynamic binary translation method comprises the following steps:

[0079] S1. QEMU loads the binary file under the original architecture instruction set and initializes the program running environment, and sends the processor status and initialization request maintained by QEMU to the Instrew Server through the inter-process communication pipeline;

[0080] S2. The Instrew Server receives the processor status and initialization request maintained by QEMU, performs initialization, and establishes a register mapping relationship with the QEMU side;

[0081] S3. After initialization, QEMU searches for translated code based on the program entry address. If so, it loads and executes it. If not, it searches for the corresponding code snippet from the target code cache. If found, it loads and executes it. If not found, it uses the inter-process communication pipeline to initiate a translation request to the Instrew Server.

[0082] S4. After receiving the translation request, the Instrew Server loads the corresponding code fragment from the binary file loaded by the QEMU side according to the code address, decodes the code block to be translated, translates it into an intermediate language and optimizes it, and finally generates a binary file in the ELF format of the target platform and stores it in the target code cache, and replies to the QEMU side through the inter-process communication pipe to inform it that the translation is completed;

[0083] S5.QEMU receives the message that the translation is completed from the Instrew Server, loads the code fragment stored in the ELF format from the target code cache, loads it and executes it.

[0084] In order to further implement the above technical solution, the QEMU end includes a QEMU backend, a QEMU agent and a QA API; the QEMU backend interacts with the QEMU agent through the QA API; the QEMU agent communicates with the Instrew Server end by using an inter-process communication pipe;

[0085] The QEMU backend loads the binary files under the original architecture instruction set and initializes the program running environment; after the QEMU backend is initialized, the QEMU agent uses the pipeline to initiate an initialization request to the Instrew Server, and sends the processor state maintained by QEMU to the Instrew Server for initialization; the QEMU agent receives the message that the initialization is completed from the InstrewServer, and the QEMU backend uses a continuous area in the memory to store the translated code snippets. Before each run, it searches the area for translated code snippets. If found, it loads and executes them. If not found, it uses the QA API to deliver the QEMU agent to initiate a translation request.

[0086] In order to further implement the above technical solution, the specific content of step S4 is:

[0087] S41. After receiving the translation request, the corresponding code fragment is loaded from the binary file loaded by the QEMU end according to the code address, and the code block of the class Function granularity is decoded;

[0088] S42. According to the mapping between the source architecture register and the target architecture register, the Function-like granularity code block is translated into the intermediate language LLVM IR;

[0089] S43. Use the general LLVM Pass and the custom optimization Pass to perform preliminary optimization, code refactoring, and semantic recovery to obtain the optimized LLVM IR and generate multi-threaded code that can be executed in parallel for the target architecture;

[0090] S44. Package the multi-threaded code that can be executed in parallel into an ELF binary file and store it in the target code cache.

[0091] In order to further implement the above technical solution, the specific content of step S43 is:

[0092] S431. Perform preliminary optimization on the intermediate language LLVM IR;

[0093] S432. Combining the translation rules to identify the reading and writing of temporary variables in the simulated stack operation, and then rewriting the corresponding part of the code to remove unnecessary memory dependencies while ensuring correctness;

[0094] S433. Obtain the array dimension and the size of each dimension according to the relevant instructions of address calculation for the code part that can be optimized in parallel, and rewrite the access to the array elements into GEP instructions;

[0095] S434. Process the rewritten code, detect and analyze the code parts that can be optimized in parallel, and generate multi-threaded code that can be executed in parallel based on the rewritten GEP instructions.

[0096] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.

[0097] The above description of the disclosed embodiments enables one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. An automatic parallel low-coupling dynamic binary translation tool, characterized in that: Including QEMU side, inter-process communication pipe, Instrew Server side and target code cache; QEMU is used to load binary files under the original architecture instruction set and initialize the program running environment. It sends the processor status and initialization request maintained by QEMU to the Instrew Server through the inter-process communication pipeline. After the initialization is completed, it searches for translated code based on the program entry address. If so, it loads and executes it. If not, search for the corresponding code snippet from the target code cache, and if found, load and execute it; If not found, the inter-process communication pipeline is used to initiate a translation request to the Instrew Server, and is also used to receive the message that the translation is completed from the Instrew Server, load the code fragment stored in the ELF format from the target code cache, load it and execute it; The Instrew Server is used to receive the processor status and initialization request maintained by QEMU, perform initialization and establish a register mapping relationship with the QEMU side. After receiving the translation request, the corresponding code fragment is loaded from the binary file loaded by the QEMU side according to the code address, and the code block to be translated is decoded, translated into an intermediate language and optimized. Finally, a binary file in the ELF format of the target platform is generated and stored in the target code cache. The translation completion message is replied to the QEMU side through the inter-process communication pipe.

2. The automatic parallel low-coupling dynamic binary translation tool according to claim 1, characterized in that: The QEMU side includes the QEMU backend, QEMU agent, and QA API; The QEMU backend interacts with the QEMU agent through the QA API; The QEMU agent communicates with the Instrew Server using an inter-process communication pipe.

3. The automatic parallel low-coupling dynamic binary translation tool according to claim 2, characterized in that: QEMU backend is used to initialize the program environment, use a continuous area in the memory to store the translated code snippets, and search the area before each run to see if there is a translated code snippet. If found, it will be loaded and executed. If not found, it will be delivered to QEMU agent for processing using QA API. After the translation is completed on the Instrew Server side, it will be loaded and executed from the cache of QEMU backend; QEMU agent is used to start the Instrew Server process. After the QEMU backend is initialized, it uses the pipeline to initiate an initialization request to the Instrew Server, and sends the processor status maintained by QEMU to the Instrew Server. It receives the message that the Instrew Server initialization is completed. When the translated code fragment is not found in the code cache and target code cache of the QEMU backend, it initiates a translation request and receives messages of successful and failed translation. When the translation is successful, it is responsible for loading the code fragment from the target code cache and storing it in the code cache of the QEMU backend, sending a message of the end of execution and receiving a message containing the exit status of the Instrew Server.

4. The automatic parallel low-coupling dynamic binary translation tool according to claim 1, characterized in that: The Instrew Server includes a decoding module, a Rellume module, an automatic parallel optimization module, and a target code generation module; The decoding module is used to load the corresponding code fragment from the binary file loaded by the QEMU end according to the code address after receiving the translation request, and decode it to obtain the function-like granularity code block; The Rellume module is used to establish a mapping between the source architecture registers and the target architecture registers according to the processor state maintained by QEMU, and translate the Function-like granularity code blocks into the intermediate language LLVM IR; Automatic parallel optimization module, which uses common LLVM Pass and custom optimization Pass to perform preliminary optimization, code refactoring and semantic recovery, obtain optimized LLVM IR, and generate multi-threaded code that can be executed in parallel for the target architecture; The target code generation module is used to package the multi-threaded code that can be executed in parallel into an ELF binary file and store it in the target code cache.

5. The automatic parallel low-coupling dynamic binary translation tool according to claim 1, characterized in that: The automatic parallel optimization module includes the existing LLVM Pass, IR reconstruction Pass, GEP instruction recovery Pass and the existing Polly Pass; There is already an LLVM Pass for preliminary optimization of the intermediate language LLVM IR; IR reconstruction pass is used to identify the reading and writing of temporary variables in the simulated stack operation in combination with translation rules, and then rewrite the corresponding part of the code to remove unnecessary memory dependencies while ensuring correctness; The GEP instruction recovery pass is used to obtain the array dimensions and the sizes of each dimension based on the address calculation instructions for the code part that can be optimized in parallel, and rewrite the access to the array elements into GEP instructions; There is already a Polly Pass for processing the rewritten code, detecting and analyzing the code parts that can be optimized in parallel, and generating multi-threaded code that can be executed in parallel based on the rewritten GEP instructions.

6. The automatic parallel low-coupling dynamic binary translation tool according to claim 3, characterized in that: The process of decoding the code block of the Function-like granularity by the decoding module is as follows: starting from the address that has not been translated, the machine code instructions in the binary file are translated into assembly code in sequence. When encountering a non-direct jump or call instruction, all the code blocks that have been translated into assembly code are regarded as a translation unit, that is, a code block of the Function-like granularity.

7. An automatic parallel low-coupling dynamic binary translation method, characterized in that: The following steps are involved: S1. QEMU loads the binary file under the original architecture instruction set and initializes the program running environment, and sends the processor status and initialization request maintained by QEMU to the Instrew Server through the inter-process communication pipeline; S2. The Instrew Server receives the processor status and initialization request maintained by QEMU, performs initialization, and establishes a register mapping relationship with the QEMU side; S3. After initialization, QEMU searches for translated code based on the program entry address. If so, load and execute it. If not, search for the corresponding code snippet from the target code cache, and if found, load and execute it; If not found, a translation request is sent to the Instrew Server using the inter-process communication pipeline; S4. After receiving the translation request, the Instrew Server loads the corresponding code fragment from the binary file loaded by the QEMU side according to the code address, decodes the code block to be translated, translates it into an intermediate language and optimizes it, and finally generates a binary file in the ELF format of the target platform and stores it in the target code cache, and replies to the QEMU side through the inter-process communication pipe to inform it that the translation is completed; S5.QEMU receives the message that the translation is completed from the Instrew Server, loads the code fragment stored in the ELF format from the target code cache, loads it and executes it.

8. The automatic parallel low-coupling dynamic binary translation method according to claim 7, characterized in that: The QEMU side includes the QEMU backend, QEMU agent, and QA API. The QEMU backend interacts with the QEMU agent through the QA API. The QEMU agent communicates with the Instrew Server side by using an inter-process communication pipe. The QEMU backend loads the binary files under the original architecture instruction set and initializes the program running environment; after the QEMU backend is initialized, the QEMU agent uses the pipeline to initiate an initialization request to the Instrew Server, and sends the processor state maintained by QEMU to the Instrew Server for initialization; the QEMU agent receives the message that the initialization is completed on the Instrew Server, and the QEMU backend uses a continuous area in the memory to store the translated code snippets. Before each run, it searches the area for translated code snippets. If found, it loads and executes them. If not found, it uses the QA API to deliver the QEMU agent to initiate a translation request.

9. The automatic parallel low-coupling dynamic binary translation method according to claim 7, characterized in that: The specific content of step S4 is: S41. After receiving the translation request, the corresponding code fragment is loaded from the binary file loaded by the QEMU end according to the code address, and the code block of the class Function granularity is decoded; S42. According to the mapping between the source architecture register and the target architecture register, the Function-like granularity code block is translated into the intermediate language LLVM IR; S43. Use the general LLVM Pass and the custom optimization Pass to perform preliminary optimization, code refactoring, and semantic recovery to obtain the optimized LLVM IR and generate multi-threaded code that can be executed in parallel for the target architecture; S44. Package the multi-threaded code that can be executed in parallel into an ELF binary file and store it in the target code cache.

10. The automatic parallel low-coupling dynamic binary translation method according to claim 9, characterized in that: The specific content of step S43 is: S431. Perform preliminary optimization on the intermediate language LLVM IR; S432. Combining the translation rules to identify the reading and writing of temporary variables in the simulated stack operation, and then rewriting the corresponding part of the code to remove unnecessary memory dependencies while ensuring correctness; S433. Obtain the array dimension and the size of each dimension according to the relevant instructions of address calculation for the code part that can be optimized in parallel, and rewrite the access to the array elements into GEP instructions; S434. Process the rewritten code, detect and analyze the code parts that can be optimized in parallel, and generate multi-threaded code that can be executed in parallel based on the rewritten GEP instructions.

Citation Information

Cited By

  • Dynamic library mapping execution method and device in binary translation, equipment and medium

    CN120255959A