Binary link file generation method and device and program source code compiling method and device

By generating binary link files, the problems of large storage capacity occupied by binary intermediate files and pre-compilation resource requirements on resource-constrained devices are solved, improving file download and execution efficiency and reducing device resource consumption.

CN121635890APending Publication Date: 2026-03-10BEIJING CEC HUADA ELECTRONIC DESIGN CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-29
Publication Date
2026-03-10

AI Technical Summary

Technical Problem

On resource-constrained devices, existing technologies use large amounts of storage space for binary intermediate files, resulting in low program loading efficiency. Furthermore, pre-compilation methods require additional resources and cannot be completed on devices such as smart cards.

Method used

Generate a binary linker file by obtaining the binary intermediate file after compiling the program source code. If there are exported functions, generate the corresponding binary linker file based on the binary intermediate file. Define the module name length, module name, and exported function information, and provide external function linking information.

Benefits of technology

It improves the efficiency of file downloading and execution on resource-constrained devices and reduces device resource consumption.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121635890A_ABST
    Figure CN121635890A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a binary link file generation method and device and a program source code compiling method and device. The binary link file generation method comprises the steps that a binary intermediate file generated after a program source code is compiled is obtained; if the export function exists in the binary intermediate file, generating a corresponding binary link file according to the binary intermediate file; wherein a module name length, a module name and export function information are defined in the binary link file. According to the technical scheme, a mode of generating the binary link file outside the device is provided, the file downloading and executing efficiency in the resource-limited device can be improved, and the resource consumption of the device is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a method for generating binary link files, a method for compiling program source code, and an apparatus. Background Technology

[0002] WebAssembly, as a bytecode format, is designed to run on various platforms and can also serve as a common compilation target for various high-level languages ​​(such as Rust, C++, and C), exhibiting better runtime performance than other general-purpose languages. This bytecode enables write-once-run-anywhere functionality.

[0003] In related technologies, when compiling the source code of a program running on a virtual machine, it is usually done on a resource-constrained device. A compiler is used to compile the source code files into binary intermediate files corresponding to different types of modules, such as app.wasm or lib.wasm.

[0004] However, in the process of implementing this application, the inventors discovered that the above-mentioned technology has at least the following problems: Since the storage capacity occupied by the binary intermediate file is large, the source code compilation method seriously reduces the program loading efficiency. The method of timely compilation on resource-constrained devices to speed up the execution speed requires additional resources (such as the pre-compiler occupying more code space and the pre-compilation process requiring a larger cache) to complete. For smaller resource-constrained devices such as smart cards and secure elements (SE), it is impossible to support the compilation.

[0005] Specifically, in related technologies, on resource-constrained devices, an advance compilation method is adopted, which uses a first exported symbol table (which can be stored in a configuration file or a register) to advance link external symbols in the binary intermediate file, and the link is resolved to the physical address where the symbol is located.

[0006] This technology is implemented on resource-constrained devices, so the compilation process needs to be completed when the binary intermediate file is loaded for the first time. Although pre-compilation improves runtime efficiency, it significantly reduces loading time (download time). Summary of the Invention

[0007] This application provides a method for generating binary link files, a method for compiling program source code, and an apparatus, which can improve the efficiency of file downloading and execution in resource-constrained devices and reduce the resource consumption of the devices.

[0008] According to one aspect of the embodiments of this application, a method for generating a binary linker file is provided, the method comprising:

[0009] Obtain the binary intermediate file generated after compiling the program source code;

[0010] If the binary intermediate file contains exported functions, then a corresponding binary linker file is generated based on the binary intermediate file;

[0011] The binary linker file defines the module name length, module name, and exported function information.

[0012] According to another aspect of the embodiments of this application, a method for compiling program source code is provided, including:

[0013] Obtain the binary intermediate file generated after compiling the program source code, and the binary linker file called by the binary intermediate file;

[0014] Based on the binary link file, the binary intermediate file is converted into a binary loadable file.

[0015] According to another aspect of the embodiments of this application, a binary linker file generation apparatus is provided, the apparatus comprising:

[0016] The intermediate file acquisition module is used to acquire the binary intermediate files generated after compiling the program source code;

[0017] The link file generation module is used to generate a corresponding binary link file based on the binary intermediate file if there are exported functions in the binary intermediate file.

[0018] The binary linker file defines the module name length, module name, and exported function information.

[0019] According to another aspect of the embodiments of this application, a program source code compilation apparatus is provided, the apparatus comprising:

[0020] The input file acquisition module is used to acquire the binary intermediate file generated after compiling the program source code, as well as the binary linker file called by the binary intermediate file;

[0021] The file conversion module is used to convert the binary intermediate file into a binary loadable file based on the binary link file.

[0022] According to another aspect of the embodiments of this application, an electronic device is provided, the electronic device comprising:

[0023] At least one processor; and

[0024] A memory communicatively connected to the at least one processor; wherein,

