Code compiling method, device and system, code compiler and product

By loading the source code file and its dynamic database of running records, parsing and identifying indirect jump code entry points, the problem of indirect jump recognition difficulty in code compilation is solved, and the code translation quality and scanning coverage are improved.

CN119002923APending Publication Date: 2024-11-22PHYTIUM TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411093353.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-08
Publication Date
2024-11-22

AI Technical Summary

Technical Problem

The existing technology cannot accurately analyze indirect jumps in the source code during the code compilation process, resulting in low code scanning coverage, which in turn affects the quality of code translation.

Method used

By loading the source code file and its dynamic database recorded during the running process of the source platform, the code entry point is parsed, and the corresponding code entry point is identified based on the dynamic database to form a collection of code entry points, so as to compile the code entry point Accurately identify the running path of the source code.

Benefits of technology

It improves the scanning coverage of code compilation and improves the quality of code translation, especially effectively identifying indirect jump operations during AOT compilation, and enhances the accuracy and coverage of code translation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119002923A_ABST
    Figure CN119002923A_ABST
Patent Text Reader

Abstract

The invention provides a code compiling method, device and system, a code compiler and a product, and the method comprises the steps that a source code file and a dynamic database are loaded, and the dynamic database comprises operation process records when the source code file operates on a source platform; and performing code entry point analysis on the source code file, and identifying a code entry point corresponding to indirect jump in the source code based on the dynamic database to obtain a code entry point set. According to the method, the code scanning coverage rate of code compiling can be improved, and therefore the code translation quality can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a code compilation method, device, system, code compiler and product. Background Art

[0002] Binary translation refers to the technology of converting machine code of one architecture into machine code of another architecture. When translating the code, the code needs to be compiled. During the compilation process, the source code is statically scanned to obtain the code entry point, and then the code is compiled based on the code entry point.

[0003] The above-mentioned compilation method realizes code compilation by statically analyzing the source code files. However, the compilation method is usually unable to accurately analyze the indirect jumps in the source code, resulting in low code scanning coverage, which in turn leads to poor code translation quality. Summary of the invention

[0004] In response to the above technical problems, the present application proposes a code compilation method, device, system, code compiler and product, which can improve the code scanning coverage of AOT compilation, thereby helping to improve the quality of code translation.

[0005] The first aspect of the present application provides a code compilation method, comprising:

[0006] Loading a source code file and a dynamic database, wherein the dynamic database includes a running process record of the source code file when running on a source platform;

[0007] A code entry point set is obtained by parsing the code entry point of the source code file and identifying the code entry point corresponding to the indirect jump in the source code based on the dynamic database.

[0008] In some implementations, the method further includes: based on the set of code entry points, converting the source code file into an object code file, wherein the object code file is a code file suitable for running on a target platform.

[0009] In some implementations, the code entry point set is obtained by parsing the source code file and identifying the code entry point corresponding to the indirect jump in the source code based on the dynamic database, including:

[0010] Performing code entry point analysis on the source code file to determine potential code entry points in the source code file;

[0011] Querying the running records corresponding to the indirect jump instructions in the source code from the dynamic database to determine the code entry point corresponding to the indirect jump in the source code;

[0012] Based on the determined potential code entry points and the code entry points corresponding to the indirect jumps, the code entry point parsing of the source code file continues to be performed to obtain a code entry point set.

[0013] In some implementations, querying the dynamic database for a running record corresponding to the indirect jump instruction in the source code to determine a code entry point corresponding to the indirect jump in the source code includes:

[0014] In the process of parsing the code entry point of the source code file, when an indirect jump instruction is parsed from the source code file, querying the running record corresponding to the indirect jump instruction from the dynamic database;

[0015] When the operation record corresponding to the indirect jump instruction is queried from the dynamic database, the destination address of the indirect jump instruction is determined based on the operation record, and the code entry point corresponding to the indirect jump is determined based on the destination address.

[0016] In some implementations, when an indirect jump instruction is parsed from the source code file, querying the dynamic database for a running record corresponding to the indirect jump instruction includes:

[0017] When an indirect jump instruction is parsed from the source code file, determining the address of the indirect jump instruction in the source code file;

[0018] According to the address of the indirect jump instruction in the source code file, the code running record corresponding to the address is queried from the dynamic database.

[0019] In some implementations, determining a destination address of the indirect jump instruction based on the operation record, and determining a code entry point corresponding to the indirect jump based on the destination address includes:

[0020] Determine the starting address of the function table pointed to by the indirect jump instruction based on the operation record;

[0021] Determine the destination address of the indirect jump instruction based on the starting address of the function table and the address range of each code segment in the source code file;

[0022] The destination address of the indirect jump instruction is determined as a code entry point corresponding to the indirect jump.

[0023] In some implementations, determining the destination address of the indirect jump instruction based on the start address of the function table and the address range of each code segment in the source code file includes:

[0024] Starting from the starting address of the function table, determining the address of each function in the function table;

[0025] Based on the addresses of the respective functions and the address ranges of the respective code segments in the source code file, determining the jump target function from the respective functions;

[0026] The address of the jump target function is determined as the destination address of the indirect jump instruction.

[0027] In some implementations, based on the addresses of the respective functions and the address ranges of the respective code segments in the source code file, determining the jump target function from the respective functions includes:

[0028] For each function, perform the following processing:

[0029] Comparing the address of the function with the address ranges of each code segment in the source code file;

[0030] If the address of the function is within the address range of any code segment in the source code file, the function is determined as the jump target function.

[0031] The second aspect of the present application provides a code compilation device, comprising:

[0032] A data loading unit, used for loading source code files and a dynamic database, wherein the dynamic database includes a running process record of the source code files when running on a source platform;

