Service pack generation method, readable storage medium, program product and electronic equipment

By comparing the section contents of the compiled file, a patch package of the difference section fragments is generated, which solves the problems of low patch package efficiency and large data volume caused by compilation optimization, and realizes efficient patch package generation.

CN121635888APending Publication Date: 2026-03-10HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

Existing compilation tools cannot effectively utilize compilation optimizations when generating patch packages, resulting in low running efficiency and large data volume in the generated patch packages, and the inability to extract differences between non-redirectable files.

Method used

By comparing the section contents in the first and second compiled files, the differing section segments are identified and stored in a reversible file to generate a patch package. This reduces the storage of identical content and optimizes the data volume and running efficiency of the patch package.

Benefits of technology

It achieves a balance between the effectiveness and data volume of the generated patch package under compilation optimization, improving the running efficiency of the patch package and reducing data storage requirements.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121635888A_ABST
    Figure CN121635888A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of computers, and discloses a service pack generation method, a readable storage medium, a program product and electronic equipment. In the method, the electronic equipment can compare contents of at least one first type of section in a first compiling file obtained by compiling and optimizing an original code file with contents of at least one first type of section in a second compiling file obtained by compiling and optimizing the original code file; and determining different section segments (such as a difference function, a correlation function of the difference function, read-only data associated with the difference function / the correlation function of the difference function, exception handling information and the like) which have differences relative to the first type of sections of the first compiled file in the first type of sections of the second compiled file. Finally, the electronic device may generate a service pack based on the determined difference section segments. In this way, the service pack does not need to store the segment fragment, which is the same as the first type of segment of the first compiled file, in the first type of segment of the second compiled file, and the data size of the service pack can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a method for generating patch packages, a readable storage medium, a program product, and an electronic device. Background Technology

[0002] Patch technology is an effective way to address vulnerabilities in operating systems and / or applications. By installing patches for corresponding vulnerabilities in electronic devices, the devices can replace the vulnerable functions by executing the functions in the patch, thereby fixing the vulnerabilities.

[0003] refer to Figure 1 The patch package building process can include: the electronic device compiles the vulnerable code file (hereinafter referred to as the original code file) and the code file that fixes the vulnerability in the original code file (hereinafter referred to as the patch code file) into reversible files (e.g., files with the .o extension) using a compilation tool (hereinafter, the reversible file obtained by compiling the original code file is called the original reversible file, and the reversible file obtained by compiling the patch code file is called the patch reversible file). Then, the electronic device can use a difference extraction tool (e.g., the difference extraction tool in kpatch, livepatch, ksplice) to extract the content that differs from the original reversible file from the patch reversible file, and then generate the patch package based on the extracted content that differs.

[0004] To improve code execution efficiency, compilers can optimize code files during compilation using techniques such as link-time optimization (LTO) and binary optimization and layout tool (BOLT). However, the difference extraction tools in compilers only support extracting differences between reversible files. During compilation optimization, the data structure (or data organization) of the compiled output changes, resulting in a data structure different from that of reversible files (e.g., files with the .so extension). These reversible files are referred to as non-reversible files. Therefore, difference extraction tools cannot extract the differences between the original non-reversible files (original non-reversible files) and the patch non-reversible files (patch non-reversible files) obtained from compiling the original code file. Consequently, they cannot generate patch packages that only include the differences between the original and patch non-reversible files. Therefore, current compilers typically do not support compilation optimization during patch generation (e.g., hot patching), leading to lower execution efficiency in the generated patch packages. Summary of the Invention

[0005] This application provides a method for generating patch packages, a readable storage medium, a program product, and an electronic device.

[0006] Firstly, a patch package generation method is provided, applied to electronic devices. The method includes: obtaining a first compiled file and a second compiled file, wherein the first compiled file is a compiled file obtained by compiling a first code file through compilation optimization, and the second compiled file is a compiled file obtained by compiling a second code file through compilation optimization. The second code file is a code file that fixes vulnerabilities in the first code file. The compiled files are executable and linkable format files, and include a first type of section, which includes at least one of a code section, a read-only data section, and an exception information section; comparing the contents of the first type of section in the first and second compiled files, and determining at least one difference section fragment in the first type of section of the second compiled file that differs from the first type of section in the first compiled file; and obtaining a patch package based on the at least one difference section fragment.

[0007] Based on the above method, the electronic device can determine the segment segments that differ in each of the first type of sections by comparing the contents of the first and second compiled files. These segments (e.g., segment segments of differing functions, segment segments of differing read-only data, segment segments of differing functions, and segment segments corresponding to exception handling information of differing functions) can then be used to generate a patch package. Therefore, the patch package does not need to store the contents of segment segments other than the differing segments in each of the first type of sections, which helps reduce the data size of the patch package.

[0008] In one possible implementation of the first aspect above, obtaining a patch package based on at least one differential section segment includes: storing at least one differential section segment in a reversible file, and obtaining a patch package based on the reversible file, wherein the reversible file includes a first type of section segment, and the differential section segment corresponding to each first type of section segment is stored in the corresponding first type of section segment in the reversible file.

[0009] In this method, the electronic device can store the difference section fragments in one or more relocatable files, and relink the functions and data based on the relocatable files to obtain the patch package.

[0010] In one possible implementation of the first aspect described above, determining at least one difference section segment in the first type of section of the second compiled file that differs from the first type of section of the first compiled file includes: determining, based on the function information of each function in the first compiled file and the function information of each function in the second compiled file, the first section segment corresponding to the code section of the first compiled file and the second section segment corresponding to the code section of the second compiled file, wherein the function information includes the size of the function and the starting address where the function is stored in the corresponding code section; determining, based on the first section segment and the second section segment corresponding to each function, the difference functions that satisfy the first condition among the functions; and using the second section segment corresponding to the difference function as the difference section segment of the code section.

[0011] In this implementation, the electronic device separates the first section segment and the second section segment corresponding to each function in the first and second compilation files based on the function information of each function. Based on the comparison of the contents of the first section segment and the second section segment of each function, it determines the difference function in the second compilation file that differs from that in the first compilation file, and places the difference function in the difference section segment of the code section of the second compilation file.

[0012] In one possible implementation of the first aspect above, the first condition includes at least one of the following conditions: the size of the first section segment and the second section segment corresponding to the function are different; the content pointed to by the relocation term in the first section segment of the function is different from the content pointed to by the relocation term in the second section segment; the first section segment of the function and the other contents in the second section segment, excluding the relocation term, are different.

[0013] In this implementation, if the sizes of the first and second section segments of a function are different, it indicates that the contents of the first and second section segments of the function are different, and the function is identified as a difference function. If the contents of the first and second section segments of a function differ except for the relocation terms, it indicates that the function logic of the first and second section segments may be different, and the function is identified as a difference function.

[0014] If a function corresponds to the same size in the first and second section segments, but the content pointed to by the relocation entries in the first and second section segments differs, then the function is considered a difference function. If the relocation entries in the first and second section segments of a function differ in content but point to the same content, then the function logic corresponding to the first and second section segments is identical, and the function is not identified as a difference function. This reduces the number of difference functions, which helps to further reduce the data size of the patch package.

[0015] In one possible implementation of the first aspect above, the method further includes: determining the associated function of each difference function based on the call chain corresponding to each difference function in the second compilation file; taking the second section segment corresponding to the associated function of each difference function as the difference section segment of the code section; wherein, the first difference function in the difference function includes the first call chain, and the associated function of the first difference function on the first call chain includes the first basic function traversed from the first difference function to the calling difference function in the first call chain, and the function on the first call chain between the first difference function and the first basic function.

[0016] In this implementation, the electronic device can also identify the section segment corresponding to the associated function of the difference function in the code section of the second compiled file as the difference section segment. This avoids the difference function in the patch package failing to be called correctly because it is part of a function (e.g., an inline function, a cold instruction block, or a hot instruction block), thus improving the effectiveness of the patch package.

[0017] In one possible implementation of the first aspect above, the reversible file includes a symbol table section; and storing at least one difference section fragment in the reversible file includes: for a difference function, or a first function that is not a base function among the related functions of the difference function, adding a new first symbol in the symbol table section of the reversible file to indicate the first function.

[0018] In this implementation, if a difference function or its associated function is not a base function, the electronic device can add a new symbol in the include symbol table section of the redirected file to indicate that the function is not a base function, so that the redirectable file can be linked correctly.

[0019] In one possible implementation of the first aspect above, determining at least one difference section segment in the first type of section of the second compiled file that is different from the first type of section of the first compiled file further includes: determining the frame description entry corresponding to each difference function and / or the associated function of each difference function in the exception information section of the second compiled file, and the general information entry corresponding to each frame description entry; and taking the section segment corresponding to the exception information section of the second compiled file as the difference section segment of the exception information section.

[0020] In this implementation, the exception information section of the second compiled file, apart from the frame description entries corresponding to the difference functions and their associated functions, and the general information entries corresponding to each frame description entry, does not need to be stored in the reversible file, and therefore will not be stored in the patch package. This helps to reduce the data size of the patch package.

[0021] In one possible implementation of the first aspect above, the relocatable file further includes a relocation item section; and determining at least one difference section fragment in the first type section of the second compiled file that is different from the first type section of the first compiled file further includes: storing the difference section fragment of the exception information section in the exception information section of the relocatable file, and updating the relocation information corresponding to each difference function and / or each difference function's associated function in the relocation item section of the relocatable file; wherein, the relocation information of the second function in the relocation item section of the relocatable file points to the storage location of the frame description entry corresponding to the second function in the exception information section of the relocatable file, and the second function is any function among each difference function and / or each difference function's associated function.

[0022] In one possible implementation of the first aspect described above, determining at least one difference section segment in the first type of section of the second compiled file that differs from the first type of section of the first compiled file further includes: determining a third section segment whose content differs from the read-only section of the second compiled file based on a comparison of the contents of the read-only data sections of the first and second compiled files; if the second compiled file contains first signed read-only data corresponding to the third section segment, then a fourth section segment in the read-only data section of the second compiled file corresponding to the first signed read-only data is taken as a difference section segment of the read-only data section; or, if the second compiled file does not contain signed read-only data corresponding to the third section segment, then a fifth section segment in the read-only data section of the second compiled file is taken as a difference section segment of the read-only data section. The fifth section segment is the section segment between the first signed read-only data before the third section segment and the first signed read-only data after the third section segment in the read-only data section of the second compiled file; or, corresponding to the case where the data corresponding to the third section segment is a read-only string, the sixth section segment in the read-only data section of the second compiled file is used as the difference section segment of the read-only data section, wherein the sixth section segment is the section segment between the first string terminator before the third section segment and the first string terminator after the third section segment in the read-only data section of the second compiled file; or, corresponding to the case where there is a first read-only constant corresponding to the third section segment in the second compiled file, the seventh section segment in the read-only data section of the second compiled file corresponding to the first read-only constant is used as the difference section segment of the read-only data section.

[0023] In this implementation, for signed read-only data, unsigned read-only data, read-only strings, and read-only constants in the read-only data section, the electronic device can extract the corresponding difference section fragments from the second compiled file for the signed read-only data, unsigned read-only data, read-only strings, and read-only constants that differ from each other. Thus, other read-only data besides the read-only data corresponding to these difference fragments does not need to be stored in the reversible file and therefore will not be stored in the patch package. This helps reduce the data size of the patch package.