[0025] The memory stores a computer program that can be executed by the at least one processor. The computer program is executed by the at least one processor to enable the at least one processor to execute the binary linker generation method or the program source code compilation method described in any embodiment of this application.

[0026] According to another aspect of the embodiments of this application, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions, the computer instructions being configured to cause a processor to execute and implement the binary linker generation method or program source code compilation method described in any embodiment of this application.

[0027] The technical solution provided in this application provides a way to generate binary link files outside of resource-constrained devices by obtaining the binary intermediate file generated after compiling the program source code, and generating a corresponding binary link file based on the exported functions in the binary intermediate file. Since the binary link file is a collection of exported function information of the module, used to provide external function link information for the binary intermediate file, compared with the existing technology where standard binary intermediate files need to search for matching module names, function names, or variable names to locate external functions or variables when executed on the device, this application embodiment only needs 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. This can improve the efficiency of file download and execution on resource-constrained devices and reduce the resource consumption of the device.

[0028] It should be understood that the content described in this section is not intended to identify key or important features of the embodiments of this application, nor is it intended to limit the scope of the embodiments of this application. Other features of the embodiments of this application will become readily apparent from the following description. Attached Figure Description

[0029] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0030] Figure 1a This is a flowchart of a method for generating a binary link file according to an embodiment of this application;

[0031] Figure 1b This is a compilation diagram of program source code provided according to an embodiment of this application;

[0032] Figure 2 This is a flowchart of another method for generating a binary link file according to an embodiment of this application;

[0033] Figure 3a This is a flowchart of a program source code compilation method provided according to an embodiment of this application;

[0034] Figure 3b This is a schematic diagram illustrating the conversion of a binary intermediate file according to an embodiment of this application;

[0035] Figure 4a This is a flowchart of another program source code compilation method provided according to an embodiment of this application;

[0036] Figure 4b This is a schematic diagram illustrating the conversion of another binary intermediate file according to an embodiment of this application;

[0037] Figure 4c This is a schematic diagram illustrating the conversion of another binary intermediate file according to an embodiment of this application;

[0038] Figure 4d This is a schematic diagram illustrating the conversion of another binary intermediate file according to an embodiment of this application;

[0039] Figure 4e This is a schematic diagram illustrating the conversion of another binary intermediate file according to an embodiment of this application;

[0040] Figure 5 This is a schematic diagram of a binary link file generation device provided according to an embodiment of this application;

[0041] Figure 6 This is a schematic diagram of the structure of a program source code compilation device according to an embodiment of this application;

[0042] Figure 7 This is a schematic diagram of the structure of an electronic device that implements the binary link file generation method or program source code compilation method of the embodiments of this application. Detailed Implementation

[0043] To enable those skilled in the art to better understand the embodiments of this application, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of this application.

[0044] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of the embodiments of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or device that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or devices.

[0045] Figure 1a This is a flowchart illustrating a method for generating a binary link file according to an embodiment of this application. This embodiment is applicable to generating binary link files corresponding to binary intermediate files. This method can be executed by a binary link file generation device, which can be implemented in hardware and / or software and can be configured in an electronic device. Figure 1a As shown, the method includes:

[0046] Step 110: Obtain the binary intermediate file generated after compiling the program source code.

[0047] In this embodiment, the binary intermediate file is a standard WebAssembly (WASM) file, which is the output file of the compiler when compiling the program source code. Figure 1b This can be a compilation diagram of a program source code in this embodiment, such as... Figure 1b As shown, *.c files represent C language application source files. After compiling the source file, you can obtain the binary intermediate file (app.wasm) corresponding to the application module or the binary intermediate file (lib.wasm) corresponding to the library module.

[0048] Step 120: If the binary intermediate file contains exported functions, then generate the corresponding binary linker file based on the binary intermediate file.

[0049] In this embodiment, optionally, the application converter can merge module export information based on the exported functions in the binary intermediate file, including: exported function name, exported function index, exported function type, etc., and generate a binary link file based on the merging result.

[0050] The exported function refers to an interface in the binary intermediate file that is explicitly marked as being available for external programs or modules to call.

[0051] The binary linker file is a collection of exported function information for the module, including the module name, identifier, names and indexes of exported functions within the module, etc., used to provide external function linking information for the binary intermediate file. External functions refer to functions that the binary intermediate file, by default or explicitly declared, are accessible to both this file and other files.

[0052] In this embodiment, the name of the binary link file consists of the module name and the extension ".link". The binary link file defines the module name length, module name, and exported function information. Furthermore, the binary link file also defines the link file magic number, version number, module identifier (Application Identifier, AID), module AID length, and number of functions. The function information in the binary link file may include: function name, function name length, function index, number of function input parameters, and number of function return values.

[0053] In one specific embodiment, the binary link file consists of an 8-bit byte stream, with multi-byte data items stored in little-endian order. The format of the binary link file is defined as follows:

[0054]

[0055] In LINKFile, magic represents the magic number of the binary link file, with a fixed value of 0x6B6E696C; version represents the version number, with the current version being 0x01000000.

[0056] module_name_size represents the length of the module name; module_name represents the module name.

[0057] `export_function_count` indicates the number of functions; `functions` lists information about exported functions; each value in `functions` is a variable-length `function_info` structure. The module name `module_name` must match the name of the binary linker file and the standard WASM binary file name.

[0058] Specifically, the function_info structure is defined as follows:

[0059]

[0060] Wherein, function_name_size represents the length of the function name; function_name represents the function name; funIdx represents the function index; param_count represents the number of input parameters; and return_count represents the number of return values, with a value of 0 or 1. The function name function_name comes from the exported section of the binary intermediate file; the function index funIdx comes from the exported section of the binary intermediate file.

[0061] In this embodiment, the version numbers of both the binary link file and the binary intermediate file are defined as 32 bytes. The first byte represents the major version number VersionMinor (i.e., which generation of the product), the second byte represents the minor version number VersionMinor (incrementing the value to indicate the extent of the product update), and the third and fourth bytes are reserved.

[0062] The technical solution provided in this application provides a way to generate binary link files outside of resource-constrained devices by obtaining the binary intermediate file generated after compiling the program source code, and generating a corresponding binary link file based on the exported functions in the binary intermediate file. Since the binary link file is a collection of exported function information of the module, used to provide external function link information for the binary intermediate file, compared with the existing technology where standard binary intermediate files need to search for matching module names, function names, or variable names to locate external functions or variables when executed on the device, this application embodiment only needs 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. This can improve the efficiency of file download and execution on resource-constrained devices and reduce the resource consumption of the device.

[0063] Figure 2 A flowchart of another method for generating a binary link file provided in the embodiments of this application is shown below. Figure 2 As shown, the method includes:

[0064] Step 210: Obtain the binary intermediate file generated after compiling the program source code.

[0065] Step 220: If there are exported functions in the binary intermediate file, optimize the information of the exported segment in the binary intermediate file to obtain the function information corresponding to the binary linker file.

[0066] Specifically, in this step, the function name, function type index, function segment information, and type segment information of each function in the exported segment of the binary intermediate file can be merged to generate the function information function_info corresponding to the binary linker file, including the function name function_name, function index funIdx, number of function input parameters param_count, and number of function return values ​​return_count, etc.

[0067] Step 230: Generate the module name and module name length of the binary link file based on the module name in the binary intermediate file.

[0068] Step 240: Obtain the conversion parameter configuration file, and generate the module AID and module AID length corresponding to the binary link file based on the module AID in the conversion parameter configuration file.

[0069] 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 based on the module AID.

[0070] In one embodiment of this example, when generating the binary link file corresponding to the system application programming interface (API) module, the binary intermediate file generated after compiling the source code of the system API can be obtained, and the binary link file corresponding to the system API module can be generated based on the binary intermediate file generated after compiling the source code of the system API; or, according to the preset format of the binary link file, the data information corresponding to the system API module can be obtained, and the function name corresponding to the system API module can be converted; the binary link file corresponding to the system API module can be generated based on the data information and the converted function name.

[0071] In this embodiment, the system API module, as the first module on the resource-constrained device, provides other modules with basic operational functions, algorithm functions, communication functions, storage management, and security services. All API functions provided by the system API module are exported for use by other modules.

[0072] Specifically, binary link files for system API modules can be generated in two ways: compile the source code of all system APIs, output binary intermediate files, and generate corresponding binary link files based on these intermediate files; or organize the various data information of the system API modules according to the format and preset order of the binary link files, convert function names to UTF8 format characters using a conversion tool, and finally organize the data information and the converted function names into the binary link files.

[0073] The technical solution provided in this application provides a way to generate binary link files outside the device. This is achieved by obtaining a binary intermediate file generated after compiling the program source code; optimizing the information of the exported segments in the binary intermediate file if exported functions exist, thus obtaining the function information corresponding to the binary link file; generating the module name and module name length of the binary link file based on the module name in the binary intermediate file; obtaining a conversion parameter configuration file; and generating the module AID and module AID length of the binary link file based on the module AID in the conversion parameter configuration file. Since the binary link file is a collection of exported function information of a module, used to provide external function linking information for the binary intermediate file, compared to the existing technology where standard binary intermediate files, when executed on a device, require searching for matching module names, function names, or variable names to locate external functions or variables, this application only needs to obtain the external function linking information of the binary intermediate file from the binary link file outside the device. Based on this external function linking information, a smaller loadable file than the binary intermediate file is generated. This improves the efficiency of file downloading and execution on resource-constrained devices and reduces device resource consumption.