[0033] The code parsing unit is used to parse the code entry points of the source code file and identify the code entry points corresponding to the indirect jumps in the source code based on the dynamic database to obtain a code entry point set.

[0034] The third aspect of the present application provides a code compiler, comprising:

[0035] Memory and processor;

[0036] The memory is connected to the processor and is used to store programs;

[0037] The processor is used to implement the above-mentioned code compilation method by running the program in the memory.

[0038] A fourth aspect of the present application provides a computer program product, comprising computer program instructions, which, when executed by a processor, enable the processor to execute the above-mentioned code compilation method.

[0039] A fifth aspect of the present application provides a code compilation system, comprising:

[0040] Run the record module and code compilation module;

[0041] The operation record module is used to record the operation process of the source code file on the source platform to obtain a dynamic database;

[0042] The code compiling module is connected to the operation recording module and is used to execute the above-mentioned code compiling method.

[0043] The code compilation method proposed in the present application, in the process of code compilation, loads the source code file and also loads the dynamic database including the running process record of the source code file when it is running on the source platform. Then, by parsing the code entry point of the source code file and identifying the code entry point corresponding to the indirect jump in the source code file based on the dynamic database, a code entry point set is obtained. This step can be combined with the running process record of the source code file when it is running on the source platform to effectively identify the code entry point corresponding to the indirect jump in the source code, so that the running path of the source code can be accurately and comprehensively identified during code compilation, thereby improving the code compilation scanning coverage, and further helping to improve the quality of code translation. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0045] Figure 1 A flowchart of a code compilation method provided in an embodiment of the present application.

[0046] Figure 2 A flowchart of another code compilation method provided in an embodiment of the present application.

[0047] Figure 3 A schematic diagram of the structure of a code compilation device provided in an embodiment of the present application.

[0048] Figure 4 A schematic diagram of the structure of a code compilation system provided in an embodiment of the present application.

[0049] Figure 5 A schematic diagram of the structure of a code compiler provided in an embodiment of the present application. DETAILED DESCRIPTION

[0050] The technical solution of the embodiment of the present application is applicable to the code compilation application scenario in the binary translation process. The use of the technical solution of the embodiment of the present application can improve the scanning coverage of code compilation, thereby helping to improve the quality of code binary translation.

[0051] Binary translation refers to the technology of converting machine code (source code) of one architecture into machine code (target code) of another architecture. For example, converting the code that runs in the execution environment of the x86 architecture into the code that can run in the execution environment of the ARM architecture is called binary translation. Binary translation is usually implemented in software simulators or dynamic compilers, so that the software can run on different hardware platforms.

[0052] AOT (Ahead-Of-Time) compilation refers to compiling the source code program into target machine code before the program is executed. AOT compilation is usually implemented in an AOT compiler. AOT compilation has many advantages, especially in terms of performance, startup speed, resource utilization, and security. The following are the main advantages of AOT compilation:

[0053] 1. Performance optimization: AOT compiler has more time to perform complex and deep optimizations, such as inlining, loop unrolling, constant propagation, etc. These optimizations are usually not possible during runtime Just-In-Time (JIT) compilation because JIT needs to generate executable code quickly.

[0054] 2. Fast startup

[0055] The AOT-compiled code is already the machine code of the target platform when the application starts, so there is no need for runtime compilation, which significantly reduces the application startup time.

[0056] Based on the above advantages, AOT compilation is widely used in cross-platform software migration, high-performance computing, cloud computing and virtualization environments.

[0057] Among them, cross-platform software migration refers to migrating existing architecture software to other architectures for operation, such as migrating x86 architecture software to other architectures such as ARM. Its goal is to achieve efficient execution on the new platform and minimize performance loss.

[0058] High-performance computing means that in a large computing cluster or high-performance computing environment, some computing tasks need to be migrated from one architecture to another to take advantage of the performance advantages of specific hardware. In this process, the overall computing efficiency can be improved through AOT compilation and runtime optimization.

[0059] In cloud computing and virtualization environments, different virtual machines may run on physical hardware of different architectures. AOT compilation can achieve cross-architecture compatibility and efficient execution of virtual machines.

[0060] The ultimate performance benefit of AOT, that is, the quality of AOT compiled code translation, is mainly affected by the code scanning coverage rate during the code compilation phase. Code scanning coverage rate refers to the code range that the AOT compiler can cover and optimize when compiling code. The coverage rate will have a direct impact on the effect of AOT compilation.

[0061] At present, the code scanning coverage of AOT compilation is not high. The direct reason is that AOT compilation realizes code translation by static analysis of source code files, while modern program codes make extensive use of indirect jump operations such as function pointers, virtual function tables, callback functions, etc. to implement functions. The above-mentioned indirect jump operations are difficult to determine when the code is statically analyzed, which makes AOT compilation unable to accurately determine the control flow of the program, resulting in low code scanning coverage.

[0062] In response to the above technical problems, an embodiment of the present application proposes a code compilation method, which improves AOT compilation and can effectively identify indirect jump operations during the AOT compilation process, thereby improving the code scanning coverage of AOT compilation, which can help improve the code translation quality of AOT compilation.

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

[0064] The present application embodiment first proposes a code compilation method, which can be executed by an AOT compiler. Figure 1 As shown, the code compilation method includes:

[0065] S101, loading source code files and dynamic database.

[0066] The above-mentioned source code file refers to a source code file suitable for running on the source platform and requiring binary translation. In the embodiment of the present application, the source code file may be an ELF (Executable and Linkable Format) file of the source program code. When the AOT compiler performs binary code translation, the source code file to be translated may be recorded from a preset storage location.

