A dynamic binary translation acceleration method, system, medium, and product

By extracting and preprocessing the external dependency libraries and function symbol information of the target program, generating ELF function symbol information files, and utilizing memory mapping, the initialization overhead problem of the dynamic binary translation system is solved, improving the startup efficiency and running performance of embedded devices.

CN120596103BActive Publication Date: 2025-10-17KYLIN CORP
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511087205.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-08-05
Publication Date
2025-10-17
Estimated Expiration
2045-08-05

AI Technical Summary

Technical Problem

Existing dynamic binary translation systems suffer from high overhead and significant resource waste during the initialization phase due to symbol resolution and encapsulation matching. They also cannot reuse function information, affecting the availability of resource-constrained platforms such as embedded devices.

Method used

Extract the target program's external dependency libraries and their function symbol information, generate an ELF function symbol information file and save it to disk, load it using memory mapping, perform hash retrieval and function type mapping, and achieve fast binding of function encapsulation.

Benefits of technology

It significantly reduces dynamic translation initialization latency, improves startup efficiency and overall operating performance, and is particularly suitable for embedded systems and mobile devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120596103B_ABST
    Figure CN120596103B_ABST
Patent Text Reader

Abstract

The application discloses a dynamic binary translation acceleration method, system, medium and product, and comprises the following steps: before executing a target program, an ELF file of the target program is parsed, an external dependent library and function symbol information thereof are extracted, function name and meta information of each function symbol are generated by combining function information in the function library to generate an ELF function symbol information file and are mapped into memory; when external function lookup and calling are performed in the process of binary translation and execution of the target program in a target architecture, hash retrieval is performed on the ELF function symbol information in the memory; according to the function type retrieved, pointer mapping of the function type to a corresponding wrapper function is realized, and according to the encapsulation type retrieved, the address of a local function actually to be executed is acquired to realize actual calling, parameters and returning of the external function. The application aims to reduce the symbol parsing and encapsulation matching overhead in the dynamic translation initialization process and improve the starting efficiency and overall running performance.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computers, and particularly to a dynamic binary translation acceleration method, system, medium and product. BACKGROUND

[0002] With the development of heterogeneous computing architecture, dynamic binary translation technology is widely used to realize the compatible running between different instruction set architectures, especially running x86 architecture software on emerging processor architectures such as RISC-V. Dynamic binary translation can dynamically convert binary instructions of the source architecture (such as x86) into instructions of the target architecture (such as RISC-V) at runtime, so that programs that are not originally compatible can run on different platforms, effectively alleviating the compatibility problems caused by the fragmentation of the software ecosystem. Taking typical open source dynamic translators such as Box64 as an example, they use runtime interpretation and caching mechanisms to improve translation efficiency and program compatibility to a certain extent. However, such systems usually have a large performance overhead in the program initialization phase, especially when dealing with large programs or applications that frequently use dynamic link library functions. The translator needs to dynamically load and parse external symbols in the ELF file during the initialization process, and associate the symbols with the corresponding function encapsulation logic through a complex hash matching mechanism. This process not only involves a large amount of string parsing and hash operation, but also requires real-time judgment of the function encapsulation type (such as whether it is a weak function, whether it is a function that needs to be translated and re-encapsulated, etc.), resulting in a prolonged initialization time and significant resource consumption. In addition, the current dynamic translator repeatedly performs similar initialization processes every time the program is executed, and even if the same executable file is run, it cannot reuse the function information extracted and matched during the last run. This repeated effort further exacerbates resource waste, which is particularly evident on resource-constrained embedded platforms and low-power devices.

[0003] Although the existing dynamic binary translation system has certain performance and compatibility advantages, it can realize the conversion of instructions between different architectures, but there are still the following obvious shortcomings in function symbol analysis and function encapsulation processing: ①, large initialization overhead, low function analysis efficiency: in the program startup process, the dynamic translator needs to analyze the external function symbols in the ELF file, and add the library functions to the hash table through multiple loops, which causes significant initialization delay. Especially when the program depends on multiple external libraries, the function matching and binding process is extremely time-consuming, which seriously affects the running experience. ②, repeated analysis and matching process wastes resources: the existing translator needs to reanalyze the symbol information in the ELF every time the program is started, and rejudge the function type and bind the encapsulation logic. Even if the same program is run, the function information generated in the last translation process cannot be reused. This repeated work causes waste of computing resources and reduces the overall system efficiency. ③, multiple hash retrieval at runtime causes performance overhead: the existing dynamic binary translator (such as Box64) will retrieve each function name in multiple encapsulation type hash tables one by one when processing external function calls, to determine which encapsulation type the symbol belongs to. This "multiple hash table linear retrieval" mechanism will produce significant lookup overhead in the case of a large number of functions or high-frequency calls, affecting the startup speed and runtime performance of the program. ④, unable to preload function encapsulation mapping, lack of structured caching mechanism: the current technology lacks a structured way to solidify and reuse function encapsulation mapping information, resulting in the need for the translator to load the function table and build internal hash structures in real time every time. There is no unified data file format to support preloading and fast retrieval, so the system cannot enjoy the initialization speedup advantage of early processing. ⑤, affecting the usability of resource-sensitive platforms such as embedded devices: for resource-constrained platforms such as embedded systems and mobile devices, symbol analysis and dynamic function binding operations during initialization put a lot of pressure on memory and CPU, limiting the ability of such platforms to use dynamic binary translation technology to run complex software. SUMMARY