[0074] Figure 3a This is a flowchart illustrating a method for compiling program source code according to an embodiment of this application. This embodiment is applicable to the conversion of binary intermediate files. The method can be executed by a program source code compilation device, which can be implemented in hardware and / or software. The device for generating the binary linker file can be configured in an electronic device. Figure 3a As shown, the method includes:

[0075] Step 310: Obtain the binary intermediate file generated after compiling the program source code, and the binary linker file called by the binary intermediate file.

[0076] In this embodiment, a binary intermediate file, along with a binary link file generated from other binary intermediate files called by the binary intermediate file, can be input into an application converter (i.e., a conversion device). The binary link file is used to provide the application converter with external function link information for the binary intermediate file being converted.

[0077] Step 320: Based on the binary link file, convert the binary intermediate file into a binary loadable file.

[0078] In this embodiment, the application converter can perform external linking of the binary intermediate file based on the binary link file, and output a smaller binary loadable file. The binary link file and the binary loadable file maintain the same version number. Specifically, .link files represent binary link files, and .sef files represent binary loadable files.

[0079] In one embodiment of this example, the module types corresponding to the binary loadable file include library modules and application modules.

[0080] In one embodiment of this example, converting the binary intermediate file into a binary loadable file based on the binary link file includes: verifying 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 based on the binary link file.

[0081] In a specific embodiment, verifying whether the version information corresponding to the binary intermediate file and the binary link file is consistent includes: verifying 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, verifying 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, then determining that the version information corresponding to the binary intermediate file and the binary link file is consistent.

[0082] In this embodiment, the library module is taken as an example. Figure 3b This can be a schematic diagram of the conversion of a binary intermediate file in this embodiment, such as... Figure 3b As shown, the library module's binary intermediate file (lib.wasm) and the binary link file (cuos.link) of the called system API module are taken as input. The conversion device converts and outputs the library module's binary loadable file (lib.sef) and the corresponding binary link file (lib.link). The binary link file corresponding to the library module is used by the application module that calls the library module when performing external linking to generate the binary loadable file.

[0083] The technical solution provided in this application embodiment obtains the binary intermediate file generated after compiling the program source code, as well as the binary link file called by the binary intermediate file. Based on the binary link file, the binary intermediate file is converted into a binary loadable file. Compared with the existing technology where standard binary intermediate files need to search for matching module names, function names, or variable names to locate external functions or variables when executed on a device, this application embodiment only needs to obtain the external function link information of the binary intermediate file based on the binary link file outside the device, and generate a smaller binary loadable file based on this external function link information. This improves module loading speed and file execution efficiency, and reduces device resource consumption.

[0084] Figure 4a A flowchart of another program source code compilation method provided in the embodiments of this application is shown below. Figure 4a As shown, the method includes:

[0085] Step 410: Obtain the binary intermediate file generated after compiling the program source code, and the binary linker file called by the binary intermediate file.

[0086] Step 420: Match the imported module name in the binary intermediate file with the module name in the binary linker file, and query the function information in the binary linker file based on the imported function name in the binary intermediate file.

[0087] Step 430: Obtain the function index from the exported function information in the binary linker file, and replace the imported function name in the binary intermediate file with the function index.

[0088] Step 440: If the binary intermediate file includes an exported section, then replace the function name in the exported section with the function index.

[0089] Step 450: Obtain the module AID and the module AID length from the binary link file.

[0090] Step 460: Generate the AID information corresponding to the imported module in the binary intermediate file based on the module AID in the binary link file and the module AID length.

[0091] Step 470: Arrange the AID information corresponding to all imported modules in the binary intermediate file in order, and generate the index of the module containing the imported function in the imported module information array based on the arrangement result.

[0092] Step 480: Replace the imported module name in the binary intermediate file with the index of the module containing the imported function in the imported module information array.

[0093] The advantage of this setting is that by replacing the names of imported and exported functions in the binary intermediate file with function indices, and replacing the name of the imported module with the index of the module containing the imported function in the imported module information array, the size of the binary loadable file can be optimized, saving device resources.

[0094] In one embodiment of this example, before matching the import module name in the binary intermediate file with the module name in the binary linker file, the method further 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 linker file; if the binary intermediate file check is successful, then 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 the code segment corresponding to the binary intermediate file.

[0095] In one 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 linker file. This includes: obtaining the type segment information corresponding to the binary intermediate file based on the import function type index of the import 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 linker file.

[0096] In one specific embodiment, if the binary intermediate file calls multiple binary link files simultaneously, converting the binary intermediate file into a binary loadable file based on the binary link files includes: matching each imported module name in the binary intermediate file with the module names in each of the binary link files sequentially; querying the function index in each of the binary link files based on the matching results and the imported function names in the binary intermediate file; and replacing the corresponding function name in the binary intermediate file based on each function index.