[0067] The above-mentioned dynamic database is a database used to store the operation records of the above-mentioned source code files when they are running on the source platform. The database includes the operation process records of the source code files when they are running on the source platform. The operation process records include the operation process data of the source code files when they are running on the source platform, such as the program execution path, performance data, etc.

[0068] Exemplarily, when the source code file is running on the source platform, the running process data of the source code file can be recorded by the running monitoring module, and the recorded running process data can be stored in the dynamic database.

[0069] When the AOT compiler loads the above source code file, the above dynamic database is recorded from the set storage location.

[0070] S102: Obtain a code entry point set by parsing the source code file for code entry points and identifying code entry points corresponding to indirect jumps in the source code based on the dynamic database.

[0071] Specifically, the AOT compiler loads the source code file into memory, and then scans the source code file to parse the potential code entry points therein. The above-mentioned code entry point refers to the entry point of the code snippet. The source code file can be divided into multiple code snippets, including but not limited to symbol tables, debug tables, initialization tables, deinitialization tables, etc. Each code snippet can correspond to a code entry point, and each code entry point can be regarded as a potential code entry point.

[0072] Whenever the AOT compiler parses a potential code entry point from the source code file, it adds it to the code entry point set. In the subsequent parsing process, the code entry points in the set are analyzed again to discover new code entry points or eliminate false code entry points to obtain the final code entry point set.

[0073] In the above-mentioned code entry point parsing process, when the AOT compiler parses an indirect jump instruction from the source code file, such as an indirect jump instruction such as JMP[eax+ecx*4] or CALL[eax+8], the destination address corresponding to the indirect jump is determined by querying the running record corresponding to the indirect jump instruction from the above-mentioned dynamic database, that is, the code entry point of the indirect jump is determined, and the code entry point corresponding to the indirect jump is added to the code entry point set.

[0074] Then, the AOT compiler continues to parse the source code based on the code entry point corresponding to the discovered indirect jump to discover more new code entry points, and adds the discovered code entry points to the code entry point set.

[0075] The AOT compiler repeatedly executes the above process, continuously parsing the code entry points in the source code file, and finally obtains a code entry point set containing all real code entry points.

[0076] From the above introduction, it can be seen that the code compilation method proposed in the embodiment of the present application, while loading the source code file, also loads a dynamic database including the running process record of the source code file when it is running on the source platform during the code compilation process. Then, by parsing the code entry point of the source code file and identifying the code entry point corresponding to the indirect jump in the source code file based on the dynamic database, a code entry point set is obtained. This step can be combined with the running process record of the source code file when it is running on the source platform to effectively identify the code entry point corresponding to the indirect jump in the source code, so that the running path of the source code can be accurately and comprehensively identified during code compilation, thereby improving the code compilation scanning coverage, and then helping to improve the quality of code translation.

[0077] In other embodiments, see Figure 2 As shown, the above code compilation method also includes:

[0078] S103. Based on the code entry point set, convert the source code file into a target code file, where the target code file is a code file suitable for running on a target platform.

[0079] Specifically, the AOT compiler decodes the code entry points in the code entry point set, and then decodes and compiles the code entry point set and the source code file to generate code and metadata suitable for the target platform, and then records the generated code and metadata into the AOT file, thus obtaining a code file suitable for running on the target platform.

[0080] Among them, the process of AOT editor compiling the code entry point is divided into three steps: front-end decoding, mid-end optimization, and back-end emission:

[0081] Front-end decoding: This step mainly cuts the instruction stream into basic blocks and generates CFG (program control flow graph)

[0082] Mid-end optimization: According to the program control flow graph generated by the front-end decoding, all decoded instructions are converted into IR (intermediate expression), and activity analysis, common sub-expression deletion, constant propagation, register allocation and other processing are performed respectively.

[0083] Back-end emission: finally generates instructions based on the results of mid-end optimization.

[0084] Based on the above code compilation process, more code entry points can be found, especially indirect jump code entry points, so as to improve the code scanning coverage. Code translation based on the code entry point set found by the code compilation can improve the code translation quality.

[0085] In other embodiments, a specific process for determining a set of code entry points is also disclosed.

[0086] In these embodiments, the code entry point set is obtained by parsing the source code file and identifying the code entry point corresponding to the indirect jump in the source code based on the dynamic database. This can be specifically achieved by processing the following steps A1-A3:

[0087] A1. parse the source code file for code entry points to determine potential code entry points in the source code file.

[0088] Specifically, the AOT compiler loads the ELF file of the source code into memory, and then scans and analyzes the ELF file to parse the potential code entry points therein, including but not limited to the symbol table, debug table, initialization table, deinitialization table, etc., thereby determining the potential code entry points in the source code file.

[0089] These potential code entry points are not necessarily the real code entry points, and these are not the only code entry points in the source code. The AOT compiler will further parse these potential code entry points to confirm whether they are the real code entry points, or further scan and discover other code entry points based on these potential code entry points.

[0090] A2. Query the running records corresponding to the indirect jump instructions in the source code from the dynamic database to determine the code entry point corresponding to the indirect jump in the source code.

[0091] Specifically, during the process of the AOT compiler parsing the source code file, when unparseable indirect jump instructions are parsed from the source code file, these indirect jump instructions are parsed in conjunction with the dynamic database.

[0092] For example, JMP[eax+ecx*4] or call[eax+N], etc. At this time, since the source code file is statically analyzed, the values ​​of eax and ecx in JMP[eax+ecx*4] and the values ​​of eax and N in call[eax+N] are unknown. In other words, it is unknown where JMP[eax+ecx*4] or call[eax+N] actually jumps to when the source code file is running, so it is impossible to determine the code entry points corresponding to these indirect jumps.

