Program execution method, program processing method and related equipment

By using a combination of small stub functions and complementary real functions in computer devices, the problem of insufficient running memory is solved, smaller memory and storage space requirements are achieved, and user experience and device performance are improved.

CN114518913BActive Publication Date: 2025-10-03HUAWEI TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202011198663.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-10-31
Publication Date
2025-10-03
Estimated Expiration
2040-10-31

AI Technical Summary

Technical Problem

Insufficient running memory of computer devices causes third-party programs to fail to run, especially when there are too many function calls of third-party programs under limited running memory conditions. Existing miniaturized operating system technology cannot effectively solve this problem.

Method used

A combination of small stub functions and complementary real functions is adopted. The small stub functions are used as buffers to control whether to load the complementary real functions, thereby reducing the demand for running memory. The complementary real functions are loaded when needed. The coverage and dependency rates are combined to generate small images and complementary images, which are stored in different storage media respectively.

Benefits of technology

It effectively reduces the demand for running memory and storage space, improves user experience, reduces device costs, and improves program loading speed and security.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114518913B_ABST
    Figure CN114518913B_ABST
Patent Text Reader

Abstract

This application discloses a program execution method applicable to the field of program processing. The method comprises: receiving a call request from a first program for a small stub function; loading the small stub function in response to the call request; and determining, based on the small stub function, whether to load a complementary real function corresponding to the small stub function. The function that the first program may actually need to call is a complementary real function, and the small stub function can be understood as a buffer for loading the complementary real function. By adding a buffer, whether to load the complementary real function can be controlled, thereby reducing the first program's runtime memory requirements.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of program processing, and in particular to a program execution method, a program processing method, and related devices. Background Art

[0002] To simplify the memory usage of software systems in computer systems, the industry uses the "miniaturized operating system (OS)-complementary OS" technology. Miniaturized OS is also called a mini-image, and complementary OS is also called a complementary image.

[0003] Small mirror and complementary mirror technology refers to the process by which a computer device generates small and complementary images based on source code, as well as the process by which they are used. The specific generation method is as follows: First, the computer device distinguishes between a function set B in the source code that has a dependency on the program's entry point, and a function set A that has no dependency on the entry point. The computer device then deletes functions from function set A from the source code, retaining functions from function set B, to obtain a small mirror. The computer device then retains functions from function set A from the source code and replaces functions from function set B with null functions, to obtain a complementary mirror. Functions in function set A in the complementary mirror are referred to as real functions. The empty function set in the complementary mirror corresponds to function set B in the small mirror, or in other words, there is a one-to-one correspondence between functions in the empty function set in the complementary mirror and functions in function set B in the small mirror. Small mirrors are statically linked, while complementary mirrors are dynamically linked. When code in a third-party program includes a function from the complementary mirror, upon launching the third-party program, the first device will pre-load that function into running memory and wait for the function to be executed.

[0004] The running memory of the first device is generally limited. If the code of the third-party program calls too many functions, it may cause insufficient running memory, causing the third-party program to fail to run. Summary of the Invention

[0005] The present application provides a program execution method, a program processing method, and related devices, which can reduce the demand of a first program for running memory.

[0006] In a first aspect, the present application provides a program execution method, which is applied to a computer system, wherein the computer system includes a first small image. The method can be executed by the computer system or by a first device on which the computer system is installed. The following will be explained using the example of the method being executed by the first device.

[0007] The method includes: a first device receives a call request from a first program for a small stub function, the small stub function being a function in a small stub function set, the first small image including the small stub function set and a small real function set; the first device loads the small stub function according to the call request; the first device determines, according to the small stub function, whether to load a complementary real function corresponding to the small stub function, the complementary real function being a function in the complementary real function set, the first complementary image including the complementary real function set and the complementary stub function set, the complementary stub function set corresponding to the small real function set, and the complementary real function set corresponding to the small stub function set.

[0008] The function that the first program may actually need to call is a complementary real function, and the small stub function can be understood as a buffer for loading the complementary real function. By adding a buffer, whether to load the complementary real function can be controlled, thereby reducing the first program's demand for runtime memory. For example, if the first program does not enable the corresponding function of the complementary real function, the complementary real function will not be loaded.

[0009] Based on the first aspect of the present application, in a first implementation of the first aspect of the present application, a first device attempts to run a small stub function according to instructions from a first program. If an exception is detected, the device loads a complementary real function. When the first program is about to activate the functionality associated with the complementary real function, the first device may receive instructions from the first program. It should be noted that the instruction may specifically be a change in a judgment variable within the first program's code (or a function called by the code) that affects the program flow. This change in the judgment variable triggers the execution of the small stub function. After triggering the small stub function, the first device attempts to execute the small stub function. This attempt does not necessarily mean that the first device is actually able to execute the small stub function; it may simply be an attempt to execute the small stub function, for example, by obtaining the address of the small stub function and making partial preparations for executing the small stub function. By detecting the exception, the first device can determine that the first program is about to activate the functionality associated with the complementary real function and, therefore, load the complementary real function. Conversely, the first device may not need to load the complementary real function before detecting the exception. In short, the present application triggers the loading of the complementary real function by detecting an exception associated with the small stub function. When an exception is detected, it indicates that the small stub function has not completed successfully. In this case, the first program will not continue execution just because the small stub function has completed execution. Therefore, this application not only adds a buffer for loading the complementary real function, but also pauses the first program, providing a time basis for loading the complementary real function, reducing possible errors in the first program and improving the user experience.

[0010] Based on the first aspect of the present application, or the first embodiment of the first aspect, in the second embodiment of the first aspect of the present application, the small real function set is the set of functions that the target code executes when executing the target use case set, and the complementary real function set is the set of functions that the target code does not execute when executing the target use case set. The small mirror and complementary image obtained based on the small real function set and complementary real function set are referred to as the small mirror and complementary image obtained based on coverage. The small mirror and complementary image obtained based on function set B and function set A in the background art are referred to as the small mirror and complementary image obtained based on dependency. In some scenarios, the small real function set in the small mirror obtained based on coverage may be smaller than function set B in the small mirror obtained based on dependency. The smaller the range of the small real function set, the fewer functions the first program directly loads, thereby further reducing the first program's runtime memory requirements. Direct loading refers to loading without using a small stub function. For ease of description, functions loaded through a small stub function are referred to as indirectly loaded functions. Indirectly loaded functions are not directly loaded into the runtime memory of the first device. Instead, the first device loads the function into the runtime memory when the first program activates the function associated with the function. If the first device does not start the function related to the function, the first device may not load the function. In simple terms, the scope of directly loaded functions becomes smaller, and the scope of indirectly loaded functions becomes larger.

[0011] Based on the second embodiment of the first aspect of the present application, in a third embodiment of the first aspect of the present application, the method further includes: the first device loading a target function, the target function including a target string, the target string having a smaller data size than the source string, the target code including the target function, the target code being derived from source code, the source code including the source function, and the source function including the source string. The source function and the target function correspond, and correspondence here means that the source function and the target function have the same string processing capabilities, but specifically process different strings, one being the target string and the other being the source string. In many scenarios, users do not need to read the source strings through the first device, such as washing machine log data or UE alarm logs. When the function corresponding to the source strings is loaded, these source strings are also loaded into the runtime memory, thereby occupying the runtime memory of the first device. By using the "IDization" method to process the source strings, the present application can reduce the demand for the runtime memory of the first device and increase the security of the source strings, making them less likely to be read by malicious parties.

[0012] Based on the third implementation manner of the first aspect of the present application, in a fourth implementation manner of the first aspect of the present application, after the first device loads the target function, the method further includes: the first device sending a target string to the second device, where the target string is used by the second device to obtain a source string based on the target correspondence relationship and the target string. Restoring the source string using the target string facilitates reading and improves the user experience.

[0013] It should be noted that, for ease of description, a second device appears in multiple embodiments of the first aspect of this application. The second device is one or more second devices different from the first device, that is, the second devices in different embodiments can be the same computer device or different computer devices.

[0014] Based on any of the first to fourth embodiments of the first aspect of the present application, in a fifth embodiment of the first aspect of the present application, the first device loads a complementary real function from the second device based on a small stub function. Storing the first complementary image on the second device can reduce the storage space required on the first device. When the fifth embodiment refers to the second embodiment, compared to the small image obtained based on the dependency ratio, the small image obtained based on the coverage ratio generally has a smaller size, or in other words, a smaller amount of data, thereby further reducing the storage space required on the first device. Furthermore, the coverage ratio is obtained based on a target use case set. By properly setting the target use case set, the first device's frequently used functions can be stored in the first small image, while less frequently used functions can be stored in the first complementary image. This achieves a balance between reducing data transmission volume (the data volume of the complementary real function sent by the second device to the first device) and reducing the memory requirements on the first device. Therefore, compared to small images and complementary images obtained based on the dependency ratio, small images and complementary images obtained based on the coverage ratio have greater advantages when combined with distributed scenarios.