[0004] The technical problem to be solved by the present application is to provide a dynamic binary translation acceleration method, system, medium and product, which can reduce the symbol analysis and encapsulation matching overhead in the initialization process of dynamic translation, and improve the startup efficiency and overall running performance.

[0005] In order to solve the above technical problems, the technical scheme adopted by the present application is:

[0006] A dynamic binary translation acceleration method, comprising the following steps:

[0007] S101, extracting external dependent libraries and external functions required by a target program from a system of an original architecture of the target program and statically registering the external dependent libraries and the external functions to a function library;

[0008] S102, before binary translation of the target program in a target architecture, parsing an ELF file of the target program, extracting external dependent libraries and function symbol information thereof, combining function information in the function library to generate an ELF function symbol information file containing function names and meta information of each function symbol and saving the ELF function symbol information file to a disk;

[0009] S103, mapping the ELF function symbol information file in the disk to a memory by using a memory mapping mode;

[0010] S104, during binary translation of the target program in the target architecture, performing hash retrieval on the ELF function symbol information mapped to the memory when looking up and calling an external function;

[0011] S105, generating an ELF function symbol information file containing function names and meta information of each function symbol according to a function type of the external function retrieved by the hash retrieval, realizing pointer mapping of the function type to a corresponding wrapper function, and obtaining an address of a local function actually to be executed according to an encapsulation type of the external function;

[0012] S106, realizing actual calling, parameters and return of the external function by the wrapper function combined with the address of the local function through the pointer mapping, so as to realize normal running of the external function in the target architecture.

[0013] Optionally, when extracting external dependent libraries and external functions required by a target program from a system of an original architecture of the target program and statically registering the external dependent libraries and the external functions to a function library in step S101, a uniform interface is defined for the external functions by using a macro definition mechanism to realize unified management, and a plurality of arrays are defined for each external dependent library according to an encapsulation type of the external functions, and meta information of the external functions in each external dependent library is respectively expanded into a corresponding array according to the encapsulation type of the external functions, the meta information of the external functions including function names, function types and encapsulation types of the external functions.

[0014] Optionally, the step S102 of extracting external dependent libraries and function symbol information thereof and combining function information in the function library to generate an ELF function symbol information file containing function names and meta information of each function symbol includes:

[0015] S201, extracting function names of external dependent libraries and function symbols thereof and adding the function names to a function name list;

[0016] S202, constructing a structure for each loaded external dependent library, elements in the structure including: a name of the external dependent library, a type of the external dependent library, and a hash table for indexing external functions of different encapsulation types under the external dependent library;

[0017] S203, for each external dependent library, according to the meta information of the external functions expanded into the corresponding array, cyclically adding into the hash table corresponding to the external dependent library according to the encapsulation type;

[0018] S204, creating a data structure for structured storage of function information and hash index relationship;

[0019] S205, for each function name in the extracted function name list, respectively searching for a matching item in the hash table of each loaded external dependent library to fill the data structure for structured storage of function information and hash index relationship; generating an ELF function symbol information file containing the function name and meta information of each function symbol according to the filled data structure for structured storage of function information and hash index relationship, and saving to the disk.

[0020] Optionally, the data structure for structured storage of function information and hash index relationship created in step S204 includes the following fields: a macro definition SLOT_COUNT of the maximum slot number of the hash structure, used to define the maximum slot number of the hash structure; a function symbol information structure symbolInfo_t, used to record function symbol information, the function symbol information including a function name, an encapsulation type, a function type, and a resolution state; a hash table structure hashTable_t, used to record data in the hash table, the content under the hash table structure hashTable_t including: a function entry number count, used to record the external function entry number under the hash table, an offset offset, used to record the offset of the initial address corresponding to each hash slot; a hash disturbance array asso_values

[256] , used to store a hash disturbance array used as a parameter for a hash function to define an index value for calculating a hash slot; a payload array payload[] of indefinite length, used to save the ELF function symbol information of the function symbol information structure symbolInfo_t, and the ELF function symbol information of different external functions is distinguished by the offset.

[0021] Optionally, step S205 includes:

[0022] S301, generating a hash perturbation array, including: first, writing the function name and its metadata of each function recorded in the function symbol information structure body symbolInfo_t into a temporary file, and supplementing a plurality of placeholder keywords in the temporary file to meet the length requirement of the hash function generation tool gperf to generate the hash perturbation array asso_values

[256] ; then, based on the temporary file, executing the hash function generation tool gperf, extracting the array text of the output hash perturbation array asso_values

[256] from the output of the hash function generation tool gperf, and parsing the array text into an integer and filling the hash perturbation array asso_values

