Binary loadable file downloading method and device, equipment and medium

By converting binary intermediate files into binary loadable files and utilizing binary link files to provide external function linking information, the problem of large storage space occupied by binary intermediate files in resource-constrained devices is solved, download and execution efficiency is improved, and device resource consumption is reduced.

CN121644548APending 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

In existing technologies, binary intermediate files occupy a large amount of storage space, resulting in low program loading efficiency. Furthermore, they cannot be compiled on resource-constrained devices such as smart cards and secure elements, thus failing to meet the requirements for execution speed.

Method used

By obtaining the binary intermediate file and binary linker file after compiling the program source code, converting them into a binary loadable file, and using the external function linker file to provide linking information, a smaller binary loadable file is generated and directly downloaded to a resource-constrained device.

Benefits of technology

It improves the download and execution efficiency of the WebAssembly module on resource-constrained devices, and reduces the device's resource consumption.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121644548A_ABST
    Figure CN121644548A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a binary loadable file downloading method and device, equipment and a medium. The method comprises the steps that a binary intermediate file generated after a program source code is compiled and a binary link file of a module where the binary intermediate file is imported are obtained; converting the binary intermediate file into a binary loadable file according to the binary link file; in response to a downloading command stream, downloading the binary loadable file to a resource-constrained device to obtain a binary execution file; wherein the binary loadable file comprises a first segment, a function segment, a global segment and a code segment. According to the technical scheme provided by the embodiment of the invention, the downloading and execution efficiency of the WebAssessment module in the resource-constrained equipment can be improved, and the resource consumption of the equipment 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, apparatus, device, and medium for downloading binary loadable files. 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] The binary intermediate file is directly loaded into the device's memory. During the loading process, the binary intermediate file occupies a large amount of storage capacity in the existing technology. The existing source code compilation method seriously reduces the program loading efficiency. Furthermore, the use of timely compilation on resource-constrained devices to speed up execution requires additional resources to complete. For smaller devices such as smart cards and Secure Elements (SE), it is impossible to support the compilation. Summary of the Invention

[0004] This application provides a binary loadable file download method, apparatus, device, and medium, which can improve the download and execution efficiency of WebAssembly modules in resource-constrained devices and reduce device resource consumption.

[0005] According to one aspect of the embodiments of this application, a method for downloading binary loadable files is provided, the method comprising:

[0006] Obtain the binary intermediate file generated after compiling the program source code, and the binary linker file of the module imported by the binary intermediate file;

[0007] Based on the binary link file, the binary intermediate file is converted into a binary loadable file;

[0008] In response to the download command stream, the binary loadable file is downloaded to a resource-constrained device to obtain a binary executable file;

[0009] The binary loadable file includes: a header segment, a function segment, a global segment, and a code segment.

[0010] According to another aspect of the embodiments of this application, a binary loadable file downloading apparatus is provided, the apparatus comprising:

[0011] 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 link file of the module imported by the binary intermediate file;

[0012] The file generation module is used to convert the binary intermediate file into a binary loadable file based on the binary link file;

[0013] The file download module is used to respond to the download command stream and download the binary loadable file to a resource-constrained device to obtain a binary executable file;

[0014] The binary loadable file includes: a header segment, a function segment, a global segment, and a code segment.

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

[0016] At least one processor; and

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

[0018] The memory stores a computer program that can be executed by the at least one processor, which enables the at least one processor to perform the binary loadable file download method described in any embodiment of this application.

[0019] 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 loadable file download method described in any embodiment of this application.

[0020] The technical solution provided in this application embodiment obtains the binary intermediate file generated after compiling the program source code, and the binary link file of the module imported by the binary intermediate file. Based on the binary link file, the binary intermediate file is converted into a binary loadable file. In response to a download command stream, the binary loadable file is downloaded to a resource-constrained device to obtain a binary executable file. Since the binary link file is used to provide external function linking information for the binary intermediate file, compared to 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 linking 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 linking information. This can improve the download and execution efficiency of WebAssembly modules on resource-constrained devices and reduce device resource consumption.

[0021] 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

[0022] 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.

[0023] Figure 1a This is a flowchart of a binary loadable file download method provided according to an embodiment of this application;

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

[0025] Figure 2 This is a flowchart of another binary loadable file download method provided according to an embodiment of this application;

[0026] Figure 3 This is a schematic diagram of a binary loadable file download device according to an embodiment of this application;

[0027] Figure 4 This is a schematic diagram of the structure of an electronic device that implements the binary loadable file download method of the embodiments of this application. Detailed Implementation

[0028] 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.

[0029] 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.

[0030] Figure 1a This is a flowchart illustrating a binary loadable file download method provided in this application embodiment. This embodiment is applicable to situations where binary intermediate files are converted to generate binary loadable files. This method can be executed by a binary loadable file download 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:

[0031] Step 110: Obtain the binary intermediate file generated after compiling the program source code, and the binary link file of the module imported by the binary intermediate file.

[0032] In this embodiment, the program source code can be code written in an application programming language (such as C language). After the program source code is compiled into standard WebAssembly bytecode, a binary intermediate file .wasm is generated. During the compilation process, function signatures, functions, tables, memory, global variables, local variables, and jump tags (each element item) generate their respective indexes.

[0033] The binary intermediate file may include the following 12 types of segments: custom segment, type segment, import segment, function segment, table segment, memory segment, global segment, export segment, start segment, element segment, code segment, and data segment.

[0034] The module comprises the following sections: a custom segment for storing custom information; a type segment for listing all function types (also called function signatures or function prototypes) used by the binary intermediate file module; an import segment for listing all imported items of the module, allowing multiple modules to be linked together through imports and exports; a function segment for storing partial function information, listing the type indices of all functions within the module, and indexing the type segment to identify its parameters and return value types; a table segment for listing all tables defined within the module; a memory segment for listing all memory defined within the module, with each memory segment defined in 64KB units, containing the number of units; a global segment for listing all global variable information defined within the module; an export segment for listing all exported items of the module, allowing multiple modules to be linked together through imports and exports; a start segment for listing the module's starting function index; an element segment for listing table initialization data; a code segment for storing partial function information, including local variable information and bytecode of functions within the module, with the function and code segments storing the same number of items in a one-to-one correspondence; and a data segment for listing memory initialization data.