[0015] Based on the first aspect of the present application, or any one of the first to fourth embodiments of the first aspect, in the sixth embodiment of the first aspect of the present application, the first complementary image and the first small image are stored in different storage media of the first device. When the sixth embodiment refers to the second embodiment, according to the description of the fifth embodiment, it can be seen that the first small image includes functions commonly used by the first device, and the first complementary image includes functions not commonly used by the first device. Therefore, the first device's requirements for the first small image and the first complementary image are different, such as reading frequency, reading speed, etc. Therefore, storing the first complementary image and the first small image in different storage media, such as storage media of different costs, can reduce the cost of the first device.

[0016] Based on the first aspect of the present application, or any one of the first to sixth embodiments of the first aspect, in the seventh embodiment of the first aspect of the present application, if the first device determines to load a complementary real function based on a small stub function, the first device sends relevant information about the complementary real function to the second device, where the relevant information is used by the second device to obtain a second small image based on the relevant information, where the second small image includes a small real function set and a complementary real function. Adding the complementary real function to the second small image can increase the speed at which the first program calls the complementary real function, thereby improving the user experience.

[0017] The second aspect of this application provides a program processing method.

[0018] The method includes: a second device sending a first small image to a first device, the first small image including a small real function set and a small stub function set, the small stub function set corresponding to the complementary real function set of the first complementary image, the small real function set corresponding to the complementary stub function set of the first complementary image, the small stub function set including a small stub function, the small stub function being used by the first device to determine whether to load a complementary real function corresponding to the small stub function according to the small stub function, and the complementary real function set including the complementary real function.

[0019] For the description of the beneficial effects of the second aspect of the present application, reference may be made to the aforementioned description of the beneficial effects of the first aspect of the present application.

[0020] Based on the second aspect of the present application, in a first implementation of the second aspect of the present application, the small stub function is specifically used for the first device to attempt to run the small stub function according to the instructions of the first program, and if an exception is detected, the complementary real function is loaded.

[0021] Based on the second aspect of the present application, or the first implementation of the second aspect, in the second implementation of the second aspect of the present application, the small real function set is a set of functions that the target code runs when running the target use case set, and the complementary real function set is a set of functions that the target code does not run when running the target use case set.

[0022] Based on the second implementation of the second aspect of the present application, in the third implementation of the second aspect of the present application, the target code includes a target function, the target function includes a target string, the data volume of the target string is smaller than the data volume of the source string, the target code is obtained according to the source code, the source code includes a source function, and the source function includes a source string.

[0023] Based on the third implementation of the second aspect of the present application, in a fourth implementation of the second aspect of the present application, the target character string is used to obtain a source character string in a corresponding relationship with the target.

[0024] Based on the second aspect of the present application, or any one of the first to fourth embodiments of the second aspect, in a fifth embodiment of the second aspect of the present application, the first device stores a first small image, and the first small image and the first complementary image are stored on different devices.

[0025] Based on the second aspect of the present application, or any one of the first to fourth embodiments of the second aspect, in a sixth embodiment of the second aspect of the present application, the first complementary image and the first small image are stored in different storage media of the first device.

[0026] Based on the second aspect of the present application, or any one of the first to sixth embodiments of the second aspect, in the seventh embodiment of the second aspect of the present application, the second device receives relevant information of the complementary real function sent by the first device; the second device obtains a second small image based on the relevant information, and the second small image includes a small real function set and a complementary real function.

[0027] A third aspect of the present application provides a device for executing a program. The device is installed with a computer system, the computer system including a first small image, and the device includes: a receiving module for receiving a call request from a first program for a small stub function, the small stub function being one function in a small stub function set, the first small image including the small stub function set and a small real function set; a loading module for loading the small stub function according to the call request; and a processing module for determining, based on the small stub function, whether to load a complementary real function corresponding to the small stub function, the complementary real function being one function in the complementary real function set, the first complementary image including the complementary real function set and a complementary stub function set, the complementary stub function set corresponding to the small real function set, and the complementary real function set corresponding to the small stub function set.

[0028] Based on the third aspect of the present application, in a first implementation of the third aspect of the present application, the processing module is specifically used to attempt to run a small stub function according to the instructions of the first program, and if an exception is detected, load the complementary real function.

[0029] Based on the third aspect of the present application, or the first implementation of the third aspect, in the second implementation of the third aspect of the present application, the small real function set is the function set that the target code runs when running the target use case set, and the complementary real function set is the function set that the target code does not run when running the target use case set.

[0030] Based on the second implementation of the third aspect of the present application, in the third implementation of the third aspect of the present application, the loading module is also used to load the target function, the target function includes a target string, the data volume of the target string is smaller than the data volume of the source string, the target code includes the target function, the target code is obtained based on the source code, the source code includes the source function, and the source function includes the source string.

[0031] Based on the third implementation of the third aspect of the present application, in the fourth implementation of the third aspect of the present application, the apparatus further includes: a first sending module, configured to send a target string to the second device, where the target string is used by the second device to obtain a source string based on a target correspondence relationship and the target string.

[0032] Based on any one of the first to fourth embodiments of the third aspect of the present application, in the fifth embodiment of the third aspect of the present application, the processing module is specifically used to load the complementary real function from the second device according to the small stub function.

[0033] Based on the third aspect of the present application, or any one of the first to fourth embodiments of the third aspect, in a sixth embodiment of the third aspect of the present application, the first complementary image and the first small image are stored in different storage media of the first device.

[0034] Based on the third aspect of the present application, or any one of the first to sixth embodiments of the third aspect, in the seventh embodiment of the third aspect of the present application, the apparatus further includes: a second sending module, configured to send relevant information of the complementary real function to the second device if it is determined to load the complementary real function based on the small stub function, the relevant information being used by the second device to obtain a second small image based on the relevant information, the second small image including a small real function set and a complementary real function.

[0035] A fourth aspect of the present application provides a computer system, the system comprising: a processor and a memory;

[0036] The storage stores a first small image;

[0037] The processor is configured to receive a call request from a first program for a small stub function, where the small stub function is a function in a small stub function set, and the first small image includes the small stub function set and a small real function set;

[0038] The processor is further configured to load the small stub function according to the call request;

[0039] The processor is further configured to determine, based on the small stub function, whether to load a complementary real function corresponding to the small stub function, where the complementary real function is a function in a complementary real function set, the first complementary image includes the complementary real function set and a complementary stub function set, the complementary stub function set corresponds to the small real function set, and the complementary real function set corresponds to the small stub function set.

[0040] Based on the fourth aspect of the present application, in a first implementation of the fourth aspect of the present application, the processor is specifically used to attempt to run the small stub function according to the instructions of the first program, and if an exception is detected, load the complementary real function.

[0041] Based on the fourth aspect of the present application, or the first implementation of the fourth aspect, in the second implementation of the fourth aspect of the present application, the small real function set is a set of functions that the target code runs when running the target use case set, and the complementary real function set is a set of functions that the target code does not run when running the target use case set.

[0042] Based on the second implementation of the fourth aspect of the present application, in the third implementation of the fourth aspect of the present application, the processor is also used to load a target function, the target function includes a target string, the data volume of the target string is smaller than the data volume of the source string, the target code includes the target function, the target code is obtained based on the source code, the source code includes the source function, and the source function includes the source string.

[0043] Based on the third implementation of the fourth aspect of the present application, in the fourth implementation of the fourth aspect of the present application, the processor is further used to send the target string to the second device, and the target string is used by the second device to obtain the source string according to the target correspondence relationship and the target string.

[0044] Based on any one of the first to fourth implementations of the fourth aspect of the present application, in the fifth implementation of the fourth aspect of the present application, the processor is specifically used to load the complementary real function from the second device according to the small stub function.

[0045] Based on the fourth aspect of the present application, or any one of the first to fourth embodiments of the fourth aspect, in a sixth embodiment of the fourth aspect of the present application, the first complementary image and the first small image are stored in different storage media of the first device.

[0046] Based on the fourth aspect of the present application, or any one of the first to sixth embodiments of the fourth aspect, in the seventh embodiment of the fourth aspect of the present application, the processor is further used to send relevant information of the complementary real function to the second device if it is determined to load the complementary real function based on the small stub function, and the relevant information is used by the second device to obtain a second small image based on the relevant information, and the second small image includes the small real function set and the complementary real function.