[0024] In this implementation, for the unsigned read-only data corresponding to the third section segment, the electronic device uses the section segment between the first signed read-only data before the third section segment and the first signed read-only data after the third section segment as the difference section segment. This avoids the situation where only the third section segment is used as a difference section segment, resulting in incomplete extraction of a portion of the read-only data, thus improving the effectiveness of the patch package. For example, assuming the address range of the third section segment is 0x100 to 0x130, and the address range of an unsigned read-only data is 0x095 to 0x105, using only the third section segment as a difference section segment would result in the reversible file storing only a portion of the signed read-only data, making it impossible for the electronic device installing the patch package to accurately extract the unsigned read-only data. In one possible implementation of the first aspect described above, the reversible file includes a symbol table section; and storing at least one difference section segment in the reversible file further includes adding symbols to the symbol table section of the reversible file to respectively indicate each fifth section segment or each sixth section segment.

[0025] In this implementation, for the difference section segments corresponding to unsigned read-only data and read-only strings, the electronic device can add symbols to the symbol table section of the reversible file to indicate those difference segments. This allows the electronic device to accurately extract the relevant data during the linking process or when the patch package is running.

[0026] In one possible implementation of the first aspect above, the executable and linkable format file has the extension .so.

[0027] In one possible implementation of the first aspect above, the aforementioned compilation optimization process includes one or more of link-time optimization, compiler feedback optimization, and binary optimization layout tool optimization.

[0028] In a second aspect, a readable storage medium is provided, on which instructions are stored, which, when executed by an electronic device, cause the electronic device to implement the first aspect and any possible implementation of the patch package generation method provided above.

[0029] Thirdly, an electronic device is provided, comprising: a memory for storing instructions; and at least one processor for executing the instructions to cause the electronic device to implement the first aspect and any possible implementation of the patch generation method provided in the first aspect.

[0030] Fourthly, a computer program product is provided that, when run on an electronic device, enables the electronic device to implement the patch generation method provided in the first aspect and any possible implementation of the first aspect.

[0031] The beneficial effects of the second to fourth aspects mentioned above can be referred to the content of the first aspect mentioned above, and will not be repeated here. Attached Figure Description

[0032] Figure 1 According to some embodiments of this application, a schematic diagram of a process for generating a patch package based on a reversible file is shown.

[0033] Figure 2 According to some embodiments of this application, a schematic diagram of the structure of an ELF file and a .so file is shown.

[0034] Figure 3 According to some embodiments of this application, a schematic diagram is shown of a server storing and sending a full installation package to a terminal.

[0035] Figure 4 According to some embodiments of this application, a schematic diagram of storing differential section fragments in an obj file is shown.

[0036] Figure 5 According to some embodiments of this application, a schematic diagram is shown for determining differential segment fragments in a code segment region.

[0037] Figure 6A According to some embodiments of this application, a schematic diagram of determining a function call chain is shown.

[0038] Figure 6B According to some embodiments of this application, a schematic diagram of a function call chain is shown.

[0039] Figure 7 According to some embodiments of this application, a flowchart illustrating a method for generating patch packages for difference functions is shown.

[0040] Figure 8 According to some embodiments of this application, a schematic diagram is shown for determining differential segment fragments in a read-only data segment.

[0041] Figure 9 According to some embodiments of this application, a schematic diagram is shown for determining differential segment fragments in a read-only string sub-segment region.

[0042] Figure 10 According to some embodiments of this application, a schematic diagram is shown for determining differential segment segments in a read-only constant quantum node region.

[0043] Figure 11 According to some embodiments of this application, a schematic diagram of the extraction process of differential segment of read-only data section is shown.

[0044] Figure 12 According to some embodiments of this application, a schematic diagram is shown for determining differential segment segments in anomaly information segments.

[0045] Figure 13 According to some embodiments of this application, a flowchart of a patch package corresponding to an abnormal information section is shown.

[0046] Figure 14 According to some embodiments of this application, a flowchart of a patch package generation method is shown.

[0047] Figure 15 According to some embodiments of this application, a schematic diagram of the architecture of a patch package generation method is shown.

[0048] Figure 16 According to some embodiments of this application, a schematic diagram of a patch package generation method is shown.

[0049] Figure 17 According to some embodiments of this application, a flowchart of another patch package generation method is shown.

[0050] Figure 18 According to some embodiments of this application, a schematic diagram of the structure of an electronic device 10 is shown. Detailed Implementation

[0051] The embodiments of this application include, but are not limited to, patch generation methods, readable storage media, program products, electronic devices, and systems.

[0052] To facilitate understanding, the terminology used in the embodiments of this application will be introduced first.

[0053] (1) Executable and linkable format (ELF) files

[0054] ELF files are a standard binary file format. Generally, an ELF file consists of four parts: the ELF header, the program header, one or more sections (also called segments), and the section header. The ELF header records basic information about the entire file; the program header records how the file is loaded into memory by the system; the sections store the actual data in the file, such as code and data; and the section header records information about each section, such as its name, size, and location.

[0055] It should be noted that an ELF file may include some or all of the aforementioned four parts.

[0056] It should be noted that ELF files can be packaged into different file formats, such as files with the extension .so (hereinafter referred to as .so files), files with the extension .elf (hereinafter referred to as .elf files), files with the extension .prx (hereinafter referred to as .prx files), etc.

[0057] (2).so file

[0058] A .so file is a type of ELF file, typically the product of compiling and optimizing code. (See reference.) Figure 2 The .so file includes multiple sections, such as the symbol table section (also known as the .symtab section), the initialized data section (also known as the .data section), the uninitialized data (block started by symbol, bss) section (also known as the .bss section), the read-only data section (also known as the .rodata section), the code (text) section (also known as the .text section, text segment, etc.), the exception information section (also known as the .eh_frame section), and the relocation item section (also known as the .rela section).

[0059] The symbol table section contains symbol information for symbols (such as functions, variables, and constants) defined in the file. These symbols can be used by tools such as the linker and debugger to parse and reference code and data in the program. The symbol information recorded in the symbol table section may include, but is not limited to, the symbol's name (e.g., st_name), type (e.g., function, variable, read-only data, read-only string, read-only constant), binding information (e.g., local, global), value (e.g., st_value) (an address for functions and an offset for variables), the size of the data occupied by the symbol (e.g., st_size), and the symbol's relationship with other sections.

[0060] Optionally, the symbol table section can also record function identifiers, such as `hot` (indicating a function is a hot instruction block), `cold` (indicating a function is a cold instruction block), and `.part` (indicating a function is part of another function, which is not a base function). For example, for function A (symbol name A), function A.cold (symbol name A.cold) is a cold instruction block of function A, function A.hot (symbol name A.hot) is a hot instruction block of function A, and function A.part (symbol name A.part) is a part of function A.

[0061] The initialized data section is used to store initialized global and static variables in the program.

[0062] Uninitialized data sections are used to store uninitialized global and static variables in the program.

[0063] Read-only data segments are used to store read-only data in a program, such as read-only strings and read-only constants. This data is not modified during program execution, so it can be placed in read-only memory segments to save memory and improve security.

[0064] The read-only data section can also include one or more subsections, such as read-only data subsections, read-only string subsections (also known as the .rodata.strX section) (used to store read-only data of string type), read-only constant quantum section (also known as the .rodata.cstN section) (used to store read-only data of constant type), etc.

[0065] Code sections are used to store the executable code of a program. In a .so file, the code corresponding to multiple functions or symbols is stored in a single code section.

[0066] The exception information section is used to store debugging information and stack trace information for each function in the file. This part is used for exception handling and stack construction of functions.

[0067] The relocation entry section stores the relocation information required by instructions (such as functions and function segments) in the .so file during linking. The relocation entry section can include multiple subsections, such as the code segment relocation entry subsection (.rela.text subsection) (used to store information about other functions that different functions depend on), and the exception information relocation entry subsection (.rela.eh_frame subsection) (used to store the frame description entry (FDE) corresponding to the exception information of different functions in the exception information section), etc.

[0068] It should be noted that the names of the sections in the above .so file are just examples. In different compilation tools or compilation environments, other names may be used for the sections, which are not limited here.

[0069] It should be noted that the sections in the above .so file are just examples. In different compilation tools or compilation environments, .so files may include more or fewer sections, which is not limited here.

[0070] (3) Redirectable files

[0071] Redirectible files, also known as relocatable object files or relocatable target files, are binary files output by the compiler, typically with the ".o" extension. Redirectible files contain machine code, symbol tables, relocation information, and other data generated during compilation, but they do not contain absolute addresses. Instead, they use relative addresses and symbolic references to represent the relationships between different code segments.

[0072] The technical solutions in this application will now be described with reference to the accompanying drawings.

[0073] As described in the background section, since the difference extraction tool in the compilation tool only supports the extraction of differences between reversible files, and the data structure of the compilation product obtained by compiling and optimizing the compiled code is different from that of the reversible files, the difference extraction tool cannot extract the differences between the compilation products of the original code file and the patch code file.

[0074] For example, during the compilation of code files using compiler optimization, electronic devices may modify cross-files, perform deep compression and folding of file contents, and inline and optimize functions within files. This can lead to situations where functions are deleted or hidden in the generated compilation artifacts, and function differences spread with inlining. As a result, the data structure of the compilation artifacts obtained through compiler optimization is different from that of the reversible files.

[0075] Therefore, current compilation tools offer two methods for compiling patch code files:

[0076] The first method involves compiling the patch code file and the original code file without using compilation optimization to obtain the aforementioned patch reversible file and original reversible file, and then generating a patch package based on the differences between the patch reversible file and the original reversible file.

[0077] The second method involves compiling the patch code files through compilation optimization, and then packaging all the compiled artifacts (such as all .so files) obtained by compiling the patch code files through compilation optimization into a full installation package.

[0078] For the first compilation method, the patch package is smaller in size because it is generated based on the differences between the patch reversible file and the original reversible file. However, since the code in the patch package has not undergone compilation optimization, its running efficiency is low.

[0079] For the second compilation method, the code in the full installer package is optimized and therefore has high execution efficiency. However, because the full installer package includes all the compiled artifacts obtained from compiling and optimizing the patch code files, its data size is large, which is not conducive to the storage and transmission of the patch package. For example, suppose the patch code file is a code file that fixes a minor vulnerability in an application. The difference between the patch code file and the original application code file is small. If all the corresponding .so files are packaged in the full installer package, the data size of the full installer package will be close to the total data size of the application's installer, which is not conducive to the storage and transmission of the full installer package. For example, see reference. Figure 3 The server will consume a lot of storage space when storing the full installation package, and the time it takes for the server to transmit the full installation package to the terminal that is installing the application is long and consumes a lot of data from the terminal device.

[0080] For ease of description, the compiled output obtained by compiling and optimizing the original code file of the electronic device is referred to as the first compiled file, and the compiled output obtained by compiling and optimizing the patch code file of the electronic device is referred to as the second compiled file.

[0081] It should be noted that although the first and second compiled files are non-redirectable files, they are both ELF files (e.g., .so files). In the .so file, different sections are used to store different contents after the code file is compiled (e.g., the aforementioned code section is used to store the executable code of each function in the code file after compilation, the read-only data section is used to store the read-only data involved in the functions in the code file, and the exception information section is used to store exception handling information that indicates how each function should handle exceptions).