[0097] In this embodiment, the application module is taken as an example. Figure 4bThis embodiment can be used as a schematic diagram of the conversion of a binary intermediate file. The binary intermediate file of the application module (e.g., 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 the binary link file (app.link) of the application module.

[0098] In another specific embodiment, when converting the binary intermediate file of a module, if the module does not support providing service interface calls to other modules, only the binary loadable file of the module can be generated, without generating the binary linker file of the module.

[0099] Figure 4c This can be a schematic diagram of the conversion of another binary intermediate file in this embodiment, such as... Figure 4c As shown, after the binary intermediate file (.wasm) and the called binary link file (.link) of the module are input into the conversion device, if the module does not support providing service interface calls for other modules, the conversion device may only output the binary loadable file of the module and not output the corresponding binary link file.

[0100] In another specific embodiment, if multiple program source codes are compiled to generate multiple binary intermediate files with calling relationships, the binary intermediate files are converted into binary loadable files according to the binary linker file, including: matching the import module names in each binary intermediate file with the module names in the binary linker file; querying the function index and module AID corresponding to each binary intermediate file according to the matching results; and generating binary loadable files corresponding to each binary intermediate file according to each function index and module AID.

[0101] In this embodiment, Figure 4d This can be a schematic diagram of the conversion of another binary intermediate file in this embodiment, such as... Figure 4dAs shown, multiple binary intermediate files with calling relationships (.wasm application file 1, .wasm library file 2, .wasm library file 3) and the calling binary link file (.link1) can be input into the conversion device. The conversion device can first generate the corresponding module's binary link file (.link application file 1, .link library file 2, .link library file 3) based on the import section and type information of each binary intermediate file. Then, based on the aforementioned calling binary link file (.link1), it completes function linking for all binary intermediate files and outputs the binary loadable file (.sef application file 1, .sef library file 2, .sef library file 3) corresponding to the module of each binary intermediate file.

[0102] 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 simultaneously according to each of the binary intermediate files and the corresponding binary link files.

[0103] In this embodiment, Figure 4e This can be a schematic diagram of the conversion 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) and the binary link files (.link1, .link2) called by different application modules can be input into the conversion device. The conversion device can compile each application module one by one and generate the corresponding binary loadable files (.sef application file 1, .sef application file 2) and binary link files (.link application file 1, .link application file 2) for each application module.

[0104] In one embodiment of this example, after obtaining the binary intermediate file generated after compiling the program source code and the binary linker file called by the binary intermediate file, the method further includes: obtaining a pre-configured conversion parameter configuration file; and converting the binary intermediate file into a binary loadable file according to the binary linker file, including: converting the binary intermediate file into a binary loadable file according to the conversion parameter configuration file and the binary linker file.

[0105] In this embodiment, the module AID information and 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 for the command line. When converting the binary intermediate file, function linking can be performed on the binary intermediate file according to the conversion parameter configuration file and the binary linker file.

[0106] The technical solution provided in this application involves obtaining the binary intermediate file generated after compiling the program source code and the called binary link file. It matches the imported module names in the binary intermediate file with the module names in the binary link file, queries the function information in the binary link file based on the imported function names in the binary intermediate file, obtains the function index of the function information in the binary link file, replaces the imported function names in the binary intermediate file with the function index, and if the binary intermediate file includes an export section, replaces the function names in the export section with the function index. It also obtains the module AID and module AID length in the binary link file, generates AID information corresponding to the imported modules in the binary intermediate file, and assigns the AID to each imported module in the binary intermediate file. The D information is arranged in order, and the index of the module containing the imported function in the imported module information array is generated based on the arrangement result. The imported module name in the binary intermediate file is replaced with the index of the module containing the imported function in the imported module information array. Compared with the existing technology where the standard binary intermediate file needs to search for matching module name, function name or variable name to locate external functions or variables when executed on the device, this application embodiment only needs to obtain the external function link information of the binary intermediate file based on the binary link file outside the device, and generate a smaller binary loadable file than the binary intermediate file based on this external function link information. This improves the module loading speed and file execution efficiency, and reduces the resource consumption of the device.

[0107] Figure 5 This is a schematic diagram of a binary link file generation device provided in an embodiment of this application. The device is applied in 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.

[0108] The intermediate file acquisition module 510 is used to acquire the binary intermediate file generated after compiling the program source code;

[0109] The link file generation module 520 is used to generate a corresponding binary link file based on the binary intermediate file if there are exported functions in the binary intermediate file.

[0110] The binary linker file defines the module name length, module name, and exported function information.

[0111] The technical solution provided in this application provides a way to generate binary link files outside the device by obtaining the binary intermediate file generated after compiling the program source code, and generating a corresponding binary link file based on the binary intermediate file if the binary intermediate file contains exported functions. Since the binary link file is a collection of exported function information of the module, used to provide external function link information of the binary intermediate file, compared with the existing technology where the standard binary intermediate file needs to search for matching module names, function names or variable names to locate external functions or variables when executed on the device, this application embodiment only needs 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. This can improve the efficiency of file download and execution on resource-constrained devices and reduce the resource consumption of the device.