[0047] A fifth aspect of the present application provides a program processing apparatus. The apparatus includes: a sending module configured to send a first small image to a first device, the first small image including a small real function set and a small stub function set, the small stub function set corresponding to the complementary real function set of the first complementary image, the small real function set corresponding to the complementary stub function set of the first complementary image, the small stub function set including a small stub function, the small stub function being used by the first device to determine whether to load a complementary real function corresponding to the small stub function based on the small stub function, the complementary real function set including the complementary real function.

[0048] Based on the fifth aspect of the present application, in a first implementation of the fifth aspect of the present application, the small stub function is specifically used for the first device to attempt to run the small stub function according to the instructions of the first program, and if an exception is detected, the complementary real function is loaded.

[0049] Based on the fifth aspect of the present application, or the first implementation of the fifth aspect, in the second implementation of the fifth aspect of the present application, the small real function set is the function set that the target code runs when running the target use case set, and the complementary real function set is the function set that the target code does not run when running the target use case set.

[0050] Based on the second implementation of the fifth aspect of the present application, in the third implementation of the fifth aspect of the present application, the target code includes a target function, the target function includes a target string, the data volume of the target string is smaller than the data volume of the source string, the target code is obtained according to the source code, the source code includes a source function, and the source function includes a source string.

[0051] Based on the third implementation of the fifth aspect of the present application, in the fourth implementation of the fifth aspect of the present application, the target character string is used to obtain a source character string in a corresponding relationship with the target.

[0052] Based on the fifth aspect of the present application, or any one of the first to fourth embodiments of the fifth aspect, in the fifth embodiment of the fifth aspect of the present application, the first device stores a first small image, the first small image and the first complementary image are stored in different devices, and the device storing the first complementary image is used to provide a set of complementary real functions for multiple devices, and the multiple devices include the first device.

[0053] Based on the fifth aspect of the present application, or any one of the first to fourth embodiments of the fifth aspect, in a sixth embodiment of the fifth aspect of the present application, the first complementary image and the first small image are stored in different storage media of the first device.

[0054] Based on the fifth aspect of the present application, or any one of the first to sixth embodiments of the fifth aspect, in the seventh embodiment of the fifth aspect of the present application, the device also includes: a receiving module for receiving relevant information of the complementary real function sent by the first device; a processing module for obtaining a second small image based on the relevant information, the second small image including a small real function set and a complementary real function.

[0055] In a sixth aspect, the present application provides a program execution device, characterized in that it includes: a processor and a memory; the memory stores a first small image and an execution program, and the first small image includes a small stub function; the processor is used to obtain the execution program from the memory and process the small stub function according to the execution program, and the specific processing method includes the method described in the first aspect or any one of the embodiments of the first aspect.

[0056] In a seventh aspect, the present application provides a program processing device, characterized in that it includes: a processor and a memory; a processing program is stored in the memory; the processor is used to obtain the processing program from the memory, and obtain a first small image based on the processing program and source code. The specific processing method includes the method described in the aforementioned second aspect or any one of the embodiments of the second aspect.

[0057] The eighth aspect of the present application provides a computer storage medium, characterized in that instructions are stored in the computer storage medium, and when the instructions are executed on a computer, the computer executes the method as described in the first aspect or any one of the embodiments of the first aspect, or the computer executes the method as described in the second aspect or any one of the embodiments of the second aspect.

[0058] The ninth aspect of the present application provides a computer program product, characterized in that when the computer program product is executed on a computer, it enables the computer to execute the method as described in the first aspect or any one of the embodiments of the first aspect, or enables the computer to execute the method as described in the second aspect or any one of the embodiments of the second aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0059] Figure 1 This is a flowchart for function pruning based on function dependency ratio;

[0060] Figure 2 A flowchart for obtaining a small image and a complementary image based on source code;

[0061] Figure 3 This is a flowchart of the processing procedure in the embodiment of the present application;

[0062] Figure 4 A schematic diagram of an application scenario in an embodiment of the present application;

[0063] Figure 5 Schematic diagram of the process flow of the program processing method in the embodiment of the present application;

[0064] Figure 6 This is a flow chart of miniaturizing a character string through “IDization” in an embodiment of the present application;

[0065] Figure 7 A diagram showing the relationship between dependent functions and overridden functions in the source code;

[0066] Figure 8 This is a schematic diagram of a process for obtaining a mirror image based on coverage in an embodiment of the present application;

[0067] Figure 9 Schematic diagram of the process of executing a program in an embodiment of the present application;

[0068] Figure 10 This is a schematic diagram of the structure of the program execution device in the embodiment of the present application;

[0069] Figure 11 This is a schematic diagram of the structure of the program processing device in an embodiment of the present application;

[0070] Figure 12 This is a structural diagram of the first device or the second device in an embodiment of the present application. DETAILED DESCRIPTION

[0071] The embodiments of the present application provide a program execution method, a program processing method, and related devices, which are applied to the field of program processing and can reduce the demand of a first program for running memory.

[0072] In order to facilitate understanding of the technical solutions provided by this application, some related concepts are described below.

[0073] Functional dependency is a mathematically derived term that describes the dependence of the value of one attribute or set of attributes on the value of another attribute or set of attributes. Let R(U) be a relational schema on a set of attributes U, and let X and Y be subsets of U. If for any two possible relations r1 and r2 in R(U), if r1[x] = r2[x], then r1[y] = r2[y], or if r1[y] is not equal to r2[y], then r1[x] is not equal to r2[x], then X is said to determine Y, or Y is said to depend on X.

[0074] The function dependency ratio (abbreviated as dependency ratio) indicates the proportion of functions in a program that have dependencies (or call relationships). The function dependency ratio can be calculated using the following steps: Assuming the number of all functions in a program is N, scan the program's entry point (e.g., main) for the sub-functions of the program that entry point depends on. All sub-functions and entry points form set A. Assuming the number of functions in set A is M, and set A and the program do not contain duplicate functions (if set A contains duplicate functions, the number of functions in set A after deduplication is M), then the function dependency ratio of this program is equal to M / N.

[0075] Function coverage (or coverage for short) indicates the proportion of functions in a program that have been executed. Function coverage can be calculated using the following steps: Assume that the number of functions in a program is N. Assume that after the program runs through a set of use cases, the number of functions executed is K. Then, function coverage equals K / N. Repeated functions are counted only once.

[0076] Stub function also cries pile point, pile function, stub function, and stub function is generally used for replacing some interface functions, is used to test the characteristic of current function.Stub function in the application can be the function with less volume in realization, can also be empty (null) function.And stub function in the application can produce unusual when making to carry out stub function by special design.

[0077] A computer system consists of hardware and software. The hardware is an organic combination of various physical components, constructed using principles such as electricity, magnetism, optics, and mechanics, and is the entity upon which the system operates. The software consists of various programs and files that direct the entire system to operate according to specified requirements. Therefore, from a macro perspective, a computer system's software is also a program, and it can be customized. Some computer systems, such as those on UEs and laptops, can provide an operating environment for third-party programs.

[0078] With the rapid development of the internet, sales of computer devices have continued to grow. For example, in 2019, the top three global mobile phone manufacturers each sold over 200 million units. Faced with this massive sales volume, in addition to user experience and product quality, the cost of computer devices is a key competitive advantage. Computer devices generally rely on programs to implement their functions, and the storage and execution of programs are inseparable from storage media. In the embedded field, the cost of storage media is a significant component of device costs. To reduce storage media costs, programs can be miniaturized. Program miniaturization reduces program size, thereby saving storage space. Several miniaturization techniques exist: 1. Program or service granularity tailoring (such as Windows and Android); 2. Package granularity tailoring (such as Red Hat, SUSE, and Ubuntu); 3. File granularity tailoring (such as deleting unused files directly through commands in Windows and Linux); and 4. Function granularity tailoring (such as the --gc-section linker option in the GCC compiler). Function-granularity tailoring is the smallest of the aforementioned tailoring methods and is referred to as function tailoring. The following describes function pruning using the gcc compiler as an example.

[0079] Generally speaking, the GCC compiler places each function and global variable into a separate section during the source code compilation process. A section can contain either a function or a global variable. During the linking process, the GCC compiler identifies the dependencies between each section and its entry point and removes sections that have no dependencies on the entry point. This is described in detail below, with some specific code included for ease of understanding.

[0080] See also Figure 1 , Figure 1 Figure 1 is a flow chart illustrating function pruning based on function dependency. Step 11 is the compilation phase, where the gcc compiler compiles each function in source code 101 into an independent section. Source code 101 includes four functions: hello1(), hello2(), hello3(), and main(). Figure 1The specific contents of the first three functions are not shown. It is assumed here that there is no dependency between hello1(), hello2(), and hello3(). Function main() is the entry point of the program. Function main() includes the code hello1() and hello3(), indicating that when main() is executed, hello1() and hello3() will be called, that is, there is a dependency between hello1(), hello3(), and main(). Compiling with the gcc compiler, a section set 102 is obtained. Section set 102 includes four sections, named .text.hello1-3 and .text.main. Step 12 is the link preparation phase, in which the linker in the gcc compiler scans the call relationship starting from the entrypoint. Based on the example of step 1 above, it can be determined that there is a dependency between .text.hello1, .text.hello3, and .text.main; .text.hello2 is an isolated function, that is, there is no dependency between text.hello2 and .text.main. Step 13 is the linking phase, in which the linker deletes the sections corresponding to the isolated functions and generates an executable file 104.

