Program compilation and startup method, device and storage medium
By using the separation mode to compile the program to be compiled in the IoT device, the identification of its dependent components is written into the dynamic information segment of the image file, and the separate compilation of the program and components is achieved. This solves the problems of long compilation time and low OTA upgrade efficiency of IoT devices, and improves the compilation efficiency and upgrade efficiency.
Patent Information
- Application Number
- CN202210483490.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-05
- Publication Date
- 2025-09-26
- Estimated Expiration
- 2042-05-05
AI Technical Summary
The long compilation time of IoT device software packages leads to low development efficiency, large OTA upgrade traffic, and long upgrade time, which affects upgrade efficiency.
The program to be compiled is compiled in separation mode, and the identifiers of the separated components it depends on are written into the dynamic information segment of the image file to obtain an independent image file. This realizes the separation of the program to be compiled and its dependent components, reduces the amount of compiled data, and supports finer-grained upgrades.
It improves program compilation efficiency, reduces the amount of compiled data, supports finer-grained upgrades, reduces the amount of data transmitted during OTA upgrades, and improves upgrade efficiency.
Smart Images

Figure CN114840214B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of Internet of Things technology, and in particular to a program compilation and startup method, device, and storage medium. Background Art
[0002] With the continuous development of Internet of Things (IoT) technology, the functions of IoT devices are increasing. This makes IoT application systems more and more complex and relies on more and more components. As a result, IoT software packages are also getting larger and larger, which in turn leads to long compilation times for IoT software packages. Summary of the Invention
[0003] Various aspects of the present application provide a program compilation and startup method, device, and storage medium to improve program compilation efficiency.
[0004] The present invention provides a method for compiling a program, including:
[0005] Get the configuration file of the program to be compiled;
[0006] Obtaining compilation mode information of the program to be compiled from a configuration file of the program to be compiled;
[0007] When the compilation mode information of the program to be compiled is a separate mode, compiling the program to be compiled;
[0008] During the compilation process of the program to be compiled, the identifier of the separate component on which the program to be compiled depends is written into the dynamic information segment of the image file to obtain the image file of the program to be compiled; wherein the separate component has an independent image file.
[0009] The present application also provides a method for starting a program, including:
[0010] Get the image file of the program to be started into the memory;
[0011] Parsing the image file of the program to be started to obtain information segments contained in the image file of the program to be started; the information segments include dynamic information segments;
[0012] Determining, from the dynamic information segment, the separation component on which the program to be started depends;
[0013] Obtaining the image file of the separated component into the memory;
[0014] The program to be started is started according to the image file of the program to be started and the image file of the separated component.
[0015] An embodiment of the present application further provides a computing device, comprising: a memory and a processor; wherein the memory is used to store a computer program;
[0016] The processor is coupled to the memory and is configured to execute the computer program to perform the steps in the above-mentioned program compiling method and / or program starting method.
[0017] An embodiment of the present application also provides a computer-readable storage medium storing computer instructions. When the computer instructions are executed by one or more processors, the one or more processors are caused to execute the steps in the above-mentioned program compilation method and / or program startup method.
[0018] In an embodiment of the present application, for a program to be compiled in separate mode, during the compilation process, the identifier of the separate component on which the program to be compiled depends can be written into the dynamic information segment of the image file, thereby obtaining the image file of the program to be compiled. The separate component on which the program to be compiled depends has an independent image file. This allows the program to be compiled and the separate component on which it depends to be compiled to be compiled separately, resulting in an independent image file, thus separating the program to be compiled from the separate component on which it depends. In particular, when compiling the program to be compiled, the identifier of the separate component on which the program to be compiled depends is written into the dynamic information segment of the image file, eliminating the need to compile the separate component during the compilation process. This reduces the amount of data required for the compilation of the program to be compiled and helps improve compilation efficiency. When the program to be compiled is subsequently upgraded, the program to be compiled and the components it depends on can be upgraded separately, without upgrading the entire file package, achieving a more granular upgrade. For example, if the upgrade target is a separate component on which the program to be compiled depends, the separate component can be upgraded separately; if the upgrade target is another module of the program to be compiled, the other module can be upgraded separately without upgrading the separate component, thus achieving a more granular upgrade. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0020] Figure 1 A structural framework diagram of the embedded operating system provided in an embodiment of the present application;
[0021] Figure 2 A flowchart of a program compilation method provided in an embodiment of the present application;
[0022] Figure 3 A schematic diagram of the dependency relationship between applications and components provided in an embodiment of the present application;
[0023] Figure 4 A flowchart of a program startup method provided in an embodiment of the present application;
[0024] Figure 5 A functional diagram of the dynamic engine provided in an embodiment of the present application;
[0025] Figure 6 A schematic diagram of the structure of a computing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0026] To make the purpose, technical solutions, and advantages of this application more clear, the technical solutions of this application will be clearly and completely described below in conjunction with the specific embodiments of this application and the corresponding drawings. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0027] Embedded operating system is designed for the specific hardware system and user requirements of embedded system. It is an important component of embedded system and the key to realize the functions of embedded system. Figure 1 As shown in Figure 1, an embedded operating system can be divided into the kernel, components, and application layers. The kernel is responsible for managing the embedded system's processes, memory, device drivers, files, and network systems. It is also the software that provides applications (APPs) with secure access to computer hardware. This access is limited, and the kernel determines when and how long an application can operate on a piece of hardware.
[0028] A component is a basic framework that provides applications with various functions. Applications can select the components they need to implement their functions. In this embodiment, the components provided by the embedded operating system include, but are not limited to, storage components, audio components, network components, communication components, and OTA upgrade components. Optionally, applications can configure the components using YAML.
[0029] With the continuous development of IoT technology, IoT devices are becoming increasingly versatile, making IoT application systems increasingly complex and relying on a growing number of components. This has led to larger IoT software packages, which in turn increases compilation and program burning times, impacting program development efficiency. Furthermore, OTA upgrades for IoT devices require significant bandwidth and increase upgrade times, impacting OTA upgrade efficiency.
[0030] In response to the above technical problems, an embodiment of the present application provides a solution. The basic idea is: for a program to be compiled in a separate mode, during the compilation process of the program to be compiled, the identifier of the separate component that the program to be compiled depends on can be written into the dynamic information segment of the image file, thereby obtaining the image file of the program to be compiled. The separate component that the program to be compiled depends on has an independent image file. In this way, the program to be compiled and the separate component it depends on can be compiled separately to obtain an independent image file, thereby realizing the separation of the program to be compiled and the separate component it depends on. In particular, when the program to be compiled is compiled, the identifier of the separate component that the program to be compiled depends on is written into the dynamic information segment of the image file, without the need to compile the separate component during the compilation process of the program to be compiled. This can reduce the amount of data compiled by the program to be compiled and help improve the compilation efficiency of the program to be compiled. When the program to be compiled is subsequently upgraded, the program to be compiled and the components it depends on can be upgraded separately without upgrading the entire file package, thereby achieving a more fine-grained upgrade. For example, if the object to be upgraded is a separate component that the program to be compiled depends on, the separate component can be upgraded separately; if the object to be upgraded is other modules of the program to be compiled, the other modules can be upgraded separately without upgrading the separate component, thus achieving a finer-grained upgrade.
[0031] The following describes in detail the technical solutions provided by various embodiments of the present application in conjunction with the accompanying drawings.
[0032] It should be noted that the same reference numerals denote the same objects in the following drawings and embodiments, and therefore, once an object is defined in one drawing or embodiment, it does not need to be further discussed in the subsequent drawings and embodiments.
[0033] Figure 2 Schematic diagram of the process of program compilation provided in the embodiment of the present application. Figure 2 As shown, the program compilation method mainly includes:
[0034] 201. Obtain a configuration file of the program to be compiled.
[0035] 202. Obtain compilation mode information of the program to be compiled from a configuration file of the program to be compiled.
[0036] 203. When the compilation mode information of the program to be compiled is the separation mode, compile the program to be compiled.
[0037] 204 During the compilation process of the program to be compiled, the identifier of the separate component that the program to be compiled depends on is written into the dynamic information segment of the image file to obtain the image file of the program to be compiled; wherein the separate component has an independent image file.
[0038] In this embodiment, the program to be compiled can be an application to be compiled or a component program to be compiled. For an embedded operating system, the program to be compiled can be an embedded application or a component of the embedded operating system. In this embodiment, a configuration file for the program to be compiled can be provided. The configuration file can be a YAML file. The configuration file is used to store configuration information for the program to be compiled. In this embodiment, compilation mode information for the program to be compiled can be configured in the configuration file.
[0039] In this embodiment, the compilation mode information of the program to be compiled is mainly used to reflect whether the program to be compiled is in separate mode or integrated mode. Separate mode means that the program to be compiled can be compiled separately or independently from its dependent components to obtain an independent image file. Integrated mode means that the program to be compiled and its dependent components are integrated and compiled to obtain an integrated image file.
[0040] In some embodiments, the program to be compiled is an application to be compiled. Accordingly, for a separate mode application, the compilation mode information of the application can be set to separate mode in the configuration file of the application. For example, the compilation mode information of the application can be set to "separate app: 1" in the configuration file of the application, that is, the compilation mode information item "separate app" can be added to the application. For a separate mode application, the "separate app" can be set to 1, that is, the compilation mode information of the application can be set to separate mode.
[0041] For a component, you can add its compilation mode information. For example, you can add a type item to the component's configuration file. Type is used to indicate the component's compilation mode information. For example, you can set type to "dynamic," which means the architecture component's compilation mode information is set to separate mode. This component is then a separate component. Alternatively, you can set type to "static," which means the architecture component's compilation mode information is set to integrated mode. This component is then an integrated component.
[0042] In the embodiments of this application, Figure 3As shown, an application in separate mode can rely on separate components or integrated components, that is, an application in separate mode can call functions in separate components or integrated components. For components in separate mode, it can rely on separate components or integrated components, that is, separate components can call functions of other separate components and integrated components. Therefore, in this embodiment, in addition to setting the configuration file of the program to be compiled, the configuration file of the component that the program to be compiled depends on can also be set. For the configuration file of the component that the program to be compiled depends on, the compilation mode information of the component can be added, and whether the component is a separate component can be specified by configuring the compilation mode information of the component. For the setting method of the compilation mode information of the component, please refer to the above-mentioned related content, which will not be repeated here.
[0043] After obtaining the configuration files of the program to be compiled and the configuration files of the components on which the program to be compiled depends, the program to be compiled can be compiled based on the configuration files of the program to be compiled and the configuration files of the components on which the program to be compiled depends. Specifically, in step 201, the configuration file of the program to be compiled can be obtained. The program to be compiled can be an application program to be compiled or a component program to be compiled.
[0044] Furthermore, in step 202, the compilation mode information of the program to be compiled can be obtained from the configuration file of the program to be compiled. This compilation mode information is used to indicate whether the program to be compiled is in separate mode or integrated mode. For example, for the above-mentioned application, if the "separate app" item in the application configuration file is 1, the application is determined to be in separate mode. For another example, for a component, if the "type" item in the component configuration file is "dynamic", the component is determined to be in separate mode, etc.
[0045] Furthermore, in the case where the compilation mode information of the program to be compiled is a separate mode, in step 203, the program to be compiled can be compiled separately. Since the component that the program to be compiled depends on may be a separate component or an integrated component. In the case where the component that the program to be compiled depends on has a separate component, in step 204, during the compilation process of the program to be compiled, the identifier of the separate component that the program to be compiled depends on can be written into the dynamic information segment of the image file, thereby obtaining the image file of the program to be compiled. The separate component that the program to be compiled depends on has an independent image file. Among them, the dynamic information segment of the image file can be a DT-NEEDED segment, and the identifier (such as the name, etc.) of the separate component that the program to be compiled depends on can be written into this segment.
[0046] The image file of the separate component that the program to be compiled depends on can be independently compiled in real time during the compilation process of the program to be compiled, or it can be an image file pre-compiled from the separate component. The image file of any separate component and the image file of the program to be compiled are two independent image files. This allows the program to be compiled and the separate component it depends on to be compiled to separately compile, resulting in independent image files. In particular, when compiling the program to be compiled, the identifier of the separate component that the program to be compiled depends on is written into the dynamic information segment of the image file, eliminating the need to compile the separate component during the compilation process. This reduces the amount of data required to compile the program to be compiled and helps improve compilation efficiency. When the program to be compiled is subsequently upgraded, the program to be compiled and the components it depends on can be upgraded separately without upgrading the entire file package, enabling more granular upgrades. For example, if the upgrade target is a separate component that the program to be compiled depends on, the separate component can be upgraded separately; if the upgrade target is another module of the program to be compiled, the other module can be upgraded separately without upgrading the separate component, thus achieving a more granular upgrade.
[0047] Optionally, during the compilation process of the program to be compiled, for the target component that the program to be compiled depends on, the compilation mode information of the target component can be obtained from the configuration file of the target component; if the compilation mode information of the target component is a separation mode, the target component is determined to be a separation component.
[0048] During the compilation process of a program to be compiled, when a target component that the program to be compiled depends on is compiled, a configuration file of the target component can be obtained; and from the configuration file of the target component, compilation mode information of the target component can be obtained; if the compilation mode information of the target component indicates separation mode, the target component is determined to be a separation component. Furthermore, the separation component can be compiled separately to obtain an image file of the separation component. Furthermore, after the separation component is compiled, the program to be compiled can continue to be compiled until the compilation of the program to be compiled is completed, thereby obtaining an image file of the program to be compiled.
[0049] In the embodiment of the present application, the image file of the program to be compiled and the image file of the separated component are relocatable files. Accordingly, step 203 can be implemented as follows: compiling the program to be compiled into assembly language; further, translating the assembly language into target machine language; and writing each segment included in the target machine language into the corresponding segment position of the relocatable file; thereafter, writing the name, relative address and size of each segment included in the target machine language into the segment header of the relocatable file, thereby obtaining the relocatable file of the program to be compiled.
[0050] In other embodiments, the image file of the program to be compiled and the image file of the separated component are executable files. Accordingly, step 203 can be implemented as follows: compiling the program to be compiled into a relocatable file. For details on compiling the program to be compiled into a relocatable file, please refer to the relevant content of the above embodiments and will not be repeated here. Furthermore, the relocatable file can be linked to obtain the information segment of the executable file. Furthermore, the information segment of the executable file can be relocated from relative addresses to absolute addresses to obtain the executable file of the program to be compiled. The information segment of the executable file includes, but is not limited to, a code segment, a data segment, a debug segment, and a symtab segment. The code segment is used to store instructions for the executable file; the data segment stores initialized global and static variables; the symtab segment stores function and local variable information; the debug segment is used to store debugging symbol tables, etc. The data segment may include a BSS segment. The BSS segment stores uninitialized global and static variables that are initialized to 0, etc. Of course, the information segment of the executable file may also include the aforementioned dynamic information segment, etc.
[0051] In an embodiment of the present application, for each information segment of an executable file, some information segments are valid and some are invalid. In this embodiment, a valid segment refers to an information segment that is effective for the execution or startup of the program to be compiled, and correspondingly, an invalid segment refers to an information segment that is ineffective for the execution or startup of the program to be compiled. For example, the debug segment stores a debugging symbol table that is effective during the debugging phase of the program to be compiled. Therefore, in an embodiment of the present application, when relocating the relative addresses of each information segment of the program to be compiled to absolute addresses, invalid and valid segments in the relocatable file can be identified based on a set invalid segment identifier; then, based on the relative address distribution of the invalid and valid segments in the relocatable file, the valid segments can be relocated from relative addresses to absolute addresses so that the absolute addresses of the valid segments are continuous. That is, based on the relative address distribution of the valid segments in the relocatable file, valid segments with continuous or adjacent relative addresses can be relocated to continuous absolute addresses, and the relative addresses of the invalid segments can be positioned after the absolute addresses of all valid segments. In this way, when deleting invalid segments, no memory address gaps will be caused. Furthermore, the invalid segments in the relocatable file can be deleted to obtain the executable file of the program to be compiled, which helps to reduce the size of the executable file of the program to be compiled. In this way, when the program to be compiled is subsequently burned or started, the memory usage of the executable file can be reduced.
[0052] Specifically, an invalid segment identifier, such as the name of the invalid segment, can be set in the linker script. Thus, when linking a relocatable file, the linker script can identify invalid and valid segments in the relocatable file based on the set invalid segment identifier. Regarding the implementation method for relocating invalid and valid segments in a relocatable file, please refer to the relevant content above and will not be repeated here.
[0053] In the actual development process, to improve development efficiency and reduce development costs, some ready-made dependencies may be used when developing a compiled program. Since these dependencies are not specifically developed for the compiled program, they may contain functions and modules that the compiled program does not need. This may result in the compiled program containing some functions that are not actually used or having multiple external interfaces, and not all interfaces require all modules and functions.
[0054] In the process of compiling a program to be compiled into a relocatable file, the program to be compiled is compiled with sections as compilation units. In an embodiment of the present application, in order to reduce the size of the executable file of the program to be compiled, when the program to be compiled is compiled, functions and data can be created into independent sections. Specifically, ffunction-sections and fdata-sections can be used to compile the program to be compiled with functions and data as compilation units, respectively, to obtain a relocatable file; further, when the relocatable file is linked, gc-section can be used to link the relocatable file with functions and data as link units to delete useless functions and useless data in the relocatable file to obtain an information segment of the executable file. Further, the information segment of the executable file can be relocated from a relative address to an absolute address to obtain the executable file of the program to be compiled. Since useless functions and useless data in the relocatable file are deleted when the relocatable file is linked, the size of the executable file can be reduced, and then when the executable file of the program to be compiled is subsequently burned or the memory usage of the executable file can be reduced.
[0055] The compilation process of the program to be compiled can be a program that is already installed or burned into an Internet of Things (IoT) device to be upgraded or updated, or a program that has not yet been installed or burned. Regardless of whether it is a program to be upgraded or a program that has not yet been installed or burned, after obtaining the image file of the program to be compiled and the image files of the separate components that the program to be compiled depends on, the program to be compiled can be burned into the IoT device and started or run in the IoT device. Accordingly, an embodiment of the present application also provides a program startup method.
[0056] Figure 4 This is a flow chart of the program startup method provided in the embodiment of the present application. Figure 4As shown, the program startup method may include:
[0057] 401. Obtain the image file of the program to be started into the memory.
[0058] 402. Parse the image file of the program to be started to obtain information segments contained in the image file of the program to be started.
[0059] 403. Determine the separation component that the program to be started depends on from the dynamic information segment contained in the image file of the program to be started.
[0060] 404. Get the image file of the separated component into memory.
[0061] 405. Start the program to be started according to the image file of the program to be started and the image file of the separated component.
[0062] The program startup method provided in the embodiments of the present application can be adapted for use with physical network devices or other computing devices. In this embodiment, the image file of the program to be started can be an image file compiled using the aforementioned program compilation method. The program to be started can be an application program or a program for a component upon which the program to be started depends. When starting the program to be started, in step 401, the image file of the program to be started can be retrieved and stored in memory. This memory refers to the memory of the device executing the program startup method, such as an IoT device. Furthermore, in step 402, the image file of the program to be started can be parsed to obtain information segments contained in the image file of the program to be started. For a description of the information segments contained in the image file, please refer to the relevant content regarding the information segments of the executable file described above and will not be repeated here. The information segments contained in the image file include dynamic information segments, which are used to store identifiers of separate components upon which the program to be started depends, such as the names of the separate components. Furthermore, based on the segment names of the information segments contained in the image file of the program to be started, dynamic information segments, such as the DT-NEEDED segment, are identified.
[0063] Optionally, after obtaining the information segments contained in the image file of the program to be started, the memory occupied by the image file of the program to be started may be released, thereby reducing the memory usage during the program startup process.
[0064] Furthermore, in step 403, the separated component that the program to be started depends on can be determined from the dynamic information segment contained in the image file of the program to be started. Specifically, the identifier of the separated component that the program to be started depends on can be obtained from the dynamic information segment contained in the image file of the program to be started; and the separated component that the program to be started depends on can be determined based on the identifier of the separated component.
[0065] Furthermore, in step 404, the image file of the separated component may be acquired into the memory; thereafter, in step 405, the program to be started may be started according to the image file of the program to be started and the image file of the separated component.
[0066] In this embodiment, the image files of the program to be started and the image files of the separated components are independent image files. In this way, when upgrading the program to be started or the separated component, the program to be started or the separated component can be upgraded separately without upgrading the entire binary package of the program to be started. Therefore, the amount of data transmitted during the OTA upgrade process can be reduced, which helps to improve the efficiency of OTA upgrades.
[0067] In some embodiments, the image file of the separation component is a relocatable file. Accordingly, when starting the program to be started based on the image file of the program to be started and the image file of the separation component, the relocatable file of the separation component can be parsed to obtain information segments contained in the relocatable file of the separation component; then, the information segments contained in the relocatable file of the separation component can be linked to obtain information segments of the executable file of the separation component; the information segments of the executable file of the separation component can be redirected to obtain the executable file of the separation component; further, the program to be started can be started based on the image file of the program to be started and the executable file of the separation component.
[0068] Of course, the image file of the program to be started can also be a relocatable file. Accordingly, when starting the program to be started based on the image file of the program to be started and the executable file of the separated component, the information segments contained in the relocatable file of the program to be started can be linked to obtain the information segments of the executable file of the program to be started; then, the information segments of the executable file of the program to be started can be redirected to obtain the executable file of the program to be started; then, the program to be started can be started based on the executable file of the program to be started and the executable file of the separated component. Specifically, the executable file of the program to be started and the executable file of the separated component can be executed to start the program to be started.
[0069] For the description of the information segments of the executable file and the relocatable file, please refer to the relevant contents of the above embodiment, which will not be repeated here. In the embodiment of the present application, for each information segment of the executable file, some information segments are valid, and some information segments are invalid information segments. For the description of valid information segments and invalid information segments, please refer to the relevant contents of the above embodiment, which will not be repeated here. In the embodiment of the present application, when relocating the relative addresses of the information segments of the program to be started to the absolute addresses, the invalid segments and valid segments in the relocatable file can be identified based on the set invalid segment identifier; thereafter, the valid segments can be relocated from the relative addresses to the absolute addresses based on the relative address distribution of the invalid segments and the valid segments in the relocatable file, so that the absolute addresses of the valid segments are continuous; further, the invalid segments in the relocatable file can be deleted to obtain the executable file of the program to be started, which helps to reduce the size of the executable file of the program to be started. In this way, the memory usage of the executable file can be reduced.
[0070] In the actual development process, in order to improve development efficiency and reduce development costs, some ready-made dependencies may be called when developing the startup program. Since the dependencies are not specifically developed for the program to be started, there may be some functions and modules that the program to be compiled does not need. This may result in the program to be compiled having some functions that are not actually used or having multiple external interfaces, and not all interfaces require all modules and functions. Accordingly, when compiling the program to be compiled into a relocatable file, ffunction-sections and fdata-sections can be used to compile the program to be started using functions and data as compilation units, respectively, to obtain the relocatable file of the program to be started. Accordingly, in this embodiment, when linking the relocatable file of the startup program, gc-sections can be used to link the relocatable file using functions and data as linking units, thereby deleting useless functions and useless data in the relocatable file and obtaining the information segment of the executable file. Furthermore, the information segment of the executable file can be relocated from a relative address to an absolute address to obtain the executable file of the program to be compiled. Since useless functions and useless data in the relocatable file are deleted when the relocatable file is linked, the size of the executable file can be reduced, and thus the memory usage of the executable file can be reduced.
[0071] Of course, in some embodiments, the image file of the program to be started and the image file of the separated component on which it depends may also be executable files. In this case, step 405 may be implemented as: executing the program to be started and the executable file of the separated component on which the program to be started depends, thereby starting the program to be started.
[0072] It is worth noting that the startup process of the above-mentioned program to be started can be completed by the command line compilation system of the embedded operating system. The command line compilation system may include a dynamic engine (dm-engine). Figure 5 As shown, the dynamic engine can complete the loading, parsing, redirection and execution of the program to be started (such as the application in the separated mode); as well as the loading, parsing, redirection and function symbol search of the separated components.
[0073] It should be noted that the execution entity of each step of the method provided in the above embodiment can be the same device, or the method can be executed by different devices. For example, the execution entity of steps 401 and 402 can be device A; for another example, the execution entity of step 401 can be device A, and the execution entity of step 402 can be device B; and so on.
[0074] In addition, some of the processes described in the above embodiments and the accompanying drawings include multiple operations that appear in a specific order. However, it should be clearly understood that these operations may not be executed in the order in which they appear in this document or may be executed in parallel. The sequence numbers of the operations, such as 401 and 402, are merely used to distinguish between different operations and do not represent any execution order. In addition, these processes may include more or fewer operations, and these operations may be executed sequentially or in parallel.
[0075] Accordingly, an embodiment of the present application also provides a computer-readable storage medium storing computer instructions. When the computer instructions are executed by one or more processors, the one or more processors are caused to execute the steps in the above-mentioned program compilation and / or program startup method.
[0076] Figure 6 This is a schematic diagram of the structure of the computing device provided in the embodiment of the present application. Figure 6 As shown, the computing device may include: a memory 60a and a processor 60b. The memory 60a is used to store computer programs.
[0077] The processor 60b is coupled to the memory 60a and is configured to execute a computer program for: obtaining a configuration file of a program to be compiled; obtaining compilation mode information of the program to be compiled from the configuration file of the program to be compiled; compiling the program to be compiled when the compilation mode information of the program to be compiled is a separation mode; and during the compilation of the program to be compiled, writing an identifier of a separation component on which the program to be compiled depends into a dynamic information segment of an image file to obtain an image file of the program to be compiled; wherein the separation component has an independent image file.
[0078] Optionally, the program to be compiled is an embedded application program or a component of an embedded operating system.
[0079] Optionally, the processor 60b is further configured to: during the compilation process of the program to be compiled, obtain compilation mode information of the target component from the configuration file of the target component for the target component on which the program to be compiled depends; if the compilation mode information of the target component is a separation mode, determine that the target component is a separation component.
[0080] Optionally, the processor 60b is further configured to: when compiling into a separate component, compile the separate component to obtain an image file of the separate component.
[0081] In the embodiment of the present application, the image file of the program to be compiled is a relocatable file or an executable file. Optionally, when compiling the program to be compiled, the processor 60b is specifically configured to: compile the program to be compiled into a relocatable file; or compile the program to be compiled into a relocatable file; link the relocatable file to obtain an information segment of the executable file; and relocate the information segment of the executable file from a relative address to an absolute address to obtain the executable file of the program to be compiled.
[0082] Furthermore, when the processor 60b relocates the information segments of the program to be compiled from relative addresses to absolute addresses, it is specifically used to: identify invalid segments and valid segments in the relocatable file according to the set invalid segment identifier; relocate the valid segments from relative addresses to absolute addresses according to the relative address distribution of the invalid segments and the valid segments in the relocatable file so that the absolute addresses of the valid segments are continuous; and delete the invalid segments in the relocatable file.
[0083] Optionally, when compiling a program to be compiled into a relocatable file, the processor 60b is specifically configured to: use ffunction-sections and fdata-sections to compile the program to be compiled, with functions and data as compilation units, respectively, to obtain a relocatable file. Correspondingly, when linking the relocatable file, the processor 60b is specifically configured to: use gc-section to link the relocatable file, with functions and data as link units, to delete unused functions and unused data in the relocatable file, thereby obtaining an information segment of the executable file.
[0084] The computing device for compiling the program to be compiled can be any device with computing capabilities. For example, the computing device can be a single server, a cloud-based server array, or a virtual machine (VM) running on a cloud-based server array. Furthermore, the computing device can also refer to other computing devices with corresponding service capabilities, such as computers and other terminal devices (running service programs).
[0085] The computing device provided in this embodiment can, during the compilation process of a program to be compiled, write the identifier of the separate component that the program to be compiled depends on into the dynamic information segment of an image file, thereby obtaining an image file of the program to be compiled. This allows the program to be compiled and the separate component it depends on to be compiled to be compiled separately, resulting in an independent image file. In particular, when compiling the program to be compiled, the identifier of the separate component that the program to be compiled depends on is written into the dynamic information segment of the image file, eliminating the need to compile the separate component during the compilation process. This reduces the amount of data required to compile the program to be compiled and helps improve the compilation efficiency of the program to be compiled. When the program to be compiled is subsequently upgraded, the program to be compiled and the components it depends on can be upgraded separately without upgrading the entire file package, achieving a more granular upgrade. For example, if the upgrade target is a separate component that the program to be compiled depends on, the separate component can be upgraded separately; if the upgrade target is another module of the program to be compiled, the other module can be upgraded separately without upgrading the separate component, thus achieving a more granular upgrade.
[0086] In some embodiments of the present application, the processor 60b is further used to: obtain the image file of the program to be started into the memory 60a1 of the computing device; parse the image file of the program to be started to obtain the information segment contained in the image file of the program to be started; the information segment includes a dynamic information segment; determine the separation component that the program to be started depends on from the dynamic information segment; obtain the image file of the separation component into the memory 60a1; thereafter, the program to be started can be started according to the image file of the program to be started and the image file of the separation component.
[0087] In some embodiments, the image file of the separation component is a relocatable file. When the processor 60b starts the program to be started, it is specifically used to: parse the relocatable file of the separation component to obtain the information segments contained in the relocatable file of the separation component; link the information segments contained in the relocatable file of the separation component to obtain the information segments of the executable file of the separation component; redirect the information segments of the executable file of the separation component to obtain the executable file of the separation component; and, start the program to be started according to the image file of the program to be started and the executable file of the separation component.
[0088] Optionally, the image file of the program to be started is a relocatable file. Accordingly, when starting the program to be started, the processor 60b is further configured to: link the information segments contained in the relocatable file of the program to be started to obtain the information segments of the executable file of the program to be started; redirect the information segments of the executable file of the program to be started to obtain the executable file of the program to be started; and start the program to be started based on the executable file of the program to be started and the executable file of the separated component.
[0089] In some embodiments, the relocatable file of the program to be started is compiled using ffunction-section and fdata-sections. Accordingly, when linking the information segments contained in the relocatable file of the program to be started, the processor 60b is specifically configured to link the relocatable file using gc-section with functions and data as linking units, thereby deleting unused functions and unused data in the relocatable file to obtain the information segments of the executable file.
[0090] In some embodiments, when the processor 60b redirects the information segment of the executable file of the startup program, it is specifically used to: identify the invalid segments and valid segments in the relocatable file according to the set invalid segment identifier; relocate the valid segment from the relative address to the absolute address according to the relative address distribution of the invalid segment and the valid segment in the relocatable file, so that the absolute address of the valid segment is continuous; and delete the invalid segment in the relocatable file.
[0091] The device for starting the program to be started can be any computing device, such as a device with an embedded operating system installed. For example, the computing device for starting the program to be started can be an IoT device, a computer, a mobile phone, or other terminal device.
[0092] In some optional embodiments, such as Figure 6 As shown, the computing device may further include optional components such as a communication component 60c, a power component 60d, a display component 60e, and an audio component 60f. Figure 6 Only some components are shown schematically, and it does not mean that the computing device must include Figure 6 The components shown do not necessarily mean that the computing device can only include Figure 6 Components shown.
[0093] In an embodiment of the present application, the memory is used to store computer programs and can be configured to store various other data to support operations on the device where it is located. The processor can execute the computer program stored in the memory to implement the corresponding control logic. The memory can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0094] In the embodiment of the present application, the processor can be any hardware processing device that can execute the logic of the above method. Optionally, the processor can be a central processing unit (CPU), a graphics processing unit (GPU) or a microcontroller unit (MCU); it can also be a programmable device such as a field programmable gate array (FPGA), a programmable array logic device (PAL), a general array logic device (GAL), a complex programmable logic device (CPLD); or an advanced reduced instruction set (RISC) processor (Advanced RISC Machines, ARM) or a system on chip (System on Chip, SOC), etc., but is not limited thereto.
[0095] In an embodiment of the present application, the communication component is configured to facilitate wired or wireless communication between the device in which it is located and other devices. The device in which the communication component is located can access a wireless network based on a communication standard, such as WiFi, 2G or 3G, 4G, 5G or a combination thereof. In an exemplary embodiment, the communication component receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component can also be implemented based on near field communication (NFC) technology, radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology or other technologies.
[0096] In an embodiment of the present application, the display component may include a liquid crystal display (LCD) and a touch panel (TP). If the display component includes a touch panel, the display component may be implemented as a touch screen to receive input signals from a user. The touch panel includes one or more touch sensors to sense touches, slides, and gestures on the touch panel. The touch sensor may not only sense the boundaries of a touch or slide action, but also detect the duration and pressure associated with the touch or slide operation.
[0097] In embodiments of the present application, a power supply assembly is configured to provide power to various components of the device in which it is located. The power supply assembly may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the device in which the power supply assembly is located.
[0098] In an embodiment of the present application, the audio component may be configured to output and / or input audio signals. For example, the audio component includes a microphone (MIC), and when the device where the audio component is located is in an operating mode, such as call mode, recording mode, and voice recognition mode, the microphone is configured to receive an external audio signal. The received audio signal may be further stored in a memory or sent via a communication component. In some embodiments, the audio component further includes a speaker for outputting an audio signal. For example, for a device with a language interaction function, voice interaction with a user can be achieved through the audio component.
[0099] It should be noted that the descriptions such as "first" and "second" in this article are used to distinguish different messages, devices, modules, etc., and do not represent the order of precedence, nor do they limit "first" and "second" to different types.
[0100] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0101] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the steps in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0102] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0103] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0104] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.
[0105] Memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
[0106] Computer storage media is readable storage media, also known as computer-readable media. Computer-readable storage media include both permanent and non-permanent, removable and non-removable media that can be implemented using any method or technology to store information. The information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices, or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory media such as modulated data signals and carrier waves.
[0107] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.
[0108] The foregoing is merely an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application should all be included within the scope of the claims of the present application.
Claims
1. A program compiling method, characterized in that: include: Get the configuration file of the program to be compiled; Obtaining compilation mode information of the program to be compiled from a configuration file of the program to be compiled; When the compilation mode information of the program to be compiled is a separate mode, compiling the program to be compiled; the separate mode means that the program to be compiled and its dependent components are compiled separately; During the compilation process of the program to be compiled, the identifier of the separation component on which the program to be compiled depends is written into the dynamic information segment of the image file to obtain the image file of the program to be compiled; wherein the separation component and the program to be compiled each have an independent image file.
2. The method according to claim 1, characterized in that Also includes: During the compilation process of the program to be compiled, for a target component that the program to be compiled depends on, obtaining compilation mode information of the target component from a configuration file of the target component; If the compilation mode information of the target component is a separate mode, the target component is determined to be a separate component.
3. The method according to claim 1, characterized in that Also includes: When the separation component is compiled, the separation component is compiled to obtain the image file of the separation component.
4. The method according to claim 1, wherein The image file of the program to be compiled is a relocatable file or an executable file; and compiling the program to be compiled includes: Compiling the program to be compiled into a relocatable file; or, The program to be compiled is compiled into a relocatable file; the relocatable file is linked to obtain an information segment of an executable file; and the information segment of the executable file is relocated from a relative address to an absolute address to obtain an executable file of the program to be compiled.
5. The method according to claim 4, characterized in that The relocation of the relative addresses of the information segments of the program to be compiled to absolute addresses includes: Identifying invalid segments and valid segments in the relocatable file according to the set invalid segment identifier; relocating the valid segment from a relative address to an absolute address according to the relative address distribution of the invalid segment and the valid segment in the relocatable file, so that the absolute address of the valid segment is continuous; Delete the invalid sections in the relocatable file.
6. The method according to claim 4, characterized in that Compiling the program to be compiled into a relocatable file includes: Use ffunction-sections and fdata-sections to compile the program to be compiled with functions and data as compilation units respectively, to obtain the relocatable file; The linking of the relocatable file comprises: The relocatable file is linked using gc-section with functions and data as linking units, so as to delete useless functions and useless data in the relocatable file and obtain an information segment of an executable file.
7. The method according to any one of claims 1 to 6, characterized in that The program to be compiled is an embedded application program or a component of an embedded operating system.
8. A program startup method, characterized in that: include: Get the image file of the program to be started into the memory; The compilation mode of the program to be started is the separation mode; Parsing the image file of the program to be started to obtain information segments contained in the image file of the program to be started; the information segments include dynamic information segments; Determining, from the dynamic information segment, a separate component on which the program to be started depends; the separate component and the program to be started each having an independent image file; The image file of the separated component and the image file of the program to be started are compiled separately; Obtaining the image file of the separated component into the memory; The program to be started is started according to the image file of the program to be started and the image file of the separated component.
9. The method according to claim 8, characterized in that The image file of the separated component is a relocatable file, and starting the program to be started according to the image file of the program to be started and the image file of the separated component includes: Parsing the relocatable file of the separation component to obtain information segments contained in the relocatable file of the separation component; Linking the information segments contained in the relocatable file of the separation component to obtain the information segments of the executable file of the separation component; redirecting the information segment of the executable file of the separation component to obtain the executable file of the separation component; The program to be started is started according to the image file of the program to be started and the executable file of the separated component.
10. The method according to claim 9, characterized in that The image file of the program to be started is a relocatable file, and starting the program to be started according to the image file of the program to be started and the executable file of the separated component includes: Linking the information segments contained in the relocatable file of the program to be started to obtain the information segments of the executable file of the program to be started; redirecting the information segment of the executable file of the program to be started to obtain the executable file of the program to be started; The program to be started is started according to the executable file of the program to be started and the executable file of the separated component.
11. The method according to claim 10, characterized in that The relocatable file of the program to be started is obtained by compiling the program to be started using ffunction-section and fdata-sections; The linking of the information segments contained in the relocatable file of the program to be started includes: The relocatable file is linked using gc-section with functions and data as linking units, so as to delete useless functions and useless data in the relocatable file and obtain the information segment of the executable file.
12. The method according to claim 10, characterized in that The redirecting of the information segment of the executable file of the program to be started includes: Identifying invalid segments and valid segments in the relocatable file according to the set invalid segment identifier; relocating the valid segment from a relative address to an absolute address according to the relative address distribution of the invalid segment and the valid segment in the relocatable file, so that the absolute address of the valid segment is continuous; Delete the invalid sections in the relocatable file.
13. A computing device, characterized in that include: A memory and a processor; wherein the memory is used to store a computer program; The processor is coupled to the memory and configured to execute the computer program to perform the steps of the method according to any one of claims 1 to 12.
14. A computer-readable storage medium storing computer instructions, characterized in that: When the computer instructions are executed by one or more processors, the one or more processors are caused to perform the steps of the method according to any one of claims 1 to 12.
Citation Information
Patent Citations
Method and device for dynamically loading relocatable file
CN101697131A
Software vulnerability fixing method and device for terminal
CN107451474A
Module development method and device
CN111399840A
Multi-project independent compiling method and system, terminal and medium
CN112306540A