[0035] In this embodiment, the binary intermediate file and the binary link file of the module to which the binary intermediate file is imported can be input into the application converter (i.e., the conversion device). The binary link file is used to provide the application converter with external function link information of the binary intermediate file being converted.

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

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

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

[0039] In this embodiment, the library module is taken as an example. Figure 1b This can be a schematic diagram of the conversion of a binary intermediate file in this embodiment, such as... Figure 1bAs 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.

[0040] In this embodiment, the binary loadable file may include: a header segment, a function segment, a global segment, and a code segment. The header segment, also known as the configuration segment, stores the module's space and configuration information; the function segment lists the parameter information, local variable information, and virtual machine stack of all functions within the module; the global segment stores the address allocation and space information of various variables defined in the module; and the code segment stores the local variable information and bytecode of the functions.

[0041] Step 130: In response to the download command stream, download the binary loadable file to the resource-constrained device to obtain a binary executable file.

[0042] The technical solution provided in this application embodiment obtains the binary intermediate file generated after compiling the program source code, and the binary link file of the module imported by the binary intermediate file. Based on the binary link file, the binary intermediate file is converted into a binary loadable file. In response to a download command stream, the binary loadable file is downloaded to a resource-constrained device to obtain a binary executable file. Since the binary link file is used to provide external function linking information for the binary intermediate file, compared to 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 linking 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 linking information. This can improve the download and execution efficiency of WebAssembly modules on resource-constrained devices and reduce device resource consumption.

[0043] Figure 2 A flowchart of another binary loadable file download method provided in the embodiments of this application is shown below. Figure 2 As shown, the method includes:

[0044] Step 210: Obtain the binary intermediate file generated after compiling the program source code, and the binary link file of the module imported by the binary intermediate file.

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

[0046] In this embodiment, the binary loadable file further includes at least one of the following: an import segment, an application segment, an export segment, an element segment, a data segment, and a custom segment. The import segment lists all imported items of the module; the export segment lists all exported items of the module, and multiple modules can be linked together through imports and exports; the application segment contains information that can be registered as application modules, with each set of information including an application identifier (AID) and application installation and interface registration method ID information; the element segment stores function indexes of functions called via function pointers; the data segment lists read-only data and memory initialization data; and the custom segment can store custom information.

[0047] The binary loadable file encoding begins with a 4-byte magic number and a 4-byte version number, where the magic number is 0x00736566 and the version number is 0x01000000. Following the magic number and version number are several segments, each module having the following uniform format:

[0048] sef{

[0049] u32 magic

[0050] u32 version

[0051] section sections[]

[0052] }

[0053] There are 10 types of segments in a binary loadable file, and each segment is assigned an ID. Each segment appearing in a binary loadable file has the following uniform format:

[0054] section{

[0055] u8 sect ion_id

[0056] u32 size

[0057] u8 contents[]

[0058] }

[0059] Each segment begins with a 1-byte `section_id` that identifies the entire segment type. The `size` field indicates the number of bytes in the segment's `contents` array, excluding the `section_id` and `size` fields. The contents and format of the `contents` array vary depending on the segment type. Specifically, the segment ID allocation and valid `section_id` values ​​in a binary loadable file are listed in Table 1:

[0060] Table 1

[0061]

[0062]

[0063] In one specific embodiment, the custom segment stores custom data, which may include debugging information such as function names and local variable names, as well as third-party extended information. The custom segment includes at least one of the following: a custom segment ID, custom data, and the number of bytes of the custom data. The items in this segment structure are shown below:

[0064]

[0065] Here, section_id is 0; size represents the number of bytes in the custom_section structure, excluding section_id and size; and contents represents the data within this custom section.

[0066] The first segment includes at least one of the following: first segment ID, first segment length, module information, length of the binary loadable file, configuration fields, number of imported modules, number of imported functions, function segment space size, application segment space size, element segment space size, data segment space size, and code segment space size. The module information includes at least one of the following: module version information, module identifier (AID), and module AID length. The items in the first segment structure are shown below:

[0067]

[0068]

[0069] Where section_id is 0x0D; segSize represents the length of the first section; module_Info represents module information; module_version represents the module version; module_aid_size represents the length of the module AID; module_aid[module_aid_size] represents the module AID; SEFLen represents the length of the binary loadable file; and SefConfig represents the Sef configuration field, which is reserved.

[0070] Specifically, to maintain compatibility, the following fields are retained, and users can choose to handle them as they see fit:

[0071] `import_module_count` represents the number of imported modules (lower 4 bits are valid, higher 4 bits are RFU); `import_function_count` represents the number of imported functions; `segFuncLen` represents the size of the function segment space, equal to the function segment size; `segAppLen` represents the size of the application segment space, equal to the application segment size; `segElemLen` represents the size of the element segment space, equal to the element segment size; `segDataLen` represents the size of the data segment space, equal to the data segment size; `segCodeLen` represents the size of the code segment space, equal to the code segment size.

[0072] The import segment includes at least one of the following: import segment ID, the number of bytes of all information in the import segment, the number of imported modules, the number of imported functions, an array of imported module information, and an array of imported function information. The array of imported module information includes at least one of the following: the version of the imported module, the AID of the imported module, and the length of the AID of the imported module. The array of imported function information includes at least one of the following: the index of the module containing the imported function in the array of imported module information, and the index of the imported function in the importing module. The items in the import segment structure are shown below:

[0073]

[0074]

[0075] Here, `section_id` is 2; `size` represents the number of bytes in the `import_section` structure, excluding `section_id` and `size`; `import_module_count` represents the number of modules imported; `import_module_items` represents detailed information about the imported modules; `version` represents the version of the imported modules; `module_aid_size` represents the length of the imported module's AID; `module_aid` represents the imported module's AID; `import_function_count` represents the number of imported functions; and `import_function_items` represents detailed information about the imported functions.

[0076] Specifically, the high 4 bits of import_moduleidx_funcidx represent the index of the module containing the imported function in import_module_items, and the low 12 bits of import_funcidx represent the index of the imported function in the importing module.