[0081] The above-mentioned function pruning is based on the function dependency ratio. The smaller the function dependency ratio, the better the function pruning effect and the smaller the size of the resulting executable file 104. This pruning method is generally applicable to pruning programs containing entry points (such as main), but is not applicable to pruning shared libraries or OS kernels (system kernels), such as computer systems that include shared libraries or OS kernels (system kernels). Because the shared libraries or OS kernels (system kernels) in the computer system provide an operating environment for third-party programs, they may include a function that has no dependency on the entry point of the computer system, but has a dependency on the entry point of the third-party program. If the function is deleted through the above-mentioned function pruning method, the third-party program may not run normally. For this reason, the industry uses the "small mirror-complementary mirror" technology, which can be divided into two parts. The first part is the process of obtaining the small mirror and complementary mirror based on the source code, and the second part is the process of using the small mirror and complementary mirror, which are described below.

[0082] The first part is usually completed by computer equipment. Figure 2 , Figure 2The present invention is a flowchart for obtaining a small image and a complementary image based on the source code. In step 21, the computer device distinguishes between a function set B that has a dependency relationship with the entry point and a function set A that has no dependency relationship with the entry point in the source code. In step 22, the computer device deletes the functions in the function set A from the source code and retains the functions in the function set B to obtain a small image. In steps 23 and 24, the computer device retains the functions in the function set A from the source code and replaces the functions in the function set B with empty (null) functions, that is, replaces the function set B with an empty function set to obtain a complementary image. Among them, the functions in the function set A in the complementary image are called real functions. The empty function set in the complementary image corresponds to the function set B in the small image, or the functions in the empty function set in the complementary image correspond one-to-one to the functions in the function set B in the small image. For ease of understanding, combined with the above Figure 1 The source code 101 in the description. Figure 2 The source code in is equal to Figure 1 When the source code 101 in the image is used, the small image is equal to the executable file 104. The small image includes hello1(), hello3(), and main(); the complementary image includes hello2(), empty function 1, empty function 3, and empty function 2. Among them, empty function 1 corresponds to hello1(), empty function 3 corresponds to hello3(), and empty function 2 corresponds to main().

[0083] The second part is the process of using the small image and the complementary image, which is executed by the first device installed with the computer system. Assume that the code in a third-party program calls function 1 and function 2, function 1 is a function in the small image, and function 2 is a real function in the complementary image. When the first device starts the third program, the first device will load function 1 and function 2 from the flash memory or hard disk into the running memory of the first device. However, in actual applications, the running memory of the first device is generally limited. If the code of the third-party program calls too many functions, it may lead to insufficient running memory, causing the third-party program to fail to run.

[0084] To this end, the present application proposes a program processing method, in which a computer device executing the first part of the operation does not delete the complementary real function set when obtaining a small image based on the source code, but instead replaces the complementary real functions with stub functions, that is, replaces the complementary real function set with a small stub function set. The complementary real function set described here can be the above-mentioned function set A, or it can be other than function set A. When the complementary real function set is function set A, the complementary real function set is obtained based on the dependency ratio, and the complementary real function set refers to the set of functions that have no functional dependency relationship with the entry point in the source code; when the complementary real function set is not function set A, the complementary real function set can be obtained based on the function coverage ratio, and the complementary real function set is the set of functions that are not run in the source code during the execution of the target use case set. In addition to replacing the complementary real function set with the small stub function set, the computer device also retains the correspondence between the small stub function set and the complementary real function set in the complementary image.

[0085] When a third-party program is run in a first device using the program execution method provided in the present application, if the third-party program includes code that calls a complementary real function, the first device will not directly load the complementary real function into the running memory when starting the third-party program, but will first load the small stub function corresponding to the complementary real function. When the small stub function is about to run or is running, the computer device will indirectly load the complementary real function through the small stub function. The small stub function can be understood as a buffer for the computer device to load the complementary real function. By adding a buffer, it is possible to control whether the complementary real function is loaded, thereby reducing the third-party program's demand for running memory. For example, when the third-party program does not enable the related functions corresponding to the complementary real function, the complementary real function is not loaded.

[0086] In order to facilitate understanding of the technical solutions provided in the embodiments of this application, the process flow of the processing program is first described. Figure 3 , Figure 3 Schematic diagram of the process flow in the embodiment of the present application. Figure 3As shown, the program processing process may include program writing 301, program processing 302, and program execution 303. Program writing 301 refers to the process of generating source code, including but not limited to manual input and software generation. Program processing 302 refers to the process of preprocessing the fully or partially written program based on program writing, such as automatic correction, trimming, and compilation. Trimming refers to reducing the size of the source code by deleting or replacing some functions in the source code. Program processing 302 in the embodiment of the present application mainly includes the above-mentioned program processing method: by trimming the source code to obtain a complementary real function set and a small real function set, and based on the complementary real function set and the small real function set, obtaining a small mirror and a complementary mirror, the small mirror includes a small real function and a small stub function, and the complementary mirror includes a complementary real function and a complementary stub function. Program execution 303 refers to the running process of a third-party program. The third-party program implements its corresponding related functions through running. For example, if the third-party program is a program related to photography, the related functions may be photography, photo editing, and portrait beautification. During the running process of the third-party program, the third-party program relies on functions in the small mirror and complementary mirror to implement the related functions. The program execution 303 in the embodiment of the present application mainly includes the above-mentioned program execution method: a function that the third-party program actually depends on, or a function that the third-party program needs to call is a complementary real function, and the complementary real function is in the complementary image. When the third-party program needs to call the complementary real function, the third-party program can call the complementary real function through the small stub function in the small image.

[0087] The above describes the process of processing a program, which is roughly divided into program writing 301, program processing 302, and program execution 303. The process of processing a program requires a specific computer device to execute. Different steps can be completed in different computer devices or in the same computer device. For example, program writing 301 is completed in device 1, and device 1 sends the completed source code to device 2. Device 2 obtains a small image and a complementary image based on the source code, and device 2 runs the third-party program through the small image and the complementary image. Alternatively, please refer to Figure 4 , Figure 4 This is a schematic diagram of an application scenario in an embodiment of the present application. Figure 4As shown, the second device 401 obtains the source code, and the source code may be written in the second device 401 or in other devices. After obtaining the source code, the second device 401 performs program processing 302 on the source code to obtain a small image and a complementary image. After obtaining the small image and the complementary image, the second device 401 transfers the small image and the complementary image to the first device 402, and the first device 402 performs the step of program execution 303. Specifically, it may be the computer system in the first device 402 that performs the step of program execution 303, that is, the execution subject of the program execution method in the embodiment of the present application may be the first device 402 or the computer system 402. In the subsequent description of the embodiment of the present application, the first device 402 will be used as the execution subject for example. In the embodiment of the present application, the following will be described Figure 4 For example, the corresponding processing in other scenarios can refer to Figure 4 Description of the scene in .

[0088] exist Figure 4 In the scenario, the second device 401 can be a desktop computer, a laptop, or a server. The first device 402 can be a bracelet, a washing machine, a router, a desktop computer, a laptop, or a smart phone. The second device 401 can establish a connection with the first device 402 or not. If the second device 401 establishes a connection with the first device 402, the connection method can be a wired connection or a wireless connection. The wireless connection can be a wireless hotspot or Bluetooth. If the second device 401 does not establish a connection with the first device 402, the small image and the complementary image can be transmitted by relying on a storage medium, such as a USB flash drive.

[0089] The following describes the program processing method and program execution method in the embodiments of the present application. Figure 5 , Figure 5 Schematic diagram of the process flow of the program processing method in the embodiment of the present application.

[0090] In step 51, the second device obtains the target code according to the source code.

[0091] The source code may include some character strings, which will occupy a certain volume in the source code. For example, program logs refer to logs that need to be recorded or printed during program operation. For a program, logs are often recorded or printed when key initialization or abnormal branches occur (to facilitate maintenance and testing). Log-related strings in the source code will be compiled into the executable program, increasing the size of the program. In a compiled executable program, log strings generally account for 5% to 10% of the program volume; the impact of this volume consumption on the storage space of the first device cannot be ignored. To this end, this application miniaturizes the character strings through the "IDization" method, which is described in detail below. Please refer to Figure 6 , Figure 6 This is a flow chart of miniaturizing a character string through “IDization” in an embodiment of the present application.