[256] in the hash table structure body hashTable_t;

[0023] S302, using the specified hash function to calculate the index value of the hash slot of each function name in the extracted function name list in combination with the hash perturbation array asso_values

[256] filled in the hash table structure body hashTable_t;

[0024] S303, according to the index value of the hash slot, writing the function name and its metadata of each function recorded in the function symbol information structure body symbolInfo_t into the corresponding hash slot, and determining the offset of the hash slot of each function name according to the index value of the hash slot and filling it into the offset, finally completing the filling of the hash table structure body hashTable_t;

[0025] S304, generating an ELF function symbol information file containing the function name and its metadata of each function symbol according to the hash table structure body hashTable_t and saving it to the disk.

[0026] Optionally, the hash retrieval of the ELF function symbol information mapped to the memory in step S104 includes: using the specified hash function to calculate the index value of the hash slot in combination with the hash perturbation array asso_values

[256] filled in the hash table structure body hashTable_t, finding the corresponding offset in the offset according to the index value of the hash slot, locating the corresponding ELF function symbol information of the payload array payload[] through the offset, and completing the hash retrieval of the ELF function symbol information mapped to the memory.

[0027] Optionally, in the data structure for the function information for structured storage and the hash index relationship created in step S204, the content under the hash table structure body hashTable_t also includes a check information element magic, the check information element magic is a fixed value for judging the correctness of the ELF function symbol information file; before mapping the ELF function symbol information file in the disk into the memory by using the memory mapping mode in step S103, first verifying the check information element magic, and if the check information element magic is verified, then mapping the ELF function symbol information file in the disk into the memory by using the memory mapping mode, and if the check information element magic is not verified, then ending and exiting.

[0028] In addition, the present application also provides a dynamic binary translation acceleration system, comprising a microprocessor and a memory connected to each other, the microprocessor being programmed or configured to perform the dynamic binary translation acceleration method.

[0029] In addition, the present application also provides a computer readable storage medium, the computer readable storage medium storing a computer program or instructions, the computer program or instructions being programmed or configured to perform the dynamic binary translation acceleration method by a processor.

[0030] In addition, the present application also provides a computer program product, comprising a computer program or instructions, the computer program or instructions being programmed or configured to perform the dynamic binary translation acceleration method by a processor.

[0031] Compared with the prior art, the present application mainly has the following beneficial effects: in order to reduce the symbol analysis and encapsulation matching overhead in the dynamic translation initialization process, improve the starting efficiency and overall running performance, the present application implements dynamic binary translation acceleration based on function symbol preprocessing and mapping loading, including operations such as analysis, classification and encapsulation type identification of function symbols in advance to an independent preprocessing phase, pre-processing to generate an ELF function symbol information file and solidifying it as a file, and the translation process directly loading the ELF function symbol information file and quickly completing function encapsulation judgment and binding according to the file during running, so as to avoid repeated calculation, reduce initialization delay, and significantly improve the overall efficiency and response capability of the dynamic translation system, which can significantly improve the system performance, and is particularly suitable for computing environments with high resource and performance requirements, such as embedded systems, mobile devices and high-performance computing platforms, providing an efficient and flexible solution for the application of dynamic binary translation technology. BRIEF DESCRIPTION OF DRAWINGS

[0032] Figure 1 The basic flowchart of the embodiment method of the present application is shown.

[0033] Figure 2A schematic diagram for implementing the modules in the embodiments of the present application is shown. DETAILED DESCRIPTION

[0034] In order to enable those skilled in the art to better understand the technical solutions of the present application, the technical solutions of the present application will be further described in detail below with reference to the accompanying drawings of the embodiments of the present application.

[0035] As shown in Figure 1 , the dynamic binary translation acceleration method of the present embodiment comprises the following steps:

[0036] S101, extracting the external dependent library (dynamic library) and its external functions required by the target program from the system of the original architecture of the target program and statically registering them to the function library;

[0037] S102, before the binary translation execution of the target program in the target architecture, parsing the ELF file of the target program, extracting the external dependent library and its function symbol information, combining the function information in the function library to generate the ELF function symbol information file containing the function name and meta information of each function symbol and saving it to the disk;

[0038] S103, mapping the ELF function symbol information file in the disk to the memory by using the memory mapping (mmap) method;

[0039] S104, when performing external function lookup and calling in the process of binary translation execution of the target program in the target architecture, performing hash retrieval on the ELF function symbol information mapped to the memory;

[0040] S105, generating the ELF function symbol information file containing the function name and meta information of each function symbol according to the function type of the external function retrieved by hash, realizing the pointer mapping of the function type to the corresponding wrapper function, and obtaining the local function address actually to be executed according to the encapsulation type of the external function;

[0041] S106, realizing the actual call, parameters and return of the external function by the wrapper function combined with the local function address through pointer mapping, so as to realize the normal running of the external function in the target architecture.

[0042] As shown in Figure 2 , the dynamic binary translation acceleration method of the present embodiment is composed of two independent modules: the helper module and the translation module, and the two modules run cooperatively and undertake different responsibilities.