[0077] The function segment lists function-related information within the module, excluding imported functions. The function segment includes at least one of the following: function segment ID, number of bytes in the function segment, and number of bytes of code corresponding to a function. The items in the function segment structure are shown below:

[0078]

[0079] Here, section_id is 3; size represents the number of bytes in the function_section structure, excluding section_id and size; code_size represents the number of bytes of code corresponding to a function.

[0080] The application segment includes at least one of the following: application segment ID, number of bytes in the application segment, number of registrable application module information groups, and application module information groups. The application module information group includes at least one of the following: application module AID, length of the application module AID content in this group, and entry function information for application module installation and interface registration. The items in the application segment structure are shown below:

[0081]

[0082] Wherein, section_id is 14; size represents the number of bytes in the App_section structure, excluding section_id and size; AppNum represents the number of information groups for registrable application modules, and its value must be greater than 0; AIDLen represents the length of the AppAID content in this group; AppAID[] is used to distinguish the identifier of the installable application module; AppBuilderMethodID: is used to indicate the entry function information for application module installation and interface registration.

[0083] The global segment includes at least one of the following: global segment ID, number of bytes in the global segment, starting address of module read-only data, starting address of module global variables, reserved fields, and ending address of global variables. The items in the global segment structure are shown below:

[0084] global_section{

[0085] u8 section_id

[0086] u32 size

[0087] u16 rodata_base

[0088] u16 rwdata_base

[0089] u16 RFU_1

[0090] u16 RFU_2

[0091] u16 data_end

[0092] }

[0093] Wherein, section_id is 6; size represents the number of bytes in the global_section structure, excluding section_id and size; rodadata_base represents the starting address of the module's read-only data; the module's read-only data size rodadataSize is rwdata_base - rodadata_base; rwdata_base represents the starting address of the module's global variables; the module's global variable space size is RFU_1 - rwdata_base; RFU_1 is a reserved field; RFU_2 is a reserved field; and data_end represents the ending address of the global variables.

[0094] The exported segment includes at least one of the following: exported segment ID, number of bytes in the exported segment, and function index corresponding to each exported function. The items in the exported segment structure are shown below:

[0095]

[0096] Among them, section_id has a value of 7; size represents the number of bytes in the export_section structure, excluding the section_id and size items; function_idxs lists the function indices of each exported function.

[0097] The element segment stores the function index of the function called via a function pointer. The element segment includes at least one of the following: element segment ID, the number of bytes in the element segment, and the function index of the function called by the function pointer. The items in the element segment structure are shown below:

[0098] elem_section{

[0099] u8 section_id

[0100] u32 size

[0101] u16 function_idx[size / 2]

[0102] }

[0103] Among them, section_id has a value of 9; size represents the number of bytes in the elem_section structure, excluding the section_id and size items; function_idx lists the function indices.

[0104] The code segment includes at least one of the following: code segment ID, number of bytes in the code segment, information on all functions defined within the module, and bytecode of all functions defined within the module. The information on all functions defined within the module includes at least one of the following: function code flags, number of parameters, number of local variables, number of units in the function's maximum stack frame, and number of units in the stack used for indirect variable access. The items in the code segment structure are shown below:

[0105]

[0106]

[0107] Here, section_id is 0x0A; size represents the number of bytes in the code_section structure, excluding section_id and size; CodeInfo lists all function information defined in the module; headconfig_paraNum's highest bit, headconfig, defaults to 1, and the lower 7 bits, paraNum, represent the number of parameters; localNum represents the number of local variables; max_cell_stack represents the maximum number of stack frame units for a function, with one unit being 4 bytes; stackBlockNum represents the number of stack units used by the function for indirect access to variables, with one unit being 16 bytes; ByteCode lists the bytecode of all functions defined within the module.

[0108] The data segment includes at least one of the following: data segment ID, number of bytes in the data segment, module read-only data space size, module global data space size with initial value, reserved field length, module read-only data, non-zero initial value of module global data, and reserved field. The items in the data segment structure are shown below:

[0109] data_section{

[0110] u8 section_id

[0111] u32 size

[0112] u16 rodata_size

[0113] u16 rwdata_init_size

[0114] u16 RFU_size

[0115] u8 rodata[rodata_size]

[0116] u8 rwdata[rwdata_init_size]

[0117] u8 RFU[RFU_size]

[0118] }

[0119] Wherein, section_id is 0x0B; size represents the number of bytes in the data_section structure, excluding section_id and size; rodadata_size represents the size of the module's read-only data space; rwdata_init_size represents the size of the module's global data space with initial values; RFU_size represents the length of reserved fields; roda lists the module's read-only data; rwdata lists the module's global data initial values, which are not 0; and RFU represents reserved fields.

[0120] In one embodiment of this example, converting the binary intermediate file into a binary loadable file includes: deleting the type segment in the binary intermediate file; deleting the type information of the function segment in the binary intermediate file and generating the function code size; generating the function index corresponding to the function segment in the binary intermediate file, replacing the function information in the exported segment with the function index, and updating the size of the exported segment.

[0121] In a specific embodiment, based on the type index information of the function segment and exported segment in the binary intermediate file, the function type can be obtained from the type segment, the correctness of the function types in the type segment can be checked, and then the type segment can be deleted. An index `function_idx` can be generated for all functions in the function segment of the file. The starting encoding of the index is the number of functions in the exported segment, the index length is 2 bytes, and the index increments sequentially from the starting encoding, establishing a mapping relationship between function names and function indices. The type information in the function segment of the binary intermediate file is deleted and replaced with the size `code_size` of each function's code, outputting the function segment `function_section` of the binary loadable file. After converting the code segment, the size of each function in the final output executable file is obtained, and the size `code_size` of each function in the function segment is updated accordingly. The information of each function in the exported segment is converted into a function index `function_idx`, and the size of the exported segment is updated. Based on the function names in the exported segment of the binary intermediate file, and through the established mapping relationship between function names and function indices, the index `function_idx` of each function in the exported segment is obtained, and the exported segment of the binary loadable file is generated accordingly.

