Dynamic library mapping execution method and device in binary translation, equipment and medium
By translating the instructions of the X86 executable program and mapping the dynamic link library, the problem of low translation efficiency of the dynamic link library file on the RISC-V platform of X86 programs is solved, and efficient program operation is achieved, meeting the needs of high-performance applications.
Patent Information
- Application Number
- CN202510740154.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-05
- Publication Date
- 2025-07-04
- Estimated Expiration
- 2045-06-05
AI Technical Summary
In the prior art, when X86 executable programs are ported to the RISC-V platform, the translation process of dynamic link library files is relatively expensive, making it difficult to meet the needs of high-performance application scenarios.
By translating and executing the instructions of the X86 executable program, we can determine whether it is a dynamic link library function call instruction, parse the call instruction and obtain the function; use the pre-established dynamic link library map allocator to query the first and second values of the RISC-V dynamic link library; determine the first address and parameter address of the RISC-V dynamic link library in memory, and directly perform function calculations to avoid complex translation and calculations.
It reduces the system overhead during the translation process, improves program operation efficiency, and meets the needs of high-performance application scenarios.
Smart Images

Figure CN120255959A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of dynamic link library translation, and particularly to a method, device, equipment and medium for dynamic library mapping execution in binary translation. Background Art
[0002] As a new instruction set architecture, RISC-V has developed rapidly in the past decade due to its open source, modularity and high scalability, and has become the third largest instruction set after X86 and ARM.
[0003] However, the RISC-V software ecosystem is still in its infancy and faces many challenges in transplanting mature ecosystem software such as X86 to the RISC-V architecture. Binary translation technology realizes instruction set translation at the software level, enables executable programs to run across platforms, and greatly simplifies software transplantation work. Usually, when an X86 executable program runs, it needs to link the required dynamic link libraries to complete the call and execution of specific functions. When performing binary translation, the binary translation system loads the X86 dynamic link library and translates and executes it as an X86 executable program. Although the above method has good generality, since the dynamic link library file itself usually contains a large number of function entries and execution logics, the time overhead in the translation stage is large, seriously affecting the program running efficiency and making it difficult to effectively meet the requirements of high-performance application scenarios. Summary of the Invention
[0004] Embodiments of the present invention provide a method, device, equipment and medium for dynamic library mapping execution in binary translation to solve the technical problem that the translation of dynamic link library files when transplanting X86 to the RISC-V platform in the prior art cannot meet the requirements 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: Translating and executing the instructions of the X86 executable program, determining whether it is a dynamic link library function call instruction, and when it is a dynamic link library function call instruction, parsing the call instruction to obtain the called function; Querying the pre-established dynamic link library mapping allocator with the called function as a query index key to obtain a first value and a second value corresponding to the function in the RISC-V dynamic link library; Determining the starting address of the RISC-V dynamic link library in memory, and using the first value as an offset value to calculate the absolute address of the function in memory; Determining the parameter address of the function according to the second value; Calculating the function using the parameter address and the absolute address and returning the calculation result.
[0006] In a second aspect, an embodiment of the present invention further provides a dynamic library mapping execution device in binary translation, including: A judgment module, configured to translate and execute instructions of an X86 executable program, judge whether it is a dynamic link library function call instruction, and when it is a dynamic link library function call instruction, parse the call instruction to obtain the called function; A query module, configured to query the called function as a query index key in 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; An address determination module, configured 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; A parameter address determination module, configured to determine the parameter address of the function according to the second value; A calculation module, configured to calculate the function using the parameter address and the absolute address and return a calculation result.
[0007] In a third aspect, an embodiment of the present invention further provides a device, including: A device, the device includes: One or more processors; A storage device, configured to store one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement any one of the binary translation dynamic library mapping execution methods provided in the above embodiments.
[0008] In a fourth aspect, an embodiment of the present invention further provides a storage medium containing computer-executable instructions, and the computer-executable instructions are used to execute the binary translation dynamic library mapping execution method provided in the above embodiments when executed by a computer processor.
[0009] The method, device, equipment and medium for dynamic library mapping execution in binary translation provided by the embodiments of the present invention translate and execute the instructions of the X86 executable program, determine whether it is a dynamic link library function call instruction, and when it is a dynamic link library function call instruction, parse the call instruction to obtain the called function; use the called function as a query index key to query in the pre-established dynamic link library mapping allocator to obtain the first value and the second value corresponding to the function in the RISC-V dynamic link library; determine the starting address of the RISC-V dynamic link library in memory, use the first value as the offset value, and calculate the absolute address of the function in memory; determine the parameter address of the function according to the second value; calculate the function using the parameter address and the absolute address, and return the calculation result. During the translation process, by judging whether it is a dynamic link library function, when it is a dynamic link library function, by looking up the dynamic link library mapping allocator, obtain the offset address and parameter address of the function, use the currently loaded RISC-V dynamic link library to determine the starting address, and then determine the specific address and parameter address of the function in memory. Use the above specific address and parameter address to directly calculate the dynamic link library function, avoiding complex translation and calculation, reducing the system overhead during the translation process, improving the running efficiency of the transplanted program, and effectively meeting the requirements of high-performance application scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] Other features, objects and advantages of the present invention will become more apparent from the following detailed description of non-limiting embodiments read in conjunction with the accompanying drawings: Figure 1 is a flowchart of the method for dynamic library mapping execution in binary translation provided in Embodiment 1 of the present invention; Figure 2 is a schematic diagram of the mapping execution of the dynamic link library mapping allocator in the method for dynamic library mapping execution in binary translation provided in Embodiment 1 of the present invention; Figure 3 is a flowchart of the method for dynamic library mapping execution in binary translation provided in Embodiment 2 of the present invention; Figure 4 is a schematic diagram of the establishment of the dynamic link library mapping allocator in the method for dynamic library mapping execution in binary translation provided in Embodiment 2 of the present invention; Figure 5 is a schematic diagram of the structure of the device for dynamic library mapping execution in binary translation provided in Embodiment 3 of the present invention; Figure 6 is a schematic diagram of the structure of the equipment provided in Embodiment 4 of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0011] The present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It can be understood that the specific embodiments described herein are only for explaining the present invention, rather than limiting the present invention. Additionally, it should be noted that for the sake of description, only the parts related to the present invention rather than all the structures are shown in the accompanying drawings.
[0012] Embodiment 1 Figure 1 FIG. 6 is a flowchart of a method for executing dynamic library mapping in binary translation provided by Embodiment 1 of the present invention. This embodiment is applicable to the case of translating dynamic link library functions when transplanting an X86 program to a RISC-V platform. This method can be executed by a device for executing dynamic library mapping in binary translation, and specifically includes the following steps: Step 110: Translate and execute the instructions of the X86 executable program, and determine whether it is a dynamic link library function call instruction. When it is a dynamic link library function call instruction, parse the call instruction to obtain the called function.
[0013] The method for executing dynamic library mapping in binary translation provided by this embodiment can translate programs of other architectures. In particular, it can translate programs of the X86 architecture so that they can run on the RISC-V architecture.
[0014] During translation, usually, the program can be translated instruction by instruction. However, during the program translation process, it is inevitable to call functions in the X86 dynamic link library. Therefore, during translation, it is also necessary to call functions in the dynamic link library adapted to the RISC-V architecture after translation.
[0015] Exemplarily, the determining whether it is a dynamic link library function call instruction and, when it is a dynamic link library function call instruction, parsing the call instruction to obtain the called function may include: determining whether it is a CALL call instruction to determine whether it is a dynamic link library function 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.
[0016] Therefore, the CALL instruction can be used to determine whether it is a dynamic link library function call instruction. When it is determined that it is a dynamic link library function call instruction, the call instruction can be parsed to determine the function of the dynamic link library pointed to by the call instruction. Step 120: Query the pre-established dynamic library mapping allocator using the called function as a query index key to obtain the first value and the second value corresponding to the function in the RISC-V dynamic library.
[0017] To reduce the system overhead of translating the X86 dynamic link library during program translation, the relevant information of the functions in the dynamic link library can be recorded using a pre-established dynamic link library mapping allocator, and the functions of the dynamic link library of the RISC-V architecture can be directly operated on. Figure 2 It is a schematic diagram of the mapping execution of the dynamic link library mapping allocator in the dynamic library mapping execution method in the binary translation provided by the first embodiment of the present invention. Refer to Figure 2 , when translating the executable program of the X86 system, the dynamic link library mapping allocator can be used. When the translation system executes the dynamic link library function during translation, the first value can be obtained by the dynamic link library mapping allocator according to the function name.
[0018] Optionally, the dynamic link library mapping allocator can be based on a database to record the relevant information of the functions in the dynamic link library. The called function, especially the function name, can be used as a query index key to query in the pre-established dynamic link library mapping allocator, and the relevant entry of the function can be obtained, and the corresponding first value and second value can be obtained from the entry.
[0019] 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.
[0020] In this embodiment, before program translation, the RISC-V dynamic link library can be loaded into memory, and the starting address of the RISC-V dynamic link library loaded into memory can be determined through system instructions.
[0021] Optionally, the translation system can use the first value obtained in the above steps as the 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. The function can be directly accessed using this absolute address.
[0022] Step 140, determine the parameter address of the function according to the second value.
[0023] Exemplarily, it can include: determining whether the second value exceeds the register quantity threshold. When it does not exceed the register quantity threshold, determine the address of each parameter in the order of the registers; when it exceeds the register quantity threshold, determine the addresses of some parameters in the order of the registers, and determine the addresses of the remaining parameters according to the stack of the translation process. Different from the first value, the second value is not an address reference quantity, but a quantity value.
[0024] When some programs call functions in a dynamic link library, corresponding parameters need to be passed to the functions so that the functions can perform calculations using the passed parameters. When executing a program by mapping a dynamic library in binary translation, registers can be used to pass parameters to the functions. However, the number of registers is limited. Therefore, it is necessary to determine the number of parameters according to a second value, and then determine the number of registers required. Exemplarily, if the number of registers is greater than the number of the second value, each register can correspond to passing one parameter. Therefore, the address of the register can be used as the address of the parameter. Further, the address of the parameter can also be determined according to the normal order of the registers.
[0025] When the second value exceeds the register quantity threshold, all the registers have been used. Data can be passed using the stack corresponding to the translation process. Therefore, parameters other than the data stored in the registers can be written into the stack by pushing, and the addresses of other parameters can be determined based on the push order and the address of the stack.
[0026] Step 150, calculate the function using the parameter address and the absolute address, and return the calculation result.
[0027] Jump to the address of the function, directly execute the function in the RISC-V dynamic link library called in the program translation, read the parameters from the parameter address, and pass the parameters to the function. So that the function performs calculations to obtain a calculation result, and the calculation result of the function call in the program translation can be returned through registers or other means.
[0028] In this embodiment, by translating and executing the instructions of the X86 executable program, it is determined whether it is a dynamic link library function call instruction. When it is a dynamic link library function call instruction, the call instruction is parsed to obtain the called function; the called function is used as a query index key to query in the pre-established dynamic link library mapping allocator, and the first value and the second value corresponding to the function in the RISC-V dynamic link library are obtained; the starting address of the RISC-V dynamic link library in the memory is determined, and the first value is used as an offset value to calculate the absolute address of the function in the memory; the parameter address of the function is determined according to the second value; the function is calculated using the parameter address and the absolute address, and the calculation result is returned. During the translation process, by determining whether it is a dynamic link library function, when it is a dynamic link library function, by looking up the dynamic link library mapping allocator, the offset address and the parameter address of the function are obtained. Using the currently loaded RISC-V dynamic link library to determine the starting address, and then determining the specific address and the parameter address of the function in the memory. Using the above specific address and parameter address to directly calculate the dynamic link library function, avoiding complex translation and calculation, reducing the system overhead during the translation process, improving the running efficiency of the ported program, and effectively meeting the requirements of high-performance application scenarios.
[0029] In a preferred implementation manner of this embodiment, the method may further add the following steps: when the first value and the second value cannot be obtained by using the dynamic link library mapping allocator, translate and execute the functions in the X86 dynamic link library that cannot be obtained. Since the dynamic link library file may be updated, etc., so that the dynamic link library mapping allocator does not have the corresponding function information. In this case, directly perform function translation and execution to enable the translation to run normally, and the dynamic link library mapping allocator can be updated later.
[0030] Embodiment 2 Figure 3 FIG. is a flowchart of the dynamic library mapping execution method in binary translation provided by Embodiment 2 of the present invention. This embodiment is optimized based on the above embodiment and may add the following steps: traverse the X86 architecture dynamic link library file to find the functions therein; calculate the index value of the function and write the index value into the dynamic link library mapping allocator; traverse the RISC-V dynamic link library file to 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; store the relative address value as the first value into the dynamic link library mapping allocator, and establish a key-value pair structure of the index value and the relative address value in the mapping allocator; return to the step of finding the functions therein until the X86 architecture dynamic link library file traversal is completed.
[0031] See Figure 3, the method for executing dynamic library mapping in binary translation includes: Step 210, traverse the X86 architecture dynamic link library file to find the functions therein; calculate the index value of the function, and write the index value into the dynamic link library mapping allocator.
[0032] In this embodiment, the dynamic link library mapping allocator can be established in advance before program translation. Optionally, the dynamic link library mapping allocator can be initialized first to form a structure similar to a database, which is convenient for transplantation and replication.
[0033] Figure 4 It is a schematic diagram for establishing the dynamic link library mapping allocator in the method for executing dynamic library mapping in binary translation provided in Embodiment 2 of the present invention. Refer to Figure 4 , the transpose can be generated by using the dynamic link library mapping allocator. After the dynamic link library mapping allocator is initialized, traverse the X86 architecture dynamic link library file to find the functions therein. Exemplarily, the function can be determined according to the definition format of the function, and the index value of the function can be calculated. Exemplarily, the name of the function 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 is written into the dynamic link library mapping allocator.
[0034] Step 220, traverse the RISC-V dynamic link library file to 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.
[0035] By traversing the RISC-V dynamic link library file after translation of the X86 dynamic link library file, find the corresponding function of the function in the X86 dynamic link library file, and determine the relative address value according to 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.
[0036] Step 230, store the relative address value as the first value into the dynamic link library mapping allocator, and establish a key-value pair structure of the index value and the relative address value in the mapping allocator; return to the step of finding the function therein until the traversal of the X86 architecture dynamic link library file is completed.
[0037] The function index value and the relative address value can be bound and stored into the dynamic link library mapping allocator as a key-value pair structure, so that the relative address value, that is, the first value, can be found by using the index value in the later stage.
[0038] Step 240, translate and execute the instructions of the X86 executable program, determine whether it is a dynamic link library function call instruction, and when it is a dynamic link library function call instruction, parse the call instruction to obtain the called function.
[0039] Step 250: Query the called function as a query index key in 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.
[0040] Step 260: 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.
[0041] Step 270: Determine the parameter address of the function according to the second value, calculate the function using the parameter address and the absolute address, and return the calculation result.
[0042] In this embodiment, by adding the following steps: traversing the X86 architecture dynamic link library file to find the functions therein; calculating the index value of the function and writing the index value into the dynamic link library mapping 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 mapping allocator and establishing a key-value pair structure of the index value and the relative address value in the mapping allocator; returning to the step of finding the functions therein until the X86 architecture dynamic link library file traversal is completed. By using the above method, a dynamic link library mapping allocator can be established in advance, which is convenient for directly using the information therein during later program translation to quickly complete the call of the dynamic link library file. Further, the dynamic link library mapping allocator can be persistently stored, and when program translation is required each time, the dynamic link library mapping allocator can be directly used. In addition, the persistently stored dynamic link library mapping allocator can be migrated, so that other devices performing program translation do not need to perform dynamic link library translation, further reducing the system overhead during the translation process and improving the running efficiency of the transplanted program.
[0043] In a preferred embodiment of this embodiment, the method may further add the following steps: determining the type of the function; determining the number of parameters of the function according to the type; adding the number of parameters as the second value to the key-value pair structure. Generally, functions in a dynamic link library can be divided into several types, and the type can be determined according to the name of the function or some other definitions. The number of parameters of each type is fixed, so the number of parameters of the function can be determined in the above manner and added as the second value to the key-value pair structure. This is convenient for quickly determining the parameter address during later program translation and improving the running efficiency of the transplanted program.
[0044] Embodiment III Figure 5 This is a schematic structural diagram of a dynamic library mapping execution device in binary translation provided by Embodiment 3 of the present invention. Refer to Figure 5 , the dynamic library mapping execution device in the binary translation includes: A judgment module 310, configured to translate and execute instructions of an X86 executable program, judge whether it is a dynamic link library function call instruction, and when it is a dynamic link library function call instruction, parse the call instruction to obtain the called function; A query module 320, configured to query the pre-established dynamic link library mapping allocator with the called function as a query index key to obtain a first value and a second value corresponding to the function in the RISC-V dynamic link library; An address determination module 330, configured 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; A parameter address determination module 340, configured to determine the parameter address of the function according to the second value; A calculation module 350, configured to calculate the function using the parameter address and the absolute address and return a calculation result.
[0045] The dynamic library mapping execution device in the binary translation provided in this embodiment translates and executes instructions of an X86 executable program, judges whether it is a dynamic link library function call instruction, and when it is a dynamic link library function call instruction, parses the call instruction to obtain the called function; queries the pre-established dynamic link library mapping allocator with the called function as a query index key 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 value to calculate the absolute address of the function in memory; determines the parameter address of the function according to the second value; calculates the function using the parameter address and the absolute address and returns a calculation result. During the translation process, by judging whether it is a dynamic link library function, when it is a dynamic link library function, by looking up the dynamic link library mapping allocator, the offset address and parameter address of the function are obtained, and the starting address is determined using the currently loaded RISC-V dynamic link library, thereby determining the specific address and parameter address of the function in memory, and directly calculating the dynamic link library function using the above specific address and parameter address, avoiding complex translation and calculation, reducing the system overhead during the translation process, improving the running efficiency of the ported program, and effectively meeting the requirements of high-performance application scenarios.
[0046] Based on the above embodiments, the parameter address determination module includes: A judgment unit, configured to judge whether the second value exceeds a register quantity threshold, and when not exceeding the register quantity threshold, determine the address of each parameter according to the order of the registers; A parameter address determination unit, configured to, when exceeding the register quantity threshold, determine the addresses of some parameters according to the order of the registers, and determine the addresses of the remaining parameters according to the stack of the translation process.
[0047] Based on the above embodiments, the judgment module includes: A call instruction judgment unit, configured to judge whether it is a CALL call instruction and determine whether it is a dynamic link library function call instruction; An analysis unit, configured to analyze the CALL call instruction to obtain the corresponding called function name.
[0048] Based on the above embodiments, the device further includes: Traverse the X86 architecture dynamic link library file to find the functions therein; Calculate the index value of the function, and write the index value into the dynamic link library mapping allocator; Traverse the RISC-V dynamic link library file to 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; Store the relative address value as the first value into the dynamic link library mapping allocator, and establish a key-value pair structure of the index value and the relative address value in the mapping allocator; Return to the step of finding the functions therein until the X86 architecture dynamic link library file traversal is completed.
[0049] Based on the above embodiments, the device further includes: A storage module, configured to perform persistent storage on the dynamic link library mapping allocator.
[0050] Based on the above embodiments, the device further includes: A type determination module, configured to determine the type of the function; A parameter quantity determination module, configured to determine the parameter quantity of the function according to the type; An addition module, configured to add the parameter quantity as the second value to the key-value pair structure.
[0051] Based on the above embodiments, the device further includes: A translation execution module, configured to perform translation execution on the functions that cannot be obtained in the X86 dynamic link library when the first value and the second value cannot be obtained by using the dynamic link library mapping allocator.
[0052] The dynamic library mapping execution device provided in the embodiments of the present invention can execute the dynamic library mapping execution method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0053] Embodiment 4 Figure 6 FIG. 6 is a schematic structural diagram of a device provided in Embodiment 4 of the present invention. Figure 6 FIG. 7 shows a block diagram of an exemplary device 12 suitable for implementing the embodiments of the present invention. Figure 6 The shown device 12 is only an example and should not impose any limitation on the functions and usage scope of the embodiments of the present invention.
[0054] As Figure 6 shown, the device 12 is presented in the form of a general-purpose computing device. The components of the device 12 may include, but are not limited to: one or more processors or processing units 16, a system memory 28, and a bus 18 connecting different system components (including the system memory 28 and the processing unit 16).
[0055] The bus 18 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, a graphics acceleration port, a processor, or a local bus using any of the multiple bus structures. By way of example, these architectures include, but are not limited to, Industry Standard Architecture (ISA) bus, Micro Channel Architecture (MAC) bus, Enhanced ISA bus, Video Electronics Standards Association (VESA) local bus, and Peripheral Component Interconnect (PCI) bus.
[0056] The device 12 typically includes a variety of computer system-readable media. These media can be any available media accessible by the device 12, including volatile and non-volatile media, removable and non-removable media.
[0057] The 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. The device 12 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, a storage system 34 can be used to read and write non-removable, non-volatile magnetic media ( Figure 6 not shown, commonly referred to as a "hard disk drive"). Although Figure 6Not shown in the figure, a disk drive for reading and writing to a removable non-volatile disk (such as a "floppy disk") and an optical disk drive for reading and writing to a removable non-volatile optical disk (such as a CD-ROM, DVD-ROM, or other optical medium) can be provided. In these cases, each drive can be connected to the bus 18 through one or more data medium interfaces. The memory 28 may include at least one program product having a set (such as at least one) of program modules configured to perform the functions of the embodiments of the present invention.
[0058] A program / utilities 40 having a set (at least one) of program modules 42 can be stored, for example, in the 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. The implementation of a network environment may be included in each or some combination of these examples. The program modules 42 generally perform the functions and / or methods in the embodiments described in the present invention.
[0059] The device 12 can also communicate with one or more external devices 14 (such as a keyboard, a pointing device, a display 24, etc.), and can also communicate with one or more devices that enable a user to interact with the device 12, and / or communicate with any device that enables the device 12 to communicate with one or more other computing devices (such as a network card, a modem, etc.). Such communication can be carried out through an input / output (I / O) interface 22. In addition, the device 12 can also communicate with one or more networks (such as a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) through a network adapter 20. As shown in the figure, the network adapter 20 communicates with other modules of the device 12 through the bus 18. It should be understood that although not shown in the figure, other hardware and / or software modules can be used in combination with the 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, etc.
[0060] 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 by the embodiments of the present invention.
[0061] Embodiment Five Embodiment Five of the present invention also provides a storage medium containing computer-executable instructions, and the computer-executable instructions are used to execute the dynamic library mapping execution method in binary translation provided in any of the above embodiments when executed by a computer processor.
[0062] The computer storage medium of an embodiment of the present invention may adopt any combination of one or more computer-readable media. The computer-readable media may be computer-readable signal media or computer-readable storage media. The computer-readable storage media may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples (non-exhaustive list) of the computer-readable storage media include: an electrical connection having one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, the computer-readable storage media may 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.
[0063] The computer-readable signal media may include a data signal propagated in a baseband or as part of a carrier wave, which carries computer-readable program code. Such a propagated data signal may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer-readable signal media may also be any computer-readable media other than the computer-readable storage media, which can send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0064] The program code contained on the computer-readable media may be transmitted by any appropriate medium, including but not limited to wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0065] The computer program code for performing the operations of the present invention may be written in one or more programming languages or combinations thereof. The programming languages include object-oriented programming languages such as Java, Smalltalk, C++, and also include conventional procedural programming languages such as the "C" language or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, executed as an independent software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or device. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0066] Note that the above is only a preferred embodiment of the present invention and the technical principles applied. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and various obvious changes, re-adjustments, and substitutions can be made by those skilled in the art without departing from the protection scope of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments only. Without departing from the concept of the present invention, more other equivalent embodiments can be included, and the scope of the present invention is determined by the scope of the appended claims.
Claims
1. A method for executing dynamic library mapping in binary translation, characterized in that Including: Translate and execute the instructions of the X86 executable program, determine whether it is a dynamic link library function call instruction. When it is a dynamic link library function call instruction, parse the call instruction to obtain the called function; Use the called function as a query index key to query in the pre-established dynamic link library mapping allocator, and obtain the first value and the second value corresponding to 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 an offset value to calculate the absolute address of the function in memory; Determine the parameter address of the function according to the second value; Calculate the function using the parameter address and the absolute address, and return the calculation result.
2. The method according to claim 1, wherein Determine the parameter address of the function according to the second value, including: Judge whether the second value exceeds the register quantity threshold. When it does not exceed the register quantity threshold, determine the address of each parameter in the order of the registers; When it exceeds the register quantity threshold, determine the addresses of some parameters in the order of the registers, and determine the addresses of the remaining parameters according to the stack of the translation process.
3. The method according to claim 1, characterized in that The judgment of whether it is a dynamic link library function call instruction. When it is a dynamic link library function call instruction, parse the call instruction to obtain the called function, including: Judge whether it is a CALL call instruction to determine whether it is a dynamic link library function call instruction; Parse the CALL call instruction to obtain the corresponding called function name.
4. The method according to claim 1, wherein The method further includes: Traverse the X86 architecture dynamic link library file to find the functions therein; Calculate the index value of the function and write the index value into the dynamic link library mapping allocator; Traverse the RISC-V dynamic link library file to 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; Store the relative address value as the first value into the dynamic link library mapping allocator, and establish a key-value pair structure of the index value and the relative address value in the mapping allocator; Return to the step of finding the functions therein until the traversal of the X86 architecture dynamic link library file is completed.
5. The method according to claim 4, characterized in that, The method further includes: Perform persistent storage on the dynamic link library mapping allocator.
6. The method according to claim 5, wherein The method further includes: Determine the type of the function; Determine the number of parameters of the function according to the type; Add the number of parameters as the second value to the key-value pair structure.
7. The method according to claim 1, wherein The method further includes: When the first value and the second value cannot be obtained by using the dynamic link library mapping allocator, perform translation and execution on the functions that cannot be obtained in the X86 dynamic link library.
8. A dynamic library mapping execution device in binary translation, characterized in that Including: A judgment module for translating and executing the instructions of the X86 executable program, judging whether it is a dynamic link library function call instruction. When it is a dynamic link library function call instruction, parse the call instruction to obtain the called function; A query module for using the called function as a query index key to query in the pre-established dynamic link library mapping allocator, and obtaining the first value and the second value corresponding to the function in the RISC-V dynamic link library; An address determination module, configured 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; A parameter address determination module, configured to determine the parameter address of the function according to the second value; A calculation module, configured to calculate the function using the parameter address and the absolute address and return a calculation result.
9. A device, characterized in that, The device includes: One or more processors; A storage device, configured to store 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-7.
10. A storage medium containing computer-executable instructions, characterized in that, The computer-executable instructions, when executed by a computer processor, are used to execute the dynamic library mapping execution method in binary translation as described in any one of claims 1-7.
Citation Information
Patent Citations
Code processing method, device and equipment
CN114327497A
Binary translation method and device, electronic equipment and storage medium
CN117093229A
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
Automatic parallelization low-coupling dynamic binary translation tool and method
CN118689489A