[0043] The helper module is mainly used to perform steps S101 and S102, i.e., the steps before the binary translation of the target architecture performs the target program. The main function is to analyze the target ELF file (the ELF file of the target program) before the program is executed to provide the required ELF function symbol information file for the translation module, extract the dependency information of external functions and external dependent libraries, and structure the extracted function name and its metadata, generate the corresponding function information file and store it to the disk. Each ELF file corresponds to an independent structured function information data file. The helper module mainly includes the following steps: all external dependent libraries and the functions contained therein are pre-registered in the helper module by a static method, and a unified macro definition mechanism is used for centralized management. In the module initialization stage, the required external dependent libraries are selectively loaded according to the dependency relationship of the target ELF file. The ELF file to be translated and executed is read and parsed, and the dependent external dependent library name and external function symbol are extracted and temporarily stored in the memory structure for subsequent processing. According to the ELF external dependent library extraction result, the dependent library is searched and loaded in the registered library, mainly the functions and metadata information contained in the dependent library are saved to different hash tables according to different packaging types (such as weak functions, functions that need to be wrapped by the translator, and functions that can be directly called locally), each external dependent library contains multiple hash tables to organize its internal function information; according to the exported ELF external function entry, the function is searched in the hash table to which the loaded external dependent library belongs, and after the function name and its metadata are searched and structured, they are uniformly stored to the disk file to form the ELF function symbol information file corresponding to the ELF file, which is used for efficient query in the subsequent translation execution stage.

[0044] The translation module is used to perform steps S103-S106, i.e., the steps of the target architecture binary translation when executing the target program. The main work of the translation module is to perform dynamic binary translation based on the ELF function information file. In the translation process, the function information file generated in advance is read, and the processing strategy of each external function is quickly determined according to the function name, type and packaging method and other information recorded therein. In this way, this translation process effectively avoids the performance loss caused by the circular import of the hash table of the external dependent library function and the multiple hash calculation and function retrieval in the traditional binary translation. The main work steps are as follows: during program initialization, the function information data file corresponding to the ELF file is directly mapped to the memory through memory mapping (mmap) to facilitate subsequent fast access, without frequent disk I / O operations; when the external function needs to be called during dynamic binary translation, the function name in the ELF file is used to perform hash retrieval on the function information mapped to the memory, and the metadata information entry of the corresponding function is quickly located. The hash algorithm is consistent with the hash function used when generating the data file, ensuring consistency and efficiency of the retrieval; according to the retrieved function metadata, the function packaging type is read to determine the processing method of the function in the translator. Each packaging type corresponds to different calling or packaging strategies; based on the function type, the switch-case control structure or equivalent logical branching mechanism is used to map to the corresponding wrapper function pointer (it is a normal function itself, which does some "preprocessing" before calling the real function, such as parameter conversion, type compatibility, etc.). According to different packaging types, if the function can be directly called in the local external dependent library, it is dynamically resolved through dlsym and directly called; if the function needs to be wrapped by the translator, the pre-defined wrapper function is used to complete the packaging and then executed; for other special types such as weak symbols and variable parameter functions, the corresponding processing strategy is adopted according to the packaging characteristics to ensure that various external functions can be correctly and effectively called in a heterogeneous platform or a specific execution environment; according to the resolved processing method, the wrapper function pointer is determined, and the actual address of the target function is obtained through the dlsym interface. The wrapper function will be bound with the target function address to ensure that the parameters and return values can be correctly passed and processed during calling; after completing the function pointer binding, the target function is executed in a dynamic calling manner during program running, ensuring that the external dependencies required by the ELF file can be correctly and efficiently executed in a heterogeneous platform or a specific running environment.

[0045] In step S101 of the embodiment, when the external dependent libraries and the external functions required by the target program are extracted from the system of the original architecture of the target program and statically registered in the function library, a unified interface is defined for the external functions through a macro definition mechanism to realize unified management, and a plurality of arrays are defined for each external dependent library according to the encapsulation types of the external functions. The meta information of the external functions in each external dependent library is respectively expanded into the corresponding array according to the encapsulation types of the external functions, and the meta information of the external functions includes the function name, the function type and the encapsulation type of the external functions.

[0046] In step S102 of the embodiment, the external dependent libraries and the function symbol information are extracted, and the ELF function symbol information file containing the function name and the meta information of each function symbol is generated by combining the function information in the function library.

[0047] S201, the function name of the external dependent library and the function symbol is extracted and added to the function name list;

[0048] S202, a structure is constructed for each loaded external dependent library, and the elements in the structure include the name of the external dependent library, the type of the external dependent library and the hash table for indexing the external functions of different encapsulation types under the external dependent library;

[0049] S203, for each external dependent library, the meta information of the external functions expanded into the corresponding array is added to the hash table corresponding to the external dependent library according to the encapsulation type;

[0050] S204, a data structure for structurally storing the function information and the hash index relationship is created;