[0082] Within the code section, the executable code of a function is stored contiguously. The symbol table section of the .so file records the size of the executable code for different functions and their starting addresses within the code section. Electronic devices can separate the executable code segments corresponding to different functions from the code section based on the size of their executable code and their starting addresses. Thus, by comparing the segment of a function in the code section of a first compiled file with the segment of the same function in a second compiled file, it can be determined whether there are differences in the executable code of that function between the first and second compiled files.

[0083] Within the read-only data section, signed read-only data (read-only data for which a corresponding symbol (e.g., variable, constant, etc.) exists in the symbol table section) and unsigned read-only data (read-only data for which a corresponding symbol (e.g., variable, constant, etc.) does not exist in the symbol table section, also known as anonymous read-only data). For signed read-only data, the corresponding section segment in the read-only data section can be determined by the address range of the signed read-only data within the read-only data section (e.g., start address and end address, or start address and size). For unsigned read-only data, the section segment in the read-only data section can be obtained by extracting the section segment between the corresponding section segments of the signed read-only data within the read-only data section.

[0084] For signed read-only data, the difference between the signed read-only data in the first and second compiled files can be determined by comparing the section fragment of a certain signed read-only data in the read-only data section of the first compiled file with the section fragment of the same signed read-only data in the read-only data section of the second compiled file.

[0085] For unsigned read-only data, the difference between the unsigned read-only data in the first and second compiled files can be determined by comparing the section segments between the two corresponding sections in the read-only data section of the first compiled file and the section segments between the two corresponding sections in the read-only data section of the second compiled file.

[0086] The exception information section stores exception handling information for different functions, and the relocation section of the .so file records the correspondence between functions and their exception handling information in the FDE of the exception information section. Thus, based on this correspondence, the section fragments corresponding to functions whose executable code differs between the first and second compiled files can be extracted from the exception information section of the second compiled file.

[0087] Based on this, to balance the running efficiency and data volume of the patch package, this application provides a patch package generation method. In this method, an electronic device can obtain a first compiled file obtained by compiling and optimizing the original code file and a second compiled file obtained by compiling the patch code file. Then, the electronic device can determine the difference section segments in the first type of sections of the second compiled file that differ from the first type of sections of the first compiled file by comparing the contents of at least one first type of section (e.g., code section, read-only data section, exception information section) in the first and second compiled files. Finally, the electronic device can generate a patch package based on the difference section segments of each first type of section in the second compiled file, for example, by encapsulating the difference section segments of each first type of section in the patch package.

[0088] In this way, the patch package does not need to store the same section segments in the first type of section of the second compiled file as those in the first compiled file, which helps to reduce the data size of the patch package.

[0089] It should be noted that the first and second compiled files can be any ELF file, including but not limited to .so files, .elf files, .ptr files, etc., without any restrictions. For ELF files other than .so files, such as .elf files and .ptr files, the naming of the sections in the files can be different from that in the .so file, without any restrictions.

[0090] In some embodiments, the electronic device may store the difference section fragments of the first type of section (which may also include associated data of functions in the second compiled file that are different from the first compiled file (hereinafter referred to as difference functions)) in one or more or redirected files, such as common object file format (hereinafter referred to as obj files). The electronic device may then generate a patch package based on the one or more obj files (e.g., relinking the functions and related data in the patch package to obtain the patch package).

[0091] It should be noted that the one or more redirected files can be in any format, such as files with extensions like ".o", ".ko", ".so", intermediate representation (IR) files (files that can undergo symbol redirection resolution), source code, and files derived from source code. For ease of description, the following will use "obj" as the name of the one or more redirected files, and the obj file will include at least some sections of the various sections of the second compiled file that correspond to the corresponding sections (e.g., sections with the same or different names). For ease of description, the following will use the example where the names of the sections in the obj file are the same as the names of the corresponding sections in the second compiled file.

[0092] The following uses the .so file as an example to introduce the technical solution of this application.

[0093] For example, a code section segment could be a segment storing the code of functions in the second compiled file that differ from the first compiled file (hereinafter referred to as "difference functions"). Electronic devices can store the code of difference functions within the code section of an obj file. This eliminates the need to store the code of functions other than difference functions in the obj file, thus reducing the size of the patch package. (Reference) Figure 4 If the section segment SS1′ corresponding to function F1 in the code section of the second compiled file is different from the section segment SS1 of function F1 in the code section of the first compiled file, then the electronic device can store the section segment SS1′ into the obj file, for example, in the code section of the obj file. In this way, the patch package section does not need to store the code of functions other than function F1.

[0094] For example, for read-only data sections, the difference section segments can include section segments corresponding to read-only data in the second compiled file that differs from the first compiled file. The electronic device can store the section segments corresponding to the changed read-only data in the patch package. This eliminates the need to store identical read-only data in the second and first compiled files in the patch package, thus reducing the size of the patch package. (Reference) Figure 4 If the section segment SS2′ corresponding to the read-only data ROD1 in the second compiled file is different from the section segment SS2 corresponding to the read-only data ROD1 in the first compiled file, then the electronic device can store the section segment SS2′ into the obj file, for example, in the read-only data section (.rodata section) of the obj file. Thus, the read-only data section of the obj file does not need to store read-only data other than read-only data ROD1.

[0095] For example, for the exception information section, the difference section fragment can include the section fragment corresponding to the exception information of the difference function. The electronic device can store the section fragment corresponding to the exception information of the difference function in the patch package. In this way, it is unnecessary to store the exception information corresponding to functions that are the same in the second compiled file as the first compiled file in the patch package, which helps to reduce the data size of the patch package. (Reference) Figure 4 If the exception information segment SS3′ of function F2 in the read-only data section of the second compiled file (e.g., the segment corresponding to FDE for function F2) differs from the exception information segment SS3 of function F2 in the exception information section of the first compiled file (e.g., the segment corresponding to FDE for function F2), then the electronic device can store the segment SS3′ in the patch package, for example, in the exception information section (.eh_frame section) of the obj file. In this way, the exception information section of the patch package does not need to store exception information (e.g., FDE) for functions other than F2.

[0096] It should be noted that in some embodiments, the associated data of the difference function (e.g., the associated data of the difference function in other sections, such as the .data section, .bss section, etc.) can also be stored in the corresponding section of the obj file. For example, continue to refer to Figure 4 If function F2 has associated data in the .data, .bss, and .rela sections, the electronic device can also store the associated data of function F2 in the .data, .bss, and .rela sections of the second compiled file in the .data, .bss, and .rela sections of the obj file, respectively.

[0097] The following uses .so files as an example to introduce how to determine the differential segment segments for different types of first-order segments.

[0098] In some embodiments, the first and second compiled files are compiled based on Clang (a compilation tool) and the low-level virtual machine (LVMM) compilation toolchain.

[0099] It should be noted that, in some embodiments, the first and second compiled files can also be obtained by any other compilation tool by compiling the original code file and the patch code file respectively based on compilation optimization. This compilation optimization includes, but is not limited to, LTO, BOLT, and profile-guided optimization (PGO) (also known as feedback-directed optimization, FDO).

[0100] First, we will introduce how to determine the difference section segments of the code section.

[0101] In .so files, the executable code of functions is entirely stored in the code section, which is completely different from .o files, where the executable code and dependency data of different functions are stored in different sections. Therefore, current compilation tools cannot separate the section fragments corresponding to different functions from the code section.

[0102] In some embodiments, the electronic device can separate the first section segment corresponding to each function in the first compiled file and the second section segment corresponding to each function in the second compiled file in the code section segment based on the function information (e.g., function name, data size (st_size) of the function (hereinafter referred to as function size), and the starting address of the executable code of the function in the code section segment) recorded in the symbol table section segment. Then, the electronic device can compare the first section segment corresponding to each function in the first compiled file and the second section segment corresponding to the first function in the second compiled file to determine the difference function, and store the second section segment corresponding to the difference function in the code section segment of the second compiled file in the patch package. Thus, the patch package does not need to store section segments corresponding to functions other than the difference function, which helps reduce the data size of the patch package. In some embodiments, if the first section segment corresponding to the first function in the first compiled file and the second section segment corresponding to the first function in the second compiled file satisfy the following difference function conditions, then the first function can be determined to be a difference function.

[0103] For example, the difference function condition may include at least one of the following conditions:

[0104] The first segment and the second segment are of different sizes;

[0105] The content pointed to by the relocation item in the first section segment is different from the content pointed to by the relocation item in the second section segment;

[0106] The content in the first section differs from that in the second section, except for the relocation items.

[0107] For example, Figure 5 According to some embodiments of this application, a schematic diagram is shown for determining differential segment fragments in a code segment region.

[0108] like Figure 5As shown, the symbol table section of the first compiled file records symbols including functions F1, F2, and F3, with sizes of 10 bytes, 20 bytes, and 30 bytes respectively. The symbol table section of the second compiled file also records symbols including functions F1, F2, and F3, with sizes of 10 bytes, 25 bytes, and 30 bytes respectively. The relocation entry in the relocation section of the first compiled file points to function RF3 for function F3, and the relocation entry in the relocation section of the second compiled file points to function RF3' for function F3.

[0109] for Figure 5 As shown, the electronic device can determine the corresponding section segments for functions F1, F2, and F3 based on the function information recorded in the symbol table. For example, in the code section of the first compiled file, since the sizes of functions F1, F2, and F3 are 10 bytes, 20 bytes, and 30 bytes respectively, and their starting addresses are byte 1, byte 11, and byte 31 respectively, then the first 10 bytes of the code section correspond to function F1, the 11th to 30th bytes correspond to function F2, and the 31st to 60th bytes correspond to function F3. In the code section of the second compiled file, since the sizes of functions F1, F2, and F3 are 10 bytes, 25 bytes, and 30 bytes respectively, and their starting addresses are byte 1, byte 11, and byte 36 respectively, then the first 10 bytes of the code section correspond to function F1, the 11th to 35th bytes correspond to function F2, and the 36th to 65th bytes correspond to function F3.

[0110] For function F1, the first section segment corresponding to function F1 in the first compiled file is the first 10th section of the code section of the first compiled file, and the second section segment corresponding to function F1 in the second compiled file is also the first 10th section of the code section of the first compiled file. Since the size of the first section segment of function F1 is the same as the first section segment of function F1, and their contents are identical, function F1 does not satisfy the condition for a difference function, and the electronic device does not identify function F1 as a difference function.

[0111] For function F2, the first section segment corresponding to function F2 in the first compiled file is words 11-30 of the code section of the first compiled file, and the second section segment corresponding to function F2 in the second compiled file is words 11-35 of the code section of the first compiled file. Because the sizes of the first section segments of function F2 and F2 are different, the electronic device can identify function F2 as a difference function.

[0112] For function F3, the first section segment corresponding to function F3 in the first compiled file is words 31-60 of the code section of the first compiled file, and the second section segment corresponding to function F3 in the second compiled file is words 36-65 of the code section of the first compiled file. Since the size of the first section segment of function F3 is the same as the size of the first section segment of function F1, but the relocation term of function F3 in the first section segment points to function RF3, which is different from the function RF3′ pointed to by the relocation term of the function in the second section segment, function F3 satisfies the difference function condition. Therefore, the electronic device identifies function F3 as a difference function.