[0122] In another embodiment of this example, converting the binary intermediate file into a binary loadable file includes: obtaining the corresponding module AID information in the binary linker file based on the import function information of the binary linker file and the binary intermediate file; obtaining the corresponding function index in the binary linker file based on the import function name in the binary intermediate file; generating import module information corresponding to the import segment in the binary loadable file based on the corresponding module AID information in the binary linker file; organizing all import module information to generate an array of import module information for the import segment in the binary loadable file; generating the number of import modules in the import segment in the binary loadable file based on the number of import modules in the binary linker file; and optimizing (e.g., replacing) the function information in the binary intermediate file based on the obtained module index in the binary intermediate file and the function index obtained in the binary linker file to obtain an array of import function information for the import segment in the binary loadable file.

[0123] In one specific embodiment, the conversion device performs import function linking from the binary intermediate file based on the module name and function name: It searches the input binary link file and the binary intermediate file for import function information (module name and function name), and obtains the `mudule_aid` information recorded in the binary link file; based on the function names of the imported functions in the binary intermediate file, it searches the binary link file for matching function names and function indexes (`function_id`); based on the number of modules imported in the import segment, it generates the `import_module_count` data segment of the import segment; based on the AIDs of all imported modules, it sequentially arranges all imported modules, assigns an index to all imported modules, organizes the AID information of all imported modules, and generates `module_aid_size` and `mudule_aid` data in the `import_function_items` item of the import segment; using the assigned module index and the found function index, it replaces the function information in the binary intermediate file, generating `import_module_idx` and `import_function_idx` information in the `import_function_items` item, and finally generates the export segment of the binary loadable file.

[0124] In another embodiment of this example, converting the binary intermediate file into a binary loadable file includes deleting memory segments and / or table segments in the binary intermediate file.

[0125] In another embodiment of this example, converting the binary intermediate file into a binary loadable file includes: deleting variable information in the global segment of the binary intermediate file; generating the module read-only data start address of the global segment in the binary loadable file based on the start address of the global variables in the global segment of the binary intermediate file; generating the global variable end address of the global segment in the binary loadable file based on the end address of the global variables in the global segment of the binary intermediate file; and generating the module global variable start address of the global segment in the binary loadable file based on the read-only data information corresponding to the data segment and the custom segment in the binary intermediate file.

[0126] In one specific embodiment, information about each variable in the global segment, as well as information about the memory and table segments, can be deleted. Based on the global_base value in the global segment of the binary intermediate file, the rodata_base information of the global segment of the binary loadable file can be generated. Based on the data_end value in the global segment of the binary intermediate file, the data_end information of the global segment of the binary loadable file can be generated. Based on the <.rodata> attribute in the data segment and custom segment of the binary intermediate file, the rwata_base information of the global segment of the binary loadable file can be generated.

[0127] In another embodiment of this example, converting the binary intermediate file into a binary loadable file includes: generating module read-only data of the data segment and module global data initial values ​​that are not zero in the binary loadable file based on the read-only data information, global variable information and custom module information of the data segment and custom segment in the binary intermediate file.

[0128] In one specific embodiment, the binary intermediate file data segment and the custom segment containing <.rodata>, <.data>, ... can be used as the basis for the binary intermediate file data segment and the custom segment.<MOD_SGE> The attributes generate the roda, rwdata, and moddata information for the binary loadable file data segment, respectively.

[0129] In another embodiment of this invention, converting the binary intermediate file into a binary loadable file includes: obtaining the table index and table offset information of the element segments in the binary intermediate file; and generating the function index corresponding to the element segments in the binary loadable file based on the table index and table offset information.

[0130] In another embodiment of this example, converting the binary intermediate file into a binary loadable file includes: obtaining the application module AID and the function names of the installation and interface registration functions according to the conversion parameter configuration file; obtaining the corresponding function index and the entry function information of the application module installation and interface registration corresponding to the binary loadable file according to the installation and interface registration function names; outputting the application module AID and the entry function information of the application module installation and interface registration as application module information groups to the application segment of the binary loadable file, and generating the number of registrable application module information groups in the application segment according to the number of application execution modules; wherein, the application segment in the binary loadable file includes one or more application module information groups.

[0131] In another embodiment of this example, converting the binary intermediate file into a binary loadable file includes: determining the number of parameters and the number of local variables in the binary intermediate file based on the number of local variables and the number of parameters in the binary loadable file; simulating the execution of function code in the binary intermediate file, calculating the maximum number of units in the operand stack space during execution, and generating the maximum number of units in the stack frame of the function corresponding to the binary loadable file; generating the number of units in the stack used by the function in the binary loadable file based on the bytecode that allocates the stack space for indirect access variables in the function code of the binary intermediate file; and determining the function code flag bit of the code segment in the binary loadable file based on the number of parameters, the number of local variables, the maximum number of units in the stack frame of the function, and the number of units in the stack used by the function for indirect access variables.

[0132] In another embodiment of this example, converting the binary intermediate file into a binary loadable file includes: generating the first segment of the binary loadable file based on the import segment, function segment, application segment, element segment, data segment, and code segment in the binary loadable file.

[0133] In a specific embodiment, based on the conversion parameter configuration file, the AID of the binary loadable file is obtained, and the module AID length and module AID are generated; the number of imported modules in the import section of the binary loadable file is obtained, and import_module_count is generated; the number of imported functions in the import section is obtained, and import_function_count is generated; the size information of the generated function section is obtained, and the first section segFuncLen is generated; the size of the generated application section is obtained, and the first section segAppLen is generated; the size of the generated element section is obtained, and the first section segElemLen is generated; the size of the generated data section is obtained, and the first section segDataLen is generated; the size of the generated code section is obtained, and the first section segCodeLen is generated.

[0134] In one specific embodiment, converting the binary intermediate file into a binary loadable file includes: generating version information corresponding to the binary loadable file based on version information in the conversion parameter configuration file. Converting the binary intermediate file into a binary loadable file based on the binary linker file includes: verifying whether the version information corresponding to the binary intermediate file and the binary linker file are consistent; if so, converting the binary intermediate file into a binary loadable file based on the binary intermediate file and the binary linker file.

[0135] The process of 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 it is determined that the version information corresponding to the binary intermediate file and the binary link file is consistent.

[0136] Step 230: In response to the download command stream, download the binary loadable file to the resource-constrained device to obtain a binary executable file.

