Method, device, equipment and medium for executing dynamic library mapping in binary translation
By directly mapping and calculating the function call instructions of the dynamic link library of x86 executable programs on the RISC-V platform, the problem of low translation efficiency of dynamic link libraries for x86 programs on the RISC-V platform is solved, and efficient program execution is achieved.
Patent Information
- Application Number
- CN202510740154.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-05
- Publication Date
- 2025-10-28
- Estimated Expiration
- 2045-06-05
AI Technical Summary
In existing technologies, when x86 executable programs are ported to the RISC-V platform, the translation process of dynamic link library files incurs significant time overhead, making it difficult to meet the needs of high-performance application scenarios.
By translating the instructions of the x86 executable program, it is determined whether they are dynamic link library function call instructions. The call instructions are parsed to obtain the function, and the first and second values of the RISC-V dynamic link library are queried using a pre-established dynamic link library map allocator to determine the absolute address and parameter address of the function in memory. The calculation is then performed directly to avoid complex translation and calculation.
It reduces system overhead during the translation process, improves the program's running efficiency on the RISC-V platform, and meets the needs of high-performance application scenarios.
Smart Images

Figure CN120255959B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of dynamic link library translation technology, and in particular to a method, apparatus, device, and medium for dynamic library mapping execution in binary translation. Background Technology
[0002] As a new instruction set architecture, RISC-V has developed rapidly over the past decade due to its open-source, modular, and highly scalable characteristics, becoming the third largest instruction set after x86 and ARM.
[0003] However, the RISC-V software ecosystem is still in its early stages of development, facing numerous challenges in porting mature ecosystem software such as x86 to the RISC-V architecture. Binary translation technology enables software-level instruction set translation, allowing executable programs to run across platforms and significantly simplifying software porting. Typically, x86 executable programs need to link to required dynamic link libraries to complete the calling and execution of specific functions. During binary translation, the binary translation system loads the x86 dynamic link library and translates it as an x86 executable program for execution. While this method has good versatility, the large amount of time overhead during the translation phase due to the large number of function entries and execution logic in the dynamic link library files significantly impacts program efficiency and makes it difficult to effectively meet the needs of high-performance application scenarios. Summary of the Invention
[0004] This invention provides a method, apparatus, device, and medium for dynamic library mapping execution in binary translation, to solve the technical problem that the translation of dynamic link library files when porting X86 to the RISC-V platform cannot meet the needs of high-performance application scenarios.
[0005] In a first aspect, embodiments of the present invention provide a method for dynamic library mapping execution in binary translation, including:
[0006] The instructions of the x86 executable program are translated and executed to determine whether they are dynamic link library function call instructions. If they are dynamic link library function call instructions, the call instructions are parsed to obtain the called function.
[0007] The called function is used as the query index key to query the pre-established dynamic link library map allocator to obtain the first and second values of the function in the RISC-V dynamic link library.
[0008] Determine the starting address of the RISC-V dynamic link library in memory, and use the first value as the offset value to calculate the absolute address of the function in memory;
[0009] The address of the function's parameters is determined based on the second value;
[0010] The function is calculated using the parameter address and absolute address, and the calculation result is returned.
[0011] Secondly, embodiments of the present invention also provide a dynamic library mapping execution apparatus for binary translation, comprising:
[0012] The judgment module is used to translate and execute the instructions of the x86 executable program, determine whether it is a dynamic link library function call instruction, and if it is a dynamic link library function call instruction, parse the call instruction to obtain the called function;
[0013] The query module is used to use the called function as the query index key to query a pre-established dynamic link library mapping allocator to obtain the first and second values of the function in the RISC-V dynamic link library.
[0014] The address determination module is used to determine the starting address of the RISC-V dynamic link library in memory, and use the first value as the offset value to calculate the absolute address of the function in memory;
[0015] The parameter address determination module is used to determine the parameter address of the function based on the second value;
[0016] The calculation module is used to perform calculations on the function using the parameter address and absolute address, and return the calculation result.
[0017] Thirdly, embodiments of the present invention also provide an apparatus, comprising:
[0018] An apparatus, the apparatus comprising:
[0019] One or more processors;
[0020] Storage device for storing one or more programs.
[0021] When the one or more programs are executed by the one or more processors, the one or more processors implement the dynamic library mapping execution method in binary translation as described in any of the above embodiments.
[0022] Fourthly, embodiments of the present invention also provide a storage medium containing computer-executable instructions, which, when executed by a computer processor, are used to perform the dynamic library mapping execution method in binary translation as provided in the above embodiments.
[0023] The present invention provides a method, apparatus, device, and medium for executing dynamic library mapping in binary translation. This method translates and executes the instructions of an x86 executable program, determines whether it is a dynamic link library function call instruction, and if so, parses the call instruction to obtain the called function. The called function is then used as a lookup index key to query a pre-established dynamic link library mapping allocator to obtain a first value and a second value corresponding to the function in the RISC-V dynamic link library. The starting address of the RISC-V dynamic link library in memory is determined, and the first value is used as an offset to calculate the absolute address of the function in memory. The parameter address of the function is determined based on the second value. The function is then calculated using the parameter address and the absolute address, and the calculation result is returned. During the translation process, the system determines whether a function is a dynamic link library (DLL). If it is, it searches the DLL mapper to obtain the function's offset and parameter addresses. It then uses the already loaded RISC-V DLL to determine the starting address, and further determines the function's specific memory address and parameter addresses. Using these addresses, the system directly performs calculations on the DLL, avoiding complex translation and computation, reducing system overhead during translation, improving the efficiency of the ported program, and effectively meeting the needs of high-performance application scenarios. Attached Figure Description
[0024] Other features, objects, and advantages of the invention will become more apparent from the following detailed description of non-limiting embodiments with reference to the accompanying drawings:
[0025] Figure 1 This is a flowchart illustrating the dynamic library mapping execution method in binary translation provided in Embodiment 1 of the present invention;
[0026] Figure 2 This is a schematic diagram of the dynamic link library mapping allocator mapping execution in the dynamic library mapping execution method in binary translation provided in Embodiment 1 of the present invention;
[0027] Figure 3 This is a flowchart illustrating the dynamic library mapping execution method in binary translation provided in Embodiment 2 of the present invention;
[0028] Figure 4 This is a schematic diagram of the establishment of the dynamic link library mapping allocator in the dynamic library mapping execution method in binary translation provided in Embodiment 2 of the present invention;
[0029] Figure 5 This is a schematic diagram of the structure of the dynamic library mapping execution device in binary translation provided in Embodiment 3 of the present invention;
[0030] Figure 6This is a schematic diagram of the device provided in Embodiment 4 of the present invention. Detailed Implementation
[0031] The present invention will now be described in further detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and not intended to limit it. Furthermore, it should be noted that, for ease of description, the accompanying drawings show only the parts relevant to the present invention, and not all of the structures.
[0032] Example 1
[0033] Figure 1 This is a flowchart of the dynamic library mapping execution method in binary translation provided in Embodiment 1 of the present invention. This embodiment is applicable to the translation of dynamic link library functions when porting an x86 program to a RISC-V platform. This method can be executed by a dynamic library mapping execution device in binary translation, and specifically includes the following steps:
[0034] Step 110: Translate and execute the instructions of the X86 executable program, determine whether it is a dynamic link library function call instruction, and if it is a dynamic link library function call instruction, parse the call instruction to obtain the called function.
[0035] The dynamic library mapping execution method in binary translation provided in this embodiment can translate programs for other architectures. In particular, it can translate programs for the x86 architecture, enabling them to run on the RISC-V architecture.
[0036] During translation, the program is typically translated line by line. However, the translation process inevitably involves calling functions from x86 dynamic link libraries. Therefore, it is also necessary to call functions from the translated dynamic link libraries adapted for the RISC-V architecture during the translation process.
[0037] For example, determining whether it is a dynamic link library function call instruction, and if it is, parsing the call instruction to obtain the called function, may include: determining whether it is a CALL call instruction; parsing the CALL call instruction to obtain the corresponding called function name. The CALL call instruction can call other functions. During program execution, the CALL call instruction can be used to call dynamic link library functions.
[0038] Therefore, the CALL instruction can be used to determine whether it is a dynamic link library function call instruction. If it is determined to be a dynamic link library function call instruction, the call instruction can be parsed to determine the function in the dynamic link library that the call instruction points to.
[0039] Step 120: Use the called function as the query index key to query the pre-established dynamic link library mapping allocator to obtain the first and second values of the function in the RISC-V dynamic link library.
[0040] To reduce the system overhead of translating x86 dynamic link libraries during program translation, a pre-established dynamic link library mapper can be used to record relevant information about functions in the dynamic link library, allowing direct manipulation of functions in RISC-V architecture dynamic link libraries. Figure 2 This is a schematic diagram of the dynamic link library mapping and allocator mapping execution in the dynamic library mapping execution method during binary translation provided in Embodiment 1 of the present invention. See also... Figure 2 The dynamic link library map allocator can be used by the translation system to obtain the first value based on the function name when translating executable programs of an x86 system and when translating and executing dynamic link library functions.
[0041] Optionally, the dynamic link library mapping allocator can be based on a database, recording relevant information about functions in the dynamic link library. The called function, particularly its name, can be used as a query index key in the pre-established dynamic link library mapping allocator to retrieve relevant entries for the function, and then obtain the corresponding first and second values from those entries.
[0042] Step 130: Determine the starting address of the RISC-V dynamic link library in memory, and use the first value as the offset value to calculate the absolute address of the function in memory.
[0043] In this embodiment, the RISC-V dynamic link library can be loaded into memory before program translation, and the starting address of the RISC-V dynamic link library loaded into memory can be determined through system instructions.
[0044] Optionally, the translation system can use the first value obtained in the above steps as an offset, and use the starting address and the first value to obtain the absolute address of the function in the RISC-V dynamic link library in memory, and use the absolute address to directly access the function.
[0045] Step 140: Determine the parameter address of the function based on the second value.
[0046] For example, this could include: determining whether the second value exceeds a register count threshold; if it does not exceed the register count threshold, determining the address of each parameter according to the register count order; if it exceeds the register count threshold, determining the addresses of some parameters according to the register count order, and determining the addresses of the remaining parameters based on the translation process stack. Unlike the first value, the second value is not an address reference, but a quantity value.
[0047] When a program calls a function in a dynamic link library, it needs to pass corresponding parameters to the function so that the function can perform calculations using the passed parameters. When executing a program using dynamic library mapping in binary translation, registers can be used to pass parameters to the function. However, the number of registers is limited; therefore, the number of parameters needs to be determined based on a second value, which in turn determines the required number of registers. For example, if the number of registers is greater than the second value, each register can correspond to one parameter. Therefore, the address of a register can be used as the address of the parameter; furthermore, the address of the parameter can be determined according to the usual order of the registers.
[0048] If the second value exceeds the register count threshold, all registers are already in use. Data can be passed using the stack corresponding to the translation process; therefore, parameters other than those stored in registers can be written onto the stack via push, and the addresses of other parameters can be determined based on the push order and the stack address.
[0049] Step 150: Calculate the function using the parameter address and absolute address, and return the calculation result.
[0050] The program jumps to the address of the function, directly executes the function in the RISC-V dynamic link library called during program translation, reads the parameters from the parameter address, and passes the parameters to the function. This allows the function to perform calculations, obtain the results, and return the results of the function call during program translation via registers or other means.
[0051] This embodiment translates and executes the instructions of an x86 executable program to determine whether they are dynamic link library function call instructions. If they are, the instruction is parsed to obtain the called function. The called function is used as a lookup index key in a pre-established dynamic link library mapping allocator to obtain a first and second value corresponding to the function in the RISC-V dynamic link library. The starting address of the RISC-V dynamic link library in memory is determined, and the first value is used as an offset to calculate the absolute address of the function in memory. The parameter address of the function is determined based on the second value. The function is then calculated using the parameter address and the absolute address, and the calculation result is returned. During the translation process, the system determines whether a function is a dynamic link library (DLL). If it is, it searches the DLL mapper to obtain the function's offset and parameter addresses. It then uses the already loaded RISC-V DLL to determine the starting address, and further determines the function's specific memory address and parameter addresses. Using these addresses, the system directly performs calculations on the DLL, avoiding complex translation and computation, reducing system overhead during translation, improving the efficiency of the ported program, and effectively meeting the needs of high-performance application scenarios.
[0052] In a preferred embodiment of this example, the method may further include the following step: when the first and second values cannot be obtained using the dynamic link library map allocator, translation execution is performed on the functions that cannot be obtained in the x86 dynamic link library. Since the dynamic link library file may be updated, resulting in the dynamic link library map allocator lacking corresponding function information, in this case, function translation execution is performed directly to ensure the translation runs correctly, and the dynamic link library map allocator can be updated later.
[0053] Example 2
[0054] Figure 3 This is a flowchart illustrating the dynamic library mapping execution method in binary translation provided in Embodiment 2 of the present invention. This embodiment is optimized based on the above embodiment and can add the following steps: traversing the x86 architecture dynamic link library file to find the function; calculating the index value of the function and writing the index value into the dynamic link library map allocator; traversing the RISC-V dynamic link library file to find the corresponding function of the function and calculating the relative address value of the corresponding function relative to the starting address of the RISC-V dynamic link library; storing the relative address value as the first value in the dynamic link library map allocator, and establishing a key-value pair structure of index value and relative address value in the map allocator; returning to the function search step until the traversal of the x86 architecture dynamic link library file is completed.
[0055] See Figure 3The method for executing dynamic library mappings in binary translation includes:
[0056] Step 210: Traverse the x86 architecture dynamic link library files to find the functions; calculate the index value of the function and write the index value into the dynamic link library map allocator.
[0057] In this embodiment, a dynamic link library mapping allocator can be pre-established before program translation. Optionally, the dynamic link library mapping allocator can be initialized first to form a database-like structure, which facilitates portability and replication.
[0058] Figure 4 This is a schematic diagram illustrating the establishment of the dynamic link library mapping allocator in the dynamic library mapping execution method during binary translation provided in Embodiment 2 of the present invention. See also... Figure 4 The transpose can be generated using a dynamic link library map allocator. After the dynamic link library map allocator is initialized, the x86 architecture dynamic link library files are traversed to find the functions. For example, the function can be determined based on its definition format, and its index value can be calculated. For example, the function name can be collected, combined with attribute information such as the number and type of parameters, and used as the index value through hash transformation, or the function name can be directly used as the index value, and the index value can be written into the dynamic link library map allocator.
[0059] Step 220: Traverse the RISC-V dynamic link library file, find the corresponding function of the function, and calculate the relative address value of the corresponding function with respect to the starting address of the RISC-V dynamic link library.
[0060] By traversing the translated RISC-V dynamic link library file from the x86 dynamic link library file, the corresponding function in the x86 dynamic link library file is found, and the relative address value is determined based on the size of the RISC-V dynamic link library file and the position of the corresponding function in the size of the RISC-V dynamic link library file.
[0061] Step 230: Store the relative address value as the first value in the dynamic link library map allocator, and create a key-value pair structure of index value and relative address value in the map allocator; return to the function search step until the traversal of the X86 architecture dynamic link library file is completed.
[0062] Function index values and relative address values can be bound together and stored as a key-value pair in the dynamic link library map allocator, so that the relative address value, i.e. the first value, can be found later using the index value.
[0063] Step 240: Translate and execute the instructions of the X86 executable program, determine whether it is a dynamic link library function call instruction, and if it is a dynamic link library function call instruction, parse the call instruction to obtain the called function.
[0064] Step 250: Use the called function as the query index key to query the pre-established dynamic link library mapping allocator to obtain the first and second values of the function in the RISC-V dynamic link library.
[0065] Step 260: Determine the starting address of the RISC-V dynamic link library in memory, and use the first value as the offset value to calculate the absolute address of the function in memory.
[0066] Step 270: Determine the parameter address of the function based on the second value, perform calculations on the function using the parameter address and the absolute address, and return the calculation result.
[0067] This embodiment adds the following steps: traversing x86 architecture dynamic link library files to find functions; calculating the index value of the function and writing the index value into the dynamic link library map allocator; traversing RISC-V dynamic link library files to find the corresponding function and calculating the relative address value of the corresponding function relative to the starting address of the RISC-V dynamic link library; storing the relative address value as the first value in the dynamic link library map allocator, and establishing a key-value pair structure of index value and relative address value in the map allocator; returning to the function search step until the x86 architecture dynamic link library files are traversed. Using the above method, a dynamic link library map allocator can be pre-established, facilitating the direct use of its information during later program translation to quickly complete the call to dynamic link library files. Furthermore, the dynamic link library map allocator can be persistently stored, allowing direct use each time program translation is required. Furthermore, the persistent dynamic link library map allocator can be migrated, so that other devices that perform program translation do not need to translate the dynamic link library, thereby reducing the system overhead during the translation process and improving the efficiency of porting program operation.
[0068] In a preferred embodiment of this example, the method may further include the following steps: determining the type of the function; determining the number of parameters of the function based on the type; and adding the number of parameters as a second value to the key-value pair structure. Typically, functions in a dynamic link library can be divided into several types, which can be determined based on the function's name or other definitions. The number of parameters for each type is fixed; therefore, the number of parameters can be determined in the above manner, and the number of parameters can be added as a second value to the key-value pair structure. This facilitates the rapid determination of parameter addresses during later program translation, improving the efficiency of the ported program.
[0069] Example 3
[0070] Figure 5 This is a schematic diagram of the structure of the dynamic library mapping execution device in binary translation provided in Embodiment 3 of the present invention. See also... Figure 5 The dynamic library mapping execution device in the binary translation includes:
[0071] The judgment module 310 is used to translate and execute the instructions of the X86 executable program, determine whether it is a dynamic link library function call instruction, and if it is a dynamic link library function call instruction, parse the call instruction to obtain the called function;
[0072] The query module 320 is used to use the called function as the query index key to query a pre-established dynamic link library mapping allocator to obtain the first value and the second value of the function in the RISC-V dynamic link library.
[0073] Address determination module 330 is used to determine the starting address of the RISC-V dynamic link library in memory, and use the first value as an offset value to calculate the absolute address of the function in memory;
[0074] The parameter address determination module 340 is used to determine the parameter address of the function based on the second value;
[0075] The calculation module 350 is used to perform calculations on the function using the parameter address and absolute address, and return the calculation result.
[0076] The binary translation dynamic library mapping execution device provided in this embodiment translates and executes the instructions of an x86 executable program, determines whether it is a dynamic link library function call instruction, and if it is, parses the call instruction to obtain the called function; uses the called function as a lookup index key to query a pre-established dynamic link library mapping allocator to obtain a first value and a second value corresponding to the function in the RISC-V dynamic link library; determines the starting address of the RISC-V dynamic link library in memory, and uses the first value as an offset to calculate the absolute address of the function in memory; determines the parameter address of the function based on the second value; calculates the function using the parameter address and the absolute address, and returns the calculation result. During the translation process, the system determines whether a function is a dynamic link library (DLL). If it is, it searches the DLL mapper to obtain the function's offset and parameter addresses. It then uses the already loaded RISC-V DLL to determine the starting address, and further determines the function's specific memory address and parameter addresses. Using these addresses, the system directly performs calculations on the DLL, avoiding complex translation and computation, reducing system overhead during translation, improving the efficiency of the ported program, and effectively meeting the needs of high-performance application scenarios.
[0077] Based on the above embodiments, the parameter address determination module includes:
[0078] The judgment unit is used to determine whether the second value exceeds the register number threshold. If it does not exceed the register number threshold, the address of each parameter is determined according to the order of the registers.
[0079] The parameter address determination unit is used to determine the addresses of some parameters according to the order of the registers when the number of registers exceeds the threshold, and to determine the addresses of the remaining parameters according to the stack of the translation process.
[0080] Based on the above embodiments, the determination module includes:
[0081] The instruction call determination unit is used to determine whether it is a CALL instruction and whether it is a dynamic link library function call instruction.
[0082] The parsing unit is used to parse the CALL instruction to obtain the corresponding function name.
[0083] Based on the above embodiments, the device further includes:
[0084] Traverse the x86 architecture dynamic link library files and find the functions within them;
[0085] Calculate the index value of the function and write the index value into the dynamic link library map allocator;
[0086] Traverse the RISC-V dynamic link library file, find the corresponding function of the function, and calculate the relative address value of the corresponding function with respect to the starting address of the RISC-V dynamic link library;
[0087] The relative address value is stored as the first value in the dynamic link library map allocator, and a key-value pair structure of index value and relative address value is created in the map allocator.
[0088] Return to the steps where you search for functions, until the traversal of the x86 architecture dynamic link library files is complete.
[0089] Based on the above embodiments, the device further includes:
[0090] The storage module is used to persistently store the dynamic link library mapping allocator.
[0091] Based on the above embodiments, the device further includes:
[0092] A type determination module is used to determine the type of the function;
[0093] A parameter quantity determination module is used to determine the number of parameters of the function according to the type.
[0094] The module is used to add the number of parameters as a second value to the key-value pair structure.
[0095] Based on the above embodiments, the device further includes:
[0096] The translation execution module is used to translate and execute functions that cannot be obtained from the x86 dynamic link library when the first and second values cannot be obtained using the dynamic link library map allocator.
[0097] The dynamic library mapping execution device in binary translation provided in this embodiment of the invention can execute the dynamic library mapping execution method in binary translation provided in any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0098] Example 4
[0099] Figure 6 This is a schematic diagram of the structure of a device provided in Embodiment 4 of the present invention. Figure 6 A block diagram of an exemplary device 12 suitable for implementing embodiments of the present invention is shown. Figure 6 The device 12 shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of the present invention.
[0100] like Figure 6As shown, device 12 is represented as a general-purpose computing device. Components of device 12 may include, but are not limited to: one or more processors or processing units 16, system memory 28, and a bus 18 connecting different system components (including system memory 28 and processing unit 16).
[0101] Bus 18 represents one or more of several bus architectures, including a memory bus or memory controller, a peripheral bus, a graphics acceleration port, a processor, or a local bus using any of the various bus architectures. For example, these architectures include, but are not limited to, the Industry Standard Architecture (ISA) bus, the Micro Channel Architecture (MAC) bus, the Enhanced ISA bus, the Video Electronics Standards Association (VESA) local bus, and the Peripheral Component Interconnect (PCI) bus.
[0102] Device 12 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by device 12, including volatile and non-volatile media, removable and non-removable media.
[0103] System memory 28 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache memory 32. Device 12 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, storage system 34 may be used to read and write non-removable, non-volatile magnetic media (… Figure 6 Not shown; usually referred to as a "hard drive"). Although Figure 6 Not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk") and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to bus 18 via one or more data media interfaces. Memory 28 may include at least one program product having a set (e.g., at least one) of program modules configured to perform the functions of the embodiments of the present invention.
[0104] A program / utility 40 having a set (at least one) of program modules 42 may be stored, for example, in memory 28. Such program modules 42 include, but are not limited to, an operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include an implementation of a network environment. Program modules 42 typically perform the functions and / or methods described in the embodiments of the present invention.
[0105] Device 12 can also communicate with one or more external devices 14 (e.g., keyboard, pointing device, display 24, etc.), and with one or more devices that enable a user to interact with device 12, and / or with any device that enables device 12 to communicate with one or more other computing devices (e.g., network card, modem, etc.). This communication can be performed via input / output (I / O) interface 22. Furthermore, device 12 can also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public networks, such as the Internet) via network adapter 20. As shown, network adapter 20 communicates with other modules of device 12 via bus 18. It should be understood that, although not shown in the figures, other hardware and / or software modules can be used in conjunction with device 12, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0106] The processing unit 16 executes various functional applications and data processing by running programs stored in the system memory 28, such as implementing the dynamic library mapping execution method in binary translation provided in the embodiments of the present invention.
[0107] Example 5
[0108] Embodiment 5 of the present invention also provides a storage medium containing computer-executable instructions, which, when executed by a computer processor, are used to perform the dynamic library mapping execution method in binary translation as described in any of the above embodiments.
[0109] The computer storage medium of this invention can be any combination of one or more computer-readable media. A computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of computer-readable storage media (a non-exhaustive list) include: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination of the foregoing. In this document, a computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0110] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, capable of sending, propagating, or transmitting programs for use by or in connection with an instruction execution system, apparatus, or device.
[0111] Program code contained on a computer-readable medium may be transmitted using any suitable medium, including—but not limited to—wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.
[0112] Computer program code for performing the operations of this invention can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, and C++, as well as conventional procedural programming languages such as "C" or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or device. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0113] Note that the above are only preferred embodiments of the present invention and the technical principles employed. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments, and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in detail through the above embodiments, the present invention is not limited to the above embodiments and may include many other equivalent embodiments without departing from the concept of the present invention. The scope of the present invention is determined by the scope of the appended claims.
Claims
1. A method for dynamic library mapping execution in binary translation, characterized in that, include: The instructions of the x86 executable program are translated and executed to determine whether they are dynamic link library function call instructions. If they are dynamic link library function call instructions, the call instructions are parsed to obtain the called function. The determination of whether it is a dynamic link library function call instruction and the parsing of the call instructions to obtain the called function include: using the called function as a lookup index key to query a pre-established dynamic link library mapping allocator to obtain the first and second values of the function in the RISC-V dynamic link library. Determine the starting address of the RISC-V dynamic link library in memory, and use the first value as the offset value to calculate the absolute address of the function in memory; The address of the function's parameters is determined based on the second value; The function is calculated using the parameter address and absolute address, and the calculation result is returned. Traverse the x86 architecture dynamic link library files and find the functions within them; Calculate the index value of the function and write the index value into the dynamic link library map allocator; Traverse the RISC-V dynamic link library file, find the corresponding function of the function, and calculate the relative address value of the corresponding function with respect to the starting address of the RISC-V dynamic link library; The relative address value is stored as the first value in the dynamic link library map allocator, and a key-value pair structure of index value and relative address value is created in the map allocator. Return to the steps where you search for functions, until the traversal of the x86 architecture dynamic link library files is complete; Determine the type of the function; The number of parameters of the function is determined according to the type; The number of parameters is added as a second value to the key-value pair structure.
2. The method according to claim 1, characterized in that, Determining the parameter address of the function based on the second value includes: Determine whether the second value exceeds the register number threshold. If it does not exceed the register number threshold, determine the address of each parameter according to the register order. When the number of registers exceeds the threshold, the addresses of some parameters are determined according to the order of the registers, and the addresses of the remaining parameters are determined according to the stack of the translation process.
3. The method according to claim 1, characterized in that, The method further includes: The dynamic link library map allocator is persistently stored.
4. The method according to claim 1, characterized in that, The method further includes: When the first and second values cannot be obtained using the dynamic link library map allocator, translation execution is performed on functions that are not available in the x86 dynamic link library.
5. A dynamic library mapping execution device for binary translation, characterized in that, include: The judgment module is used to translate and execute the instructions of the x86 executable program, determine whether it is a dynamic link library function call instruction, and if it is a dynamic link library function call instruction, parse the call instruction to obtain the called function; The query module is used to use the called function as the query index key to query a pre-established dynamic link library mapping allocator to obtain the first and second values of the function in the RISC-V dynamic link library. The address determination module is used to determine the starting address of the RISC-V dynamic link library in memory, and use the first value as the offset value to calculate the absolute address of the function in memory; The parameter address determination module is used to determine the parameter address of the function based on the second value; The calculation module is used to perform calculations on the function using the parameter address and absolute address, and return the calculation result; The judgment module includes: The instruction call determination unit is used to determine whether it is a CALL instruction and whether it is a dynamic link library function call instruction. The parsing unit is used to parse the CALL instruction to obtain the corresponding function name. The traversal module is used to traverse x86 architecture dynamic link library files and find the functions within them; The writing module is used to calculate the index value of the function and write the index value into the dynamic link library map allocator; The relative address value calculation module is used to traverse the RISC-V dynamic link library file, find the corresponding function of the function, and calculate the relative address value of the corresponding function relative to the starting address of the RISC-V dynamic link library. A module is created to store the relative address value as the first value into the dynamic link library map allocator, and to create a key-value pair structure of index value and relative address value in the map allocator; The return module is used to return the steps taken to find the functions, until the traversal of the x86 architecture dynamic link library files is complete; A type determination module is used to determine the type of the function; A parameter quantity determination module is used to determine the number of parameters of the function according to the type. The module is used to add the number of parameters as a second value to the key-value pair structure.
6. A device, characterized in that, The device includes: One or more processors; Storage device for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the dynamic library mapping execution method in binary translation as described in any one of claims 1-4.
7. A storage medium containing computer-executable instructions, characterized in that, The computer-executable instructions, when executed by a computer processor, are used to perform the dynamic library mapping execution method in binary translation as described in any one of claims 1-4.
Citation Information
Patent Citations
RISC-V architecture binary translation file multiplexing method and device and storage medium
CN117827286A
Program cross-architecture migration method and device, computer equipment and storage medium
CN118276931A
Method for processing library function call in binary translation
CN1892602A