[0113] Then, the electronic device 10 can identify the section segments corresponding to functions F2 and F3 in the code section of the second code compilation file as the difference section segments of the code section, and store the difference section segments in the obj file. In this way, the section segment corresponding to function F1 in the code section of the second code compilation file does not need to be stored in the patch package, which helps to reduce the data size of the patch package.

[0114] In some embodiments, the compilation optimization process of functions may involve functions inlining, partial inlining, function decomposition, etc., thereby changing the internal calling process of the function. When the differencing function is a part of the inlined code of a base function, or a sub-function within a base function, storing only the code of the differencing function in the patch package can result in incomplete code in the patch package, preventing the electronic device after installing the patch package from correctly calling the differencing function. Therefore, in some embodiments, the section fragment corresponding to the associated function of the differencing function can also be stored in the patch package.

[0115] In some embodiments, a difference function may correspond to one or more call chains, where a call chain includes one or more functions that directly or indirectly call the difference function. For each call chain, the electronic device can traverse from the difference function toward other functions that call the difference function, following the call order of the call chain, until the first base function on that call chain is reached. This first base function, along with the functions between the difference function and the first base function, are recorded as associated functions corresponding to the difference function on that call chain. The electronic device can store the corresponding code segment fragments of the associated functions of each difference function in the code segment section of the obj file. This ensures that the code of the associated functions of the difference function is also completely added to the patch package, preventing the patch package from malfunctioning.

[0116] In some embodiments, the base function is a complete function in the first or second compiled file, rather than a part of a function, or a cold or hot instruction block corresponding to a function. The symbol table section records function identifiers indicating whether a function is a base function (e.g., function identifier .part (or other identifiers) indicates that a function is part of another function, function identifier .cold (or other identifiers) indicates that a function is a cold instruction block of another function, and function identifier .hot (or other identifiers) indicates that a function is a hot instruction block of another function).

[0117] For a given function, an electronic device can determine whether it is a basic function based on whether its function identifier in the symbol table section is ".part", ".hot", or ".cold". For example, if a function's identifier is ".part", ".hot", or ".cold", then the function is not a basic function. Similarly, if a function's name ends with ".part", ".hot", or ".cold", then the function is not a basic function.

[0118] In some embodiments, if the associated function of the difference function includes a non-basic function, the electronic device may also add the non-basic function as a new symbol to the symbol table section area to facilitate subsequent linking of the difference function and its associated function in the patch package.