[0137] In this step, specifically, the first segment, import segment, function segment, application segment, global segment, export segment, element segment, code segment, and data segment of the binary loadable file can be downloaded to the resource-constrained device in a preset download order.

[0138] In this embodiment, the first segment is downloaded first. Therefore, import_module_count, import_function_count, segFuncLen, segAppLen, segElemLen, segDataLen, and segCodeLen in the first segment can be used as space information required by other subsequent segments. Storage space is pre-allocated for each segment when the first segment is downloaded.

[0139] In one embodiment of this example, downloading the import segment from a binary loadable file to a resource-constrained device includes: directly storing the import segment code in the corresponding storage space; or, parsing the module AID imported in the import segment; and / or, querying the module AID corresponding to the index of the module containing the imported function in the imported module information array, and parsing the module AID; and / or, after parsing the index of the module containing the imported function in the imported module information array to obtain the imported module identifier, locating the imported module from the module registration information according to the index of the imported function in the imported module, querying the exported segment information corresponding to the imported module, and checking the validity of the index of the imported function in the imported module according to the exported segment information; and / or, obtaining the function address of the imported module, and optimizing the function information of the imported module to the function address.

[0140] In one specific embodiment, when downloading the import segment, the import segment code can be directly stored in the import segment's storage space; alternatively, a preliminary linking can be performed on `mudule_aid`, where the import module's `mudule_aid` information is parsed into a simplified module representation, such as a module identifier. Each module's `mudule_aid` is managed by the operating system, and the module identifier and module AID can be used to uniquely identify each module on the device; alternatively, a preliminary linking can be performed on `import_module_idx`, where the `mudule_aid` corresponding to the index value in the `import_module_items` array is found based on the `import_module_idx` information, and further parsed to obtain the import module identifier. Each import module's `mudule_aid` is managed by the operating system, and the module identifier and module AID can be used to uniquely identify each module on the device; alternatively, a preliminary linking can be performed on `import_function_idx`, where after parsing `import_module_idx` to obtain the import module identifier, the exported segment information of the imported module is found based on the `import_function_idx` information, and the validity of the `import_function_idx` index is checked. If the imported module is a system module, the function address can also be obtained.

[0141] In another embodiment of this example, downloading a function segment from a binary loadable file to a resource-constrained device includes: directly storing the function segment code in the corresponding storage space (e.g., the registry, a specific space for module code); or, according to program execution requirements, storing the target information (necessary code information, such as stack space unit size, indirect access variable stack size) in the function segment in the corresponding storage space.

[0142] In another embodiment of this example, downloading the application segment from the binary loadable file to the resource-constrained device includes: directly storing the application segment code in the corresponding storage space; or, according to the program's running requirements, parsing the entry function information of the application module installation and interface registration to obtain function address information, organizing the application module AID in the application segment, and the function address information, and storing them in the corresponding storage space.

[0143] In another embodiment of this example, downloading the global segment from the binary loadable file to the resource-constrained device includes: directly storing the global segment code into the corresponding storage space; or, storing the target fields in the global segment into the corresponding storage space according to the program's running requirements; or, obtaining the size of the module's read-only data based on the starting address of the module's global variables and the starting address of the module's read-only data in the global segment, and storing the size of the module's read-only data into the corresponding storage space.

[0144] In another embodiment of this example, downloading the exported segment from the binary loadable file to a resource-constrained device includes: directly storing the exported segment code in the corresponding storage space; or, if the exported segment passes the integrity check during the download process, then the exported segment is ignored.

[0145] In another embodiment of this example, downloading an element segment from a binary loadable file to a resource-constrained device includes: directly storing the element segment code into the corresponding storage space.

[0146] In another embodiment of this example, downloading the code segment from the binary loadable file to the resource-constrained device includes: directly storing the code segment code into the corresponding storage space; or, according to the program's execution requirements, storing all function information defined in the module content of the code segment, as well as the bytecode of all functions defined within the module, into the corresponding storage space.

[0147] In another embodiment of this example, downloading a data segment from a binary loadable file to a resource-constrained device includes: directly storing the data segment code into the corresponding storage space; or, based on program execution requirements and the starting address of the module global variables and the starting address of the module read-only data in the global segment, obtaining the module read-only data size, the module read-only data, and the non-zero initial value and size of the module global data into the storage space corresponding to the read-only data in the data segment.

[0148] It should be noted that, in this embodiment, during the entire download process of the binary loadable file, all storage space information is managed by the module registry. Each storage space can be dynamically allocated from the heap, and the information of the allocated space is associated with the registry.

[0149] Step 240: Outside the device, link the binary loadable file, or directly store the binary loadable file and generate a mask data structure based on the processing result; or, convert and link the binary intermediate file and generate a mask data structure based on the processing result; or, compile, convert, and link the source file and generate a mask data structure based on the processing result.

[0150] In this embodiment, the Mask tool can generate a mask file (e.g., a ".c" file) by specifying a standard ".wasm" file as input, or by specifying a standard ".hef" file of the mask module as input and then parsing it, organizing it according to the mask data format specified by the virtual machine, and finally outputting the required mask file; or even more directly, by taking user programming files (e.g., ".c" / ".h" files) as input, and generating a mask file through compilation, conversion, and Masking.

[0151] In this step, optionally, the storage address of the data and the format of the output code can be configured using a masking tool to link the binary loadable file. The linking process of the binary loadable file is consistent with the data conversion method in the binary loadable file download process, that is, when generating the mask data structure, the information such as modules, functions, and global segments in the binary loadable file can be initially linked to generate an optimized data structure.

[0152] The advantage of this setup is that it eliminates the download process. All source files or intermediate files generated from the compilation of all system modules or potential application modules serve as input for the Mask tool. At the same time, the configuration file sets up storage space for the mask data for the Mask tool. The Mask tool generates the binary executable file data based on the physical address provided by this storage space.

[0153] Step 250: Generate a mask file for the binary executable file based on the mask data structure.