[0093] When the indirect jump instruction is parsed in conjunction with the dynamic database, the operation record corresponding to the indirect jump instruction can be queried from the dynamic database. Since the execution path of the program is recorded in detail in the operation record, the actual execution path of the indirect jump instruction can be determined by querying the operation record of the indirect jump instruction from the dynamic database, thereby determining the destination address of the indirect jump instruction, that is, determining the code entry point corresponding to the indirect jump.

[0094] Exemplarily, when the AOT compiler parses an indirect jump instruction from a source code file, it can retrieve the running record corresponding to the name of the indirect jump instruction from the dynamic database based on the name of the indirect jump instruction. If a program running record consistent with the name of the indirect jump instruction is retrieved, it can be considered that the program running record is the running record of the indirect jump instruction. Further, the retrieved program running record is parsed to determine its destination address, and the destination address can be regarded as the code entry point corresponding to the indirect jump.

[0095] Through the above processing, the AOT compiler can determine the potential code entry points in the source code by statically parsing the source code file, and can identify the code entry points corresponding to the indirect jumps in the source code file in combination with the code running records in the dynamic database. Compared with the AOT compiler only identifying the code entry points from the source code file through static parsing, the AOT compiler in the embodiment of the present application can more comprehensively identify the code entry points through the above processing, especially the code entry points corresponding to the indirect jumps.

[0096] A3. Based on the determined potential code entry points and the code entry points corresponding to the indirect jumps, continue to parse the code entry points of the source code file to obtain a code entry point set.

[0097] Specifically, after the AOT compiler determines the potential code entry points and the code entry points corresponding to the indirect jumps from the source code file by executing the above steps A1 and A2, it further performs code entry point parsing based on these code entry points, such as verifying the determined code entry points to determine whether they are real code entry points, or continuing to discover other code entry points based on these code entry points. The newly discovered code entry points can also be further judged as true or false code entry points, and the final code entry points are stored in the code entry point set.

[0098] Through the above processing, the AOT compiler can identify the code entry points corresponding to indirect jumps during the parsing of the source code file, thereby improving the recognition range and efficiency of the code entry points and improving the code scanning coverage during the binary translation process.

[0099] In some other embodiments, the above step A2 may be implemented by executing the following steps A21 and A22:

[0100] A21. During the process of parsing the code entry point of the source code file, when an indirect jump instruction is parsed from the source code file, query the dynamic database for a running record corresponding to the indirect jump instruction.

[0101] Specifically, when the AOT compiler parses the source code file, when it parses an indirect jump instruction that cannot be parsed, such as JMP[eax+ecx*4] or call[eax+N], it starts to query the running record corresponding to the indirect jump instruction from the dynamic database.

[0102] For example, when the AOT compiler parses an indirect jump instruction that cannot be parsed, it first determines the address of the indirect jump instruction in the source code file. For example, for the JMP[eax+ecx*4] instruction, it first determines its address in the source code file. Assuming that it is at position 0x100 in the source code file, it can be determined that the address of the JMP[eax+ecx*4] instruction in the source code file is 0x100.

[0103] Then, the AOT compiler queries the dynamic database for the code execution record corresponding to the address of the indirect jump instruction in the source code file.

[0104] For example, assuming that the address of the JMP[eax+ecx*4] instruction in the source code file is 0x100, the AOT compiler will query the code execution record corresponding to the code address 0x100 from the execution record of the source code file.

[0105] If the corresponding code execution record can be queried from the dynamic database, the destination address of the indirect jump instruction can be further parsed based on the code execution record; if the corresponding code execution record is not queried from the dynamic database, it means that the indirect jump instruction was not executed when the code was running. At this time, the indirect jump instruction can be ignored and the subsequent parsing of the source code file can continue.

[0106] A22. When the operation record corresponding to the indirect jump instruction is queried from the dynamic database, the destination address of the indirect jump instruction is determined based on the operation record, and the code entry point corresponding to the indirect jump is determined based on the destination address.

[0107] Specifically, when the AOT compiler queries the running record corresponding to the above-mentioned indirect jump instruction from the dynamic database, the running record can be parsed to determine the destination address of the above-mentioned indirect jump instruction at runtime through the running record, and the code entry point corresponding to the indirect jump can be determined based on the destination address. For example, the destination address can be directly determined as the code entry point of the indirect jump.

[0108] In this embodiment, the AOT compiler uses the address of the indirect jump instruction in the source code file to query the execution record corresponding to the indirect jump instruction from the execution record of the source code file, and then determines the code entry point of the indirect jump. The above processing method realizes effective query of the code execution record.

[0109] In some embodiments, after the AOT compiler queries the running record corresponding to the indirect jump instruction from the dynamic database, it determines the destination address of the indirect jump instruction based on the running record, which can be achieved by processing the following steps B1-B3:

[0110] B1. Determine the starting address of the function table pointed to by the indirect jump instruction based on the operation record.

[0111] Specifically, through the operation records corresponding to the indirect jump instructions, the values ​​of the parameters that cannot be directly determined in the indirect jump instructions can be determined. For example, for eax in the call[eax+N] instruction and eax in the JMP[eax+ecx*4] instruction, their corresponding values ​​can be queried through the operation records.

[0112] In the source code file, indirect jumps such as call[eax+N] and JMP[eax+ecx*4] generally come from virtual functions, so the value of eax is likely to be the starting address of a function table. Therefore, by determining the value of the parameter eax in the indirect jump instruction from the running record corresponding to the above indirect jump instruction, the starting address of the function table executed by the indirect jump instruction can be determined.