[0119] In some embodiments, the call chains of each function in the second compiled file can be determined based on information in the relocation entry section and the symbol table section. For example, the electronic device can first determine the functions called by each function in the second compiled file based on the information in the relocation entry section and the symbol table section (e.g., by recording the functions called by each function through a call list (hereinafter referred to as the callee list), and then obtain the call chain corresponding to each function based on the functions called by each function (e.g., by recording the information of each function being called by other functions through a callee list (hereinafter referred to as the caller list)).

[0120] For example, refer to Figure 6A The electronic device can determine the callee list from the information in the relocation section and symbol table section of the .so file (e.g., the second compiled file). The callee list records the functions called by each function in the second compiled file. Then, the electronic device can reverse the insertion of functions in the callee list (traversing from the tail to the head of the callee list) to obtain the caller list.

[0121] For example, refer to Figure 6BIf function A calls function A.part, function A.part calls function C.hot, function C.cold calls function C.hot, and function C calls function C.cold, then the information recorded in the callee linked list is function A → function A.part → function C.hot, and function C.cold → function C.hot. Correspondingly, the information recorded in the caller linked list is function C.hot → function A.part → function A, and function C.hot → function C.cold → function C.

[0122] for Figure 6B In the scenario shown, assume function A is a basic function, function A.part is a part of inline code of function A, the differentiating function is function C.hot, function C.hot is the hot instruction block of function C, and function C.cold is the cold instruction block of function C. The electronic device can look up function C.hot from the aforementioned caller chain list, which includes two call chains: function C.hot → function A.part → function A, and function C.hot → function C.cold. Based on the call chain function C.hot → function A.part → function A, traversing from function C.hot to function A, function A.part is not a basic function, so after traversing function A.part, traversing continues to function A; since function A is a basic function, traversing terminates after reaching function A. The associated functions of function C.hot in this call chain are function A and function A.part. Based on the call chain C.hot → C.cold → C, the traversal proceeds from C.hot to C. Since C.cold is not a basic function, the traversal continues after reaching C.cold. Upon reaching C, since C is a basic function, the traversal terminates. Therefore, the associated functions of C.hot in this call chain are C.cold and C. The electronic device can determine that the associated functions of C.hot include A, A.part, C.cold, and C, where A and C are basic functions, and A.part and C.cold are non-basic functions. The electronic device can add the corresponding code segment fragments of A, A.part, C.cold, C.hot, and C to the code segment of the obj file, and add A.part, C.cold, and C.hot as new symbols to the symbol table segment of the obj file.

[0123] It should be noted that the symbol names of functions A.part, C.cold, and C.hot in the symbol table section of the obj file can be generated randomly, or they can be generated by hashing the contents of functions A.part, C.cold, and C.hot. Alternatively, the names of functions A.part, C.cold, and C.hot in the second compilation file can be used. There are no restrictions here.

[0124] Based on the above, this application provides a function extraction method for determining the difference functions in a first compiled file and a second compiled file, as well as the associated functions of the difference functions.

[0125] For example, Figure 7 According to some embodiments of this application, a flowchart illustrating a method for generating patch packages for difference functions is shown. The execution entity of this process can be an electronic device, such as... Figure 7 As shown, the process includes the following steps:

[0126] S701, based on the function information in the symbol table section of the first and second compiled files, respectively, separates the first section segment corresponding to the code section of the first compiled file and the second section segment corresponding to the code section of the second compiled file.

[0127] In some embodiments, the function to be extracted may include functions recorded in the symbol table section of the first and / or second compiled file.

[0128] For example, the electronic device can extract the first section segment corresponding to the code section of the first compiled file based on the function information (starting address and size in the code section) of each function to be extracted in the symbol table section of the first compiled file. For instance, if a function has a starting address of 0x100 and a size of 200 in the code section, then the first section segment corresponding to that function is the section segment with addresses from 0x100 to 0x299 in the code section of the first compiled file.

[0129] For example, the electronic device can extract the second section segment corresponding to the code section of the second compilation file based on the function information (starting address and size in the code section) of each function to be extracted in the symbol table section of the second compilation file.

[0130] S702, compare the first segment and the second segment corresponding to each function to be extracted to determine the difference function that satisfies the difference function condition.

[0131] After separating the first segment and the second segment corresponding to each function to be extracted, the first segment and the second segment corresponding to each function to be extracted can be compared to determine the difference function that satisfies the difference function condition.

[0132] In some embodiments, the difference function condition may include one or more of the following conditions:

[0133] The first segment of the function to be extracted differs in size from the second segment. If the first segment of the function to be extracted differs in size from the second segment, it indicates a substantial change in the content of the function to be extracted, and the function to be extracted is thus identified as a difference function.

[0134] The content pointed to by the relocation entries in the first segment of the function to be extracted differs from the content pointed to by the relocation entries in the second segment. Based on this condition, if the first and second segments of the function to be extracted differ only in the content of the relocation entries, but the content pointed to by the relocation entries is the same (e.g., pointing to the same function or function segment at different addresses), then the function to be extracted is not considered a difference function, which helps to reduce the number of difference functions.

[0135] The first segment of the function to be extracted differs from the second segment, except for the relocation terms. If the first segment of the function to be extracted differs from the second segment, except for the relocation terms, it indicates a substantial change in the content of the function to be extracted, and the function to be extracted is identified as a difference function.

[0136] In some embodiments, the relocation term may be the address to which the function to be extracted is to jump, which is included in the instruction that needs to be jumped to in the code of the function to be extracted.

[0137] In some embodiments, it can be determined whether the contents of the first section segment and the second section segment of the function to be extracted are the same by comparing the binary contents of the first section segment and the second section segment of the function to be extracted.

[0138] S703, based on the call chain corresponding to each difference function, determines the associated function of each difference function.

[0139] After the difference functions are determined, the electronic device can determine the associated functions of each difference function based on the call chain of each difference function.

[0140] For example, for each call chain that includes a certain difference function, the electronic device can start from that difference function and traverse in the direction of other functions that call the difference function until it reaches the first base function, and treat the first base function and the functions between the difference function and the first base function as the associated functions of the difference function.

[0141] For example, for the call chain recorded in the aforementioned callee linked list, the electronic device can traverse forward from the difference function; for the call chain recorded in the aforementioned caller linked list, the electronic device can traverse backward from the difference function.

[0142] In some implementations, the call chain of the difference function can be determined based on the contents of the relocation section and the symbol table section.

[0143] It should be noted that basic functions are functions in the symbol table that are not part of a function, nor are they hot or cold instruction blocks of a function. Function identifiers (such as the suffix of the function name) do not include functions with ".cold", ".hot", or ".part".

[0144] S704 stores the difference function and its associated function in the code section of the second compiled file in the code section of the obj file.

[0145] After determining the difference function and its associated function, the electronic device can store the difference function and its associated function, along with the corresponding section segment in the code section of the second compiled file, in the code section of the obj file.

[0146] In some embodiments, the electronic device may also store the dependency data of the difference function and its associated functions in other sections in the section corresponding to the patch package. The dependency data of the difference function and its associated functions in other sections may be determined based on the contents of the symbol table section and / or the relocation item section.

[0147] In some embodiments, after determining the difference function and its associated function, the electronic device may also store the difference function and its associated function in the exception information section of the second compiled file, corresponding to the FDE, in the exception information section of the obj file. This will be described in detail below and will not be elaborated upon here.

[0148] Based on the above method, the code sections in the patch package generated by the electronic device only include the difference function and its associated functions, without storing the section fragments corresponding to other functions, which helps to reduce the data size of the patch package. Furthermore, since the associated functions of the difference functions are also stored in the patch package, it avoids the possibility that incomplete associated functions of the difference functions could prevent the difference functions in the patch package from failing to run.

[0149] The following describes how to determine the difference segment segments of read-only data related segments (such as read-only data segments, read-only character substring segments, read-only constant quantum segments, etc.).

[0150] Read-only data section

[0151] For signed read-only data in read-only data sections, the difference between the signed read-only data in the first and second compiled files can be determined by comparing the section fragments of a certain signed read-only data in the first and second compiled files. If the contents of the corresponding section fragments of a certain signed read-only data in the first and second compiled files are different, the electronic device can identify the section fragment corresponding to the signed read-only data in the second compiled file as the difference section fragment of the read-only data section and store the difference section fragment in the obj file (e.g., in the read-only data section of the obj file).

[0152] For unsigned read-only data, the difference between the unsigned read-only data in the first and second compiled files can be determined by comparing the section segments between the corresponding two sections in the read-only data section of the first compiled file and the section segments between the corresponding two sections in the read-only data section of the second compiled file. If the unsigned read-only data differs between the two adjacent signed read-only data in the first and second compiled files, the electronic device can identify the section segments between the corresponding sections in the second compiled file as the difference section segments in the read-only data section. The electronic device can then store this difference section segment in the obj file (e.g., in the read-only data section of the obj file) and add a new symbol to the symbol table section to indicate this difference section segment.

[0153] For example, Figure 8 According to some embodiments of this application, a schematic diagram is shown for determining differential segment fragments in a read-only data segment.

[0154] like Figure 8As shown, the read-only data sections of the first and second compiled files include section segments corresponding to signed read-only data ROD1, signed read-only data ROD2, and signed read-only data ROD3, as well as section segments corresponding to unsigned read-only data between the section segments corresponding to signed read-only data ROD1 and signed read-only data ROD2, and section segments corresponding to unsigned read-only data between the section segments corresponding to signed read-only data ROD2 and signed read-only data ROD3. Specifically, the section segments corresponding to signed read-only data ROD1 and signed read-only data ROD2 are the same in the first and second compiled files, the section segments corresponding to signed read-only data ROD3 are different in the first and second compiled files, and some content in the section segments corresponding to unsigned read-only data between the section segments corresponding to signed read-only data ROD1 and signed read-only data ROD2 in the first and second compiled files differs. The electronic device can identify the segment between the signed read-only data ROD1 and the signed read-only data ROD2 in the second compiled file as the difference segment DS1, and identify the segment of the signed read-only data ROD3 in the read-only data section of the second compiled file as the difference segment DS2. The electronic device can store the difference segment DS1 and the difference segment DS2 in the obj file (where the starting address of the difference segment DS2 in the read-only data section of the obj file is D1), and add a new symbol SB1 to the symbol table section to indicate the difference segment DS1, where the starting address of SB1 in the symbol table section is D1.

[0155] Read-only string subsection

[0156] For read-only string subsections, different read-only strings can be separated into subsections based on the character terminator (e.g., "\n", or other character terminators). Therefore, by comparing the subsections of a read-only string in the first and second compiled files, it can be determined whether there are differences between the read-only strings in the first and second compiled files. If the subsections of a read-only string in the first and second compiled files are different, the subsection corresponding to that read-only string in the second compiled file can be identified as the difference subsection. The electronic device can then store this difference subsection in the patch package and add a new symbol to the symbol table subsection to indicate the difference subsection.

[0157] For example, Figure 9 According to some embodiments of this application, a schematic diagram is shown for determining differential segment fragments in a read-only string sub-segment region.

[0158] like Figure 9 As shown, the read-only string subsections of the first and second compiled files include subsections corresponding to read-only strings STR1, STR2, and STR3. Each of these subsections is terminated by a character terminator. The electronic device can extract the subsections corresponding to read-only strings STR1, STR2, and STR3 from the read-only string subsections of the first and second compiled files based on these character terminators. Then, the electronic device can compare the contents of the extracted subsections corresponding to read-only strings STR1, STR2, and STR3 in the first and second compiled files to determine if there are any differences between them.

[0159] It should be noted that the character table section of the first and second compiled files does not store the corresponding information for the read-only strings STR1, STR2, and STR3.

[0160] Continue to refer to Figure 9 The contents of the section segments corresponding to the read-only strings STR1 and STR3 in the first compiled file are the same as those in the second compiled file. However, the contents of the section segment corresponding to the read-only string subsection in the first compiled file are different from those in the second compiled file. The electronic device 10 can identify the section segment corresponding to the read-only string STR2 in the second compiled file as the difference section segment DS3. The electronic device can store the difference section segment DS3 in the obj file (where the starting address of the difference section segment DS3 in the read-only string subsection of the obj file is D2), and add a new symbol SB2 to the symbol table section to indicate the difference section segment DS3, where the starting address of SB2 in the symbol table section is D2.

[0161] Read-only constant quantum nodes

[0162] For read-only constant quantum nodes, the symbol table stores the data size (e.g., the number of bytes occupied by the read-only constant) and starting address of each read-only constant. Therefore, different read-only constant segments within the read-only constant quantum node can be separated by their sizes and starting addresses. Thus, by comparing the segment of a read-only constant in the read-only constant quantum node of the first compiled file with the segment of the same read-only constant in the read-only constant quantum node of the second compiled file, it can be determined whether there is a difference between the first and second compiled files. If the segment of a read-only constant in the read-only constant quantum node of the first compiled file and the segment of the same read-only constant in the read-only constant quantum node of the second compiled file are different, the segment corresponding to the read-only constant in the read-only constant quantum node of the second compiled file can be identified as a differing segment. The electronic device can then store this differing segment in the patch package and add a new symbol to the symbol table sub-segment to indicate the differing segment.

[0163] For example, Figure 10 According to some embodiments of this application, a schematic diagram is shown for determining differential segment segments in a read-only constant quantum node region.

[0164] refer to Figure 10 Assume that the symbol table subsection of the first compiled file records read-only constants C1, C2, and C3, with sizes of 10 bytes, 20 bytes, and 30 bytes respectively, and starting addresses of byte 1, byte 11, and byte 31 respectively; the symbol table subsection of the second compiled file records read-only constants C1, C2, and C3, with sizes of 10 bytes, 25 bytes, and 30 bytes respectively, and starting addresses of byte 1, byte 11, and byte 36 respectively. In the read-only constant quantum section of the second compiled file, words 1-10 correspond to read-only constant C1, words 11-30 correspond to read-only constant C2, and words 31-60 correspond to read-only constant C3; similarly, words 1-10 correspond to read-only constant C1, words 11-35 correspond to read-only constant C2, and words 36-65 correspond to read-only constant C3. The electronic device can then determine whether read-only constants C1, C2, and C3 have changed by comparing the contents of the corresponding sections in the read-only constant quantum sections of the first and second compiled files.

[0165] Continue to refer to Figure 10The content of the read-only constant C2 in the read-only constant quantum section of the first and second compiled files is different, while the content of the corresponding section segments of read-only constants C1 and C3 in the first and second compiled files is the same. The electronic device can identify the section segment corresponding to read-only constant C2 in the second compiled file as the difference section segment DS4, store DS4 in the obj file (where the starting address of DS4 in the read-only constant quantum section of the obj file is D4), and add a symbol SB3 (or C2 or others) to the symbol table section of the obj file to indicate the difference section segment DS4, where the starting address of SB3 in the symbol table section of the obj file is D3.

[0166] In some embodiments, the electronic device may first compare the candidate section segments that differ from the read-only data section segments of the first compiled file and the read-only data section segments of the second compiled file, and then, based on the type of read-only data corresponding to the candidate section segments (e.g., signed read-only data, unsigned read-only data, read-only string, read-only constant, etc.), use different methods to extract the difference section segments corresponding to the candidate section segments.

[0167] For example:

[0168] If the data corresponding to a candidate section segment is signed read-only data, then the section segment corresponding to that signed read-only data in the read-only data section of the second compiled file can be determined as the difference section segment.

[0169] If the data corresponding to a candidate section segment is unsigned read-only data, the read-only data section of the second compiled file can be searched using the section segments before and after the candidate section segment to determine the section segment corresponding to the first signed read-only data (denoted as the first signed read-only data) before the candidate section segment, and the section segment corresponding to the first signed read-only data (denoted as the second signed read-only data) after the candidate section segment. Then, the electronic device can determine the section segment corresponding to the first signed read-only data and the section segment corresponding to the second signed read-only data in the read-only data section of the second compiled file as the difference section segment corresponding to the candidate section segment. For example, if the address range of the candidate section segment is 0X120 to 0X160, the address corresponding to the last sub-data of the section segment corresponding to the first signed read-only data before address 0X120 is 0X100, and the address corresponding to the first sub-data of the section segment corresponding to the first signed read-only data after address 0X160 is 0X180, then the electronic device can use the section segment corresponding to the address range of 0X101 to 0X179 in the read-only data section of the second compiled file as the difference section segment.

[0170] If the data corresponding to a candidate section segment is a read-only string, the section segment between the address of the first character terminator before the candidate section segment and the address of the first character terminator after the candidate section segment can be determined as the difference section segment corresponding to the candidate section segment based on the character terminator (e.g., "\n", or other character terminators) in the read-only string section segment of the second compiled file. For example, if the address range of the candidate section segment is 0X120 to 0X160, the address of the first character terminator before address 0X120 is 0X110, and the address of the first character terminator after address 0X160 is 0X170, the electronic device can store the section segment corresponding to the address range of 0X111 to 0X169 in the read-only string section segment of the second compiled file as the difference section segment in the obj file (e.g., in the read-only string subsection of the obj file), and add a symbol in the symbol table to indicate the content of the section segment corresponding to 0X111 to 0X169.

[0171] If the data corresponding to a candidate section segment is a read-only constant, the section segment corresponding to the candidate section segment can be extracted from the read-only constant section of the second compiled file based on the size of the read-only constant, and the extracted section segment can be identified as a difference section segment. For example, if the address range of the candidate section segment is 0X120 to 0X160, and the size of the corresponding read-only constant is 60 with a starting address of 0X115 (the address range corresponding to this constant is 0X115 to 0X174 (i.e., 0X115+60-1)), the electronic device can store the section segment corresponding to the address range of 0X115 to 0X174 in the read-only string section of the second compiled file as a difference section segment in the obj file (e.g., in the read-only constant section of the obj file), and add a symbol to the symbol table of the obj file to indicate the content of the section segment corresponding to 0X115 to 0X174.

[0172] It should be noted that, in some embodiments, the size of a read-only constant can be found in the symbol table section.

[0173] Based on the above, this application provides a method for extracting the difference segment of the read-only data section of a first compiled file and a second compiled file.

[0174] For example, Figure 11 According to some embodiments of this application, a schematic diagram of a process for extracting differential segment data from a read-only data section is shown. The entity executing this process can be an electronic device, such as... Figure 11 As shown, the process includes the following steps:

[0175] S1101, compare the read-only data section of the first compiled file and the read-only data section of the second compiled file, and determine at least one candidate section segment in the read-only data section of the second compiled file that is different from the content of the read-only data section of the first compiled file.

[0176] For example, an electronic device can determine at least one alternative segment in the read-only data area of ​​the second compiled file that is different from the content of the read-only data area of ​​the first compiled file by comparing the binary content of the read-only data area of ​​the first compiled file and the read-only data area of ​​the second compiled file.

[0177] S1102A, the data corresponding to the candidate section segment is signed read-only data, and the section segment corresponding to the signed read-only data of the candidate section segment is taken as the first type of read-only data difference section segment in the second compilation file.

[0178] When the data corresponding to the candidate section segment is signed read-only data, such as when the candidate section segment is inside one or more symbol-corresponding section segments recorded in the symbol table section segment, the electronic device can use the signed read-only data corresponding to the candidate section segment as the section segment corresponding to the read-only data section segment of the second compiled file as the first type of read-only data difference section segment.

[0179] For example, if the address range of the candidate segment is 0X220 to 0X250, and the starting address of a certain symbol recorded in the symbol table segment is 0X200 and the size is 80 (corresponding to the address range of 0X200 to 0X279), then the electronic device can identify the segment with the address range of 0X200 to 0X279 corresponding to that symbol as the first type of read-only data difference segment.

[0180] For example, if the address range of the candidate segment is 0X220 to 0X300, and the starting address of a certain symbol recorded in the symbol table segment is 0X200 and the size is 80, and the starting address of another symbol is 0X280 and the size is 60, then the electronic device can identify the segment with the address of the first symbol from 0X200 to 0X279 and the segment with the address of the other symbol from 0X280 to 0X339 as a first type of read-only data difference segment.

[0181] S1102B stores the first type of read-only data difference section segments in the obj file, and stores the information of the signed read-only data corresponding to each first type of read-only data difference section segment in the symbol table section of the obj file.

[0182] For example, an electronic device may store first type read-only data difference section segments in the read-only data section of an obj file, and store the correspondence between the starting address, size and corresponding signed read-only data of each first type read-only data difference section segment in the read-only data section of the obj file in the symbol table section of the obj file.

[0183] Since one type I read-only data difference segment corresponds to one signed read-only data, the electronic device can store the type I read-only data difference segment in the read-only data section of the obj file. Furthermore, the electronic device can also store the correspondence between the starting address and size of each type I read-only data difference segment in the read-only data section of the obj file and the corresponding signed read-only data in the symbol table section of the obj file.

[0184] S1103A, corresponding to the data in the candidate section segment being unsigned read-only data, the section segment in the read-only data section of the second compiled file between the first address and the second address is determined as the second type of read-only data difference section segment. Here, the first address is the address corresponding to the last sub-data of the signed read-only data in the read-only data section of the second compiled file that is adjacent to the candidate section segment before the candidate section segment, and the second address is the address corresponding to the first sub-data of the signed read-only data in the read-only data section of the second compiled file that is adjacent to the candidate section segment after the candidate section segment.

[0185] When the data corresponding to the candidate section segment is unsigned read-only data, for example, when the address range corresponding to the candidate section segment does not belong to the address range of any symbol corresponding to the section segment in the symbol table section, the electronic device can determine the first address corresponding to the last sub-data of the signed read-only data adjacent to the candidate section segment before the candidate section segment in the read-only data section of the second compiled file, and the second address corresponding to the first sub-data of the signed read-only data adjacent to the candidate section segment after the candidate section segment in the read-only data section of the second compiled file, and determine the section segment between the first address and the second address as a second type of read-only data difference segment.

[0186] For example, suppose that the address range of the candidate section segment is 0X120 to 0X160, the address corresponding to the last sub-data of the section segment corresponding to the first signed read-only data before address 0X120 is 0X100 (as the first address), and the address corresponding to the first data of the section segment corresponding to the second signed read-only data after address 0X160 is 0X180 (as the second address), then the electronic device can determine the section segment with addresses between 0X100 and 0X180 (i.e., the section segment with address range 0X101 to 0X179) in the read-only data section of the second compiled file as the second type of read-only data difference section segment.

[0187] S1103B: Store each type II read-only data difference section segment in the obj file, add symbols to indicate each type II read-only data difference section segment, and store the information of the newly added symbols corresponding to each type II read-only data difference section segment in the symbol table section of the obj file.

[0188] For example, an electronic device may store second-type read-only data difference section segments in the read-only data section of an obj file, add symbols in the symbol table section to indicate each second-type read-only data difference section segment, and store the correspondence between the starting address, size and corresponding added symbol of each second-type read-only data difference section segment in the read-only data section of the obj file in the symbol table section of the obj file.

[0189] Since there are no symbols in the symbol table of the second compiled file that correspond to the second type of read-only data difference section fragments, the electronic device can add symbols to indicate each second type of read-only data difference section fragment (one new symbol corresponds to one second type of read-only data difference section fragment), and store the correspondence between the starting address and size of each second type of read-only data difference section fragment in the read-only data section of the obj file and the corresponding new symbol in the symbol table section of the obj file.

[0190] S1104A, since the data corresponding to the candidate section segment is a read-only string, the section segment in the third to fourth address interval of the read-only data section of the second compiled file is determined as the third type of read-only data difference section segment. Here, the third address is the address corresponding to the first character terminator before the candidate section segment in the read-only data section of the second compiled file, and the fourth address is the address corresponding to the first character terminator after the candidate section segment in the read-only data section of the second compiled file.

[0191] When the data corresponding to the candidate section segment is a read-only string, for example, when the address range corresponding to the candidate section segment is within the read-only substring subsection, the electronic device can determine the third address corresponding to the first character terminator before the candidate section segment and the fourth address corresponding to the first character terminator after the candidate section segment, and determine the section segment in the read-only data section segment of the second-optimized compiled file between the third and fourth addresses as the third type of read-only data difference section segment.

[0192] For example, suppose that if the address range of the candidate section segment is 0X120 to 0X160, the address of the first character terminator before address 0X120 is 0X110 (as the third address), and the address of the first character terminator after address 0X160 is 0X170 (as the fourth address), then the electronic device can identify the section segment in the read-only string section of the second compiled file with an address range between 0X110 and 0X160 (that is, the section segment with an address range between 0X111 and 0X169) as the third type of read-only data difference section segment.

[0193] S1104B: Store each type III read-only data difference section segment in the obj file, add symbols to indicate each type III read-only data difference section segment, and store the information of the newly added symbols corresponding to each type III read-only data difference section segment in the symbol table section of the obj file.

[0194] For example, an electronic device may store third-class read-only data difference section segments in the read-only data section of an obj file, add symbols in the symbol table section to indicate each third-class read-only data difference section segment, and store the correspondence between the starting address, size and corresponding added symbol of each third-class read-only data difference section segment in the read-only data section of the obj file in the symbol table section of the obj file.

[0195] Since there are no symbols in the symbol table of the second compiled file that correspond to the third type of read-only data difference section fragments, the electronic device can add symbols to indicate each third type of read-only data difference section fragment (one new symbol corresponds to one third type of read-only data difference section fragment), and store the correspondence between the starting address and size of each third type of read-only data difference section fragment in the read-only data section of the obj file and the corresponding new symbol in the symbol table section of the obj file.

[0196] S1105A, the data corresponding to the candidate section segment is a read-only constant, and the read-only constant corresponding to the candidate section segment is determined as the fourth type of read-only data difference section segment in the read-only data section of the second compiled file.

[0197] When the data corresponding to the candidate section segment is a read-only constant, such as when the candidate section segment is inside one or more read-only constants recorded in the symbol table section segment, the electronic device can use the section segment corresponding to the read-only constant of the candidate section segment as the fourth type of read-only data difference section segment in the second compiled file.

[0198] For example, if the address range of the candidate segment is 0X320 to 0X340, and the starting address of a certain read-only constant recorded in the symbol table segment is 0X280 and the size is 90 (corresponding to the address range of 0X280 to 0X369), then the electronic device can identify the segment with the address range of 0X280 to 0X369 corresponding to the read-only constant as the fourth type of read-only data difference segment.

[0199] S1105B stores each type of fourth-class read-only data difference section segment in the obj file, and stores the information of the read-only constants corresponding to each type of fourth-class read-only data difference section segment in the symbol table section of the obj file.

[0200] For example, an electronic device may store fourth type read-only data difference section segments in the read-only data section of an obj file, and store the correspondence between the starting address, size and corresponding read-only constant symbol of each fourth type read-only data difference section segment in the read-only data section of the obj file in the symbol table section of the obj file.

[0201] It should be noted that the symbol names of the fourth type of read-only data recorded in the symbol table section of the obj file can be the same as or different from the symbol names of the corresponding read-only constants; this is not limited here.

[0202] It should be noted that the first to fourth categories mentioned above are only used to distinguish different types of read-only data. In fact, read-only data may not be classified, and this is not a limitation here.

[0203] Based on the above method, the read-only data section of the obj file does not need to store the same section fragments as the read-only data section of the second compiled file, which helps to reduce the amount of data in the read-only data section of the patch package.

[0204] The following describes how to determine the difference segment in the abnormal information section.

[0205] In some embodiments, the exception information section contains section fragments corresponding to multiple common information entries (CIEs). Each CIE-corresponding section fragment is followed by one or more FDE-corresponding section fragments, and each FDE-corresponding section fragment corresponds to the exception handling information of a function. In the exception information relocation item subsection of the relocation item section, the correspondence between each function and the corresponding FDE in the exception information section is stored. Thus, based on this correspondence, the difference functions that differ between the executable code in the first and second compiled files can be extracted from the exception information section of the second compiled file. Based on this, the electronic device can use the FDEs corresponding to the difference functions and their associated functions in the exception information section as the difference section fragments of the exception information section.

[0206] In some embodiments, the difference segment of the anomaly information segment may further include the difference function and the segment corresponding to the CIE to which the FDE to which the difference function belongs.

[0207] In some embodiments, the electronic device may also bind the relocation information of the difference function and the FDE corresponding to the difference function's associated function in the exception information relocation item subsection area. For example, the electronic device may store the section fragment of the difference function and the FDE corresponding to the difference function's associated function, as well as the section fragment of the CIE to which this part belongs, in the exception information section (e.g., exception information section) of the patch package. Furthermore, it may add relocation information of the difference function and the FDE corresponding to the difference function's associated function to the exception information relocation item subsection area of ​​the relocation item section in the obj file, whereby the relocation information indicates that the address of each difference function is the address corresponding to the exception information section in the obj file.

[0208] For example, Figure 12 According to some embodiments of this application, a schematic diagram is shown for determining differential segment segments in anomaly information segments.

[0209] like Figure 12 As shown, the exception information section of the second compiled file includes CIE C1 and CIE C2. Between the sections corresponding to CIE C1 and CIE C2, FDE C1.1 and FDE C1.2 associated with CIE C1 are stored. Following the section corresponding to CIE C2, FDE C2.1 and FDE C2.2 associated with CIE C2 are stored. FDE C1.1 corresponds to the aforementioned function F1, FDE C1.2 corresponds to the aforementioned function F2, FDE C2.1 corresponds to the aforementioned function F3, and FDE C2.2 corresponds to other functions. Based on... Figure 5 In the scenario shown, the difference functions include functions F2 and F3. The electronic device can identify the section segments corresponding to FDE C1.2, FDE C2.1, CIE C1, and CIE C2 in the exception information section of the second compiled file as the difference section segments of the exception information section, and store the section segments corresponding to FDE C1.2, FDE C2.1, CIE C1, and CIE C2 in the patch package, for example, in the exception information section of the obj file.

[0210] In addition, continue to refer to Figure 12 Because the relocation information in the exception information relocation item subsection of the obj file is used to record the exception handling information corresponding to functions F2 and F3, the electronic device can adjust the relocation information of function F2 to point to the information of FDE C1.2 in the exception information relocation item subsection of the obj file, and adjust the relocation information of function F3 to point to the information of FDE C2.1 in the exception information subsection of the obj file.

[0211] Based on the above, this application provides a method for extracting the difference segment of the read-only data section of a first compiled file and a second compiled file.

[0212] For example, Figure 13 According to some embodiments of this application, a flowchart of a patch package corresponding to an abnormal information section is shown. The execution entity of this process can be an electronic device, such as... Figure 13 As shown, the process includes the following steps:

[0213] S1301, based on the contents of the difference function and its associated function in the exception information relocation item subsection area, and the correspondence between FDE and CIE in the exception information section area of ​​the second compiled file, determine the difference function and its associated function in the exception information section area of ​​the second compiled file, and the FDE and CIE corresponding to each FDE.

[0214] In some embodiments, the exception information relocation item subsection records information (e.g., addresses) of the FDEs corresponding to different functions. Based on this, the electronic device can determine the correspondence between FDEs and CIEs in the exception information relocation item subsection based on the difference function and its associated function, as well as the correspondence between FDEs and CIEs in the exception information section of the second compiled file.

[0215] In some embodiments, the correspondence between FDE and CIE in the exception information section can be determined according to the storage order of FDE and CIE. The FDE corresponding to a CIE may include one or more FDEs stored after the CIE and before the next CIE.

[0216] For example, for Figure 12 In the scenario shown, the difference functions include function F2 and function F3. The electronic device can determine the FDEs corresponding to function F2 and function F3 as FDE C1.2 and FDEC2.2 respectively based on the content of the abnormal information relocation item sub-section area. Furthermore, FDE C1.2 corresponds to CIE C1, and FDE C2.1 corresponds to CIE C2.

[0217] S1302, store the difference function and the associated function of the difference function in the exception information section of the second compilation file, along with the FDE and CIE corresponding to each FDE, in the exception information section of the obj file.

[0218] After determining the FDE corresponding to each difference function and the CIE corresponding to each FDE, the FDE corresponding to the association function of each difference function and the CIE corresponding to each FDE, the electronic device can store the FDE corresponding to each difference function and the CIE corresponding to each FDE, the FDE corresponding to the association function of each difference function and the CIE corresponding to each FDE in the abnormal information section of the obj file.

[0219] For example, for Figure 12 As shown, the electronic device can sequentially store CIE C1, FDEC1.1, CIE C2, and FDE C2.2 in the exception information section of the obj file.

[0220] S1303, based on the addresses of the FDEs corresponding to each difference function and the associated function of the difference function in the anomaly information section of the obj file, update the relocation information of each difference function and the associated function of the difference function in the anomaly information relocation item subsection of the obj file.

[0221] After storing the difference functions and their associated functions' FDEs and corresponding CIEs in the exception information section of the second compiled file in the exception information section of the obj file, the electronic device can further update the relocation information of each difference function and its associated function in the exception information relocation item subsection of the obj file based on the addresses of the FDEs corresponding to each difference function and its associated function in the exception information section of the obj file. It should be noted that the updated relocation information of each difference function (or its associated function) in the exception information relocation item subsection of the obj file points to the address of the FDE corresponding to each difference function (or its associated function) in the exception information section of the obj file.

[0222] Based on the above method for determining the difference segment in each first type of section, the electronic device can store the difference segment in each first type of section in the second compilation file relative to the first compilation file in the patch package, without having to store the same segment in each first type of section in the second compilation file as in the first compilation file, which helps to reduce the data volume of the patch package.

[0223] Based on the foregoing embodiments, this application provides a method for generating patch packages.

[0224] For example, Figure 14 According to some embodiments of this application, a flowchart of a patch package generation method is shown. The execution subject of this process is an electronic device, such as... Figure 14 As shown, the method includes the following steps:

[0225] S1401, obtain the first and second compiled files.

[0226] In some embodiments, the first compiled file is obtained by compiling a first code file (e.g., the aforementioned original code file) using compilation optimization, and the second compiled file is obtained by compiling a second code file (e.g., the aforementioned patch code file) using compilation optimization. The second code file is the code file after fixing the vulnerabilities in the first code file.

[0227] It should be noted that the first and second compiled files can be obtained by the electronic device from other devices, or they can be compiled by the electronic device using compilation optimization.

[0228] S1402, Based on comparing the contents of the code sections of the first and second compiled files, determine the difference function between the second compiled file and the first compiled file.

[0229] Electronic devices can determine the differences between the second compiled file and the first compiled file by comparing the contents of code sections of the first and second compiled files. See the foregoing for details. Figures 4 to 7 The embodiments shown are not described in detail here.

[0230] S1403, determine the correlation function of the difference function, and the FDE corresponding to the difference function and the correlation function of the difference function.

[0231] For example, after determining the difference function, the electronic device can determine the associated function of the difference function based on the call chain of the difference function. See the foregoing for details. Figures 4 to 7 The details of the corresponding embodiments will not be elaborated here.

[0232] For example, after determining the correlation function of the difference function, the electronic device can also determine the FDE corresponding to the difference function and its correlation function in the exception information section based on the content of the exception information relocation item subsection of the second compilation file, as well as the CIE corresponding to each FDE. See the foregoing for details. Figure 12 and Figure 13 The details of the corresponding embodiments will not be elaborated here.

[0233] In some embodiments, step S403 is optional or partially optional. For example, the electronic device may not determine the correlation function of the difference function, but only determine the FDE corresponding to the difference function and the CIE corresponding to the FDE. As another example, the electronic device may not determine the correlation function of the difference function, nor the FDE corresponding to the difference function and its correlation function. No limitations are imposed here.

[0234] S1404, Based on comparing the contents of the read-only data sections of the first and second compiled files, determine the difference in read-only data between the second compiled file and the first compiled file.

[0235] The electronic device can determine the differences in read-only data between the second compiled file and the first compiled file by comparing the contents of the read-only data sections of the first and second compiled files (e.g., the aforementioned first type of read-only data difference section fragment, second type of read-only data difference section fragment, first type of read-only data difference section fragment, and fourth type of read-only data difference section fragment). The specific method by which the electronic device determines the differences in read-only data between the second compiled file and the first compiled file by comparing the contents of the read-only data sections of the first and second compiled files can be referred to the aforementioned... Figures 8 to 11 The details of the corresponding embodiments will not be elaborated here.

[0236] In some embodiments, the difference read-only data may include read-only data (e.g., signed read-only data, unsigned read-only data, read-only constants, read-only strings, etc.) that are stored in the read-only data section of the second compiled file, relative to the read-only data section of the first compiled file.

[0237] In some embodiments, step S1404 may be executed in parallel with steps S1402 to S1403, or it may be executed before step S1402, which is not limited here.

[0238] S1405, obtain the patch package based on the difference function, the correlation function of the difference function, the difference read-only data, the difference function and the FDE corresponding to the correlation function of the difference function.

[0239] The electronic device can store the difference functions, their associated functions, difference read-only data, difference segment fragments corresponding to the difference functions and their associated functions, and the FDEs corresponding to the difference functions and their associated functions (and may also include the CIEs corresponding to each FDE) in an obj file. It then relinks the difference functions, difference read-only data, difference associated functions, and the FDEs corresponding to the difference functions and their associated functions in the obj file to obtain a patch package. The storage method for each difference segment fragment in the obj file can be referred to the aforementioned method. Figures 4 to 13 The specific implementation examples are not described in detail here.

[0240] In some embodiments, after receiving the patch package, the electronic device may also send the received patch package to other devices that need to install the patch package.

[0241] Based on the above method, since the patch package is obtained by using the difference function, the correlation function of the difference function, the difference read-only data, the difference function and the FDE corresponding to the correlation function of the difference function, it is beneficial to reduce the data size of the patch package.

[0242] Based on the above embodiments, Figure 15 According to some embodiments of this application, a schematic diagram of the architecture of a patch package generation method is shown.

[0243] like Figure 15As shown, during the compilation of code files, the electronic device can use additional instructions such as "-flto", "-wl", "-emit", and "-relocs" to compile the original code file and the patch code file separately through compilation optimization methods, resulting in a first intermediate compiled file and a second intermediate compiled file, respectively. Then, the electronic device can use compilation optimization methods such as BOLT to compile the first intermediate compiled file and the second intermediate compiled file separately, resulting in a first compiled file and a second compiled file, respectively. Next, the difference extraction module uses the method provided in the aforementioned feasible embodiment to determine the difference segment segments in each section of the first compiled file and the second compiled file. Finally, a loadable patch package can be obtained by relinking based on the difference section fragments (such as difference functions, correlation functions of difference functions, read-only data, FDEs corresponding to difference functions and correlation functions of difference functions) and byproducts of compiling the original code file and patch code file (such as byproducts generated during the process of compiling the original code file and patch code file into the first intermediate compilation file and the second intermediate compilation file, such as ELF files used to mirror symbol table information (such as information in the symbol table section), map files (a mapping file of program, data and input / output (I / O) space obtained by the compiler), ELF files generated by the difference reorganization of the original code file and patch code file, custom information data corresponding to the patch code file, etc.).

[0244] Based on the above embodiments, Figure 16 According to some embodiments of this application, a schematic diagram of a patch package generation method is shown.

[0245] like Figure 16 As shown, the method may include the following steps S1 to S6:

[0246] ① Symbol Table Section Analysis: Symbol table section analysis tools are used to analyze the code sections of the first and second compiled files to determine the difference functions. For example, electronic devices can determine the difference functions and their associated functions based on whether the corresponding section segments of each function in the first and second compiled files satisfy the aforementioned difference function conditions. For details, please refer to the aforementioned section on code section difference segment extraction and... Figure 7 The embodiments shown are not described in detail here.

[0247] ② Data and Auxiliary Information Identification: A detailed code review and requirements analysis are conducted on the data and auxiliary information required for the difference function. Electronic devices can determine the difference segment fragments in each segment that are associated with the difference function and its related functions, as well as the segments containing auxiliary information (e.g., read-only data segments, exception information segments, relocation item segments, etc.), based on the content within the relocation item segments.

[0248] ③ Difference Function Extraction: The electronic device can extract the corresponding difference function and its associated function from the code section of the second compiled file based on the determined difference function and its associated function, and store the extracted difference fragments in the code section of the obj file. For details, please refer to the aforementioned section on difference fragment extraction from the code section. Figure 7 The embodiments shown are not described in detail here.

[0249] ④ Auxiliary information extraction: Electronic devices can store the difference fragments of the auxiliary information (such as read-only data section, abnormal information section, relocation item section, etc.) in the corresponding section of the obj file.

[0250] For example, an electronic device can store the difference section fragments corresponding to the read-only data section in the read-only data section of an obj file, and add the symbols corresponding to each difference section fragment to the symbol table section of the obj file. As another example, an electronic device can store the CIE and FDE of the corresponding difference functions and their associated functions in the exception information section in the exception information section of the obj file, and store the relocation information indicating each difference function and its associated function's FDE (which may also include CIE) in the exception information relocation item subsection of the obj file. See the foregoing for details. Figures 8 to 13 The embodiments shown are not described in detail here.

[0251] ⑤ Information segment construction: Electronic devices can add a field (e.g., patch_fun field) to the patch package based on the difference function, the difference function and auxiliary information to store relevant information about the difference function (e.g., information used to assist electronic devices in finding, locating, verifying and restoring the patch package, such as the address, symbol name, offset address, function value, object identifier of the patched vulnerability (or function, function fragment) and the corresponding original function).

[0252] ⑥ Optimization and Linking: Optimize the obj file and link it with the compilation artifacts of the original code file and / or patch code file to obtain the patch package.

[0253] Based on the foregoing embodiments, this application provides a method for generating patch packages.

[0254] For example, Figure 17 According to some embodiments of this application, a flowchart of another patch package generation method is shown. The execution entity of this process is an electronic device, such as... Figure 17 As shown, the method includes the following steps:

[0255] S1701, obtain the first and second compiled files.

[0256] In some embodiments, the first compiled file is obtained by compiling a first code file (e.g., the aforementioned original code file) using compilation optimization, and the second compiled file is obtained by compiling a second code file (e.g., the aforementioned patch code file) using compilation optimization. The second code file is the code file after fixing the vulnerabilities in the first code file.

[0257] It should be noted that the first and second compiled files can be obtained by the electronic device from other devices, or they can be compiled by the electronic device using compilation optimization.

[0258] In some embodiments, the first and second compiled files are ELF files, such as .so files.

[0259] S1702, compare the contents of the first type of section in the first compilation file and the second compilation file, and determine at least one difference section segment in the first type of section of the second compilation file that is different from the first type of section in the first compilation file.

[0260] In some embodiments, the first type of section may include one or more of a code section, a read-only data section, and an exception information section.

[0261] For example, an electronic device can determine the aforementioned difference function by comparing the contents of code sections in the first and second compiled files, and identify the section segment corresponding to the difference function in the code section as the difference section segment.

[0262] For example, an electronic device can also determine the associated functions of the difference functions based on the function call chains in the first and second compilation files, and determine the section segment corresponding to the associated functions of the difference functions in the code section segment as the difference section segment.

[0263] It should be noted that the specific methods for determining the difference function and the correlation function of the difference function in electronic devices can be found in the aforementioned text. Figures 4 to 7 The specific implementation examples are not described in detail here.

[0264] For example, an electronic device can compare the contents of the read-only data sections in a first and a second compiled file to identify the difference segments in the read-only data sections of the second compiled file that differ from those in the first compiled file. The method for determining the difference segments corresponding to different read-only data (e.g., signed read-only data, unsigned read-only data, read-only strings, read-only constants, etc.) can be referred to the aforementioned methods. Figures 8 to 11 The specific implementation examples are not described in detail here.

[0265] For example, the electronic device can also determine the FDEs corresponding to the difference functions, the association functions of the difference functions, and the CIEs corresponding to each FDE based on the contents of the exception information relocation item subsection area in the second compiled file. The specific determination method can be found in the foregoing. Figure 12 and Figure 13 The embodiments described herein are not limited to these examples.

[0266] S1703, based on the at least one differential segment, a patch package is obtained.

[0267] After identifying at least one difference section segment in the first type of section of the second compiled file that differs from the first type of section of the first compiled file, the electronic device can store the contents of the difference section segment in the obj file, optimize and link the obj file to obtain a patch package.

[0268] Based on the above method, the electronic device can compare the contents of each first-type section of the first and second compiled files to obtain the difference section fragments in each first-type section of the second compiled file that are different from the corresponding sections in the first compiled file, and generate a patch package based on the obtained difference section fragments. In this way, the patch package does not need to store section fragments in the first-type section of the second compiled file that are the same as the first-type section of the first compiled file, which helps to reduce the data size of the patch package.

[0269] further, Figure 18 According to some embodiments of this application, a schematic diagram of an electronic device 10 is shown. This electronic device 10 can be used to execute the patch package generation method provided in the embodiments of this application.

[0270] like Figure 18 As shown, the electronic device 10 may include one or more processors 110, one or more memories 120, and a communication interface 130. The processors 110, memories 120, and communication interface 130 may be connected via a bus.

[0271] The processor 110 may be coupled to one or more memories 120. The memories 120 store instructions corresponding to the patch package generation method provided in the embodiments of this application, and the processor 110 may be used to execute the instructions stored in the memories 120 to implement the patch package generation method provided in the aforementioned embodiments.

[0272] In some embodiments, some or all of one or more of the memory 120 may be located inside the processor 120, i.e., the processor 110 includes the memory 120.

[0273] The communication interface 130 may include various wired or wireless communication modules for communication with other electronic devices. Electronic device 10 can obtain a first compiled file and / or a second compiled file, or a first code file (source code file) and / or a second code file (patch code file) through the communication interface 130. Electronic device 10 can also send patch packages to other devices.

[0274] It should be noted that in some other embodiments, the electronic device 10 may include more or fewer modules, which is not limited here.

[0275] It should be noted that electronic device 10 can be any electronic device, including but not limited to desktop computers, laptops, tablets, servers, etc.

[0276] This application also provides a computer program product, which includes computer program code. When the computer program code is run on a computer, it causes the computer to implement the methods described in the above embodiments of this application.

[0277] This application also provides a computer-readable storage medium storing computer instructions that, when executed on a computer, cause the computer to implement the methods described in the above embodiments of this application.

[0278] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0279] In the description of the embodiments in this application, unless otherwise stated, " / " means "or", for example, A / B can mean A or B; "and / or" in this document describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. In this application, "at least one" means one or more, and "more" means two or more. "At least one of the following" or similar expressions refer to any combination of these items, including any combination of single or multiple items.