[0051] S205, for the function name in the function name list extracted, a matching item is found in the hash table of each loaded external dependent library to fill the data structure for structurally storing the function information and the hash index relationship. The ELF function symbol information file containing the function name and the meta information of each function symbol is generated according to the filled data structure for structurally storing the function information and the hash index relationship, and is saved to the disk.

[0052] The data structure for structuring the function information and the hash index relationship created in step S204 of the embodiment includes the following fields: a macro definition SLOT_COUNT of the maximum slot number of the hash structure, used to define the maximum slot number of the hash structure, i.e., the element number of the indefinite-length payload array payload[], which is 2048 in the embodiment; a function symbol information structure body symbolInfo_t, used to record function symbol information, the function symbol information including a function name, an encapsulation type, a function type, and a resolution state; a hash table structure body hashTable_t, used to record data in the hash table, the content under the hash table structure body hashTable_t including a function entry number count, used to record the external function entry number under the hash table, an offset offset, used to record the offset of the initial address corresponding to each hash slot, a hash disturbance array asso_values

[256] , used to store the hash disturbance array used as a parameter of a hash function to define the index value of the hash slot, and an indefinite-length payload array payload[], used to save the ELF function symbol information of the function symbol information structure body symbolInfo_t, and the ELF function symbol information of different external functions is distinguished by the offset. The data structure for structuring the function information and the hash index relationship in the embodiment can also be referred to as a mapping table, the mapping table generates the hash disturbance array asso_values

[256] by the gperf tool, and the hash function can locate the required function meta information by one-time hashing during the runtime of the translator, which is constructed statically in advance and directly mapped and queried during the runtime, and does not depend on the dynamic behavior during the runtime.

[0053] In the embodiment, step S205 includes:

[0054] S301, generating a hash perturbation array, including: first, write the function name and metadata of each function recorded in the function symbol information structure symbolInfo_t into a temporary file, for example, in this embodiment, the file name of the temporary file is temp_keywords.gp, the value can be taken according to actual needs, and a plurality of placeholder keywords (such as "dummy" and the like) are supplemented in the temporary file to meet the length requirement of the hash function generation tool gperf (existing tool) to generate the hash perturbation array asso_values

[256] ; in order to ensure that the hash function generated by the hash function generation tool gperf can cover all characters from 0 to 255, the temporary file needs to have enough different character combinations, if the real keywords are too few, the complete hash perturbation array asso_values

[256] cannot be generated, or there will be holes in the middle of the array, therefore, in this embodiment, a plurality of placeholder keywords (such as "dummy" and the like) are supplemented, so that the hash function generation tool gperf can output a complete and continuous hash perturbation array asso_values

[256] ;

[0055] Then, the hash function generation tool gperf is executed based on the temporary file, for example, in this embodiment, the specific command is:

[0056] gperf -N in_word_set -H gperf_hash -p temp_keywords.gp;

[0057] This command generates a lookup function named in_word_set and a hash function named gperf_hash based on the keywords in temp_keywords.gp by using the gperf tool, and enables position-independent mode to adapt to flexible keyword lists, extracts the array text of the output hash perturbation array asso_values

[256] from the output of the hash function generation tool gperf, parses the array text into integers, and fills the hash perturbation array asso_values

[256] in the hash table structure hashTable_t for subsequent use of the hash calculation function;

[0058] S302, using the specified hash function to calculate the index value (corresponding storage position in the payload array payload[]) of the hash slot of each function name in the extracted function name list in combination with the hash perturbation array asso_values

[256] filled in the hash table structure hashTable_t;

[0059] S303, write the function name and meta information of each function recorded in the function symbol information structure symbolInfo_t into the corresponding hash slot according to the index value of the hash slot, and determine the offset of the hash slot of each function name according to the index value of the hash slot and fill it into the offset offset, and finally complete the filling of the hash table structure hashTable_t;

[0060] S304, generate an ELF function symbol information file containing the function name and meta information of each function symbol according to the hash table structure hashTable_t and save it to the disk. In this embodiment, the complete hash table structure hashTable_t is written into the target file (ELF function symbol information file) to be saved to the disk, and then the data of each valid function symbol is written into the target file in order of each slot, completing the structured storage of the ELF function symbol information file.

[0061] It should be noted that the hash function specified in step S302 can be any desired hash function, such as the DJB2 hash function from the DJB series of hash functions. However, considering the problem of hash collisions caused by repeated prefixes in the DJB2 hash function, this embodiment employs an improved DJB2 hash function, gperf_hash(). This improved DJB2 hash function, based on the traditional DJB2 hash function, adds a character perturbation table and XOR rewrite. Specifically, the output results of the traditional DJB2 hash function are concatenated. The character perturbation table contains a 256-byte array of perturbation constants, which can be mapped to a perturbation constant based on the input character. This perturbation constant is then XORed with the output result of the traditional DJB2 hash function to obtain the final calculated hash value. This improves the nonlinearity and distribution randomness of character influence, making it suitable for scenarios with multiple function strings in this embodiment. It avoids the problem of hash collisions caused by repeated prefixes in the traditional DJB2 hash function, thereby improving the hash algorithm's anti-collision capability. The method of this embodiment focuses on function-level symbol resolution optimization. In this embodiment, the improved DJB2 hash function gperf_hash() introduces the perturbed hash distribution of the hash perturbation array asso_values