[0154] The technical solution provided in this application involves obtaining the binary intermediate files generated after compiling all program source code, as well as the binary link files of the modules imported by the binary intermediate files. Based on the binary link files, the binary intermediate files are converted into binary loadable files. In response to a download command stream, the binary loadable files are downloaded to a resource-constrained device to obtain a binary executable file. The method involves using source files and / or binary intermediate files and mask tool configuration parameters for conversion and linking (optionally compilation), generating a mask data structure based on the linking results, and generating a mask file for the binary executable file based on the mask data structure. Since the binary link files provide external function linking information for the binary intermediate files, compared to the existing technology where standard binary intermediate files require searching for matching module names, function names, or variable names to locate external functions or variables when executed on a device, this application only needs to obtain the external function linking information of the binary intermediate files from the external binary link files. Based on this external function linking information, a smaller binary loadable file than the binary intermediate files is generated. This improves the download and execution efficiency of WebAssembly modules on resource-constrained devices and reduces device resource consumption.

[0155] Figure 3 This is a schematic diagram of a binary loadable file download device provided in an embodiment of this application. The device is applied in an electronic device, such as... Figure 3 As shown, the device includes: an input file acquisition module 310, a file generation module 320, and a file download module 330.

[0156] The input file acquisition module 310 is used to acquire the binary intermediate file generated after the program source code is compiled, and the binary link file of the module imported by the binary intermediate file;

[0157] The file generation module 320 is used to convert the binary intermediate file into a binary loadable file based on the binary link file;

[0158] The file download module 330 is used to respond to the download command stream and download the binary loadable file to a resource-constrained device to obtain a binary executable file;

[0159] The binary loadable file includes: a header segment, a function segment, a global segment, and a code segment.

[0160] The technical solution provided in this application involves obtaining a binary intermediate file generated after compiling the program source code, and the binary link file of the module imported by the binary intermediate file. Based on the binary link file, the binary intermediate file is converted into a binary loadable file, and in response to a download command stream, the binary loadable file is downloaded to a resource-constrained device. Since the binary link file is used to provide external function linking information for the binary intermediate file, compared to 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 linking 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 linking information. This can improve the download and execution efficiency of WebAssembly modules on resource-constrained devices and reduce device resource consumption.

[0161] Based on the above embodiments, the binary loadable file further includes at least one of the following: import segment, application segment, export segment, element segment, data segment, and custom segment;

[0162] The custom segment includes at least one of the following: custom segment ID, custom data, and the number of bytes of the custom data;

[0163] The first segment includes at least one of the following: first segment ID, first segment length, module information, length of binary loadable file, configuration fields, number of imported modules, number of imported functions, function segment space size, application segment space size, element segment space size, data segment space size, and code segment space size;

[0164] The module information includes at least one of the following: module version information, module identifier (AID), and module AID length;

[0165] The import segment includes at least one of the following: import segment ID, number of bytes in the import segment, number of imported modules, number of imported functions, array of imported module information, and array of imported function information;

[0166] The imported module information array includes at least one of the following: the imported module version, the imported module AID, and the length of the imported module AID;

[0167] The imported function information array includes at least one of the following: the index of the module containing the imported function in the imported module information array, and the index of the imported function in the importing module;

[0168] The function segment includes at least one of the following: function segment ID, number of bytes in the function segment, and number of bytes of code corresponding to a function;

[0169] The application segment includes at least one of the following: application segment ID, number of bytes in the application segment, number of registrable application module information groups, and application module information groups;

[0170] The application module information group includes at least one of the following: application module AID, the length of the application module AID content in this group of information, and the entry function information for application module installation and interface registration;

[0171] The global segment includes at least one of the following: global segment ID, number of bytes in the global segment, starting address of module read-only data, starting address of module global variables, reserved field, and ending address of global variables;

[0172] The exported segment includes at least one of the following: exported segment ID, number of bytes in the exported segment, and function index corresponding to each exported function;

[0173] The element segment includes at least one of the following: element segment ID, number of bytes in the element segment, and function index of the function pointer calling the function;

[0174] The code segment includes at least one of the following: code segment ID, number of bytes in the code segment, information on all functions defined in the module content, and bytecode of all functions defined in the module;

[0175] All function information defined in the module content includes at least one of the following: function code flags, number of parameters, number of local variables, number of units in the function's maximum stack frame, and number of units in the stack for indirect access variables used by the function.

[0176] The data segment includes at least one of the following: data segment ID, number of bytes in the data segment, module read-only data space size, module global data space size with initial value, reserved field length, module read-only data, non-zero initial value of module global data, and reserved field.

[0177] The file generation module 320 includes:

[0178] The deletion unit is used to delete the type segment in the binary intermediate file; and to delete the memory segment and / or table segment in the binary intermediate file.

[0179] The function segment processing unit is used to remove the type information of function segments in the binary intermediate file and generate the function code size.

[0180] The exported segment processing unit is used to generate function indices corresponding to function segments in the binary intermediate file, replace the function information in the exported segment with the function indices, and update the size of the exported segment;

[0181] The import segment processing unit is used to: obtain the corresponding module AID information in the binary linker file based on the import function information in the binary linker file and the binary intermediate file; obtain the corresponding function index in the binary linker file based on the import function name in the binary intermediate file; generate the import module information corresponding to the import segment in the binary loadable file based on the corresponding module AID information in the binary linker file; organize all import module information to generate an array of import module information for the import segment in the binary loadable file; generate the number of import modules in the import segment of the binary loadable file based on the number of import modules in the binary linker file; and replace the function information in the binary intermediate file based on the module index in the binary intermediate file and the function index obtained in the binary linker file to obtain an array of import function information for the import segment in the binary loadable file.

[0182] The global segment processing unit is used to delete variable information in the global segment of the binary intermediate file, generate the module read-only data start address of the global segment in the binary loadable file based on the start address of the global variables in the global segment of the binary intermediate file; generate the global variable end address of the global segment in the binary loadable file based on the end address of the global variables in the global segment of the binary intermediate file; and generate the module global variable start address of the global segment in the binary loadable file based on the read-only data information corresponding to the data segment and the custom segment in the binary intermediate file.

[0183] The data segment processing unit is used to generate, based on the read-only data information, global variable information, and custom module information of the data segment and custom segment in the binary intermediate file, the module read-only data of the data segment in the binary loadable file, and the initial value of the module global data that is not zero.

[0184] The element segment processing unit is used to obtain the table index and table offset information of the element segment in the binary intermediate file; and generate the function index corresponding to the element segment in the binary loadable file based on the table index and table offset information.