[0113] For indirect jump instructions like call[eax+N] and JMP[eax+ecx*4], the values ​​of N and ecx are indexes pointing to the function table, that is, to specific functions in the function table. After determining the value of eax, it is necessary to further determine the values ​​of N and ecx to finally determine the specific destination address of the indirect jump instruction.

[0114] B2. Determine the destination address of the indirect jump instruction based on the starting address of the function table and the address range of each code segment in the source code file.

[0115] Specifically, in the case of a clear function table, each function in the function table may be a target function to which the indirect jump instruction jumps when it is executed, that is, the address of each function in the function table may be the destination address of the indirect jump instruction.

[0116] In order to further determine the actual indirect jump destination address from the function table, the AOT compiler further parses the functions in the function table.

[0117] In some embodiments, the AOT compiler determines the destination address of the indirect jump instruction by processing the following steps B21-B23:

[0118] B21. Starting from the starting address of the function table, determine the address of each function in the function table.

[0119] Specifically, when determining the starting address of the function table, the address of each item in the function table may be further determined according to the size of each item in the function table.

[0120] Each item in the function table is the name of the function in the function table. The size of each item in the function table is based on the machine word length. In a 32-bit machine, the size of each item in the function table is 4 bytes, and in a 64-bit machine, the size of each item in the function table is 8 bytes.

[0121] Each item in the function table may be the destination address of an indirect jump, that is, it may be the code entry point corresponding to the indirect jump.

[0122] Therefore, after determining the starting address of the function table, the AOT compiler starts from the first function in the function table and determines the addresses of each function based on the starting address of the function table.

[0123] B22. Based on the addresses of the various functions and the address ranges of the various code segments in the source code file, a jump target function is determined from the various functions.

[0124] Specifically, the AOT compiler determines whether each function in the function table is the target function to which the indirect jump instruction jumps at runtime by comparing the address of each function in the function table with the address range of each code segment in the source code file.

[0125] Specifically, the AOT compiler starts from the first function in the function table and traverses each function in the function table. When traversing to each function, the address of the function is compared with the address range of each code segment in the source code file.

[0126] The source data of the ELF file of the source code includes the starting addresses and ranges of all code segments. Based on the starting addresses and ranges of the code segments, the address range of each code segment can be determined.

[0127] The AOT compiler compares the address of the function in the function table with the address range of each code segment in the source code file. If the address of the function is within the address range of any code segment in the source code file, for example: the starting address of the code segment <= the address of the function < (the starting address of the code segment + the length of the code segment), then the function can be considered as the jump target function, that is, the indirect jump instruction can jump to the jump target function at runtime.

[0128] If the address of the function is not within the address range of any code segment in the source code file, it means that the function is not the jump target function of the indirect jump, and the function cannot be the code entry point of the indirect jump instruction. At this time, continue to judge the next function in the function table.

[0129] Since the AOT compiler has only determined the starting address of the above function table but not its ending address, when the AOT compiler starts from the first function in the function table and traverses each function in the function table, if a certain function cannot be resolved during the traversal, it is determined that the traversal of the function table has been completed, and the above traversal process ends at this time.

[0130] Since the functions in the function table are continuous, when the AOT compiler traverses and parses the functions in the function table from front to back, if a function cannot be parsed, it means that the function is not a function in the function table, and the traversal of the function table can be terminated at this time.

[0131] B23. Determine the address of the jump target function as the destination address of the indirect jump instruction.

[0132] Specifically, through the processing of steps B21 and B22, the AOT compiler further determines the values ​​of N and ecx in the instruction after determining the function table pointed to by eax in call[eax+N] and JMP[eax+ecx*4]. It can be understood that there may be multiple values ​​of N and ecx, each of which corresponds to a jump target function determined by the above processing, and each jump target function is a code entry point corresponding to the indirect jump.

[0133] The AOT compiler determines the addresses of the jump target functions determined by the above processing as the destination addresses of the above indirect jump instructions. It can be understood that the destination address of the above indirect jump instructions is composed of the starting address eax of the function table and the index address ecx or N of the jump target function in the function table.

[0134] B3. Determine the destination address of the indirect jump instruction as the code entry point corresponding to the indirect jump.

[0135] Specifically, the AOT compiler uses the destination address of the indirect jump instruction determined by the above process as the code entry point corresponding to the indirect jump instruction.

[0136] For example, the AOT compiler uses eax and ecx in JMP[eax+ecx*4] to determine the code entry point corresponding to the indirect jump JMP[eax+ecx*4].

[0137] In the above processing, the AOT compiler determines the code entry point corresponding to the indirect jump by parsing the function in the function table pointed to by the indirect jump instruction.

[0138] Corresponding to the above-mentioned code compilation method, the embodiment of the present application also provides a code compilation device, see Figure 3 As shown, the device comprises:

[0139] A data loading unit 100 is used to load a source code file and a dynamic database, wherein the dynamic database includes a running process record of the source code file when the source platform is running;

[0140] The code parsing unit 110 is used to parse the code entry points of the source code file and identify the code entry points corresponding to the indirect jumps in the source code based on the dynamic database to obtain a code entry point set.

[0141] In some implementations, the above-mentioned code compiling device further includes:

[0142] A code translation unit is used to convert the source code file into a target code file based on the code entry point set, wherein the target code file is a code file suitable for running on a target platform.

[0143] In some implementations, the code parsing unit 110 performs code entry point parsing on the source code file and identifies the code entry point corresponding to the indirect jump in the source code based on the dynamic database to obtain a code entry point set, including:

[0144] Performing code entry point analysis on the source code file to determine potential code entry points in the source code file;