[0280] The use of prefixes such as "first" and "second" in this application embodiment is solely for distinguishing different descriptive objects and does not limit the position, order, priority, quantity, or content of the described objects. The use of ordinal numbers and other prefixes to distinguish descriptive objects in this application embodiment does not constitute a limitation on the described objects. The description of the described objects is found in the claims or the context of the embodiments, and the use of such prefixes should not constitute unnecessary restrictions.

[0281] In the embodiments provided in this application, the connection between electronic devices, the connection between modules, and the connection between physical network ports can be a direct connection or an indirect connection, and the connection method can be a wired connection or a wireless connection.

[0282] In the various embodiments of this application, unless otherwise specified or logically conflicting, the terminology and / or descriptions between the various embodiments are consistent and can be referenced mutually. Technical features in different embodiments can be combined to form new embodiments based on their inherent logical relationships. Units described as separate components in various embodiments may or may not be physically separate. 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 the units can be selected to achieve the purpose of this embodiment according to actual needs. Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0283] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A patch generation method applied to an electronic device, comprising: The method comprises: obtaining a first compiled file and a second compiled file, wherein the first compiled file is a compiled file obtained by compiling a first code file through a compilation optimization process, the second compiled file is a compiled file obtained by compiling a second code file through the compilation optimization process, the second code file is a code file after repairing a vulnerability of the first code file, the compiled file is an executable and linkable format file, and the compiled file comprises a first type section, and the first type section comprises at least one of a code section, a read-only data section, and an exception information section; comparing contents of the first type sections in the first compiled file and the second compiled file to determine at least one difference section segment of the first type section in the second compiled file that is different from the first type section in the first compiled file; obtaining a patch package based on the at least one difference section segment.

