Program code optimization method and device in link stage, equipment and storage medium
By identifying and optimizing clustering base point functions during the linking phase, cloning functions, and updating call relationships, the problem of missing instruction caches in direct mapping cache design is solved, thus improving the performance of device-side programs.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-12
- Publication Date
- 2026-03-10
AI Technical Summary
In existing direct-mapped cache designs, instruction cache missing issues are complex. Traditional optimization methods rely on runtime information or user behavior, which cannot effectively optimize function calls in device-side programs, leading to performance degradation.
By traversing the target file during the linking phase, clustering base point functions are identified, kernel clustering instances are created, clustering optimization operations are performed, functions are cloned and call relationships are updated, and the impact of missing instruction cache is eliminated.
No additional compilation steps or external tools are required, which improves the feasibility of code optimization and significantly enhances the performance of executable programs.
Smart Images

Figure CN121635899A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to methods, apparatus, devices, and storage media for optimizing program code during the linking stage. Background Technology
[0002] Instruction cache misses (I-cache misses) are a very common runtime problem in computer systems. The instruction cache (I-cache) is specifically used to store instruction code that has recently been executed or is about to be executed by the processor. When the processor needs to fetch an instruction, it first looks in the instruction cache. If the instruction is found, the processor can fetch and execute it directly; otherwise, a cache miss occurs. Once an instruction cache miss occurs, the processor must stop and request the next level of cache or directly from main memory to load the required instruction block into the instruction cache. This process of loading data from main memory is usually tens or even hundreds of times slower than accessing the cache, thus causing additional latency for the processor and severely reducing program execution efficiency and system performance. Direct mapping is an address mapping method in cache design that defines how data blocks in main memory are placed in fixed locations in the cache.
[0003] Currently, general instruction cache miss optimization methods may not be entirely applicable to direct mapping or may yield unsatisfactory results, especially in heterogeneous computing systems involving device-side programs. Since each device-side program is called through a unique entry point (kernel), the instruction cache miss problem becomes more complex, placing higher demands on compiler optimization. Existing technologies can employ code layout optimization, which relies on accurate profiling information to obtain function call frequencies, distinguishing between hot and cold code, and then aggregating frequently called hot code to improve spatial locality. Alternatively, link-time optimization (LTO) can be used, which compiles the entire program into an intermediate representation (IR) or bytecode, then integrates multiple related modules into a single compilation module before performing compilation optimization.
[0004] However, traditional code layout optimization methods rely on accurate runtime information and require additional steps (such as Profile-Guided Optimization (PGO)) or external tools (such as Binary Optimization and Layout Tool (BOLT)), making these optimization methods less feasible. LTO optimization methods integrate all relevant modules through linking and then compile the target program binary file. This compilation method depends on specific user behavior and cannot optimize function calls in pre-compiled binary libraries, significantly limiting its practical application. Summary of the Invention
[0005] This invention provides a method, apparatus, device, and storage medium for optimizing program code during the linking stage, which can improve the feasibility of code optimization methods, eliminate the impact of missing instruction caches, and significantly improve the performance of executable programs.
[0006] According to one aspect of the present invention, a method for optimizing program code during the linking stage is provided, applied to a linker, the method comprising:
[0007] Iterate through each object file input to the linker and obtain the program section in each object file;
[0008] If the program section is a clustering base point function, then a kernel clustering instance corresponding to the clustering base point function is created, and a clustering optimization operation is performed on the clustering base point function based on the kernel clustering instance;
[0009] After the clustering base point functions in all target files have completed the clustering optimization operation, a linking operation is performed on each of the target files.
[0010] Optionally, performing clustering optimization operations on the clustering base point function based on the kernel clustering instance includes:
[0011] Based on the calling relationship of the clustering base point functions, locate the source target file where the sub-function is located, create a pseudo target file corresponding to the source target file, store the pseudo target file in the maintenance list of the kernel clustering instance, and analyze the pseudo target file;
[0012] By calling the pseudo-target file through the kernel clustering instance, the cloning operation of the target function is completed, and an executable and linkable ELF file is created at the same time.
[0013] Replace the original call relationships of the clustering base point functions with the call relationships of the cloned functions.
[0014] Optionally, based on the calling relationship of the clustering base point functions, the source target file containing the sub-functions is located, a pseudo-target file corresponding to the source target file is created, and the pseudo-target file is analyzed, including:
[0015] Locate the source target file containing the program section of the clustering base point function, create a pseudo target file corresponding to the source target file, and mark the clustering base point function as to be cloned in the pseudo target file;
[0016] The target program section specified by the clustering base point function is traversed, all sub-functions called by the target program section are analyzed, and it is determined whether the sub-functions corresponding to the target program section need to be cloned.
[0017] If so, the program section of the sub-function is added to the list of functions to be cloned in the corresponding pseudo-object file;
[0018] The program section of the sub-function is taken as the target program section, and then the operation of all sub-functions called by the target program section is returned to be executed until the processing of all sub-functions is completed.
[0019] Optionally, after processing all sub-functions, the following may also be included:
[0020] Based on cache capacity constraints, determine whether clustering optimization operations are allowed to be performed on the clustering base point function;
[0021] If so, then continue to perform clustering optimization operations on the clustering base point function;
[0022] If not, then the clustering optimization operation on the clustering base point function is aborted.
[0023] Optionally, the pseudo-target file is invoked through the kernel clustering instance to complete the cloning operation of the target function, and an executable and linkable ELF file is created, including:
[0024] The information of the function section to be cloned in each pseudo-object file is statistically analyzed, and the ELF header format and ELF layout corresponding to each pseudo-object file are updated.
[0025] Clone the target program sections from each source object file and rename the associated symbols of the cloned functions;
[0026] After the ELF file of the pseudo-target file is created, the pseudo-target file is parsed and added to the list of target files waiting to be linked.
[0027] Optionally, the original call relationships of the clustering base point functions are replaced with the call relationships of the cloned functions, including:
[0028] The call relationships of all cloned functions in the pseudo-target file are modified to match the call relationships of the cloned functions, and the symbols of the clustering base point functions are modified.
[0029] According to another aspect of the present invention, a program code optimization apparatus for the linking stage is provided, applied to a linker, the apparatus comprising:
[0030] The file traversal module is used to traverse each object file input to the linker and obtain the program sections in each object file;
[0031] The clustering optimization module is used to create a kernel clustering instance corresponding to the clustering base point function if the program section is a clustering base point function, and to perform clustering optimization operation on the clustering base point function according to the kernel clustering instance;
[0032] The linking module is used to perform a linking operation on each of the target files after the clustering base point functions in all target files have completed the clustering optimization operation.
[0033] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:
[0034] At least one processor; and a memory communicatively connected to said at least one processor;
[0035] The memory stores a computer program that can be executed by the at least one processor, and the computer program is executed by the at least one processor to enable the at least one processor to perform the program code optimization method of the linking stage as described in any embodiment of the present invention.
[0036] According to another aspect of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions for causing a processor to execute and implement the program code optimization method of the linking stage as described in any embodiment of the present invention.
[0037] According to another aspect of the present invention, a computer program product is provided, the computer program product comprising a computer program that, when executed by a processor, implements the program code optimization method of the linking stage as described in any embodiment of the present invention.
[0038] The technical solution provided by this invention involves traversing each target file input to the linker to obtain program sections in each target file. If the program section is a clustering base point function, a kernel clustering instance corresponding to the clustering base point function is created, and clustering optimization operations are performed on the clustering base point function based on the kernel clustering instance. After the clustering base point functions in all target files have completed clustering optimization operations, a linking operation is performed on each target file. This technique can improve the feasibility of code optimization methods, eliminate the impact of missing instruction caches, and significantly improve the performance of executable programs.
[0039] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description
[0040] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0041] Figure 1 This is a flowchart of a program code optimization method during the linking stage according to an embodiment of the present invention;
[0042] Figure 2a This is a flowchart of another method for optimizing program code during the linking stage according to an embodiment of the present invention;
[0043] Figure 2b This is a schematic diagram illustrating a scenario applicable to a program code optimization method during the linking stage provided by an embodiment of the present invention;
[0044] Figure 2c This is a flowchart illustrating a clustering optimization method for clustering base point functions according to an embodiment of the present invention;
[0045] Figure 3 This is a schematic diagram of a program code optimization device for the linking stage according to an embodiment of the present invention;
[0046] Figure 4 This is a schematic diagram of the structure of an electronic device that implements the program code optimization method in the linking stage of this invention. Detailed Implementation
[0047] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0048] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0049] Figure 1 The flowchart illustrates a program code optimization method during the linking stage, as provided in this embodiment of the invention. This embodiment is applicable to situations where instruction cache missing issues are addressed by clustering and optimizing device-side entry functions during the code linking stage. This method can be executed by a program code optimization device during the linking stage, which can be implemented in hardware and / or software and configured in the linker of an electronic device, such as... Figure 1 As shown, the method includes:
[0050] Step 110: Traverse each object file input to the linker and obtain the program section in each object file.
[0051] In this embodiment, the program section is the basic unit used in Executable and Linkable Format (ELF) files to organize code and data by function. For example, the .text section stores executable code, and the .data section stores initialized global variables. In ELF files, the program section is the core logical unit used during the linking and debugging phases. It categorizes and stores different parts of the program (such as instructions, data, and symbol information), facilitating linker processing and debugger analysis. Each program section has a clear name, type, and attributes, which are managed uniformly by the Section Header Table.
[0052] Step 120: If the program section is a clustering base point function, then create a kernel clustering instance corresponding to the clustering base point function, and perform clustering optimization operation on the clustering base point function according to the kernel clustering instance.
[0053] In this step, it can be determined whether the program section in the current target file is a clustering base point function (i.e., the kernel entry function). If it is, a kernel clustering (KernelClustering) instance is created for the clustering base point function and clustering optimization is performed. If not, the process continues to traverse the next target file.
[0054] The advantage of this setup is that, for multi-kernel scenarios with a single compilation module on a heterogeneous multi-core platform, the linker can analyze the call relationships of kernel entry functions and perform function cloning to cluster and optimize kernel entry functions, thereby solving the problem of cache misses on directly mapped instruction caches.
[0055] Step 130: After the clustering base point functions in all target files have completed the clustering optimization operation, perform a linking operation on each of the target files.
[0056] In this embodiment, after the linker has completed the clustering optimization operation for the clustering base point functions in all target files, it can continue to complete the subsequent linking operation.
[0057] The technical solution provided by this invention involves traversing each target file input to the linker to obtain program sections in each target file. If the program section is a clustering base point function, a kernel clustering instance corresponding to the clustering base point function is created, and clustering optimization is performed on the clustering base point function based on the kernel clustering instance. After the clustering base point functions in all target files have completed clustering optimization, a linking operation is performed on each target file. Compared with traditional link-time code layout optimization methods or LTO optimization methods, this approach does not rely on additional compilation steps or external tools, and the optimization is implemented in a general compilation toolchain, making it more user-friendly. By analyzing function call relationships during the linking stage and specifically clustering the direct mapping instruction cache and device-side entry functions, the impact of missing instruction caches is eliminated to a certain extent, significantly improving the performance of the executable program.
[0058] Figure 2a A flowchart of another method for optimizing program code during the linking stage provided in an embodiment of the present invention is shown below. Figure 2a As shown, the method includes:
[0059] Step 210: Traverse each object file input to the linker and obtain the program section in each object file.
[0060] Step 220: If the program section is a clustering base point function, then create a kernel clustering instance corresponding to the clustering base point function.
[0061] Figure 2b This is a schematic diagram illustrating a scenario where a code optimization method during the linking stage is applicable, as shown in this embodiment. Figure 2b As shown, this embodiment can introduce kernel clustering, which acts on the clustering base point function and encapsulates the function cloning clustering method, and pseudo-target file class PseudoFile, which corresponds to the target file class ObjFile.
[0062] Step 230: Locate the source target file containing the sub-functions according to the calling relationship of the clustering base point functions, create a pseudo target file corresponding to the source target file, store the pseudo target file in the maintenance list of the kernel clustering instance, and analyze the pseudo target file.
[0063] In this step, such as Figure 2b As shown, based on the calling relationship of the clustering base point functions, the source target file ObjFile containing the sub-function (callee) can be found, and a pseudo target file PseudoFile corresponding to the source target file can be created. Then, the pseudo target file PseudoFile is put into the maintenance list of the kernel clustering instance, and all pseudo target files PseudoFile are analyzed.
[0064] In one embodiment of this example, step 230 may include:
[0065] Step 231: Locate the source target file containing the program section of the clustering base point function, create a pseudo target file corresponding to the source target file, and mark the clustering base point function as to be cloned in the pseudo target file;
[0066] Step 232: Traverse the target program section specified by the clustering base point function, analyze all sub-functions called by the target program section, and determine whether the sub-functions corresponding to the target program section need to be cloned;
[0067] Step 233: If yes, add the program section of the sub-function to the list of functions to be cloned in the corresponding pseudo-object file;
[0068] Step 234: Take the program section of the sub-function as the target program section, and then return to execute step 232 to analyze the operations of all sub-functions called by the target program section until the processing of all sub-functions is completed.
[0069] In one specific embodiment, the linker can analyze the call relationship corresponding to the target program section based on the relocation information. The target program section may include the program section corresponding to the clustering base point function and the program section corresponding to the sub-function.
[0070] In this embodiment, after processing all sub-functions, the method further includes: determining whether clustering optimization is allowed for the clustering base point function based on cache capacity constraints; if yes, then clustering optimization continues for the clustering base point function; if no, then clustering optimization is stopped for the clustering base point function.
[0071] Optionally, the cache capacity constraint may limit the maximum available memory size, as well as a series of configuration parameters and system requirements related to cache performance, resource management, and deployment limitations, to ensure that the cache system operates stably and efficiently under limited resources. If the cache capacity constraint determines that clustering optimization operations on the clustering base point function are allowed, then step 240 continues; if clustering optimization operations on the clustering base point function are not allowed, then the execution process of the clustering optimization operation is terminated.
[0072] Step 240: Call the pseudo-target file through the kernel clustering instance to complete the cloning operation of the target function and create an ELF file.
[0073] In this step, the KernelClustering instance calls the methods of each pseudo-target file, PseudoFile, to complete the cloning of the target function and the creation of the ELF file.
[0074] In one embodiment of this example, step 240 may include:
[0075] Step 241: Statistically analyze the information of the function section to be cloned in each pseudo-object file, and update the ELF header format and ELF layout corresponding to each pseudo-object file;
[0076] Step 242: Clone the target program sections from each source object file and rename the associated symbols of the cloned functions;
[0077] Step 243: After the ELF file of the pseudo-target file is created, parse the pseudo-target file and add it to the list of target files waiting to be linked.
[0078] The advantage of this setup is that by analyzing function call relationships based on relocation symbols in the linker and cloning and clustering all related sub-functions starting from the entry function together, the spatial locality of the instruction code is greatly improved. When the clustered and optimized code layout meets the constraints based on cache capacity, it can effectively eliminate instruction cache misses caused by the original scattered layout and eliminate the huge performance regression caused by cache misses.
[0079] Step 250: Replace the original call relationship of the clustering base point function with the call relationship of the clone function.
[0080] In this step, the original call relationships of the clustering base point functions can be replaced with the call relationships of the cloned functions. During the subsequent linking operation, the linker will update the output sections corresponding to these cloned functions to the same output section to complete the function clustering.
[0081] In this embodiment, replacing the original call relationship of the clustering base point function with the call relationship of the cloned function includes: modifying the call relationship of all cloned functions in the pseudo-target file to the call relationship of the cloned function, and modifying the symbol of the clustering base point function.
[0082] Step 260: After the clustering base point functions in all target files have completed the clustering optimization operation, perform a linking operation on each of the target files.
[0083] The technical solution provided by this invention involves traversing each target file input to the linker to obtain program sections in each target file. If the program section is a clustering base point function, a kernel clustering instance corresponding to the clustering base point function is created. The source target file containing the sub-function is located based on the call relationship of the clustering base point function. A pseudo-target file corresponding to the source target file is created, stored in the maintenance list of the kernel clustering instance, and analyzed. The kernel clustering instance calls the pseudo-target file to complete the cloning operation of the target function and simultaneously create an ELF file. The original call relationship of the clustering base point function is replaced with the call relationship of the cloned function. After the clustering base point functions in all target files have completed clustering optimization operations, the linking operation is performed on each target file. This technical approach does not rely on runtime information. By optimizing the code layout through function cloning and clustering during the linking stage, the instruction cache missing problem can be solved, significantly improving the performance of the executable program.
[0084] Based on the above implementation methods, in order to better explain the technical solution of this embodiment, Figure 2c The flowchart illustrates the execution of a clustering optimization method on the clustering basis point function. This clustering optimization method may include the following steps:
[0085] Step 1. Locate the source target file containing the program section of the clustering base point function, and create a pseudo target file corresponding to the source target file; if there are multiple clustering base point functions in the source target file, mark the function as to be cloned in the pseudo target file, and use the cloned function to replace the original function to complete the clustering.
[0086] Step 2. For the target program section (if the previous step of the control flow is Step 1, then the target program section is the program section of the clustering base point function; otherwise, it is the program section of other sub-functions), analyze the function call relationship corresponding to the target program section, and determine all the sub-functions called by the target program section based on the relocation information.
[0087] Step 3. Determine whether the sub-functions of each target program section need to be cloned. If the sub-function has been marked as to be cloned or specified not to be cloned by the link parameters, skip the processing of the sub-function; otherwise, continue to step 4.
[0088] Step 4. For sub-function sections, if a corresponding pseudo-object file has not yet been created for the object file it belongs to, then create a pseudo-object file; otherwise, use the pseudo-object file corresponding to the source object file.
[0089] Step 5. Add the program section of the sub-function to the list of functions to be cloned in the corresponding pseudo-object file.
[0090] Step 6. Take the program section of the sub-function as the target program section, and then return to the operation of step 2 to analyze the function call relationship corresponding to the target program section until the processing of all sub-functions is completed, and then execute step 7.
[0091] Step 7. Determine whether to allow function clustering optimization based on cache capacity constraints. If the instruction cache missing problem can be eliminated, proceed to step 8 to continue optimization; otherwise, stop the clustering optimization operation on the clustering base point function.
[0092] Step 8. Calculate the information of the function section to be cloned for each pseudo-object file, and update the ELF header format and ELF layout in the pseudo-object file.
[0093] Step 9. Clone the target program section from the source object file and rename the relevant symbols of the cloned function.
[0094] Step 10. After completing the ELF creation of the pseudo-object file, the linker parses the pseudo-object file and adds it to the input object file list for linking.
[0095] Step 11. Modify all calls to the cloned function in the pseudo-target file to calls to the cloned function, and change the clustering base point function symbol to a weak symbol, so that when the host program calls the entry function, it can call the corresponding function after the cloned clustering optimization.
[0096] The above implementation methods can improve the feasibility of code optimization methods, eliminate the impact of missing instruction caches, and significantly improve the performance of executable programs.
[0097] Figure 3 This is a schematic diagram of a program code optimization device during the linking stage provided by an embodiment of the present invention. The device is applied in the linker of an electronic device, such as... Figure 3 As shown, the device includes: a file traversal module 310, a clustering optimization module 320, and a linking module 330.
[0098] The file traversal module 310 is used to traverse each object file in the input linker and obtain the program section in each object file;
[0099] The clustering optimization module 320 is used to create a kernel clustering instance corresponding to the clustering base point function if the program section is a clustering base point function, and perform clustering optimization operation on the clustering base point function according to the kernel clustering instance;
[0100] Linking module 330 is used to perform linking operations on each of the target files after the clustering base point functions in all target files have completed the clustering optimization operation.
[0101] The technical solution provided by this invention involves traversing each target file input to the linker to obtain program sections in each target file. If the program section is a clustering base point function, a kernel clustering instance corresponding to the clustering base point function is created, and clustering optimization operations are performed on the clustering base point function based on the kernel clustering instance. After the clustering base point functions in all target files have completed clustering optimization operations, a linking operation is performed on each target file. This technique can improve the feasibility of code optimization methods, eliminate the impact of missing instruction caches, and significantly improve the performance of executable programs.
[0102] Based on the above embodiments, the clustering optimization module 320 includes:
[0103] The file search unit is used to find the source target file where the sub-function is located according to the calling relationship of the clustering base point function, create a pseudo target file corresponding to the source target file, store the pseudo target file in the maintenance list of the kernel clustering instance, and analyze the pseudo target file.
[0104] The function cloning unit is used to call the pseudo-target file through the kernel clustering instance to complete the cloning operation of the target function and create an ELF file at the same time;
[0105] The call relationship replacement unit is used to replace the original call relationship of the clustering base point function with the call relationship of the clone function;
[0106] The function marking unit is used to locate the source target file containing the program section of the clustering base point function, create a pseudo target file corresponding to the source target file, and mark the clustering base point function as to be cloned in the pseudo target file;
[0107] The sub-function judgment unit is used to traverse the target program section specified by the clustering base point function, analyze all sub-functions called by the target program section, and determine whether the sub-function corresponding to the target program section needs to be cloned; if so, the program section of the sub-function is added to the list of functions to be cloned in the corresponding pseudo-target file.
[0108] The loop execution unit is used to take the program section of the sub-function as the target program section, and then return to execute and analyze the operation of all sub-functions called by the target program section until the processing of all sub-functions is completed;
[0109] The constraint judgment unit is used to determine, based on the cache capacity constraint, whether clustering optimization operation is allowed to be performed on the clustering base point function; if yes, then the clustering optimization operation is continued to be performed on the clustering base point function; if no, then the clustering optimization operation on the clustering base point function is stopped.
[0110] The ELF file creation unit is used to statistically analyze the information of the function section to be cloned in each pseudo-object file, and update the ELF header format and ELF layout corresponding to each pseudo-object file; clone the target program section from each source object file, and rename the associated symbols of the cloned functions; after the ELF file of the pseudo-object file is created, parse the pseudo-object file, and add the pseudo-object file to the target file list waiting to perform the linking operation.
[0111] The call relationship modification unit is used to modify the call relationship of all cloned functions in the pseudo-target file to the call relationship of the cloned functions, and to modify the symbol of the clustering base point function.
[0112] The above-described apparatus can execute the methods provided in all the foregoing embodiments of the present invention, and has the corresponding functional modules and beneficial effects for executing the above methods. Technical details not described in detail in the embodiments of the present invention can be found in the methods provided in all the foregoing embodiments of the present invention.
[0113] Figure 4A schematic diagram of an electronic device 10, which can be used to implement embodiments of the present invention, is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.
[0114] like Figure 4 As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12 or a random access memory (RAM) 13, communicatively connected to the at least one processor 11. The memory stores computer programs executable by the at least one processor. The processor 11 can perform various appropriate actions and processes based on the computer program stored in the ROM 12 or loaded into the RAM 13 from the storage unit 18. The RAM 13 can also store various programs and data required for the operation of the electronic device 10. The processor 11, ROM 12, and RAM 13 are interconnected via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0115] Multiple components in electronic device 10 are connected to I / O interface 15, including: input unit 16, such as keyboard, mouse, etc.; output unit 17, such as various types of displays, speakers, etc.; storage unit 18, such as disk, optical disk, etc.; and communication unit 19, such as network card, modem, wireless transceiver, etc. Communication unit 19 allows electronic device 10 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0116] Processor 11 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, digital signal processing (DSP) processors, and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, such as program code optimization methods during the linking phase.
[0117] In some embodiments, the code optimization method during the linking phase can be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program can be loaded and / or installed on electronic device 10 via ROM 12 and / or communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the code optimization method during the linking phase described above can be performed. Alternatively, in other embodiments, processor 11 can be configured to perform the code optimization method during the linking phase by any other suitable means (e.g., by means of firmware).
[0118] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-chips (SoCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0119] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0120] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, RAM, ROM, erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0121] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a cathode ray tube (CRT) or a liquid crystal display (LCD)) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0122] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or middleware components (e.g., application servers), or frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.
[0123] A computing system can include clients and servers. Clients and servers are generally geographically separated and typically interact via communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system. It addresses the shortcomings of traditional physical hosts and Virtual Private Servers (VPS) in terms of management difficulty and weak business scalability.
[0124] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.
[0125] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A method for optimizing program code in a link phase, characterized by The method applied to a linker comprises: traversing each object file inputted into the linker to obtain program sections in each object file; if the program section is a clustering base point function, creating a kernel clustering instance corresponding to the clustering base point function and performing clustering optimization operation on the clustering base point function according to the kernel clustering instance; after the clustering optimization operation on the clustering base point function is completed, performing linking operation on each object file.
2. The method of claim 1, wherein, performing clustering optimization operation on the clustering base point function according to the kernel clustering instance comprises: finding a source object file where a sub-function is located according to a calling relationship of the clustering base point function, creating a pseudo object file corresponding to the source object file, storing the pseudo object file into a maintenance list of the kernel clustering instance, and analyzing the pseudo object file; calling the pseudo object file through the kernel clustering instance to complete cloning operation on the target function, and creating an executable linkable format ELF file; replacing the original calling relationship of the clustering base point function with a calling relationship of the cloned function.
3. The method of claim 2, wherein, finding a source object file where a sub-function is located according to a calling relationship of the clustering base point function, creating a pseudo object file corresponding to the source object file, and analyzing the pseudo object file comprises: finding a source object file where a program section of the clustering base point function is located, creating a pseudo object file corresponding to the source object file, and marking the clustering base point function in the pseudo object file as to-be-cloned; traversing a target program section specified by the clustering base point function, analyzing all sub-functions called by the target program section, and judging whether the sub-functions corresponding to the target program section need to be cloned; if yes, adding program sections of the sub-functions to a to-be-cloned function list in the corresponding pseudo object file; taking the program section of the sub-function as the target program section, and then returning to perform the operation of analyzing all sub-functions called by the target program section until processing of all sub-functions is completed.
4. The method of claim 3, wherein, after processing of all sub-functions is completed, further comprising: judging whether the clustering optimization operation on the clustering base point function is allowed based on a cache capacity constraint condition; if yes, continuing the clustering optimization operation on the clustering base point function; if no, aborting the clustering optimization operation on the clustering base point function.
5. The method of claim 3, wherein, calling the pseudo object file through the kernel clustering instance to complete cloning operation on the target function, and creating an executable linkable format ELF file comprises: counting to-be-cloned function section information in each pseudo object file, and updating an ELF header format and an ELF layout corresponding to each pseudo object file; cloning target program sections from each source object file, and renaming associated symbols of the cloned functions; after the ELF file of the pseudo object file is created, parsing the pseudo object file, and adding the pseudo object file to a target file list waiting for linking operation.
6. The method of claim 2, wherein, replacing the original calling relationship of the clustering base point function with a calling relationship of the cloned function comprises: modifying the calling relationship of all cloned functions in the pseudo object file to the calling relationship of the cloned function, and modifying symbols of the clustering base point function.
7. An apparatus for optimizing program code in a link phase, characterized by The device applied to a linker comprises: a file traversal module configured to traverse each target file input into the linker and obtain program sections in each target file; a cluster optimization module configured to, if the program section is a cluster base point function, create a kernel cluster instance corresponding to the cluster base point function, and perform a cluster optimization operation on the cluster base point function according to the kernel cluster instance; a linking module configured to, after the cluster base point functions in all target files complete the cluster optimization operation, perform a linking operation on each target file.
8. An electronic device, comprising: The electronic device comprises: at least one processor; and a memory connected to the at least one processor in communication; wherein the memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor to enable the at least one processor to execute the program code optimization method of the linking stage according to any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, The computer readable storage medium stores computer instructions for enabling the processor to implement the program code optimization method of the linking stage according to any one of claims 1-6 when executed.
10. A computer program product, characterised in that, The computer program product comprises a computer program for implementing the program code optimization method of the linking stage according to any one of claims 1-6 when executed by the processor. The computer program product comprises a computer program for implementing the program code optimization method of the linking stage according to any one of claims 1-6 when executed by the processor.