[0145] Querying the running records corresponding to the indirect jump instructions in the source code from the dynamic database to determine the code entry point corresponding to the indirect jump in the source code;

[0146] Based on the determined potential code entry points and the code entry points corresponding to the indirect jumps, the code entry point parsing of the source code file continues to be performed to obtain a code entry point set.

[0147] In some implementations, the code parsing unit 110 queries the dynamic database for a running record corresponding to the indirect jump instruction in the source code to determine a code entry point corresponding to the indirect jump in the source code, including:

[0148] In the process of parsing the code entry point of the source code file, when an indirect jump instruction is parsed from the source code file, querying the running record corresponding to the indirect jump instruction from the dynamic database;

[0149] When the operation record corresponding to the indirect jump instruction is queried from the dynamic database, the destination address of the indirect jump instruction is determined based on the operation record, and the code entry point corresponding to the indirect jump is determined based on the destination address.

[0150] In some implementations, when the code parsing unit 110 parses an indirect jump instruction from the source code file, querying the running record corresponding to the indirect jump instruction from the dynamic database includes:

[0151] When an indirect jump instruction is parsed from the source code file, determining the address of the indirect jump instruction in the source code file;

[0152] According to the address of the indirect jump instruction in the source code file, the code running record corresponding to the address is queried from the dynamic database.

[0153] In some implementations, the code parsing unit 110 determines the destination address of the indirect jump instruction based on the operation record, and determines the code entry point corresponding to the indirect jump based on the destination address, including:

[0154] Determine the starting address of the function table pointed to by the indirect jump instruction based on the operation record;

[0155] Determine the destination address of the indirect jump instruction based on the starting address of the function table and the address range of each code segment in the source code file;

[0156] The destination address of the indirect jump instruction is determined as a code entry point corresponding to the indirect jump.

[0157] In some implementations, the code parsing unit 110 determines the destination address of the indirect jump instruction based on the start address of the function table and the address range of each code segment in the source code file, including:

[0158] Starting from the starting address of the function table, determining the address of each function in the function table;

[0159] Based on the addresses of the respective functions and the address ranges of the respective code segments in the source code file, determining the jump target function from the respective functions;

[0160] The address of the jump target function is determined as the destination address of the indirect jump instruction.

[0161] In some implementations, the code parsing unit 110 determines the jump target function from each function based on the address of each function and the address range of each code segment in the source code file, including:

[0162] For each function, perform the following processing:

[0163] Comparing the address of the function with the address ranges of each code segment in the source code file;

[0164] If the address of the function is within the address range of any code segment in the source code file, the function is determined as the jump target function.

[0165] The code compilation device provided in this embodiment belongs to the same application concept as the code compilation method provided in the above embodiments of this application, and can execute the code compilation method provided in any of the above embodiments of this application, and has the corresponding functional modules and beneficial effects of the execution method. For technical details not fully described in this embodiment, please refer to the specific processing content of the code compilation method provided in the above embodiments of this application, and will not be repeated here.

[0166] The functions implemented by the above data loading unit 100, code parsing unit 110 and code translation unit may be implemented by the same or different processors respectively, which is not limited in the embodiment of the present application.

[0167] It should be understood that the units in the above devices can be implemented in the form of a processor calling software. For example, the device includes a processor, the processor is connected to a memory, and instructions are stored in the memory. The processor calls the instructions stored in the memory to implement any of the above methods or realize the functions of each unit of the device, wherein the processor can be a general-purpose processor, such as a CPU or a microprocessor, etc., and the memory can be a memory in the device or a memory outside the device. Alternatively, the units in the device can be implemented in the form of hardware circuits, and the functions of some or all units can be realized by designing the hardware circuits. The hardware circuit can be understood as one or more processors; for example, in one implementation, the hardware circuit is an ASIC, and the functions of some or all of the above units are realized by designing the logical relationship of the components in the circuit; for another example, in another implementation, the hardware circuit can be implemented by PLD, taking FPGA as an example, which can include a large number of logic gate circuits, and the connection relationship between the logic gate circuits is configured by the configuration file, so as to realize the functions of some or all of the above units. All units of the above devices can be implemented in the form of a processor calling software, or in the form of hardware circuits, or in part by a processor calling software, and the remaining part is implemented in the form of hardware circuits.

[0168] In an embodiment of the present application, a processor is a circuit with the ability to process signals. In one implementation, the processor may be a circuit with the ability to read and run instructions, such as a CPU, a microprocessor, a GPU, or a DSP; in another implementation, the processor may implement certain functions through the logical relationship of a hardware circuit, and the logical relationship of the hardware circuit is fixed or reconfigurable, such as a hardware circuit implemented by an ASIC or PLD, such as an FPGA. In a reconfigurable hardware circuit, the process of the processor loading a configuration document to implement the hardware circuit configuration can be understood as the process of the processor loading instructions to implement the functions of some or all of the above units. In addition, it can also be a hardware circuit designed for artificial intelligence, which can be understood as an ASIC, such as an NPU, TPU, DPU, etc.

[0169] It can be seen that each unit in the above device can be one or more processors (or processing circuits) configured to implement the above method, such as: CPU, GPU, NPU, TPU, DPU, microprocessor, DSP, ASIC, FPGA, or a combination of at least two of these processor forms.

[0170] In addition, all or part of the units in the above device can be integrated together, or can be implemented independently. In one implementation, these units are integrated together and implemented in the form of a SOC. The SOC may include at least one processor for implementing any of the above methods or implementing the functions of each unit of the device. The type of the at least one processor may be different, for example, including a CPU and an FPGA, a CPU and an artificial intelligence processor, a CPU and a GPU, etc.