2. The method of claim 1, wherein, The obtaining of the patch package based on the at least one difference section segment comprises: storing the at least one difference section segment in a redirectable file, and obtaining the patch package based on the redirectable file, wherein the redirectable file comprises the first type section, and each difference section segment corresponding to the first type section is stored in the first type section corresponding to the difference section segment in the redirectable file.

3. The method of claim 2, wherein, The determining of the at least one difference section segment of the first type section in the second compiled file that is different from the first type section in the first compiled file comprises: determining, based on function information of each function in the first compiled file and function information of each function in the second compiled file respectively, each function in the second compiled file in a first section segment corresponding to a code section of the first compiled file and in a second section segment corresponding to the code section of the second compiled file, wherein the function information comprises a size of the function and a starting address of the function stored in the corresponding code section; determining, based on the first section segment and the second section segment corresponding to each function, a difference function in each function that satisfies a first condition; taking the second section segment corresponding to the difference function as the difference section segment of the code section.

4. The method of claim 3, wherein, The first condition comprises at least one of the following conditions: a size of the function corresponding to the first section segment and the second section segment is different; contents pointed to by a relocation entry in the first section segment of the function are different from contents pointed to by a relocation entry in the second section segment of the function; the first section segment and other contents except the relocation entry in the second section segment of the function are different.