[0092] In step 511, the second device obtains a string in the source code. For ease of understanding, the following description uses specific source code, which includes a FuncA function.

[0093] Source code:

[0094] FuncA / *Function name* /

[0095] {……; / *Indicates that there may be other codes here* /

[0096] If (ret! = 0) / *If ret is not equal to 0* /

[0097] {Printf("Error: FuncA init Failed! The ret is%d\n", ret); / * Output Error: FuncA init Failed! The ret is%d* / ;

[0098] }else / *otherwise* /

[0099] {Printf(“FuncA init success!\n”);} / *Output FuncA init success! * /

[0100] Return ret;} / *Return ret* /

[0101] In the above source code, "Error: FuncA init Failed! The return is" and "FuncA init success!" are two strings. These two strings are referred to as source string 1 and source string 2. Source string 1 indicates that initialization failed and outputs the return value, while source string 2 indicates that initialization succeeded. The second device obtains source string 1.

[0102] In step 512, the second device obtains a hash value (also called a hash value or hash value) of the source string.

[0103] In step 513, the second device determines whether a hash value conflict has occurred. The number of strings in the source code is not fixed; step 511 only illustrates a portion of the code for a function in the source code. If the source code contains multiple strings, and the second device obtains hash values ​​for multiple strings, two strings may have the same hash value, indicating a hash value conflict. Of course, if source string 1 is the first string obtained by the second device, this step is unnecessary. If the second device determines that a hash value conflict has occurred, it executes step 514; otherwise, it executes step 511.

[0104] In step 514, the computer determines whether the source string is the same as the source string corresponding to the hash value collision.

[0105] The target correspondence list stores the correspondence between source strings and target strings. The embodiment of the present application is described using the target string as a hash value as an example. The hash value corresponding to source string 1 is referred to as hash value 1, and the hash value that conflicts with hash value 1 is referred to as hash value 3. Hash value 3 is obtained by the second device based on source string 3. The computer determines whether source string 1 is the same as source string 3 in the target correspondence list. If the same, source string 1 is skipped. The second device obtains the next source string and restarts execution from step 511. If different, step 515 is executed.

[0106] In step 515, the second device adds 1 to the hash value. In order to resolve the hash value conflict, the second device adds 1 to the hash value corresponding to the source string 1.

[0107] In step 516, the second device determines whether the hash value conflict has been resolved. If not, step 515 is executed until the hash value conflict is resolved. If so, the second device obtains the next source string and restarts from step 511.

[0108] By executing steps 511 to 516 above, the second device can obtain a target string corresponding to the source string, as well as a target correspondence relationship. The second device replaces the source string in the source function with the target string to obtain a target function. FuncA is the source function, and the target function is specifically as follows.

[0109] Objective function:

[0110] FuncA / *Function name* /

[0111] {……; / *Indicates that there may be other codes here* / If(ret!=0) / *If ret is not equal to 0* /

[0112] {Printf("afab9b15%d\n",ret); / *output afab9b15%d* /

[0113] }else / *otherwise* /

[0114] {Printf("8a52d706\n");} / *Output 8a52d706* /

[0115] Return ret;} / *Return ret* /

[0116] In the target function above, hash value 1 is afab9b15, and the hash value corresponding to source string 2 is 8a52d706. Aside from the output, the target and source functions are identical.

[0117] In step 52, the second device obtains a small real function set and a complementary real function set according to the target code.

[0118] According to the above description, the set of complementary real functions can be Figure 2 The function set A obtained by the function dependency rate can also be obtained by the function coverage rate. In contrast, the small real function set can be Figure 2 The function set B obtained according to the function dependency rate can also be obtained according to the function coverage rate. If the complementary real function set is the function set A, then step 52 can refer to the aforementioned Figure 2 The process of the computer device obtaining the function set A. Here, the focus is on describing the process of the second device obtaining the small real function set and the complementary real function set according to the function coverage. According to the above definition of function coverage, function coverage refers to the ratio of the number of functions that the source code has run in the process of running the target use case set to the number of functions in the source code. For the sake of ease of understanding, the functions that have been run and the functions in the source code do not include repeated functions. In the process of running the target use case set, different use cases, or even the same use case, may repeatedly call a certain function. However, when calculating the number of functions that have been run, the function will only be counted once. According to the definition of function coverage, the definition of the small real function set and the complementary real function set can be obtained. The small real function set is the set of functions that the target code runs in the process of running the target use case set, and the complementary real function set is the set of functions that the target code does not run in the process of running the target use case set.

[0119] Before running the code on the second device, the second device compiles the target code and runs a target use case set using the compiled target code. The target use case set includes all or part of the functions that the compiled target code can perform. For example, if the target code can perform three functions: taking photos, editing photos, and enhancing facial features, the target use case set includes any one or more of the three functions. For example, the target use case set includes taking photos and editing photos. The second device can transfer the compiled target code program to a device (e.g., the first device), so that the device can install the compiled target code program to run the photo taking and photo editing functions, and return function coverage information to the second device. The second device obtains a small real function set and a complementary real function set based on the function coverage information. Alternatively, the second device simulates the photo taking and photo editing functions using the target code. The second device then counts the function sets that were run and the function sets that were not run during the target use case set execution of the target code. The run function set is the small real function set, and the unrun function set is the complementary real function set. The ratio of the number of functions in the run function set to the number of functions in the target code is the function coverage of the target code. It should be understood that the examples of target use cases herein are provided solely to facilitate the technical solutions in the embodiments of this application and are not intended to limit this application. For example, if the compiled target code can return a value to a third-party program, then returning a value to the third-party program is also a function that the compiled target code can perform.

[0120] The above describes the second device obtaining a small real function set and a complementary real function set through the target code. It should be understood that since the target code and the source code correspond, the second device can also obtain a small real function set and a complementary real function set through the source code. For example, the second device transmits a program compiled from the source code to the first device, and the first device runs the photo taking and photo editing by installing the program compiled from the source code. The first device returns function coverage information to the second device. The function coverage information includes a set of serial numbers corresponding to the functions that have been run in the source code. In the source code and the target code, all functions are numbered according to their arrangement order, that is, each function has its corresponding serial number. In the source code and the target code, the serial numbers of corresponding functions are the same, such as the source function and the target function. Therefore, even if the serial number returned by the first device is a set of serial numbers corresponding to the functions in the source code, the second device can determine the small real function set in the target code based on the serial number set, and then determine the complementary real function set.

[0121] In step 53, the second device obtains a complementary stub function set according to the small real function set, and obtains a small stub function set according to the complementary real function set.

[0122] The second device replaces each function of the small real function set with a stub function to obtain a complementary stub function set; and replaces each function of the complementary real function set with a stub function to obtain a small stub function set.

[0123] In step 54 and step 55, the second device obtains a small image according to the small real function set and the small stub function set, and obtains a complementary image according to the complementary real function set and the complementary stub function set.

[0124] The second device compiles the code consisting of a small set of real functions and a small set of stub functions to obtain a small image; the second device compiles the code consisting of a complementary set of real functions and a complementary set of stub functions to obtain a complementary image. In other words, the second device replaces the complementary set of real functions in the source code with the small set of stub functions, then compiles the source code to obtain a small image; the second device replaces the small set of real functions in the source code with the complementary set of stub functions, then compiles the source code to obtain a complementary image.

[0125] The second device needs to maintain the correspondence between the small stub function set and the complementary real function set, i.e., one small stub function corresponds to one complementary real function. The second device can generate a mapping table that includes the correspondence between the small stub functions and the complementary real functions. Alternatively, in other embodiments, the second device sets the function name of the complementary real function to be the same as or similar to the function name of the small stub function to maintain the correspondence between the small stub functions and the complementary real functions. In other embodiments, the small stub function set of the minimal image and the complementary real function set of the complementary image are sorted in the same order, and the small real function set of the minimal image and the complementary stub function set of the complementary image are sorted in the same order to facilitate the loader to load functions and find function offset addresses. For example, the second device can maintain the correspondence between the small stub functions and the complementary real functions using function sequence numbers. In the minimal image and the complementary image, the small stub function set and the complementary real function set are numbered according to their function arrangement order, and corresponding functions have the same sequence number, for example, the small stub function and the complementary real function have the same sequence number.

[0126] When the first device subsequently runs the third-party program, the first device can call the complementary real function through the exception of the small stub function. In order to generate an exception when trying to run the small stub function, the second device can set the small stub function to be non-executable. Specifically, the second device aggregates all the small stub functions into a separate section, aligns the address of this section according to the page size, and sets the attribute of this section to be non-executable. When the first device attempts to run the small stub function, an exception will be generated because the small stub function is non-executable. In other embodiments, in order to reduce the size of the small stub function set, the small stub function is an empty function.