[0171] An embodiment of the present application further provides a control device, which includes a processor and an interface circuit. The processor in the control device is connected to an input-output component through the interface circuit of the control device.

[0172] The input-output component specifically refers to a functional component that can realize data input and output. In the embodiment of the present application, the input-output component refers to a functional component that can input source code files and dynamic databases into the control device, and can output target code files output by the control device.

[0173] The above-mentioned interface circuit can be any interface circuit that can realize the data communication function, for example, it can be a USB interface circuit, a Type-C interface circuit, a serial port circuit, a PCIE circuit, etc.

[0174] The processor in the control device is also a circuit with signal processing capability, which compiles the source code file input by the input and output component by executing any one of the code compilation methods introduced in the above embodiments. The specific implementation of the processor can refer to the above processor implementation, and the embodiments of this application are not strictly limited.

[0175] Optionally, the present application embodiment also provides a code compilation system, see Figure 3 As shown, the system includes an operation record module and a code compilation module.

[0176] The operation record module can be connected to the source platform running the source code file, or set on the source platform running the source code file, and is used to record the running process of the source code file on the source platform to obtain a dynamic database. The dynamic database generated by the operation record module will be sent to the code compilation module.

[0177] The code compilation module is connected to the operation record module and is used to execute any one of the code compilation methods introduced in any of the above embodiments.

[0178] The above-mentioned operation recording module can be any device or module that can record the operation process of the source code file on the source platform, and the above-mentioned code compilation module can be an AOT compiler, or the above-mentioned code compilation device, etc.

[0179] The above-mentioned operation record module and code compilation module can be connected through a wired or wireless communication link. When the two are connected through a wired communication link, they can be connected through any type of audio signal line such as a coaxial signal line, a digital signal line, an optical cable signal line, a balanced signal line, etc. When the two are connected through a wireless communication link, they can be connected through any type of wireless network. Exemplarily, the above-mentioned wireless network can be a network, which can be subdivided into multiple subnetworks. The wireless network or the multiple subnetworks contained in the wireless network can be a local area network (LAN), Ethernet, token ring, wide area network (WAN), Internet, virtual network, virtual private network (VPN), intranet, extranet, public switched telephone network (PSTN), infrared network, wireless network (such as Bluetooth, WIFI), mobile network (such as 4G, 5G), Internet of Things and / or any combination of these and / or other networks.

[0180] The code compilation system provided in this embodiment belongs to the same application concept as the code compilation method provided in the above embodiments of this application, and can execute the code compilation method provided in any of the above embodiments of this application, and has the corresponding functional modules and beneficial effects of the execution method. For technical details not fully described in this embodiment, please refer to the specific processing content of the code compilation method provided in the above embodiments of this application, and will not be repeated here.

[0181] Another embodiment of the present application also provides a code compiler, see Figure 4 As shown, the code compiler includes:

[0182] Memory 200 and processor 210;

[0183] The memory 200 is connected to the processor 210 and is used to store programs;

[0184] The processor 210 is used to implement the code compilation method disclosed in any of the above embodiments by running the program stored in the memory 200.

[0185] Specifically, the code compiler may further include: a bus, a communication interface 220 , an input device 230 and an output device 240 .

[0186] The processor 210, the memory 200, the communication interface 220, the input device 230 and the output device 240 are connected to each other via a bus.

[0187] A bus may include a pathway that transfers information between components of a computer system.

[0188] The processor 210 may be a general-purpose processor, such as a general-purpose central processing unit (CPU), a microprocessor, etc., or an application-specific integrated circuit (ASIC), or one or more integrated circuits for controlling the execution of the program of the scheme of the present invention. It may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0189] The processor 210 may include a main processor, and may also include a baseband chip, a modem, and the like.

[0190] The memory 200 stores a program for executing the technical solution of the present invention, and may also store an operating system and other key services. Specifically, the program may include a program code, and the program code includes a computer operation instruction. More specifically, the memory 200 may include a read-only memory (ROM), other types of static storage devices that can store static information and instructions, a random access memory (RAM), other types of dynamic storage devices that can store information and instructions, a disk storage, a flash, and the like.

[0191] The input device 230 may include a device for receiving data and information input by a user, such as a keyboard, a mouse, a camera, a scanner, a light pen, a voice input device, a touch screen, a pedometer, or a gravity sensor.

[0192] Output device 240 may include devices that allow information to be output to a user, such as a display screen, printer, speaker, etc.

[0193] The communication interface 220 may include any transceiver or the like to communicate with other devices or communication networks, such as Ethernet, Radio Access Network (RAN), Wireless Local Area Network (WLAN), etc.

[0194] The processor 210 executes the program stored in the memory 200 and calls other devices, which can be used to implement each step of any code compilation method provided in the above embodiments of the present application.

[0195] An embodiment of the present application also proposes a chip, which includes a processor and a data interface. The processor reads and runs a program stored in a memory through the data interface to execute the code compilation method introduced in any of the above embodiments. The specific processing process and its beneficial effects can be found in the introduction to the embodiment of the above code compilation method.

[0196] In addition to the above methods and devices, an embodiment of the present application may also be a computer program product, which includes computer program instructions, which, when executed by a processor, enable the processor to execute the steps in the code compilation method described in any of the above embodiments of this specification.

[0197] The computer program product may be written in any combination of one or more programming languages ​​to write program codes for performing the operations of the embodiments of the present application, including object-oriented programming languages, such as Java, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as an independent software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server.

[0198] In addition, an embodiment of the present application may also be a storage medium on which a computer program is stored, and the computer program is executed by a processor to execute the steps of the code compilation method described in any of the above embodiments of this specification.