[0185] The application segment processing unit is used to obtain the application module AID and the function name of the installation and registration interface function according to the conversion parameter configuration file; obtain the corresponding function index and the entry function information of the application module installation and interface registration corresponding to the binary loadable file according to the installation and registration interface function name; output the application module AID and the entry function information of the application module installation and interface registration as an application module information group to the application segment of the binary loadable file, and generate the number of registrable application module information groups in the application segment according to the number of application execution modules; wherein, the application segment in the binary loadable file includes one or more application module information groups;

[0186] The code segment processing unit is used to determine the number of parameters and local variables corresponding to the binary loadable file based on the number of local variables and parameters in the binary intermediate file; simulate the execution of function code in the binary intermediate file, calculate the maximum number of units in the operand stack space during execution, and generate the maximum number of units in the stack frame of the function corresponding to the binary loadable file; generate the number of units in the stack used by the function in the binary loadable file for indirect access variables based on the bytecode that allocates the stack space for indirect access variables in the function code of the binary intermediate file; and determine the function code flag bit of the code segment in the binary loadable file based on the number of parameters, the number of local variables, the maximum number of units in the stack frame of the function, and the number of units in the stack used by the function for indirect access variables.

[0187] The version information generation unit is used to generate version information corresponding to the binary loadable file based on the version information in the conversion parameter configuration file.

[0188] 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 intermediate file and the binary link file.

[0189] 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.

[0190] The first segment processing unit is used to generate the first segment of the binary loadable file based on the import segment, function segment, application segment, element segment, data segment, and code segment in the binary loadable file.

[0191] The device further includes: a mask file generation module;

[0192] The mask file generation module is used to link the binary loadable file using a binary linker, generate a mask data structure based on the linking result, and generate a mask file for the binary loadable file based on the mask data structure.

[0193] The file download module 330 includes:

[0194] The sequential download unit is used to download the first segment, import segment, function segment, application segment, global segment, export segment, element segment, code segment, and data segment of the binary loadable file to the resource-constrained device in a preset download order.

[0195] The import segment download unit is used to directly store the import segment code into the corresponding storage space; or, parse the module AID imported in the import segment; and / or, based on the index of the module containing the imported function in the imported module information array, query the module AID corresponding to the index in the imported module information array, and parse the module AID; and / or, after parsing the index of the module containing the imported function in the imported module information array to obtain the imported module identifier, locate the imported module from the module registration information based on the index of the imported function in the imported module, query the exported segment information corresponding to the imported module, and check the validity of the index of the imported function in the imported module based on the exported segment information; and / or, obtain the function address of the imported module and optimize the function information of the imported module to the function address.

[0196] The function segment download unit is used to directly store the function segment code into the corresponding storage space; or, according to the program's execution requirements, to store the target information in the function segment into the corresponding storage space.

[0197] The application segment download unit is used to directly store the application segment code into the corresponding storage space; or, according to the program's running requirements, it parses the entry function information of the application module installation and interface registration to obtain the function address information, organizes the application module AID in the application segment, and the function address information, and stores them into the corresponding storage space.

[0198] The global segment download unit is used to directly store the global segment code into the corresponding storage space; or, according to the program's running requirements, to store the target fields in the global segment into the corresponding storage space; or, according to the starting address of the module's global variables and the starting address of the module's read-only data in the global segment, to obtain the size of the module's read-only data and store the size of the module's read-only data into the corresponding storage space.

[0199] The exported segment download unit is used to directly store the exported segment code into the corresponding storage space; or, if the exported segment passes the integrity check during the download process, the exported segment is ignored.

[0200] The element segment download unit is used to directly store the element segment code into the corresponding storage space;

[0201] The code segment download unit is used to directly store the code segment code into the corresponding storage space; or, according to the program's running requirements, to store all function information defined in the module content of the code segment, as well as the bytecode of all functions defined in the module, into the corresponding storage space.

[0202] The data segment download unit is used to directly store the data segment code into the corresponding storage space; or, according to the program's running requirements, as well as the starting address of the module's global variables and the starting address of the module's read-only data in the global segment, it obtains the size of the module's read-only data, the module's read-only data, and the initial value and size of the module's global data that are not zero, and stores them into the storage space corresponding to the read-only data in the data segment.

[0203] The module registration management unit is used to manage information about all downloaded library modules and application modules.

[0204] The above-described 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 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.

[0205] Figure 4 A schematic diagram of the structure of an electronic device 10 that can be used to implement embodiments of this 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 this application described and / or claimed herein.

[0206] like Figure 4As 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.

[0207] 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.

[0208] 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 binary loadable file download methods.

[0209] In some embodiments, the binary loadable file download 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 loadable file download method described above may be performed. Alternatively, in other embodiments, processor 11 may be configured to perform the binary loadable file download method by any other suitable means (e.g., by means of firmware).

[0210] 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.

[0211] 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.

[0212] 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.

[0213] 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).

[0214] 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.

[0215] 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.

[0216] 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.

[0217] 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 binary loadable file downloading method characterized by, The method comprises the following steps: obtaining a binary intermediate file generated after compiling a program source code and a binary link file of a module imported by the binary intermediate file; converting the binary intermediate file into a binary loadable file according to the binary link file; downloading the binary loadable file to a resource-limited device to obtain a binary execution file in response to a download command stream; wherein the binary loadable file comprises a header segment, a function segment, a global segment and a code segment.

2. The method of claim 1, wherein, The binary loadable file further comprises at least one of the following: an import segment, an application segment, an export segment, an element segment, a data segment and a custom segment.

3. The method of claim 2, wherein, The downloading of the binary loadable file to the resource-limited device comprises: sequentially downloading the header segment, the import segment, the function segment, the application segment, the global segment, the export segment, the element segment, the code segment and the data segment in the binary loadable file to the resource-limited device in a preset downloading order.