[0112] Based on the above embodiments, the binary linker file also defines the linker file magic number, version number, module identifier AID, module AID length, and number of functions. The exported function information includes: function name, function name length, function index, number of function input parameters, and number of function return values. The version number of the binary linker file is defined as 32 bytes; where the first byte represents the major version number, and the second byte represents the minor version number.

[0113] Linked file generation module 520 includes:

[0114] The information optimization unit is used to merge and optimize the information of the exported segments in the binary intermediate file to obtain the function information corresponding to the binary link file.

[0115] The module name generation unit is used to generate the module name and module name length of the binary link file based on the module name in the binary intermediate file.

[0116] The module AID generation unit is used to obtain the conversion parameter configuration file and generate the module AID and module AID length corresponding to the binary link file based on the module AID in the conversion parameter configuration file.

[0117] The device further includes: a system API processing module;

[0118] The system API processing module includes:

[0119] The system API compilation unit is used to obtain the binary intermediate file generated after compiling the source code of the program corresponding to the system API, and generate the binary link file corresponding to the system API module based on the binary intermediate file generated after compiling the source code of the program corresponding to the system API.

[0120] The name conversion unit is used to obtain the data information corresponding to the system API module according to the preset format of the binary link file, and convert the function name corresponding to the system API module.

[0121] The system link file generation unit is used to generate binary link files corresponding to the system API modules based on the data information and the converted function names.

[0122] The aforementioned apparatus can execute the methods provided in all the foregoing embodiments of this application, and possesses the corresponding functional modules and beneficial effects for executing the aforementioned methods. Technical details not described in detail in the embodiments of this application can be found in the methods provided in all the foregoing embodiments of this application.

[0123] Figure 6 This is a schematic diagram of a program source code compilation device provided in an embodiment of this application. The device is applied in an electronic device, such as... Figure 6 As shown, the device includes an input file acquisition module 610 and a file conversion module 620.

[0124] The input file acquisition module 610 is used to acquire the binary intermediate file generated after the program source code is compiled, and the binary link file called by the binary intermediate file;

[0125] The file conversion module 620 is used to convert the binary intermediate file into a binary loadable file based on the binary link file.

[0126] The technical solution provided in this application embodiment obtains the binary intermediate file generated after compiling the program source code, as well as the binary link file called by the binary intermediate file. Based on the binary link file, the binary intermediate file is converted into a binary loadable file. Compared with the existing technology where standard binary intermediate files need to search for matching module names, function names, or variable names to locate external functions or variables when executed on a device, this application embodiment only needs to obtain the external function link information of the binary intermediate file based on the binary link file outside the device, and generate a smaller binary loadable file based on this external function link information. This improves module loading speed and file execution efficiency, and reduces device resource consumption.

[0127] Based on the above embodiments, the module types corresponding to the binary loadable file include library modules and application modules.

[0128] The file conversion module 620 includes:

[0129] The name matching unit is used to match the imported module names in the binary intermediate file with the module names in the binary link file, and to query the function information in the binary link file based on the imported function names in the binary intermediate file.

[0130] An index acquisition unit is used to acquire the function index in the exported function information of the binary link file and replace the imported function name of the binary intermediate file with the function index.

[0131] An index replacement unit is configured to replace the function name in the exported segment with the function index if the binary intermediate file includes an exported segment;

[0132] The AID acquisition unit is used to acquire the module AID and the module AID length in the binary link file; and generate the AID information corresponding to the imported module in the binary intermediate file based on the module AID and the module AID length in the binary link file.

[0133] The AID sorting unit is used to sort the AID information corresponding to all 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 based on the sorting result.

[0134] The import module name replacement unit is used to replace the import module name in the binary intermediate file with the index of the module containing the import function in the imported module information array;

[0135] The security check unit is used to perform 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 linker file; if the binary intermediate file is successfully checked, the function type information of the binary intermediate file is converted into the number of function input parameters and the number of function return values, and the code segment corresponding to the binary intermediate file is generated.

[0136] The type segment acquisition unit is used to obtain the type segment information corresponding to the binary intermediate file based on the import function type index of the import segment information in the binary intermediate file;

[0137] The consistency check unit is used to check 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 linker file;

[0138] The version verification unit is used to verify whether the version information corresponding to the binary intermediate file and the binary link file is consistent; if so, the binary intermediate file is converted into a binary loadable file according to the binary link file.

[0139] The version information verification unit is used to verify 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, it verifies 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, it determines that the version information corresponding to the binary intermediate file and the binary link file is consistent.

[0140] The first conversion unit is configured to, if the binary intermediate file calls multiple binary link files simultaneously, sequentially match all the imported module names in the binary intermediate file with the module names in each of the binary link files, query the function index in each of the binary link files based on the matching results and the imported function names in the binary intermediate file, and replace the corresponding function names in the binary intermediate file based on the function indexes.