[0199] For the aforementioned method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the order of the actions described, because according to the present application, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.

[0200] It should be noted that each embodiment in this specification is described in a progressive manner, and each embodiment focuses on the differences from other embodiments, and the same or similar parts between the embodiments can be referred to each other. For the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0201] The steps in the methods of each embodiment of the present application can be adjusted in order, combined and deleted according to actual needs, and the technical features recorded in each embodiment can be replaced or combined.

[0202] The modules and sub-modules in the devices and terminals of the various embodiments of the present application can be combined, divided and deleted according to actual needs.

[0203] In the several embodiments provided in the present application, it should be understood that the disclosed terminals, devices and methods can be implemented in other ways. For example, the terminal embodiments described above are only schematic, for example, the division of modules or submodules is only a logical function division, and there may be other division methods in actual implementation, for example, multiple submodules or modules can be combined or integrated into another module, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or modules, which can be electrical, mechanical or other forms.

[0204] The modules or submodules described as separate components may or may not be physically separated, and the components of the modules or submodules may or may not be physical modules or submodules, that is, they may be located in one place, or they may be distributed on multiple network modules or submodules. Some or all of the modules or submodules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0205] In addition, each functional module or submodule in each embodiment of the present application may be integrated into one processing module, or each module or submodule may exist physically separately, or two or more modules or submodules may be integrated into one module. The above-mentioned integrated modules or submodules may be implemented in the form of hardware or in the form of software functional modules or submodules.

[0206] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0207] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly by hardware, software units executed by a processor, or a combination of the two. The software units may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0208] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

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

Claims

1. A code compilation method, characterized in that: include: Loading a source code file and a dynamic database, wherein the dynamic database includes a running process record of the source code file when the source platform is running; A code entry point set is obtained by parsing the code entry point of the source code file and identifying the code entry point corresponding to the indirect jump in the source code based on the dynamic database.

2. The method according to claim 1, characterized in that The method further comprises: Based on the code entry point set, the source code file is converted into an object code file, where the object code file is a code file suitable for running on a target platform.

3. The method according to claim 1 or 2, characterized in that: By performing code entry point parsing on the source code file and identifying the code entry point corresponding to the indirect jump in the source code based on the dynamic database, a code entry point set is obtained, including: Performing code entry point analysis on the source code file to determine potential code entry points in the source code file; Querying the running records corresponding to the indirect jump instructions in the source code from the dynamic database to determine the code entry point corresponding to the indirect jump in the source code; Based on the determined potential code entry points and the code entry points corresponding to the indirect jumps, the code entry point parsing of the source code file continues to be performed to obtain a code entry point set.

4. The method according to claim 3, characterized in that Querying the running record corresponding to the indirect jump instruction in the source code from the dynamic database to determine the code entry point corresponding to the indirect jump in the source code includes: In the process of parsing the code entry point of the source code file, when an indirect jump instruction is parsed from the source code file, querying the running record corresponding to the indirect jump instruction from the dynamic database; When the operation record corresponding to the indirect jump instruction is queried from the dynamic database, the destination address of the indirect jump instruction is determined based on the operation record, and the code entry point corresponding to the indirect jump is determined based on the destination address.

5. The method according to claim 4, characterized in that When an indirect jump instruction is parsed from the source code file, querying the running record corresponding to the indirect jump instruction from the dynamic database includes: When an indirect jump instruction is parsed from the source code file, determining the address of the indirect jump instruction in the source code file; According to the address of the indirect jump instruction in the source code file, the code running record corresponding to the address is queried from the dynamic database.

6. The method according to claim 4, characterized in that Determining a destination address of the indirect jump instruction based on the operation record, and determining a code entry point corresponding to the indirect jump based on the destination address, including: Determine the starting address of the function table pointed to by the indirect jump instruction based on the operation record; Determine the destination address of the indirect jump instruction based on the starting address of the function table and the address range of each code segment in the source code file; The destination address of the indirect jump instruction is determined as a code entry point corresponding to the indirect jump.

7. The method according to claim 6, characterized in that Determining the destination address of the indirect jump instruction based on the starting address of the function table and the address range of each code segment in the source code file includes: Starting from the starting address of the function table, determining the address of each function in the function table; Based on the addresses of the respective functions and the address ranges of the respective code segments in the source code file, determining the jump target function from the respective functions; The address of the jump target function is determined as the destination address of the indirect jump instruction.

8. The method according to claim 7, characterized in that Based on the addresses of the respective functions and the address ranges of the respective code segments in the source code file, a jump target function is determined from the respective functions, including: For each function, perform the following processing: Comparing the address of the function with the address ranges of each code segment in the source code file; If the address of the function is within the address range of any code segment in the source code file, the function is determined as the jump target function.

9. A code compiling device, characterized in that: include: A data loading unit, used for loading source code files and a dynamic database, wherein the dynamic database includes a running process record of the source code files when running on a source platform; The code parsing unit is used to parse the code entry points of the source code file and identify the code entry points corresponding to the indirect jumps in the source code based on the dynamic database to obtain a code entry point set.

10. A code compiler, characterized in that: include: Memory and processor; The memory is connected to the processor and is used to store programs; The processor is used to implement the code compilation method according to any one of claims 1 to 8 by running the program in the memory.

11. A computer program product, characterized in that The method comprises computer program instructions, which, when executed by a processor, enable the processor to execute the code compiling method according to any one of claims 1 to 8.

12. A code compilation system, characterized in that: include: Run the record module and code compilation module; The operation record module is used to record the operation process of the source code file on the source platform to obtain a dynamic database; The code compilation module is connected to the operation record module and is used to execute the code compilation method as described in any one of claims 1 to 8.