Binary link file generation method and device and program source code compiling method and device
By generating a binary link file containing module name and export function information, binary intermediate files are optimized, which solves the problems of large occupancy and low loading efficiency of binary files on resource-constrained devices, and achieves more efficient file download and execution.
Patent Information
- Application Number
- CN202411199021.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-29
- Publication Date
- 2024-12-13
AI Technical Summary
On resource-constrained devices, binary intermediate files occupy a large storage capacity, resulting in reduced program loading efficiency. The precompilation method requires additional resource support, and it is impossible to complete compilation on small resource devices such as smart cards.
By generating binary link files, including module name length, module name and export function information, optimize binary intermediate files and external function link information to generate smaller loadable files, reducing resource consumption.
Improves file download and execution efficiency in resource-constrained devices and reduces resource consumption of devices.
Smart Images

Figure CN119127211A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of computer technology, and in particular to a method for generating a binary link file, and a method and device for compiling program source code. Background Art
[0002] As a bytecode format, WebAssembly is designed to run on various platforms. It can also serve as a common compilation target for various high-level languages (such as Rust, C++, C), and exhibits better runtime performance than other general-purpose languages . The bytecode can be written once and run everywhere.
[0003] In the related art, when compiling the source code of a program running on a virtual machine, usually on a resource-constrained device, a compiler is used to compile the source code file to generate binary intermediate files corresponding to different types of modules, such as app.wasm or lib.wasm.
[0004] However, in the process of implementing the present application, the inventors found that the above technology has at least the following problems: since the binary intermediate file occupies a large storage capacity, the source code compilation method seriously reduces the program loading efficiency, and the timely compilation on resource-constrained devices is used to speed up the execution speed. This method requires additional resources (for example, the precompiler occupies more code space, and the precompilation process requires a larger cache) to support completion. For smaller resource-constrained devices such as smart cards and secure elements (SE), it is impossible to support the completion of the compilation.
[0005] Specifically, in the related art, on a resource-constrained device, an advance compilation method is adopted, and a first export symbol table (which can be stored in a configuration file or a register) is used to link the external symbols in the binary intermediate file in advance, and the link is resolved to the physical address where the symbol is located. This technology is completed on a resource-constrained device, so when the binary intermediate file is loaded for the first time, the compilation process needs to be completed. Although pre-compilation improves the operating efficiency, it seriously reduces the loading time (download time). Summary of the invention
[0006] The embodiments of the present application provide a method for generating a binary link file, a method and an apparatus for compiling a program source code, which can improve the efficiency of file downloading and execution in a resource-constrained device and reduce the resource consumption of the device.
[0007] According to one aspect of an embodiment of the present application, a method for generating a binary link file is provided, the method comprising:
[0008] Get the binary intermediate file generated after compiling the program source code;
[0009] If there is an export function in the binary intermediate file, generating a corresponding binary link file according to the binary intermediate file;
[0010] The module name length, module name and export function information are defined in the binary link file.
[0011] According to another aspect of an embodiment of the present application, a program source code compiling method is provided, comprising:
[0012] Obtaining a binary intermediate file generated after compiling the program source code, and a binary link file called by the binary intermediate file;
[0013] According to the binary link file, the binary intermediate file is converted into a binary loadable file.
[0014] According to another aspect of an embodiment of the present application, a device for generating a binary link file is provided, the device comprising:
[0015] An intermediate file acquisition module is used to acquire the binary intermediate file generated after the program source code is compiled;
[0016] A link file generating module, used for generating a corresponding binary link file according to the binary intermediate file if there is an export function in the binary intermediate file;
[0017] The module name length, module name and export function information are defined in the binary link file.
[0018] According to another aspect of an embodiment of the present application, a program source code compiling device is provided, the device comprising:
[0019] An input file acquisition module is used to acquire a binary intermediate file generated after compiling the program source code, and a binary link file called by the binary intermediate file;
[0020] A file conversion module is used to convert the binary intermediate file into a binary loadable file according to the binary link file.
[0021] According to another aspect of an embodiment of the present application, an electronic device is provided, the electronic device comprising:
[0022] at least one processor; and
[0023] a memory communicatively connected to the at least one processor; wherein,
[0024] The memory stores a computer program that can be executed by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the binary link file generation method or program source code compilation method described in any embodiment of the present application.
[0025] According to another aspect of an embodiment of the present application, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the binary link file generation method or program source code compilation method described in any embodiment of the present application when executed.
[0026] The technical solution provided by the embodiment of the present application provides a method for generating a binary link file outside a resource-constrained device by obtaining a binary intermediate file generated after compiling the program source code. If there is an export function in the binary intermediate file, a corresponding binary link file is generated according to the binary intermediate file. Since the binary link file is a collection of export function information of the module and is used to provide external function link information of the binary intermediate file, compared with the standard binary intermediate file in the prior art, when executing on the device, if accessing external functions and variables, it is necessary to find a matching module name, function name or variable name for positioning, the embodiment of the present application only needs to obtain the external function link information of the binary intermediate file according to the binary link file outside the device, and generate a loadable file smaller than the binary intermediate file according to the external function link information, thereby improving the efficiency of file downloading and execution in resource-constrained devices and reducing the resource consumption of the device.
[0027] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present application, nor is it intended to limit the scope of the embodiments of the present application. Other features of the embodiments of the present application will become easy to understand through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0029] Figure 1a is a flowchart of a method for generating a binary link file provided according to an embodiment of the present application;
[0030] Figure 1b It is a schematic diagram of compiling a program source code provided according to an embodiment of the present application;
[0031] Figure 2 is a flowchart of another method for generating a binary link file provided according to an embodiment of the present application;
[0032] Figure 3a is a flowchart of a program source code compiling method provided according to an embodiment of the present application;
[0033] Figure 3b It is a conversion diagram of a binary intermediate file provided according to an embodiment of the present application;
[0034] Figure 4a is a flowchart of another program source code compiling method provided according to an embodiment of the present application;
[0035] Figure 4b is a conversion diagram of another binary intermediate file provided according to an embodiment of the present application;
[0036] Figure 4c is a conversion diagram of another binary intermediate file provided according to an embodiment of the present application;
[0037] Figure 4d is a conversion diagram of another binary intermediate file provided according to an embodiment of the present application;
[0038] Figure 4e is a conversion diagram of another binary intermediate file provided according to an embodiment of the present application;
[0039] Figure 5 It is a structural schematic diagram of a binary link file generation device provided according to an embodiment of the present application;
[0040] Figure 6 It is a structural diagram of a program source code compiling device provided according to an embodiment of the present application;
[0041] Figure 7 It is a structural schematic diagram of an electronic device that implements the method for generating a binary link file or the method for compiling a program source code according to an embodiment of the present application. DETAILED DESCRIPTION
[0042] In order to enable those skilled in the art to better understand the embodiments of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings 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 should fall within the scope of protection of this application.
[0043] It should be noted that the terms "first", "second", etc. in the specification and claims of the embodiments of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0044] Figure 1a This is a flowchart of a method for generating a binary link file provided in an embodiment of the present application. This embodiment is applicable to the case of generating a binary link file corresponding to a binary intermediate file. The method can be executed by a binary link file generating device. The binary link file generating device can be implemented in the form of hardware and / or software. The binary link file generating device can be configured in an electronic device. Figure 1a As shown, the method includes:
[0045] Step 110: Obtain a binary intermediate file generated after compiling the program source code.
[0046] In this embodiment, the binary intermediate file is a standard WebAssembly (WASM) file, which is a file output by the compiler compiling the program source code. Figure 1b It can be a schematic diagram of compiling a program source code in this embodiment, such as Figure 1b As shown, the *.c file represents the C language application source file. After the program source file is input and compiled, a binary intermediate file (app.wasm) corresponding to the application module or a binary intermediate file (lib.wasm) corresponding to the library module can be obtained.
[0047] Step 120: If there is an export function in the binary intermediate file, generate a corresponding binary link file according to the binary intermediate file.
[0048] In this embodiment, optionally, the application converter can merge module export information according to the export functions in the binary intermediate file, including: export function name, export function index, export function type, etc., and generate a binary link file according to the merge result.
[0049] The export function refers to an interface in the binary intermediate file that is clearly marked as being available for calling by an external program or module.
[0050] The binary link file is a collection of module export function information, including module name, identifier, module export function name and index information, etc., which is used to provide external function link information for binary intermediate files. The external function refers to the function that is accessible to the binary intermediate file or explicitly declared as accessible to the file and other files by default.
[0051] In this embodiment, the name of the binary link file consists of the module name and the extension ".link", and the module name length, module name and export function information are defined in the binary link file. Furthermore, the link file magic number, version number, module identifier (Application Identifier, AID), module AID length and function number are also defined in the binary link file. Among them, the function information in the binary link file may include: function name, function name length, function index, function input parameter number and function return value number.
[0052] In a specific embodiment, the binary link file consists of an 8-bit byte stream, and multi-byte data items are stored in little-endian order. The format of the binary link file is defined as follows:
[0053]
[0054] Among them, magic in LINKFile indicates the magic number of the binary link file, and its fixed value is 0x6B6E696C; version indicates the version number, and the current version is 0x01000000;
[0055] module_name_size indicates the length of the module name; module_name indicates the module name;
[0056] export_function_count indicates the number of functions; functions lists the exported function information; each value in functions is a variable-length function_info structure. The module name module_name is consistent with the file name of the binary link file and the standard WASM binary file name.
[0057] Specifically, the function_info structure is defined as follows:
[0058]
[0059] Among them, function_name_size indicates the length of the function name; function_name indicates the function name; funIdx indicates the function index; param_count indicates the number of function input parameters; return_count indicates the number of function return values, which is 0 or 1. The function name function_name comes from the export segment in the binary intermediate file; the function index funIdx comes from the export segment in the binary intermediate file.
[0060] In this embodiment, the version numbers of the binary link file and the binary intermediate file are both defined as 32 bytes, where the first byte represents the major version number VersionMinor (i.e., the generation of the product), the second byte represents the minor version number VersionMinor (the increased value indicates the magnitude of the product update), and the third and fourth bytes are reserved.
[0061] The technical solution provided by the embodiment of the present application provides a method for generating a binary link file outside a resource-constrained device by obtaining a binary intermediate file generated after compiling the program source code. If there is an export function in the binary intermediate file, a corresponding binary link file is generated according to the binary intermediate file. Since the binary link file is a collection of export function information of the module and is used to provide external function link information of the binary intermediate file, compared with the standard binary intermediate file in the prior art, when executing on the device, if accessing external functions and variables, it is necessary to find a matching module name, function name or variable name for positioning, the embodiment of the present application only needs to obtain the external function link information of the binary intermediate file according to the binary link file outside the device, and generate a loadable file smaller than the binary intermediate file according to the external function link information, thereby improving the efficiency of file downloading and execution in resource-constrained devices and reducing the resource consumption of the device.
[0062] Figure 2 A flowchart of another method for generating a binary link file provided in an embodiment of the present application is shown in FIG. Figure 2 As shown, the method includes:
[0063] Step 210: Obtain a binary intermediate file generated after compiling the program source code.
[0064] Step 220: If there is an export function in the binary intermediate file, optimize the information of the export segment in the binary intermediate file to obtain function information corresponding to the binary link file.
[0065] In this step, specifically, the function name, function type index, function segment information and type segment information of each function in the export segment of the binary intermediate file can be merged to generate the function information function_info corresponding to the binary link file, including the function name function_name, function index funIdx, function input parameter number param_count and function return value number return_count, etc.
[0066] Step 230: Generate the module name and module name length of the binary link file according to the module name in the binary intermediate file.
[0067] Step 240: Obtain a conversion parameter configuration file, and generate a module AID and a module AID length corresponding to the binary link file according to the module AID in the conversion parameter configuration file.
[0068] In this embodiment, while obtaining the binary intermediate file, a pre-built conversion parameter configuration file can also be obtained. The conversion input parameters in the conversion parameter configuration file include module AID, and the module AID and module AID length corresponding to the binary link file can be generated according to the module AID.
[0069] In one implementation of the present embodiment, when generating a binary link file corresponding to a system application programming interface (API) module, a binary intermediate file generated after compiling the system API corresponding program source code can be obtained, and a binary link file corresponding to the system API module can be generated based on the binary intermediate file generated after compiling the system API corresponding program source code; or, according to a preset format of the binary link file, data information corresponding to the system API module can be obtained, and the function name corresponding to the system API module can be converted; and a binary link file corresponding to the system API module can be generated based on the data information and the converted function name.
[0070] In this embodiment, the system API module is the first module on the resource-constrained device, providing basic operation functions, algorithm functions, communication functions, storage management and security services for other modules. All API functions provided by the system API module are exported for other modules to call.
[0071] Specifically, the binary link file of the system API module can be generated in the following two ways: compile the program source code corresponding to all system APIs, output a binary intermediate file, and generate a corresponding binary link file based on the binary intermediate file; or organize the various data information of the system API module according to the format and preset order of the binary link file, and the function name can be converted into UTF8 format characters through a conversion tool, and finally organize the data information and the converted function name into a binary link file.
[0072] The technical solution provided by the embodiment of the present application provides a method for generating a binary link file outside a device. Since the binary link file is a collection of the export function information of the module and is used to provide the external function link information of the binary intermediate file, compared with the standard binary intermediate file in the prior art, when executing on the device, if an external function or variable is accessed, it is necessary to find a matching module name, function name or variable name for positioning. In the embodiment of the present application, the external function link information of the binary intermediate file can be obtained only according to the binary link file outside the device, and a loadable file smaller than the binary intermediate file can be generated according to the external function link information. This can improve the efficiency of file download and execution in resource-constrained devices and reduce the resource consumption of the device.
[0073] Figure 3a This is a flowchart of a program source code compiling method provided in an embodiment of the present application. This embodiment is applicable to the case of converting binary intermediate files. The method can be executed by a program source code compiling device. The program source code compiling device can be implemented in the form of hardware and / or software. The binary link file generating device can be configured in an electronic device. Figure 3a As shown, the method includes:
[0074] Step 310: Obtain a binary intermediate file generated after compiling the program source code, and a binary link file called by the binary intermediate file.
[0075] In this embodiment, the binary intermediate file and the binary link file generated by other binary intermediate files called by the binary intermediate file can be input into the application converter (i.e., the conversion device). The binary link file is used to provide the application converter with the external function link information of the converted binary intermediate file.
[0076] Step 320: Convert the binary intermediate file into a binary loadable file according to the binary link file.
[0077] In this embodiment, the application converter can complete the card link for the binary intermediate file according to the binary link file, and output a smaller binary loadable file. The binary link file and the binary loadable file have the same version number. Specifically, the .link file represents the binary link file, and the .sef file represents the binary loadable file.
[0078] In one implementation of this embodiment, the module types corresponding to the binary loadable file include library modules and application modules.
[0079] In one implementation of the present embodiment, the binary intermediate file is converted into a binary loadable file according to the binary link file, including: checking whether the version information corresponding to the binary intermediate file and the binary link file is consistent; if so, converting the binary intermediate file into a binary loadable file according to the binary link file.
[0080] In a specific embodiment, checking whether the version information corresponding to the binary intermediate file is consistent with that of the binary link file includes: checking whether the major version information corresponding to the binary intermediate file is the same as the major version information corresponding to the binary link file; if so, checking whether the minor version information corresponding to the binary intermediate file is not lower than the minor version information corresponding to the binary link file; if so, determining that the version information corresponding to the binary intermediate file is consistent with that of the binary link file.
[0081] In this embodiment, taking the library module as an example, Figure 3b It can be a conversion diagram of a binary intermediate file in this embodiment, such as Figure 3b As shown, the binary intermediate file of the library module (lib.wasm) and the binary link file of the called system API module (cuos.link) are used as input, and the conversion device converts and outputs the binary loadable file (lib.sef) of the library module and the binary link file (lib.link) corresponding to the library module. Among them, the binary link file corresponding to the library module is used to call the application module of the library module to perform off-card link conversion to generate a binary loadable file.
[0082] The technical solution provided by the embodiment of the present application is a technical means for converting the binary intermediate file into a binary loadable file according to the binary link file by obtaining a binary intermediate file generated after compiling the program source code and a binary link file called by the binary intermediate file. Compared with the standard binary intermediate file in the prior art, when executing on a device, if an external function or variable is accessed, it is necessary to find a matching module name, function name or variable name for positioning. In the embodiment of the present application, it is only necessary to obtain the external function link information of the binary intermediate file according to the binary link file outside the device, and generate a binary loadable file smaller than the binary intermediate file according to the external function link information, thereby improving the module loading speed and file execution efficiency and reducing the resource consumption of the device.
[0083] Figure 4a A flowchart of another program source code compiling method provided in an embodiment of the present application is shown in FIG. Figure 4a As shown, the method includes:
[0084] Step 410: Obtain a binary intermediate file generated after compiling the program source code, and a binary link file called by the binary intermediate file.
[0085] Step 420: Match the import module name in the binary intermediate file with the module name in the binary link file, and query the function information in the binary link file according to the import function name in the binary intermediate file.
[0086] Step 430: Obtain a function index in the export function information in the binary link file, and replace the import function name of the binary intermediate file with the function index.
[0087] Step 440: If the binary intermediate file includes an export segment, replace the function name in the export segment with the function index.
[0088] Step 450: Obtain the module AID and the module AID length in the binary link file.
[0089] Step 460: Generate AID information corresponding to the imported module in the binary intermediate file according to the module AID in the binary link file and the module AID length.
[0090] Step 470: Arrange the AID information corresponding to all the imported modules in the binary intermediate file in order, and generate the index of the module where the imported function is located in the imported module information array according to the arrangement result.
[0091] Step 480: Replace the import module name in the binary intermediate file with the index of the module where the import function is located in the imported module information array.
[0092] The advantage of this setting is that by replacing the imported function name and the exported segment function name in the binary intermediate file with the function index, and replacing the imported module name with the index of the module where the imported function is located in the imported module information array, the size of the binary loadable file can be optimized and device resources can be saved.
[0093] In one implementation of the present embodiment, before matching the import module name in the binary intermediate file with the module name in the binary link file, it also includes: performing a security check on the binary intermediate file based on the number of function input parameters and the number of function return values recorded in the binary link file; if the binary intermediate file check is successful, converting the function type information of the binary intermediate file into the number of function input parameters and the number of function return values, and generating a code segment corresponding to the binary intermediate file.
[0094] In a specific embodiment, a security check is performed on the binary intermediate file based on the number of function input parameters and the number of function return values recorded in the binary link file, including: obtaining the type segment information corresponding to the binary intermediate file based on the imported function type index of the imported segment information in the binary intermediate file; and checking whether the type segment information is consistent with the number of function input parameters and the number of function return values recorded in the binary link file.
[0095] In a specific embodiment, if the binary intermediate file calls multiple binary link files at the same time, the binary intermediate file is converted into a binary loadable file according to the binary link file, including: matching each import module name in the binary intermediate file with the module name in each binary link file in turn, and querying the function index in each binary link file according to the matching result and the import function name in the binary intermediate file; and replacing the corresponding function name in the binary intermediate file according to each function index.
[0096] In this embodiment, taking the application module as an example, Figure 4bA conversion diagram of a binary intermediate file in this embodiment can be shown, in which the binary intermediate file of the application module (for example: app.wasm), the binary link file of the system API module and the binary link file of the library module (cuos.link, lib.link) are taken as input, and the conversion device converts and outputs the binary loadable file (app.sef) and binary link file (app.link) of the application module.
[0097] In another specific embodiment, when converting the binary intermediate file of a module, if the module does not support providing service interface calls for other modules, only the binary loadable file of the module may be generated without generating the binary link file of the module.
[0098] Figure 4c It can be a conversion diagram of another binary intermediate file in this embodiment, such as Figure 4c As shown, after the binary intermediate file (.wasm) of the module and the called binary link file (.link) are input into the conversion device, if the module does not support providing service interface calls for other modules, the conversion device can only output the binary loadable file of the module without outputting the corresponding binary link file.
[0099] In another specific embodiment, if multiple program source codes generate multiple binary intermediate files with a calling relationship after compilation, the binary intermediate files are converted into binary loadable files according to the binary link file, including: matching the import module name in each of the binary intermediate files with the module name in the binary link file, and querying the function index and module AID corresponding to each of the binary intermediate files according to the matching result; and generating binary loadable files corresponding to each of the binary intermediate files according to each of the function indexes and module AIDs.
[0100] In this embodiment, Figure 4d It can be a conversion diagram of another binary intermediate file in this embodiment, such as Figure 4dAs shown, multiple binary intermediate files (.wasm application file 1, .wasm library file 2, .wasm library file 3) with calling relationships and the called binary link file (.link1) can be input into the conversion device together. The conversion device can first generate a binary link file (.link application file 1, .link library file 2, .link library file 3) of the corresponding module according to the import segment and type information of each binary intermediate file, and then complete function linking for all binary intermediate files according to the above-mentioned called binary link file (.link1), and output a binary loadable file (.sef application file 1, .sef library file 2, .sef library file 3) of the module corresponding to each binary intermediate file.
[0101] In another specific embodiment, if the program source code generates multiple binary intermediate files after compilation, and different binary intermediate files call different binary link files, the binary intermediate files are converted into binary loadable files according to the binary link files, including: generating multiple binary loadable files at the same time according to each of the binary intermediate files and the corresponding binary link files.
[0102] In this embodiment, Figure 4e It can be a conversion diagram of another binary intermediate file in this embodiment, such as Figure 4e As shown, taking the application module as an example, the binary intermediate files (.wasm application file 1, .wasm application file 2) of different application modules and the binary link files (.link1, .link2) called by each module can be input into the conversion device, and the conversion device can compile each application module one by one, and generate binary loadable files (.sef application file 1, .sef application file 2) and binary link files (.link application file 1, .link application file 2) corresponding to each application module.
[0103] In one implementation of the present embodiment, after obtaining the binary intermediate file generated after compiling the program source code, and the binary link file called by the binary intermediate file, it also includes: obtaining a pre-configured conversion parameter configuration file; according to the binary link file, converting the binary intermediate file into a binary loadable file, including: according to the conversion parameter configuration file and the binary link file, converting the binary intermediate file into a binary loadable file.
[0104] In this embodiment, the module AID information and the module version information can be configured as input parameters of the conversion device in a file (i.e., the conversion parameter configuration file) to serve as configuration parameters of the command line. When converting the binary intermediate file, the function link can be completed for the binary intermediate file according to the conversion parameter configuration file and the binary link file.
[0105] The technical solution provided by the embodiment of the present application obtains a binary intermediate file generated after compiling the program source code and a called binary link file, matches the import module name in the binary intermediate file with the module name in the binary link file, queries the function information in the binary link file according to the import function name in the binary intermediate file, obtains the function index of the function information in the binary link file, replaces the import function name of the binary intermediate file with the function index, if the binary intermediate file includes an export segment, replaces the function name in the export segment with the function index, obtains the module AID and the module AID length in the binary link file, generates the AID information corresponding to the import module in the binary intermediate file, and replaces the AI corresponding to each import module in the binary intermediate file with the AI corresponding to each import module in the binary intermediate file. D information is arranged in order, and the index of the module where the imported function is located in the imported module information array is generated according to the arrangement result, and the imported module name in the binary intermediate file is replaced by the index of the module where the imported function is located in the imported module information array. Compared with the standard binary intermediate file in the prior art, when executing on the device, if an external function or variable is accessed, it is necessary to find a matching module name, function name or variable name for positioning. In the embodiment of the present application, the external function link information of the binary intermediate file can be obtained according to the binary link file outside the device, and a binary loadable file smaller than the binary intermediate file is generated according to the external function link information, thereby improving the module loading speed and file execution efficiency, and reducing the resource consumption of the device.
[0106] Figure 5 A schematic diagram of a binary link file generation device provided in an embodiment of the present application, wherein the device is applied to an electronic device, such as Figure 5 As shown, the device includes: an intermediate file acquisition module 510 and a link file generation module 520.
[0107] The intermediate file acquisition module 510 is used to acquire the binary intermediate file generated after the program source code is compiled;
[0108] A link file generating module 520, configured to generate a corresponding binary link file according to the binary intermediate file if there is an export function in the binary intermediate file;
[0109] The module name length, module name and export function information are defined in the binary link file.
[0110] The technical solution provided by the embodiment of the present application provides a method for generating a binary link file outside a device by obtaining a binary intermediate file generated after compiling the program source code. If there is an export function in the binary intermediate file, a technical means is used to generate a corresponding binary link file based on the binary intermediate file. Since the binary link file is a collection of export function information of the module and is used to provide external function link information of the binary intermediate file, compared with the standard binary intermediate file in the prior art, when executing on the device, if accessing external functions and variables, it is necessary to find a matching module name, function name or variable name for positioning. In the embodiment of the present application, it is only necessary to obtain the external function link information of the binary intermediate file based on the binary link file outside the device, and generate a loadable file smaller than the binary intermediate file based on this external function link information, thereby improving the efficiency of file downloading and execution in resource-constrained devices and reducing the resource consumption of the device.
[0111] Based on the above embodiment, the binary link file also defines the link file magic number, version number, module identifier AID, module AID length and function number. The export function information includes: function name, function name length, function index, function input parameter number and function return value number. The version number of the binary link file is defined as 32 bytes; the first byte represents the major version number and the second byte represents the minor version number.
[0112] The link file generation module 520 includes:
[0113] An information optimization unit, used for merging and optimizing the information of the export segments in the binary intermediate file to obtain function information corresponding to the binary link file;
[0114] A module name generating unit, used for generating a module name and a module name length of a binary link file according to the module name in the binary intermediate file;
[0115] The module AID generating unit is used to obtain a conversion parameter configuration file, and generate a module AID and a module AID length corresponding to a binary link file according to the module AID in the conversion parameter configuration file.
[0116] The device also includes: a system API processing module;
[0117] The system API processing module includes:
[0118] A system API compiling unit, used to obtain a binary intermediate file generated after compiling the system API corresponding program source code, and generate a binary link file corresponding to the system API module according to the binary intermediate file generated after compiling the system API corresponding program source code;
[0119] A name conversion unit, used to obtain data information corresponding to the system API module according to a preset format of the binary link file, and convert the function name corresponding to the system API module;
[0120] The system link file generating unit is used to generate a binary link file corresponding to the system API module according to the data information and the converted function name.
[0121] The above device can execute the methods provided by all the above embodiments of the present application, and has the corresponding functional modules and beneficial effects of executing the above methods. For technical details not described in detail in the embodiments of the present application, please refer to the methods provided by all the above embodiments of the present application.
[0122] Figure 6 A schematic diagram of the structure of a program source code compiling device provided in an embodiment of the present application, wherein the device is applied to an electronic device, such as Figure 6 As shown, the device includes: an input file acquisition module 610 and a file conversion module 620.
[0123] An input file acquisition module 610 is used to acquire a binary intermediate file generated after the program source code is compiled, and a binary link file called by the binary intermediate file;
[0124] The file conversion module 620 is used to convert the binary intermediate file into a binary loadable file according to the binary link file.
[0125] The technical solution provided by the embodiment of the present application is a technical means for converting the binary intermediate file into a binary loadable file according to the binary link file by obtaining a binary intermediate file generated after compiling the program source code and a binary link file called by the binary intermediate file. Compared with the standard binary intermediate file in the prior art, when executing on a device, if an external function or variable is accessed, it is necessary to find a matching module name, function name or variable name for positioning. In the embodiment of the present application, it is only necessary to obtain the external function link information of the binary intermediate file according to the binary link file outside the device, and generate a binary loadable file smaller than the binary intermediate file according to the external function link information, thereby improving the module loading speed and file execution efficiency and reducing the resource consumption of the device.
[0126] Based on the above embodiment, the module types corresponding to the binary loadable file include library modules and application modules.
[0127] The file conversion module 620 includes:
[0128] A name matching unit, used to match the import module name in the binary intermediate file with the module name in the binary link file, and query the function information in the binary link file according to the import function name in the binary intermediate file;
[0129] An index obtaining unit, used to obtain a function index in the export function information in the binary link file, and replace the import function name of the binary intermediate file with the function index;
[0130] An index replacement unit, configured to replace a function name in an export segment with the function index if the binary intermediate file includes an export segment;
[0131] An AID acquisition unit is used to acquire the module AID and the module AID length in the binary link file; and generate AID information corresponding to the imported module in the binary intermediate file according to the module AID and the module AID length in the binary link file;
[0132] An AID arrangement unit, used to arrange the AID information corresponding to all the imported modules in the binary intermediate file in order, and generate the index of the module where the imported function is located in the imported module information array according to the arrangement result;
[0133] An import module name replacement unit, used to replace the import module name in the binary intermediate file with the index of the module where the import function is located in the imported module information array;
[0134] A security check unit, configured to perform a security check on the binary intermediate file according to the number of function input parameters and the number of function return values recorded in the binary link file; if the binary intermediate file check succeeds, convert the function type information of the binary intermediate file into the number of function input parameters and the number of function return values, and generate a code segment corresponding to the binary intermediate file;
[0135] A type segment acquisition unit, configured to acquire type segment information corresponding to the binary intermediate file according to an import function type index of the import segment information in the binary intermediate file;
[0136] A consistency checking unit, used for checking whether the type segment information is consistent with the number of function input parameters and the number of function return values recorded in the binary link file;
[0137] A version checking unit, used to check whether the version information corresponding to the binary intermediate file and the binary link file is consistent; if so, converting the binary intermediate file into a binary loadable file according to the binary link file;
[0138] a version information checking unit, used to check whether the major version information corresponding to the binary intermediate file is the same as the major version information corresponding to the binary link file; if so, check whether the minor version information corresponding to the binary intermediate file is not lower than the minor version information corresponding to the binary link file; if so, determine that the version information corresponding to the binary intermediate file is consistent with the version information corresponding to the binary link file;
[0139] A first conversion unit is used for, if the binary intermediate file calls multiple binary link files at the same time, matching all the import module names in the binary intermediate file with the module names in each of the binary link files in sequence, querying the function index in each of the binary link files according to the matching result and the import function name in the binary intermediate file; and replacing the corresponding function name in the binary intermediate file according to each of the function indexes;
[0140] The second conversion unit is used for matching the import module name in each of the binary intermediate files with the module name in the binary link file if multiple program source codes are generated after being compiled into multiple binary intermediate files with a calling relationship, querying the function index and module AID corresponding to each of the binary intermediate files according to the matching result; and generating binary loadable files corresponding to each of the binary intermediate files according to each of the function indexes and module AIDs;
[0141] A third conversion unit is used for simultaneously generating a plurality of binary loadable files according to each of the binary intermediate files and the corresponding binary link files one by one if the program source code generates a plurality of binary intermediate files after being compiled, and different binary intermediate files call different binary link files;
[0142] The configuration file processing unit is used to obtain a pre-configured conversion parameter configuration file, and convert the binary intermediate file into a binary loadable file according to the conversion parameter configuration file and the binary link file.
[0143] The above device can execute the methods provided by all the above embodiments of the present application, and has the corresponding functional modules and beneficial effects of executing the above methods. For technical details not fully described in the embodiments of the present application, please refer to the methods provided by all the above embodiments of the present application.
[0144] Figure 7A schematic diagram of the structure of an electronic device 10 that can be used to implement an embodiment of the present application is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workbenches, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the embodiments of the present application described and / or required herein.
[0145] like Figure 7 As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0146] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0147] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The processor 11 executes the various methods and processes described above, such as a method for generating a binary link file or a method for compiling a program source code.
[0148] In some embodiments, the method for generating a binary link file or the method for compiling a program source code may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the method for generating a binary link file or the method for compiling a program source code described above may be executed. Alternatively, in other embodiments, the processor 11 may be configured to execute the method for generating a binary link file or the method for compiling a program source code by any other appropriate means (e.g., by means of firmware).
[0149] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0150] The computer program for implementing the method of the embodiment of the present application can be written in any combination of one or more programming languages. These computer programs can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program can be executed entirely on the machine, partially on the machine, partially on the machine as a stand-alone software package and partially on a remote machine, or entirely on a remote machine or server.
[0151] In the context of the present application embodiment, computer readable storage medium can be a tangible medium, which can contain or store a computer program for use by an instruction execution system, device or equipment or used in combination with an instruction execution system, device or equipment. Computer readable storage medium can include but is not limited to electronic, magnetic, optical, electromagnetic, infrared or semiconductor systems, devices or equipment, or any suitable combination of the above. Alternatively, computer readable storage medium can be a machine readable signal medium. A more specific example of a machine readable storage medium can include an electrical connection based on one or more lines, 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.
[0152] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0153] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0154] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0155] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in the embodiments of the present application can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions of the embodiments of the present application can be achieved, and this document does not limit them here.
[0156] The above specific implementation manner does not constitute a limitation on the protection scope of the embodiments of the present application. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the embodiments of the present application should be included in the protection scope of the embodiments of the present application.
Claims
1. A method for generating a binary link file, characterized in that: include: Obtain the binary intermediate file generated after compiling the program source code; If there is an export function in the binary intermediate file, generating a corresponding binary link file according to the binary intermediate file; The binary link file defines the module name length, module name and export function information; generating a corresponding binary link file according to the binary intermediate file includes: Merge module export information according to the export function in the binary intermediate file, including at least one of the following: export function name, export function index, and export function type; Generate a binary link file based on the merge results.
2. The method according to claim 1, characterized in that Generate a corresponding binary link file according to the binary intermediate file, including at least one of the following: Optimizing the information of the export segment in the binary intermediate file to obtain function information corresponding to the binary link file; Generate a module name and module name length of a binary link file according to the module name in the binary intermediate file; A conversion parameter configuration file is obtained, and a module AID and a module AID length corresponding to a binary link file are generated according to the module AID in the conversion parameter configuration file.
3. The method according to claim 1, characterized in that The binary link file also defines a link file magic number, a version number, a module identifier AID, a module AID length, and the number of functions.
4. A program source code compiling method, characterized in that: include: Obtaining a binary intermediate file generated after compiling the program source code, and a binary link file called by the binary intermediate file; According to the binary link file, converting the binary intermediate file into a binary loadable file; The version numbers of the binary link file and the binary loadable file are consistent.
5. The method according to claim 4, characterized in that According to the binary link file, converting the binary intermediate file into a binary loadable file comprises: Matching the import module name in the binary intermediate file with the module name in the binary link file, and querying the function information in the binary link file according to the import function name in the binary intermediate file; Obtaining a function index in the export function information in the binary link file, and replacing the import function name of the binary intermediate file with the function index; If the binary intermediate file includes an export segment, the function name in the export segment is replaced with the function index.
6. The method according to claim 5, characterized in that While replacing the imported function name of the binary intermediate file with the function index, it also includes: Obtain the module AID and the module AID length in the binary link file; Generate AID information corresponding to the imported module in the binary intermediate file according to the module AID and the module AID length in the binary link file; Arrange the AID information corresponding to all the imported modules in the binary intermediate file in order, and generate the index of the module where the imported function is located in the imported module information array according to the arrangement result; The import module name in the binary intermediate file is replaced by the index of the module where the import function is located in the imported module information array.
7. A device for generating a binary link file, characterized in that: include: An intermediate file acquisition module is used to acquire the binary intermediate file generated after the program source code is compiled; A link file generating module, used for generating a corresponding binary link file according to the binary intermediate file if there is an export function in the binary intermediate file; The binary link file defines the module name length, module name and export function information; The link file generation module is also used to merge module export information according to the export functions in the binary intermediate file, including at least one of the following: export function name, export function index, and export function type; and generate a binary link file according to the merging result.
8. A program source code compiling device, characterized in that: The device comprises: An input file acquisition module is used to acquire a binary intermediate file generated after compiling the program source code, and a binary link file called by the binary intermediate file; A file conversion module, used for converting the binary intermediate file into a binary loadable file according to the binary link file; The version numbers of the binary link file and the binary loadable file are consistent.
9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can perform the method according to any one of claims 1 to 6.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the method according to any one of claims 1 to 6 when executed.