[256] , and combines the macro definition SLOT_COUNT fixed slot strategy of the maximum number of slots in the hash structure to complete the hash slot distribution and symbol metadata organization in advance during the construction period, thereby avoiding multiple string comparisons and traversal operations at runtime. The translation module uses mmap to load the function information table during runtime, quickly locates the function entry through the hash slot, and then combines the chain processing method of encapsulation type → scheduling strategy → function address binding to greatly improve the startup speed and function call efficiency. This embodiment adopts a dual mechanism of combining the hash perturbation array asso_values

[256] generated by the hash function generation tool gperf and the improved DJB hash function to achieve rapid positioning and type matching of external functions in the loading stage, thereby significantly improving the function binding efficiency in the dynamic linking stage.

[0062] In step S104 of this embodiment, hash retrieval of the ELF function symbol information mapped to the memory includes: using a specified hash function in combination with the hash perturbation array asso_values

[256] filled in the hash table structure hashTable_t to calculate the index value of the hash slot; searching for the corresponding offset in the offset according to the index value of the hash slot; locating the ELF function symbol information corresponding to the payload array payload[] through the offset, and completing the hash retrieval of the ELF function symbol information mapped to the memory. By using the hash perturbation array asso_values

[256] to calculate the index value of the hash slot, efficient function retrieval and dynamic binding are achieved, optimizing program startup time and running performance.

[0063] In the data structure of the function information for structured storage and the hash index relationship created in step S204 of the embodiment, the content under the hash table structure body hashTable_t also includes a check information element magic, which is a fixed value for judging the correctness of the ELF function symbol information file. Before mapping the ELF function symbol information file in the disk into the memory by using the memory mapping method in step S103, the first step is to verify the check information element magic, and the ELF function symbol information file in the disk is mapped into the memory by using the memory mapping method only if the check information element magic is verified. If the check information element magic is not verified, the process is ended and exited. In addition, the check information element magic can also be a dynamic value calculated according to a check algorithm, and the file verification can also be achieved.

[0064] In step S105 of the embodiment, the ELF function symbol information file containing the function name of each function symbol and the meta information thereof is generated according to the function type of the external function retrieved by the hash, the pointer mapping of the function type to the corresponding wrapper function is implemented, and the local function address actually to be executed is obtained according to the encapsulation type of the external function. According to the extracted function encapsulation type, different processing logics are selected to obtain the corresponding wrapper function. For example, the switch-case structure or equivalent branch logic selection can be used to obtain the corresponding wrapper function. If the function needs to be re-encapsulated by the translator, the local function address encapsulated by the translator can be called, and if the function does not need special processing, the real function address of the local machine can be obtained by dlsym. In step S106 of the embodiment, the actual call of the external function and the parameters and return are implemented by the wrapper function combined with the local function address through the pointer mapping, so as to realize the normal operation of the external function in the target architecture. The function real address is transmitted into the pointer of the wrapper function, and the function of the wrapper function is responsible for encapsulating the function address, parameters, return value and the like into the standard call flow to complete the actual call of the function, so as to significantly reduce the hash calculation and function identification overhead in the dynamic linking stage, and the method is suitable for embedded systems, heterogeneous platforms or running environments with high requirements on startup performance.

[0065] In summary, in order to reduce the symbol resolution and encapsulation matching overhead in the dynamic translation initialization process, improve the startup efficiency and the whole body running performance, the embodiment method realizes dynamic binary translation acceleration based on function symbol preprocessing and mapping loading, by preprocessing the external function symbol of the executable ELF file in the independent helper process, and combining the existing encapsulation information to generate a structured mapping file (ELF function symbol information file) containing the function type and encapsulation method, the information can be directly loaded through memory mapping method when the translation process runs, avoiding multiple string hash lookup and dynamic recognition operation. The core purpose of the embodiment method is to preposition the encapsulation function matching logic originally performed at runtime to the ELF preprocessing stage, thereby significantly reducing the search overhead in the function call path, improving the execution efficiency of dynamic linking and calling. Through the pre-generated function information mapping structure, the translator can quickly build the call table in the initialization stage, accurately identify the function encapsulation type and the library it belongs to, realize efficient function search and dynamic binding, shorten the program startup time and optimize the running performance. The embodiment method is especially suitable for scenarios that require a large number of external function calls or run large and complex applications, and performs particularly outstanding in systems with limited resources or high performance requirements. It provides an efficient and structured auxiliary mechanism for dynamic binary translation, with good scalability and practical value. The function recognition and fast scheduling mechanism adopted by the embodiment method performs outstanding performance in large ELF files and multi-function dependent scenarios, and is especially suitable for binary compatible execution scenarios in heterogeneous architectures, such as RISC-V simulating x86, etc.The method of the embodiment has the following advantages: (1) The embodiment preprocesses the external function symbols of the ELF file in the helper module, structures the meta information such as function name, type and encapsulation mode to generate a function information file, and directly loads the function information file in a memory mapping mode at runtime, thereby significantly reducing the string hash calculation and dynamic type judgment operations in the initialization stage, and improving the program startup efficiency; (2) The embodiment introduces an improved DJB hash algorithm combined with an auxiliary hash perturbation array asso_values