[0127] In addition to the above methods, you can also implement exceptions by using code in a small stub function. For example, the following provides an example of a small stub function.

[0128] Int F4func(int a,void*b) / *function name* /

[0129] {asm volatile(

[0130] “push{r0~r2\n}” / *Push registers r0~r2 into the stack* /

[0131] "mov r0,#STUB_ABORT_ADDR\n" / *Assign a value to the r0 register. The assigned value is an address that can generate an exception when accessed* /

[0132] "mov r1,#STUB_ABORT_VALUE\n" / *Assign value to the r1 register, which is an immediate value* /

[0133] "str r1,[r0]\n" / *Store the r1 register in the address pointed to by r0. r0 stores the address that will cause an exception when accessed, so this instruction will cause a data exception* /

[0134] "pop r1,{r0~r2}\n";)) / *pop r0~r2 registers from stack* /

[0135] return 0; / *return* / }

[0136] In this example, the small stub function is named Int F4func. When the first device executes this small stub function, it pushes registers r0 through r2 onto the stack and then assigns a value to register r0. This value is an address that will generate an exception if accessed. When the instruction "str r1,[r0]\n" is executed, this instruction stores register r1 into the address pointed to by r0. Because r0 stores an address that will generate an exception if accessed, this instruction generates a data exception.

[0137] It should be noted that the embodiments of this application do not exhaustively enumerate all possible methods for generating exceptions. Those skilled in the art will appreciate that they can utilize CPU segment attributes / page table attributes to construct exceptions, construct special illegal instructions, or construct special data exceptions to cause the first device to generate an exception when attempting to run a small stub function, all of which fall within the scope of protection of this application.

[0138] It should be noted that step 51 above can be omitted, in which case the target code in step 52 is the source code. If step 51 is executed, its essence is to replace the source function with the target function. Therefore, there are no strict timing requirements between step 51 and steps 52-53. For example, the second device can replace the source function with the target function after obtaining the mini-image and complementary image through steps 55 and 54; or the second device can complete step 51 while executing step 52. There are also no strict timing requirements between steps 54 and 55.

[0139] Here we explain the difference between pruning based on function coverage and pruning based on function dependency.

[0140] First, the volume of a small image obtained based on function coverage is generally smaller than the volume of a small image obtained based on function dependency. Figure 7 As shown, Figure 7 The following is a diagram of the relationship between dependent functions and covered functions in the source code. Dependent functions refer to the set of functions that have a dependency relationship with the entry point in the source code. Covered functions refer to the set of functions that are run in the process of running the target use case set through the source code. In general, since functions that have a dependency relationship with the entry point are not necessarily run in the process of running the use case set, the scope of dependent functions is generally larger than that of covered functions. Therefore, the small real function set is smaller than the function set B. Therefore, the volume of the small image obtained based on the coverage rate (referred to as small image 1) is generally smaller than the volume of the small image obtained based on the dependency rate (referred to as small image 2). Because stub functions can be empty functions, the volume of small stub functions is ignored here.

[0141] When the volume of small image 1 is smaller than that of small image 2, the volume of complementary image 1 corresponding to small image 1 will be larger than the volume of complementary image 2 corresponding to small image 2. The first device can reduce costs in some ways. For example, the first device places small image 1 and complementary image 1 in different storage media, including storage medium 1 and storage medium 2, with small image 1 stored in storage medium 1 and complementary image 1 stored in storage medium 2. When the storage space size is the same, the cost of storage medium 2 is lower than that of storage medium 1. Since the volume of small image 1 is smaller than that of small image 2, the first device can save storage space in storage medium 1, which reduces the first device's storage medium costs. In other embodiments, the first device stores small image 1 locally, and complementary image 1 is stored in a cloud platform or a central device. In this case, the cost of the first device is also reduced. Furthermore, the cloud platform or central device provides complementary image 1 to multiple first devices, which can save costs for multiple first devices.

[0142] Secondly, the images obtained based on coverage are applicable to product family scenarios. For example, within the same product family, there are often low-end products (providing smaller or trimmed-down features), mid-range products (providing standard features), and high-end products (providing higher-end, richer features). For ease of understanding, assume that the low-end product's features include photography, the mid-range product's features include photography and photo editing, and the high-end product's features include photography, photo editing, and portrait enhancement. To save R&D costs, modern management methods and software engineering practices generally align products within the same product family with the same design and software version—that is, the same image. Within the same product family, placing the high-end product's software version in the low-end product may require the low-end product to have more storage space, hindering cost reduction. Furthermore, placing an image that includes photography, photo editing, and portrait enhancement features in a low-end product that generally only requires photography is a waste of storage space. For products of different tiers, the second device can run the target code with different sets of target use cases, thereby achieving different function coverage, i.e., different small and complementary images. For example, for small images and complementary images that need to be used in high-end products, the second device runs target use case set 1 through the target code, and target use case set 1 includes taking pictures, photo editing, and character beautification. For small images and complementary images that need to be used in mid-range products, the second device runs target use case set 2 through the target code, and target use case set 2 includes taking pictures and photo editing. For small images and complementary images that need to be used in low-end products, the second device runs target use case set 3 through the target code, and target use case set 3 includes taking pictures. For source code, the function dependency rate is fixed, but the function coverage rate can be adjusted according to the target use case set. Therefore, the image obtained according to the coverage rate is suitable for the scenario of the product family.

[0143] In other embodiments, a certain product family includes low-end, mid-end and high-end products, the image of the low-end product is obtained based on target use case set 1, the image of the mid-end product is obtained based on target use case set 2, and the image of the high-end product is obtained based on target use case set 3, target use case set 1 is a subset of target use case set 2, and target use case set 2 is a subset of target use case set 3. Among them, it can be determined whether these three products are products of the same product family through the source code, image, product release time, product name, etc. used by the low-end, mid-end and high-end products. For example, when the source code corresponding to these three products is the same or similar, then these three products are products of the same product family; for example, when the product names corresponding to these three products are similar, then these three products are products of the same product family, for example, the name of the low-end product is ZXX5-m, the name of the mid-end product is ZXX5, and the name of the high-end product is ZXX5-pro or ZXX5-sup or ZXX5-mate.

[0144] In other embodiments, a product family includes low-end and high-end products, the image of the low-end product is obtained based on target use case set 1, and the image of the high-end product is obtained based on target use case set 2, and the target use case set 1 is a subset of the target use case set 2.

[0145] Finally, coverage-based trimming can be used to trim source code that contains external function interfaces (such as shared libraries and OS kernels). When compiling source code that contains external function interfaces, the compiler cannot predict which interfaces in the external interface set of this source code will be used by third-party programs. For example, the C library glibc provides thousands of external function interfaces. When compiling the C library glibc, the compiler cannot predict which interfaces in the glibc external interface set will be used by third-party programs. Trimming based on coverage can call some or all of the external function interfaces in the C library glibc by setting a target use case set, so that some or all functions in the external function interface are in a small real function set. In trimming based on function dependency, since the compiler needs to scan dependencies; for programs without entry points (such as shared libraries), the compiler cannot scan function dependencies from the entry point, so that some or all of the external function interfaces in the C library glibc cannot be included in the function set B.

[0146] It should be noted that the small image obtained according to the coverage in the embodiment of the present application does not necessarily include small functions. Figure 8 As shown, Figure 8 Schematic diagram of the process of obtaining a mirror image based on coverage in an embodiment of the present application. Figure 8 The small real function set in is the function that is run when the source code runs the target use case set. The complementary real function set is the function that is not run when the source code runs the target use case set. The stub function set can be an empty function set. Figure 8 For the related description, please refer to the above Figure 2 Related description in .

[0147] The program processing method provided by this application is described above. Through the program processing method provided by this application, the second device obtains a small image and a complementary image according to the source code. The small image is also called a first small image, and the complementary image is also called a first complementary image. For the small image and complementary image obtained by this method, the first device can use Figure 2 The method described above runs the small image and the complementary image, that is, the first device does not call the complementary real function in the complementary image through the small stub function in the small image. Figure 2The following describes the program execution method provided by this application, in which the first device calls the complementary real function through a small stub function. For the sake of brevity, the description related to the program execution method in the above program processing method, such as the contents of the small image and the complementary image, the contents of the small stub function, etc., can be referenced to the program execution method accordingly. Please refer to Figure 9 , Figure 9 Schematic diagram of the process of executing a program in an embodiment of the present application.