5. The method of claim 4, wherein, The method further comprises: determining, based on a call chain corresponding to each difference function in the second compiled file, an associated function of each difference function; taking the second section segment corresponding to the associated function of each difference function as the difference section segment of the code section. The first difference function in the difference functions comprises a first call chain, and an associated function of the first difference function on the first call chain comprises a first basic function traversed from the first difference function to a function calling the difference function on the first call chain, and a function between the first difference function and the first basic function on the first call chain.

6. The method of claim 5, wherein, The relocatable file comprises a symbol table section; and the storing the at least one difference section fragment in the relocatable file comprises: For the difference function or a first function of the associated function of the difference function which is not a basic function, a first symbol is added in the relocatable file to indicate the first function.

7. The method of claim 5, wherein, The determining the at least one difference section fragment of the first type section of the second compiled file different from the first type section of the first compiled file further comprises: determining frame description entries corresponding to the difference functions and / or the associated functions of the difference functions in the exception information section of the second compiled file, and general information entries corresponding to the frame description entries; storing the frame description entries corresponding to the difference functions and / or the associated functions of the difference functions, and the general information entries corresponding to the frame description entries in section fragments of the exception information section of the second compiled file as the difference section fragments of the exception information section.

8. The method of claim 7, wherein, The relocatable file further comprises a relocation entry section; and the determining the at least one difference section fragment of the first type section of the second compiled file different from the first type section of the first compiled file further comprises: storing the difference section fragments of the exception information section in the exception information section of the relocatable file, and updating relocation information corresponding to the difference functions and / or the associated functions of the difference functions in the relocation entry section of the relocatable file; wherein the relocation information of the second function in the relocation entry section of the relocatable file points to a storage location of the frame description entry corresponding to the second function in the exception information section of the relocatable file, and the second function is any function of the difference functions and / or the associated functions of the difference functions.

9. The method according to any one of claims 2 to 8, characterized in that, The determining the at least one difference section fragment of the first type section of the second compiled file different from the first type section of the first compiled file further comprises: determining a third section fragment in the read-only data section of the second compiled file different from the read-only data section of the second compiled file based on comparing the read-only data section of the first compiled file with the read-only data section of the second compiled file; in a case where the second compiled file comprises first signed read-only data corresponding to the third section fragment, taking a fourth section fragment corresponding to the first signed read-only data in the read-only data section of the second compiled file as the difference section fragment of the read-only data section; and in a case where the second compiled file does not comprise the first signed read-only data corresponding to the third section fragment, taking a fifth section fragment corresponding to second signed read-only data in the read-only data section of the second compiled file as the difference section fragment of the read-only data section. in the case that there is no signed read-only data corresponding to the third section fragment in the second compiled file, a fifth section fragment in the read-only data section of the second compiled file is taken as the difference section fragment of the read-only data section, wherein the fifth section fragment is a section fragment between the first signed read-only data before the third section fragment and the first signed read-only data after the third section fragment in the read-only data section of the second compiled file; in the case that the data corresponding to the third section fragment is a read-only string, a sixth section fragment in the read-only data section of the second compiled file is taken as the difference section fragment of the read-only data section, wherein the sixth section fragment is a section fragment between the first string terminator before the third section fragment and the first string terminator after the third section fragment in the read-only data section of the second compiled file; in the case that there is a first read-only constant corresponding to the third section fragment in the second compiled file, a seventh section fragment corresponding to the first read-only constant in the read-only data section of the second compiled file is taken as the difference section fragment of the read-only data section.

10. The method of claim 9, wherein, the relocatable file comprises a symbol table section; and the storing the at least one difference section fragment in the relocatable file further comprises: new symbols are added in the symbol table section of the relocatable file to respectively indicate each of the fifth section fragments or each of the sixth section fragments.

11. The method of claim 1, wherein, the extension of the executable and linkable format file is.so.

12. The method of claim 1, wherein, the compilation optimization processing comprises one or more of link-time optimization, compile feedback optimization, and binary optimization layout tool optimization.

13. A readable storage medium, characterized by, one or more programs, which when executed on an electronic device, cause the electronic device to implement the patch package generation method of any one of claims 1-8.

14. An electronic device, comprising: comprise: a memory for storing one or more programs; at least one processor for executing the one or more programs to cause the electronic device to implement the patch package generation method of any one of claims 1-12.

15. A computer program product, characterised in that, the computer program product, when executed on an electronic device, causes the electronic device to implement the patch package generation method of any one of claims 1-12.