[256] , improves the hash distribution performance and retrieval speed, can efficiently support the rapid positioning of thousands of external symbols, and avoids the hash conflict problem caused by the coincidence of function name prefixes; (3) The embodiment transfers the encapsulated function matching logic from the traditional runtime recognition to the static analysis stage, greatly reduces the dynamic judgment overhead of the translation process in the function binding stage, and improves the binary translation performance in the multi-library and multi-encapsulation scenario; (4) The function information hash structure constructed by the embodiment has portability and scalability, supports one executable ELF file corresponding to one function information file, can be reused without rebuilding the translation data on the target platform, and improves the cross-platform compatibility of the translation system; (5) Through the structured mapping mechanism and the memory mapping loading mode, the embodiment effectively avoids the complex processes such as frequent access to the string table and dynamic generation of the wrapping structure in the traditional translator, simplifies the system implementation, reduces the system burden, and is suitable for performance and resource sensitive scenarios such as embedded platforms and virtualization platforms.

[0066] In addition, the embodiment also provides a dynamic binary translation acceleration system, which comprises a microprocessor and a memory connected with each other, and the microprocessor is programmed or configured to execute the dynamic binary translation acceleration method. In addition, the embodiment also provides a computer readable storage medium, which stores a computer program or instructions, and the computer program or instructions are programmed or configured to execute the dynamic binary translation acceleration method by a processor. In addition, the embodiment also provides a computer program product, which comprises a computer program or instructions, and the computer program or instructions are programmed or configured to execute the dynamic binary translation acceleration method by a processor.

[0067] Those skilled in the art will appreciate that the technology provided herein is not limited to any particular form of implementation. The technology provided herein can be implemented in hardware, software, or a combination thereof. Those skilled in the art will appreciate that the technology provided herein can be implemented in a number of different embodiments, including method embodiments, system embodiments, and computer program product embodiments. The technology provided herein can be implemented in any combination of hardware, software, or a combination thereof. The technology provided herein can be implemented in a number of different ways, including as a computer program product stored on a computer readable storage medium, as a system on chips (SOCs), as an application specific integrated circuit (ASIC), or as a cloud service. The computer program product can be implemented using two or more computer program Figure 1 one or more functions specified in the flow or flows and / or blocks Figure 1 one or more functions specified in the flow or flows and / or blocks Figure 1 one or more functions specified in the flow or flows and / or blocks Figure 1 one or more functions specified in the flow or flows and / or blocks Figure 1 one or more functions specified in the flow or flows and / or blocks Figure 1 one or more functions specified in the flow or flows and / or blocks

[0068] The above description is only preferred embodiments of the present application, the protection scope of the present application is not limited to the above-mentioned embodiments, and any technical scheme falling within the concept of the present application shall be considered as falling within the protection scope of the present application. It should be noted that, for ordinary skilled in the art, some improvements and refinements without departing from the principles of the present application are also considered as the protection scope of the present application.

Claims

1. A dynamic binary translation acceleration method, characterized in that: The steps include: S101, extracting the external dependency library and its external functions required for the target program to run from the system of the original architecture of the target program and statically registering them into the function library; S102, before binary translation executes the target program in the target architecture, parses the ELF file of the target program, extracts the external dependent library and its function symbol information, combines the function information in the function library to generate an ELF function symbol information file containing the function name and meta information of each function symbol and saves it to disk; S103, the ELF function symbol information file in the disk is mapped in the internal memory using a memory mapping method; S104, performing a hash search on the ELF function symbol information mapped to the memory when an external function is searched and called during the binary translation and execution of the target program in the target architecture; S105, generating an ELF function symbol information file containing the function name and meta-information of each function symbol according to the function type of the external function retrieved by hash, implementing a pointer mapping from the function type to the corresponding wrapper function, and obtaining the actual local function address to be executed according to the encapsulation type of the external function; S106, implementing the actual call, parameters, and return of the external function through the wrapper function mapped by the pointer in combination with the local function address, thereby achieving normal operation of the external function in the target architecture; In step S102, the external dependency library and its function symbol information are extracted, and an ELF function symbol information file containing the function name and meta information of each function symbol is generated by combining the function information in the function library. The file includes: S201, extracting the function names of the external dependent library and its function symbols and adding them to the function name list; S202: Build a structure for each loaded external dependency library. The elements in the structure include: the name of the external dependency library, the type of the external dependency library, and a hash table for indexing external functions of different package types under the external dependency library. S203: For each external dependency library, add the meta information of the external function expanded into the corresponding array to the hash table corresponding to the external dependency library in a loop according to the encapsulation type; S204, creating a data structure for structured storage of function information and hash index relationships; S205, for the function names in the extracted function name list, search for matching items one by one in the hash tables of each loaded external dependent library to fill the data structure for structured storage of function information and hash index relationship; based on the filled data structure for structured storage of function information and hash index relationship, generate an ELF function symbol information file containing the function name and meta-information of each function symbol and save it to disk.