[0148] In step 91, the first device receives a call request for a small stub function. When the first program is started, the first device loads the function that the first program needs to call into the running memory. The function that the first program needs to call includes a complementary real function. Therefore, the first device can receive a call request for a small stub function (corresponding to the complementary real function). Specifically, the code in the first program will include the function name of the small stub function. The first device preferentially searches for the function name in the small image, and then loads the searched small stub function into the running memory. The function that the first program needs to call does not mean that the first device will definitely run the function. When the first program does not start the related function corresponding to the function, the function will be stored in the running memory, waiting for the corresponding related function to be started. When the corresponding related function is started, the first device will run the function. The function that the first program needs to call may include functions in the small real function set, or may not include functions in the small real function set. The first program can Figure 9 The first program is not necessarily a third-party program, but may also be a program that comes with the computer system of the first device.

[0149] In step 92, the first device loads the small stub function according to the call request. The small image includes a small stub function set and a small real function set, and the small stub function set includes the small stub function. The first device loads the small stub function into the small image according to the call request.

[0150] In step 93, the first device determines to load the complementary real function corresponding to the small stub function based on the small stub function. When the first program starts the related function corresponding to the small stub function, the first device will attempt to run the small stub function. If an exception is detected, the first device loads the complementary real function. Specifically, the complementary function is dynamically linked, and the first device calls the loader to load the complementary real function. The loader loads the complementary real function in the complementary image from a specific path based on the small stub function. The "specific path" described here refers to an agreed, fixed path; for example, the system often searches for libraries from / lib and / usr / lib by default.

[0151] The above program processing method specifically describes two ways to generate exceptions. One of them is to set the attribute corresponding to the section where the small stub function is located to non-executable. Attributes generally include whether it is readable, writable, and executable. When the attribute is set to non-executable, the first device cannot run the small stub function, thereby detecting an exception. The other way is to realize the exception through the content of the code in the small stub function. In the first way, the first device does not run the code in the small stub function; in the second way, the first device runs part of the code in the small stub function.

[0152] Loading complementary real functions by detecting anomalies is a preferred method in the embodiments of the present application. Through this method, the first device can know that the first program is about to start the relevant functions corresponding to the complementary real functions, and then load the complementary real functions. Before the first device detects an anomaly, the first device does not load the complementary real function. When an anomaly is detected, it means that the small stub function has not been successfully executed. At this time, the first program will not continue to execute because the small stub function has been executed. Therefore, the embodiments of the present application not only add a buffer for loading complementary real functions, but also pause the first program, providing a time basis for loading complementary real functions, reducing possible errors in the first program, and improving user experience.

[0153] The above describes a method for loading complementary real functions by detecting an exception. The following describes a method for loading complementary real functions without detecting an exception. A first device monitors a physical address. When the value at the physical address is updated, the first device can detect this update. A small stub function contains code that writes a value to the physical address. When a first program executes the function corresponding to the complementary real function, the first device executes the small stub function and writes the value to the physical address. After the first device detects the update of the value at the physical address, the first device uses the processor to pause the execution of the first program. Based on the small stub function and the corresponding relationship, the first device searches for the complementary real function in the complementary image. The loader loads the complementary real function and redirects the first program to complete the call to the complementary real function. This method requires the first device to constantly monitor the physical address for updates, and the processor to promptly pause the first program. Otherwise, the first program may mistake the small stub function for the complementary real function and skip the call to the complementary real function, causing an exception in the first program's operations.

[0154] As described in the program processing method above, the second device maintains the correspondence between the small stub function and the complementary real function. This correspondence can be a sequence number, a mapping table, or the function name of the small stub function and the function name of the complementary real function. If the correspondence is a sequence number, the first device can obtain the sequence number of the small stub function. When the complementary real function needs to be loaded through the small stub function, the second device uses the sequence number to load the complementary real function with the same sequence number from the complementary image. If the correspondence is a mapping table, the first device also needs to obtain the mapping table. If the correspondence is a function name, the function name of the small stub function can be the same as or similar to the function name of the complementary real function.

[0155] According to the description in the above program processing method, the second device replaces the source function in the source code with the target function through "IDization" and generates a target correspondence. Therefore, the small image and / or complementary image obtained through the source code includes the target function. When the first program runs the target function, the first device can obtain the target string. The first device sends the target string to the second device or other devices, and the second device or other devices obtains the source string through the target correspondence of the target string. If the string is a log, the restored source string is generally in a language that is easy for humans to read. It should be noted that the target function can be a function in a small real function set, or a function in a complementary real function set, that is, the target function can be a complementary real function. In other embodiments, the first device may also store a target correspondence, and when it is necessary to read the source string, the first device obtains the source string based on the target correspondence and the target string.

[0156] In a distributed scenario of another embodiment, the first device locally stores the small image 1, and the complementary image 1 is stored on a second device, which can be a cloud platform or a central device. The second device here may or may not be the second device in the aforementioned program processing method. When the first device needs to call a complementary real function in the complementary image, the first device calls the complementary real function from the cloud platform or the central device, reducing the cost of the first device. Furthermore, the second device provides complementary images 1 to multiple first devices, saving the cost of multiple first devices.

[0157] In other embodiments, the small image in the embodiment of the present application is dynamically linked. Through dynamic linking, the occupation of the first program on the running memory of the first device is further reduced.

[0158] In other embodiments, after the first device calls the complementary real function according to the program execution method in the embodiment of the present application, the first device sends relevant information about the complementary real function to the second device or other devices, and the second device can update the small mirror and the complementary mirror according to the relevant mirror. The small mirror and the complementary mirror before the update are called the first small mirror and the first complementary mirror, and the small mirror and the complementary mirror after the update are called the second small mirror and the second complementary mirror. Before the update, the complementary real function is in the complementary real function set of the first complementary mirror, and after the update, the complementary real function is in the small real function set of the second small mirror. Simply put, the second device expands the volume or range of the small real function set and reduces the volume or range of the complementary real function set.

[0159] The above describes the program processing method and program execution method in the embodiment of the present application. The following describes the program processing device and program execution device in the embodiment of the present application. Figure 10 , Figure 10 Schematic diagram of the structure of the program execution device in the embodiment of the present application.

[0160] The device includes: a receiving module 1001, configured to receive a call request from a first program for a small stub function, where the small stub function is a function in a small stub function set, and the first small image includes the small stub function set and a small real function set;

[0161] Loading module 1002, used to load a small stub function according to a call request;

[0162] Processing module 1003 is configured to determine, based on the small stub function, whether to load a complementary real function corresponding to the small stub function, where the complementary real function is a function in a complementary real function set. The first complementary image includes a complementary real function set and a complementary stub function set. The complementary stub function set corresponds to the small real function set, and the complementary real function set corresponds to the small stub function set.

[0163] In other embodiments, the device may further include a first sending module or a second sending module. The modules in the device are specifically used to perform the above Figure 9 The first device in the corresponding embodiment may perform all or part of the operations.

[0164] See also Figure 11 , Figure 11 Schematic diagram of the structure of the program processing device in the embodiment of the present application.

[0165] The apparatus includes: a sending module 1101, configured to send a first small image to a first device, the first small image including a small real function set and a small stub function set, the small stub function set corresponding to a complementary real function set of the first complementary image, the small real function set corresponding to a complementary stub function set of the first complementary image, the small stub function set including a small stub function, the small stub function being used by the first device to determine whether to load a complementary real function corresponding to the small stub function according to the small stub function, the complementary real function set including the complementary real function.

[0166] In other embodiments, the device may further include a receiving module or a processing module. The modules in the device are specifically used to perform the above Figure 5 or Figure 6 The second device in the corresponding embodiment may perform all or part of the operations.

[0167] The program processing apparatus and program execution apparatus in the embodiments of the present application are described above. The first device and the second device in the embodiments of the present application are described below.

[0168] See also Figure 12 , Figure 12 This is a structural diagram of the first device or the second device in an embodiment of the present application.

[0169] like Figure 12 As shown, the device for processing a program or executing a program 1200 includes a processor 1210 and a memory 1220 coupled to the processor 1210. The processor 1210 can be a central processing unit (CPU), a network processor (NP), or a combination of a CPU and an NP. The processor can also be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The above-mentioned PLD can be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof. The processor 1210 can refer to one processor or include multiple processors.

[0170] Memory 1220 may include volatile memory, such as random-access memory (RAM); memory 1220 may also include non-volatile memory, such as read-only memory (ROM), FRAM memory, flash memory, hard disk drive (HDD) or solid-state drive (SSD); memory 1220 may also include a combination of the above types of memory.

[0171] when Figure 12 When it is a structural diagram of the program execution device:

[0172] The processor 1210 is configured to receive a call request from a first program for a small stub function, where the small stub function is a function in a small stub function set, and the first small image includes the small stub function set and a small real function set; load the small stub function according to the call request; and determine, based on the small stub function, whether to load a complementary real function corresponding to the small stub function, where the complementary real function is a function in the complementary real function set, and the first complementary image includes the complementary real function set and a complementary stub function set, where the complementary stub function set corresponds to the small real function set, and the complementary real function set corresponds to the small stub function set.