[0141] The second conversion unit is used to match the import module name in each binary intermediate file with the module name in the binary linker file if multiple program source codes are compiled into multiple binary intermediate files with calling relationships, and query the function index and module AID corresponding to each binary intermediate file according to the matching result; and generate binary loadable files corresponding to each binary intermediate file according to each function index and module AID.

[0142] The third conversion unit is used to generate multiple binary loadable files simultaneously based on each binary intermediate file and its corresponding binary linker if the program source code generates multiple binary intermediate files after compilation, and different binary intermediate files call different binary linker files.

[0143] 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 based on the conversion parameter configuration file and the binary link file.

[0144] The above-described apparatus can execute the methods provided in all the foregoing embodiments of this application, and has the corresponding functional modules and beneficial effects for executing the above methods. Technical details not described in detail in the embodiments of this application can be found in the methods provided in all the foregoing embodiments of this application.

[0145] Figure 7A schematic diagram of the structure of an electronic device 10, which can be used to implement embodiments of the present application, is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, 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 illustrative and are not intended to limit the implementation of the embodiments of the present application described and / or claimed herein.

[0146] like Figure 7 As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12 or a random access memory (RAM) 13, communicatively connected to the at least one processor 11. The memory stores computer programs executable by the at least one processor. The processor 11 can perform various appropriate actions and processes based on the computer program stored in the ROM 12 or loaded from storage unit 18 into the RAM 13. The RAM 13 may also store various programs and data required for the operation of the electronic device 10. The processor 11, ROM 12, and RAM 13 are interconnected via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.

[0147] Multiple components in electronic device 10 are connected to I / O interface 15, including: input unit 16, such as keyboard, mouse, etc.; output unit 17, such as various types of displays, speakers, etc.; storage unit 18, such as disk, optical disk, etc.; and communication unit 19, such as network card, modem, wireless transceiver, etc. Communication unit 19 allows electronic device 10 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.

[0148] Processor 11 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, such as methods for generating binary linker files or methods for compiling program source code.

[0149] In some embodiments, the binary linker generation method or program source code compilation method may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on electronic device 10 via ROM 12 and / or communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the binary linker generation method or program source code compilation method described above may be performed. Alternatively, in other embodiments, processor 11 may be configured to execute the binary linker generation method or program source code compilation method by any other suitable means (e.g., by means of firmware).

[0150] Various embodiments 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-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.

[0151] Computer programs used to implement the methods of the embodiments of this application may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing apparatus, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.

[0152] In the context of this application, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0153] To provide interaction with a user, the systems and techniques described herein can 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 pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).

[0154] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or computing systems that include middleware components (e.g., application servers), or computing systems that include frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.

[0155] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.

[0156] 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 described in the embodiments of this application can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of the embodiments of this application can be achieved, and this document does not impose any restrictions.

[0157] The specific embodiments described above do not constitute a limitation on the scope of protection of the embodiments of this application. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the embodiments of this application should be included within the scope of protection of the embodiments of this application.

Claims

1. A method of generating a binary link file, characterized by, The method comprises the following steps: obtaining a binary intermediate file generated after compiling a program source code; if there is an exported function in the binary intermediate file, generating a corresponding binary link file according to the binary intermediate file; wherein the binary link file defines the length of a module name, the module name and the exported function information.

2. The method of claim 1, wherein, Generating the corresponding binary link file according to the binary intermediate file comprises at least one of the following: optimizing the information of the exported segment in the binary intermediate file to obtain the function information corresponding to the binary link file; generating the module name and the length of the module name of the binary link file according to the module name in the binary intermediate file; obtaining a conversion parameter configuration file and generating the module AID and the length of the module AID corresponding to the binary link file according to the module AID in the conversion parameter configuration file.

3. The method of claim 1, wherein, The method further comprises: obtaining a binary intermediate file generated after compiling a system API corresponding program source code and generating a binary link file corresponding to a system API module according to the binary intermediate file generated after compiling the system API corresponding program source code; or obtaining data information corresponding to the system API module according to a preset format of the binary link file and converting the function name corresponding to the system API module; generating a binary link file corresponding to the system API module according to the data information and the converted function name.

4. The method of claim 1, wherein, The binary link file further defines a link file magic number, a version number, a module identifier AID, the length of the module AID and the number of functions.

5. The method of claim 1, wherein the exported function information comprises a function name, the length of the function name, a function index, the number of function input parameters and the number of function return values.

6. The method of claim 1, wherein the version number of the binary link file is defined as 32 bytes; wherein the first byte represents a major version number and the second byte represents a minor version number.

7. A program source code compiling method characterized by comprising: The method comprises the following steps: obtaining a binary intermediate file generated after compiling a program source code and a binary link file called by the binary intermediate file; converting the binary intermediate file into a binary loadable file according to the binary link file.