2. The dynamic binary translation acceleration method according to claim 1, characterized in that: In step S101, when the external dependency library and its external functions required for the operation of the target program are extracted from the system of the original architecture of the target program and statically registered to the function library, it also includes defining a unified interface for the external function through a macro definition mechanism to achieve unified management, and defining multiple arrays for each external dependency library according to the encapsulation type of the external function, and expanding the metadata of the external function in each external dependency library into the corresponding array according to the encapsulation type of the external function. The metadata of the external function includes the function name, function type and encapsulation type of the external function.

3. The dynamic binary translation acceleration method according to claim 2, characterized in that: The data structure for structured storage of function information and hash index relationships created in step S204 includes the following fields: a macro definition of the maximum number of slots in the hash structure, SLOT_COUNT, used to define the maximum number of slots in the hash structure; a function symbol information structure, symbolInfo_t, used to record function symbol information, including function name, encapsulation type, function type, and parsing status; The hash table structure hashTable_t is used to record the data in the hash table. The contents under the hash table structure hashTable_t include: function entry count, used to record the number of external function entries under the hash table, offset offset, used to record the offset of the initial address corresponding to each hash slot; hash perturbation array asso_values[256], used to store the hash perturbation array used as a parameter of the hash function to define the index value of the hash slot; variable-length payload array payload[], used to save the ELF function symbol information of the function symbol information structure symbolInfo_t, and use the offset to distinguish the ELF function symbol information of different external functions.

4. The dynamic binary translation acceleration method according to claim 3, characterized in that: Step S205 includes: S301, generating a hash perturbation array, including: first, writing the function name of each function recorded in the function symbol information structure symbolInfo_t and its meta information into a temporary file, and supplementing a plurality of placeholder keywords in the temporary file to meet the length requirement of the hash perturbation array asso_values[256] generated by the hash function generation tool gperf; then executing the hash function generation tool gperf based on the temporary file, extracting the array text of the output hash perturbation array asso_values[256] from the output of the hash function generation tool gperf execution, parsing the array text into integers, and filling the hash perturbation array asso_values[256] in the hash table structure hashTable_t; S302, using the specified hash function in combination with the hash perturbation array asso_values[256] filled in the hash table structure hashTable_t to calculate the index value of the hash slot of each function name in the extracted function name list; S303: Write the function name of each function recorded in the function symbol information structure symbolInfo_t into the corresponding hash slot according to the index value of the hash slot, and determine the offset of the hash slot of each function name according to the index value of the hash slot and fill it into the offset, finally completing the filling of the hash table structure hashTable_t; S304: Generate an ELF function symbol information file containing the function name and meta information of each function symbol according to the hash table structure hashTable_t and save it to disk.

5. The dynamic binary translation acceleration method according to claim 3, characterized in that: In step S104, the hash retrieval of the ELF function symbol information mapped to the memory includes: using the specified hash function in combination with the hash perturbation array asso_values[256] filled in the hash table structure hashTable_t to calculate the index value of the hash slot, searching for its corresponding offset in the offset according to the index value of the hash slot, locating the ELF function symbol information corresponding to the payload array payload[] through the offset, and completing the hash retrieval of the ELF function symbol information mapped to the memory.

6. The dynamic binary translation acceleration method according to claim 2, characterized in that: In the data structure of function information and hash index relationship for structured storage created in step S204, the content under the hash table structure hashTable_t also includes a check information element magic, and the check information element magic is a fixed value used to determine the correctness of the ELF function symbol information file; in step S103, before mapping the ELF function symbol information file in the disk to the memory using the memory mapping method, the check information element magic is first verified. If the check information element magic is verified successfully, the ELF function symbol information file in the disk is mapped to the memory using the memory mapping method. If the check information element magic is verified unsuccessfully, the process ends and exits.

7. A dynamic binary translation acceleration system, comprising a microprocessor and a memory connected to each other, characterized in that: The microprocessor is programmed or configured to execute the dynamic binary translation acceleration method according to any one of claims 1 to 6.

8. A computer-readable storage medium having a computer program or instruction stored therein, characterized in that: The computer program or instruction is programmed or configured to execute the dynamic binary translation acceleration method according to any one of claims 1 to 6 through a processor.

9. A computer program product comprising a computer program or instructions, characterized in that The computer program or instruction is programmed or configured to execute the dynamic binary translation acceleration method according to any one of claims 1 to 6 through a processor.

Citation Information

Patent Citations

  • Program cross-architecture migration method and device, computer equipment and storage medium

    CN118276931A

  • Program-oriented cross-processor architecture execution method and system, equipment and medium

    CN120144214A