4. The method of claim 3, wherein, The downloading of the import segment in the binary loadable file to the resource-limited device comprises: directly storing the import segment code into a corresponding storage space; or analyzing the module AID imported in the import segment; and / or querying the module AID corresponding to the index in the imported module information array according to the index of the module in which the imported function is located in the imported module information array, and analyzing the module AID; and / or analyzing the index of the module in which the imported function is located in the imported module information array to obtain the imported module identifier, positioning the imported module from the module registration information according to the index of the imported function in the imported module, querying the export segment information corresponding to the imported module, and checking the legality of the index of the imported function in the imported module according to the export segment information; and / or obtaining the function address of the imported module and optimizing the function information of the imported module into the function address.

5. The method of claim 3, wherein, The downloading of the function segment in the binary loadable file to the resource-limited device comprises: directly storing the function segment code into a corresponding storage space; or storing the target information in the function segment into a corresponding storage space according to the program running requirement.

6. The method of claim 3, wherein, The downloading of the application segment in the binary loadable file to the resource-limited device comprises: directly storing the application segment code into a corresponding storage space; or analyzing the entry function information of the application module installation and interface registration to obtain the function address information, organizing the application module AID in the application segment and the function address information, and storing them into a corresponding storage space according to the program running requirement.

7. The method of claim 3, wherein, The downloading of the global segment in the binary loadable file to the resource-limited device comprises: directly storing the global segment code into a corresponding storage space; or storing the target field in the global segment into a corresponding storage space according to the program running requirement; or obtaining the size of the module read-only data according to the module global variable start address and the module read-only data start address in the global segment, and storing the size of the module read-only data into a corresponding storage space.

8. The method of claim 3, wherein, The downloading of the export segment in the binary loadable file to the resource-limited device comprises: directly storing the export segment code into a corresponding storage space; or If the export segment passes the integrity check during the downloading process, the export segment is ignored.

9. The method of claim 3, wherein, Downloading an element segment in a binary loadable file to a resource-limited device, comprising: Storing the element segment code directly into the corresponding storage space.

10. The method of claim 3, wherein, Downloading a code segment in a binary loadable file to a resource-limited device, comprising: Storing the code segment code directly into the corresponding storage space; or According to the program running requirements, storing all function information defined by the module content in the code segment and the byte code of all functions defined in the module into the corresponding storage space.

11. The method of claim 3, wherein, Downloading a data segment in a binary loadable file to a resource-limited device, comprising: Storing the data segment code directly into the corresponding storage space; or According to the program running requirements and the module global variable start address and the module read-only data start address in the global segment, obtaining the module read-only data size, and storing the module read-only data size, the module read-only data, and the module global data initial value and size that is not 0 into the storage space corresponding to the read-only data in the data segment.

12. The method of claim 1, wherein, The method further comprises: Linking the binary loadable file outside the device, or directly storing the binary loadable file, and generating a mask data structure according to the processing result; or Converting and linking the binary intermediate file, and generating a mask data structure according to the processing result; or Compiling, converting, and linking the source file, and generating a mask data structure according to the processing result; According to the mask data structure, generating a mask file of the binary executable file.

13. The method according to any one of claims 1 to 12, characterized in that, The method further comprises: During the downloading process of the binary loadable file, managing the information of all downloaded library modules and application modules.

14. The method of claim 2, wherein The custom segment includes at least one of the following: a custom segment ID, custom data, and a byte number of the custom data.

15. The method of claim 1, wherein The first segment includes at least one of the following: a first segment ID, a first segment length, module information, a binary loadable file length, a configuration field, a number of imported modules, a number of imported functions, a function segment space size, an application segment space size, an element segment space size, a data segment space size, and a code segment space size.

16. The method of claim 15, wherein The module information includes at least one of the following: module version information, a module identification AID, and a module AID length.

17. The method of claim 2, wherein The import segment includes at least one of the following: an import segment ID, a byte number in the import segment, a number of imported modules, a number of imported functions, an imported module information array, and an imported function information array.

18. The method of claim 17, wherein The imported module information array includes at least one of the following: an imported module version, an imported module AID, and an imported module AID length. The imported function information array includes at least one of the following: an index of a module where the imported function is located in the imported module information array, and an index of the imported function in the imported module.

19. The method of claim 1, wherein, The function section includes at least one of the following: a function section ID, a number of bytes in the function section, and a number of code bytes corresponding to a function.

20. The method of claim 2, wherein, The application section includes at least one of the following: an application section ID, a number of bytes in the application section, a number of application module information groups, and an application module information group.

21. The method of claim 20, wherein, The application module information group includes at least one of the following: an application module AID, a length of the application module AID content in the group, and entry function information of the application module installation and interface registration.

22. The method of claim 1, wherein, The global section includes at least one of the following: a global section ID, a number of bytes in the global section, a start address of module read-only data, a start address of module global variables, a reserved field, and an end address of global variables.

23. The method of claim 2, wherein, The export section includes at least one of the following: an export section ID, a number of bytes in the export section, and a function index corresponding to each export function.

24. The method of claim 2, wherein, The element section includes at least one of the following: an element section ID, a number of bytes in the element section, and a function index of a function pointer calling function.

25. The method of claim 1, wherein, The code section includes at least one of the following: a code section ID, a number of bytes in the code section, all function information defined by module content, and byte code of all functions defined in the module.

26. The method of claim 25, wherein, The all function information defined by module content includes at least one of the following: a function code flag bit, a number of parameters, a number of local variables, a number of units of the maximum stack frame of the function, and a number of units of the function using indirect access variable stack.

27. The method of claim 2, wherein, The data section includes at least one of the following: a data section ID, a number of bytes in the data section, a size of module read-only data space, a size of module global data space with initial values, a reserved field length, module read-only data, non-zero module global data initial values, and a reserved field.

28. A binary loadable file download apparatus characterized by comprising: The apparatus includes: An input file acquisition module configured to acquire a binary intermediate file generated after a program source code is compiled, and a binary link file of an imported module of the binary intermediate file; A file generation module configured to convert the binary intermediate file into a binary loadable file according to the binary link file; A file download module configured to download the binary loadable file to a resource-restricted device to obtain a binary execution file in response to a download command stream. The binary loadable file includes a first section, a function section, a global section, and a code section.

29. An electronic device, comprising: The electronic device includes: 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 to enable the at least one processor to perform the method of any one of claims 1-27.

30. A computer-readable storage medium, comprising: The computer readable storage medium stores computer instructions for causing a processor to implement the method of any one of claims 1-27 when executed.