8. The method of claim 7, wherein, The module type corresponding to the binary loadable file comprises a library module and an application module.

9. The method of claim 7, wherein, Converting the binary intermediate file into a binary loadable file according to the binary link file comprises the following steps: matching the imported 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 imported function name in the binary intermediate file; obtaining the function index in the exported function information in the binary link file and replacing the imported function name in the binary intermediate file with the function index; if the binary intermediate file comprises an exported segment, replacing the function name in the exported segment with the function index.

10. The method of claim 9, wherein, When replacing the imported function name in the binary intermediate file with the function index, the method further comprises the following steps: Obtaining the module AID in the binary link file and the module AID length; According to the module AID in the binary link file and the module AID length, generating the AID information corresponding to the imported module in the binary intermediate file; Arranging the AID information corresponding to all imported modules in the binary intermediate file in order, and generating the index of the module where the imported function is located in the imported module information array according to the arrangement result; Replacing the imported module name in the binary intermediate file with the index of the module where the imported function is located in the imported module information array.

11. The method of claim 9, wherein, Before matching the imported module name in the binary intermediate file with the module name in the binary link file, further comprising: According to the number of function input parameters and the number of function return values recorded in the binary link file, performing security check on the binary intermediate file; If the binary intermediate file passes the check, 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 the code segment corresponding to the binary intermediate file.

12. The method of claim 11, wherein, According to the number of function input parameters and the number of function return values recorded in the binary link file, performing security check on the binary intermediate file, comprising: According to the imported function type index of the import segment information in the binary intermediate file, obtaining the type segment information corresponding to the binary intermediate file; 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.

13. The method of claim 7, wherein, According to the binary link file, converting the binary intermediate file into a binary loadable file, comprising: Verifying whether the version information corresponding to the binary intermediate file and the binary link file is consistent; If yes, according to the binary link file, converting the binary intermediate file into a binary loadable file.

14. The method of claim 13, wherein, Verifying whether the version information corresponding to the binary intermediate file and the binary link file is consistent, comprising: Verifying whether the main version information corresponding to the binary intermediate file is the same as the main version information corresponding to the binary link file; If yes, verifying 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 yes, it is determined that the version information corresponding to the binary intermediate file and the binary link file is consistent.

15. The method of claim 9, wherein, If the binary intermediate file calls multiple binary link files at the same time, according to the binary link file, converting the binary intermediate file into a binary loadable file, comprising: Matching each imported module name in the binary intermediate file with the module name in each binary link file in turn, querying the function index in each binary link file according to the matching result and the imported function name in the binary intermediate file; According to each function index, replacing the corresponding function name in the binary intermediate file.

16. The method of claim 9, wherein, If multiple program source codes are compiled to generate multiple binary intermediate files with calling relationship, According to the binary link file, the binary intermediate file is converted into a binary loadable file, comprising: The import module name in each binary intermediate file is matched with the module name in the binary link file, and the function index and the module AID corresponding to each binary intermediate file are queried according to the matching result; According to each function index and module AID, a binary loadable file corresponding to each binary intermediate file is generated respectively.

17. The method of claim 9, wherein, If the program source code generates multiple binary intermediate files after being compiled, and different binary intermediate files call different binary link files, According to the binary link file, the binary intermediate file is converted into a binary loadable file, comprising: According to each binary intermediate file and the corresponding binary link file, multiple binary loadable files are generated simultaneously.

18. The method of claim 7, wherein, After obtaining the binary intermediate file generated after the program source code is compiled and the binary link file called by the binary intermediate file, a pre-configured conversion parameter configuration file is further obtained; According to the binary link file, the binary intermediate file is converted into a binary loadable file, comprising: According to the conversion parameter configuration file and the binary link file, the binary intermediate file is converted into a binary loadable file.

19. An apparatus for generating a binary linked file, characterized by comprising: Comprise: An intermediate file acquisition module configured to obtain a binary intermediate file generated after a program source code is compiled; A link file generation module configured to generate a corresponding binary link file according to the binary intermediate file if there is an exported function in the binary intermediate file; The binary link file defines the module name length, the module name and the exported function information.

20. A program source code compiling apparatus characterized by comprising: The apparatus comprises: An input file acquisition module configured to obtain a binary intermediate file generated after a program source code is compiled and a binary link file called by the binary intermediate file; A file conversion module configured to convert the binary intermediate file into a binary loadable file according to the binary link file.

21. An electronic device, comprising: The electronic device comprises: At least one processor; and A memory connected with the at least one processor in communication; 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 to enable the at least one processor to execute the method in any one of claims 1-18.

22. A computer-readable storage medium, characterized in that, The computer readable storage medium stores computer instructions for enabling the processor to implement the method in any one of claims 1-18 when executed. The computer readable storage medium stores computer instructions for enabling the processor to implement the method in any one of claims 1-18 when executed.