[0173] In other embodiments, the processor 1210 is further configured to execute the computer-readable instructions in the memory 1220 and, in accordance with the instructions of the computer-readable instructions, perform all or part of the operations that the first device can perform, such as the first device performing the following operations in conjunction with the computer-readable instructions: Figure 9 The operations performed in the corresponding embodiments.

[0174] when Figure 12 When it is a structural diagram of a program processing device:

[0175] Processor 1210 is configured to send a first small image to a first device. The first small image includes a small real function set and a small stub function set. The small stub function set corresponds to the complementary real function set of the first complementary image. The small real function set corresponds to the complementary stub function set of the first complementary image. The small stub function set includes a small stub function. The small stub function is used by the first device to determine whether to load a complementary real function corresponding to the small stub function based on the small stub function. The complementary real function set includes complementary real functions.

[0176] In other embodiments, the processor 1210 is further configured to execute the computer-readable instructions in the memory 1220 and, in accordance with the instructions of the computer-readable instructions, execute all or part of the operations that the second device can execute, such as the second device Figure 5 or Figure 6 The operations performed in the corresponding embodiments.

[0177] In the several embodiments provided in this application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.

[0178] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.

[0179] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.

[0180] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as flash drives, mobile hard drives, ROM, RAM, magnetic disks or optical disks.

Claims

1. A program execution method, characterized in that: Applied to a computer system, the computer system includes a first small image, the first small image is a miniaturized operating system, and the method includes: receiving a call request from a first program for a small stub function, wherein the small stub function is a function in a small stub function set, the first small image includes the small stub function set and a small real function set, the small stub function being a buffer for a computer device to load complementary real functions, and the small real function set being a set of functions executed by the target code when executing a target use case set; Loading the small stub function according to the call request; Determine whether to load a complementary real function corresponding to the small stub function based on the small stub function, where the complementary real function is a function in a complementary real function set, and the complementary real function set is a set of functions that the target code does not run when running the target use case set. The first complementary image includes the complementary real function set and a complementary stub function set, and the complementary stub function set corresponds to the small real function set, and the complementary real function set corresponds to the small stub function set.

2. The method according to claim 1, characterized in that Determining whether to load a complementary real function according to the small stub function includes: The small stub function is attempted to be executed according to the instructions of the first program, and if an exception is detected, the complementary real function is loaded.

3. The method according to claim 1, characterized in that The method further comprises: A target function is loaded, the target function including a target string, the data amount of the target string is smaller than the data amount of the source string, the target code including the target function, the target code being obtained according to source code, the source code including a source function, and the source function including the source string.

4. The method according to claim 3, characterized in that After loading the target function, the method further includes: The target character string is sent to the second device, where the target character string is used by the second device to obtain the source character string according to the target correspondence relationship and the target character string.

5. The method according to claim 2, characterized in that The loading of the complementary real function comprises: The complementary real function is loaded from a second device according to the small stub function.

6. The method according to any one of claims 1 to 5, characterized in that The first complementary image and the first small image are stored in different storage media of the first device.

7. The method according to any one of claims 1 to 5, characterized in that The method further comprises: If it is determined to load the complementary real function based on the small stub function, relevant information of the complementary real function is sent to the second device, and the relevant information is used by the second device to obtain a second small image based on the relevant information, where the second small image includes the small real function set and the complementary real function.

8. A program processing method, characterized in that: include: The second device sends a first small image to the first device. The first small image is a miniaturized operating system. The first small image includes a small real function set and a small stub function set. The small stub function is a buffer for the computer device to load complementary real functions. The small real function set is a function set run by the target code when running the target use case set. The small stub function set corresponds to the complementary real function set of the first complementary image. The complementary real function set is a function set not run by the target code when running the target use case set. The small real function set corresponds to the complementary stub function set of the first complementary image. The small stub function set includes a small stub function. The small stub function is used by the first device to determine whether to load a complementary real function corresponding to the small stub function based on the small stub function. The complementary real function set includes the complementary real function.

9. The method according to claim 8, characterized in that The small stub function is specifically used for the first device to try to run the small stub function according to the instruction of the first program, and if an exception is detected, load the complementary real function.

10. The method according to claim 8, characterized in that The target code includes a target function, the target function includes a target string, the data volume of the target string is smaller than the data volume of the source string, the target code is obtained according to the source code, the source code includes a source function, and the source function includes the source string.

11. The method according to claim 10, characterized in that The target character string is used to obtain the source character string in a corresponding relationship with the target.

12. The method according to any one of claims 8 to 11, characterized in that The first device stores the first small image, and the first small image and the first complementary image are stored in different devices.

13. The method according to any one of claims 8 to 11, characterized in that The first complementary image and the first small image are stored in different storage media of the first device.

14. The method according to any one of claims 8 to 11, characterized in that The method further comprises: The second device receives the relevant information of the complementary real function sent by the first device; The second device obtains a second small image according to the relevant information, where the second small image includes the small real function set and the complementary real function.

15. A program execution device, characterized in that: The device is installed with a computer system, the computer system includes a first small image, the first small image is a miniaturized operating system, and the device includes: a receiving module, configured to receive a call request from a first program for a small stub function, wherein the small stub function is a function in a small stub function set, the first small image including the small stub function set and a small real function set, wherein the small stub function is a buffer for loading complementary real functions into a computer device, and the small real function set is a set of functions executed by the target code when executing a target use case set; A loading module, configured to load the small stub function according to the call request; A processing module is configured to determine, based on the small stub function, whether to load a complementary real function corresponding to the small stub function, where the complementary real function is a function in a complementary real function set, the complementary real function set being a set of functions that are not executed by the target code when executing the target use case set, the first complementary image including the complementary real function set and a complementary stub function set, the complementary stub function set corresponding to the small real function set, and the complementary real function set corresponding to the small stub function set.

16. The device according to claim 15, characterized in that The processing module is specifically configured to attempt to run the small stub function according to instructions of the first program, and load the complementary real function if an exception is detected.

17. The device according to claim 15, characterized in that The loading module is also used to load a target function, which includes a target string. The data volume of the target string is smaller than the data volume of the source string. The target code includes the target function. The target code is obtained based on the source code. The source code includes the source function. The source function includes the source string.

18. The device according to claim 17, characterized in that The device further comprises: The first sending module is configured to send the target character string to the second device, where the target character string is used by the second device to obtain the source character string according to the target correspondence relationship and the target character string.

19. The device according to claim 16, characterized in that The processing module is specifically configured to load the complementary real function from the second device according to the small stub function.

20. The device according to any one of claims 15 to 16, characterized in that The first complementary image and the first small image are stored in different storage media of the first device.

21. The device according to any one of claims 15 to 16, characterized in that The device further comprises: A second sending module is configured to send relevant information of the complementary real function to a second device if it is determined to load the complementary real function according to the small stub function, whereby the second device is used to obtain a second small image according to the relevant information, where the second small image includes the small real function set and the complementary real function.

22. A program processing device, characterized in that: include: A sending module is configured to send a first small image to a first device, where the first small image is a miniaturized operating system and includes a small real function set and a small stub function set. The small stub function is a buffer for a computer device to load complementary real functions. The small real function set is a function set executed by a target code when running a target use case set. The small stub function set corresponds to a complementary real function set of the first complementary image. The complementary real function set is a function set not executed by the target code when running the target use case set. The small real function set corresponds to a complementary stub function set of the first complementary image. The small stub function set includes a small stub function. The small stub function is used by the first device to determine, based on the small stub function, whether to load a complementary real function corresponding to the small stub function. The complementary real function set includes the complementary real function.

23. The device according to claim 22, characterized in that The small stub function is specifically used for the first device to try to run the small stub function according to the instruction of the first program, and if an exception is detected, load the complementary real function.

24. The device according to claim 22, characterized in that The target code includes a target function, the target function includes a target string, the data volume of the target string is smaller than the data volume of the source string, the target code is obtained according to the source code, the source code includes a source function, and the source function includes the source string.

25. A program execution device, characterized in that: include: processor and memory; The memory stores a first small image and an execution program, wherein the first small image includes a small stub function; The processor is used to obtain the execution program from the memory and process the small stub function according to the execution program. The specific processing method includes the method described in any one of claims 1 to 7.

26. A program processing device, characterized in that include: processor and memory; The memory stores a processing program; The processor is used to obtain the processing program from the memory, and obtain a first small image according to the processing program and source code. The specific processing method includes the method described in any one of claims 8 to 14.

Citation Information

Patent Citations

  • Program compiling method, device and system

    CN110147238A

  • Dynamically loadable stub modules

    US20050071856A1