CN115826946B - Program exception vector space optimization system, method, equipment and medium - Google Patents

Program exception vector space optimization system, method, equipment and medium Download PDF

Info

Publication number
CN115826946B
CN115826946B CN202310128388.2A CN202310128388A CN115826946B CN 115826946 B CN115826946 B CN 115826946B CN 202310128388 A CN202310128388 A CN 202310128388A CN 115826946 B CN115826946 B CN 115826946B
Authority
CN
China
Prior art keywords
program
module
code
allocation
space
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202310128388.2A
Other languages
Chinese (zh)
Other versions
CN115826946A (en
Inventor
杨亮
何鹏飞
白艳
陈静静
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Suzhou Inspur Intelligent Technology Co Ltd
Original Assignee
Suzhou Inspur Intelligent Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Suzhou Inspur Intelligent Technology Co Ltd filed Critical Suzhou Inspur Intelligent Technology Co Ltd
Priority to CN202310128388.2A priority Critical patent/CN115826946B/en
Publication of CN115826946A publication Critical patent/CN115826946A/en
Application granted granted Critical
Publication of CN115826946B publication Critical patent/CN115826946B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Stored Programmes (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

The invention belongs to the field of computers, and particularly relates to a program abnormal vector space optimization system, a system, equipment and a medium. A system, comprising: the code analysis module analyzes the output file compiled by the program to determine a hole space in an abnormal vector space corresponding to the program and a target variable compiled by the program; the hole space allocation module generates an allocation strategy for allocating the target variable to the hole space in the abnormal vector space through a preset algorithm, and sends the allocation strategy to the code modification module; the code modification module modifies a target variable in the source code of the program based on the allocation policy to generate a target code file. The program data is stored by using the abnormal vector space, so that the size of the program mirror image file is reduced, and the storage space occupied by the program mirror image file can be effectively reduced.

Description

Program exception vector space optimization system, method, equipment and medium
Technical Field
The invention belongs to the field of computers, and particularly relates to a program abnormal vector space optimization system, a system, equipment and a medium.
Background
The program will have two addresses during compiling and running: a called link address, namely the address of the program when linked after compiling, which is generally in one-to-one correspondence with the address stored in the mirror image file; another type of address is called the run address, i.e. the address during the running of the program. Most of the time, the addresses of both are consistent, but this can lead to a problem: in order to ensure that the link address and the running address are matched one by one, the program image file is subjected to 0 filling processing at the hole, so that the image file is enlarged. Sometimes, in order to reduce the size of the image file of the program and achieve the purpose of accelerating the loading of the program, a compaction technology is used, such as adding at (absolute position variable identifier in the embedded field) in a link file, and setting the memory address of the target variable in the C program, and using a key in the form of "variable name __ at __"), so that the address where the program actually operates is a parameter of the at key, and the image file sequentially arranges codes and data, and then moves binary codes or data to an operation address in the process of operating the program, where the link address is inconsistent with the operation address, although the loading time of the program is reduced, and the operation time of the program is increased. Therefore, the loading time and the running time of the program seem to be a pair of contradictors, and the loading time is reduced, and the running time is increased; the running time is reduced, and the loading time is increased.
Therefore, an effective solution is needed to solve the above-mentioned problems.
Disclosure of Invention
In order to solve the above problems, the present invention provides a program exception vector space optimization system, which includes a code analysis module, a hole space allocation module, and a code modification module, wherein:
the code analysis module is configured to analyze the output file after the program compiling to determine a hole space in the abnormal vector space corresponding to the program and a target variable after the program compiling;
the hole space allocation module is configured to generate an allocation strategy for allocating a target variable to a hole space in the abnormal vector space through a predetermined algorithm, and send the allocation strategy to the code modification module;
the code modification module is configured to modify a target variable in source code of a program based on the allocation policy to generate a target code file.
In some embodiments of the invention, the code analysis module comprises:
and the first text searching module is configured to determine a description part corresponding to the abnormal vector space and a target variable in the output file after the compiling of the program according to the compiling mode of the program.
In some embodiments of the invention, the code analysis module further comprises:
and the redundant code analysis module is configured to determine redundant data existing in the description part based on a preset abnormal vector space template.
In some embodiments of the invention, the code analysis module further comprises:
and the void space confirmation module is configured to analyze the description part determined by the first text searching module and/or the redundant data of the description part determined by the redundant code analysis module, and determine available void space in the abnormal vector space corresponding to the description part.
In some embodiments of the invention, the code analysis module further comprises:
and the sorting module is configured to sort the target variables based on the data sizes of the target variables.
In some embodiments of the present invention, the void space allocation module includes:
and the allocation strategy module is configured to generate an allocation strategy for allocating the target variable to the hole space in the abnormal vector space through a plurality of allocation algorithms.
In some embodiments of the present invention, the void space allocation module further comprises:
And the cavity space management module is configured to store the allocation strategy generated by the allocation algorithm corresponding to the allocation strategy module, and restore the initial state of the cavity space to the next allocation algorithm for allocation operation when the next allocation algorithm runs.
In some embodiments of the present invention, the void space allocation module further comprises:
and the optimal solution output module is configured to acquire allocation strategies generated by a plurality of allocation algorithms from the cavity space management module, and determine an optimal solution of the allocation strategies according to a preset mode based on the allocation strategies generated by the plurality of allocation algorithms.
In some embodiments of the invention, the code modification module comprises:
and the second text searching module is configured to find the position of the variable related to the allocation strategy in the source code of the program according to the allocation strategy.
In some embodiments of the invention, the code modification module further comprises:
and the abnormal vector modification module is configured to delete codes corresponding to redundant data in an abnormal vector space analyzed by the code analysis module on the program in the program source code.
In some embodiments of the invention, the code modification module further comprises:
and the data area variable modification module is configured to replace a variable of a target variable in program source codes with a corresponding pointer according to an allocation strategy, and point the pointer to a corresponding address in an abnormal vector space allocated in the allocation strategy.
In some embodiments of the invention, the data area variable modification module is further configured to:
and placing the corresponding variable of the target variable in the program source code into the label representing the abnormal vector space in the mode of assembling the label of the code according to the allocation strategy.
In some embodiments of the invention, the code modification module further comprises:
and the intermediate result updating module is configured to store the modification of the program source code by the data area variable modifying module and the abnormal vector modifying module.
In some embodiments of the invention, the system further comprises:
and the abnormal vector template module is configured to provide a corresponding abnormal vector space template for the code analysis module according to the hardware architecture of the program.
In some embodiments of the invention, the system further comprises:
and the merging module is configured to merge the content allowed by the user in the target code file into the source code of the program according to the operation of the user.
In some embodiments of the invention, the integration module is further configured to:
judging whether the target code files are all integrated into the source code of the program, and in response to the fact that the target code files are not all integrated into the source code of the program, recompiling the integrated source code files of the program according to a preset mode and sending the compiled output files to the code analysis module.
In some embodiments of the invention, the integration module is further configured to:
and in response to the target code files being completely merged into the source code of the program, compiling the source code of the merged program into an executable file.
Another aspect of the present invention provides a method for optimizing a program exception vector space, including:
analyzing the output file after the program compiling to determine a cavity space in an abnormal vector space corresponding to the program and a target variable after the program compiling;
Generating an allocation strategy for allocating the target variable to a hole space in the abnormal vector space through a preset algorithm;
and modifying the target variable in the source code of the program based on the allocation policy to generate a target code file.
Yet another aspect of the present invention is directed to a computer device comprising:
at least one processor; and
a memory storing computer instructions executable on the processor, which when executed by the processor, perform the steps of the method of any of the above embodiments.
Yet another aspect of the invention also proposes a computer-readable storage medium storing a computer program which, when executed by a processor, implements the steps of the method of any of the above embodiments.
By the program abnormal vector space optimization method provided by the invention, program data is stored by using the abnormal vector space, so that the size of the program mirror image file is reduced, the storage space occupied by the program mirror image file can be effectively reduced, and the program loading time is shortened along with the reduction of the program mirror image file; meanwhile, the invention also avoids the problem that the link address is inconsistent with the running address caused by using the at keyword technology in the link script.
Drawings
In order to more clearly illustrate the embodiments of the invention or the technical solutions in the prior art, the drawings that are required in the embodiments or the description of the prior art will be briefly described, it being obvious that the drawings in the following description are only some embodiments of the invention, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a schematic diagram of a program exception vector space optimization system according to an embodiment of the present invention;
FIG. 2 is a schematic flow chart of a method for optimizing a program exception vector space according to an embodiment of the present invention;
fig. 3 is a schematic structural diagram of a computer device according to an embodiment of the present invention;
FIG. 4 is a schematic diagram of a computer readable storage medium according to an embodiment of the present invention;
fig. 5 is a schematic structural diagram of a code analysis module according to an embodiment of the present invention;
fig. 6 is a schematic structural diagram of a void space allocation module according to an embodiment of the present invention;
FIG. 7 is a schematic diagram of a code modification module according to an embodiment of the present invention;
FIG. 8 is a schematic diagram of a system for providing program exception vector space optimization according to an embodiment of the present invention;
Fig. 9 is a data distribution diagram of exception handling corresponding to an exception vector space based on an ARMv8 architecture in the exception vector space according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the following embodiments of the present invention will be described in further detail with reference to the accompanying drawings.
It should be noted that, in the embodiments of the present invention, all the expressions "first" and "second" are used to distinguish two entities with the same name but different entities or different parameters, and it is noted that the "first" and "second" are only used for convenience of expression, and should not be construed as limiting the embodiments of the present invention, and the following embodiments are not described one by one.
The invention aims to solve the problem of waste of equipment storage space in the process of processing the abnormality of an abnormality processing program when the abnormality occurs in the process of running the program in the traditional program compiling mode, and particularly aims to solve the problem that in some terminal IOT equipment, if wearing equipment such as a bracelet and networking equipment such as household electrical equipment are used, a chip platform with low power consumption and low performance is generally selected as a hardware basis by considering service and cost factors in the design of the equipment, so that the operation speed and the storage space capacity of the equipment are limited. But in applications it is desirable to achieve the technical effect of a fast start-up or a fast response on these platforms. Therefore, how to achieve fast start-up and response in low configurations is a challenge.
In order to solve the above problems, as shown in fig. 1, the present invention provides a program exception vector space optimization system, which includes a code analysis module 1, a hole space allocation module 2, and a code modification module 3, wherein:
the code analysis module 1 is configured to analyze the output file after the program compiling to determine a hole space in the abnormal vector space corresponding to the program and a target variable 2 after the program compiling;
the hole space allocation module 2 is configured to generate an allocation policy for allocating a target variable to a hole space in the abnormal vector space by a predetermined algorithm, and send the allocation policy to the code modification module 3;
the code modification module 3 is configured to modify a target variable in the source code of the program based on the allocation policy to generate a target code file.
In an embodiment of the present invention, a general program image file is divided into a code section and a data section; the data segment is divided into an all 0 data segment and a non-zero data segment; wherein the optimization of the code segments is extremely complex and is not considered in the present patent; all 0 data segments, namely bss segments, actually store only the starting position and size of the data segments, so that there is no space for optimization; the data segment other than 0, namely the data segment, is often stored independently of codes, and the arrangement mode often causes holes to exist between the data segment and the code segment, and in order to ensure that the link address is consistent with the running address, when a program image file is generated, a compiler performs 0 filling operation in the hole spaces; in addition, since some code segments also have alignment operations, the 0-stuffing process is sampled, which increases the program image file. Considering that some segment positions in the program mirror image file are fixed and the utilization rate is not high, the invention fills the void space processed by 0 filling into more meaningful data, thereby not only reducing the loading time of the program mirror image, but also reducing the running time of the program. The most representative segment is the segment of data where the anomaly vector space is located. The exception vector space refers to a data space when exception processing is performed at the time of program exception. As shown in fig. 9, fig. 9 shows a data spatial distribution corresponding to an abnormal vector spatial distribution of the ARMv8 processor. For example, the space represented by 128 bytes 0×080 to 0×180 in fig. 9 is an interrupt space for executing IRQ/vIRQ under Current El with SP0, and in general, the 128-byte data space mainly stores register data (specific contents are different and more or less according to logic of a program) of an exception handling operation, and an exception handling vector mainly operates as follows:
1) The necessary registers are stacked, often referred to as a save site;
2) Jumping to an exception handling flow;
3) Restoring the registers stored in the stack, often referred to as restoring the scene;
4) Returning to execution before the exception.
Therefore, the vector space will store the data needed in the above process into the space represented by 128 bytes, 0x080 to 0x180 (assuming the exception handling is IRQ interrupt) according to the binary data instruction after program compiling. In practice, however, the program cannot fully utilize the exception vector space after compilation. The compiler will take place in a 0-filled manner with unused data at compile time.
When it needs to be described, the exception vector space of the program is a scheme that the exception handling mode of the program is realized after the source code of the program is compiled into the executable program, that is, the exception handling of the program is realized after the program is compiled, which is a mechanism designed by the program and hardware for maintaining the stable running of the program, even if a program which only prints "hello world" is written in any language, after the program is compiled, the processing mechanism exists when the exception occurs to the program, and the corresponding exception vector space exists. The same program may have different exception vector spaces after compilation due to different hardware platforms (processor architectures).
Therefore, when optimizing an abnormal vector space of a certain program, compiling the program, and obtaining a compiled output file, where the output file includes: symbol table, disassembly file, address mapping table file, executable program file.
The code analysis module 1 analyzes the output file and finds the corresponding abnormal vector space of the executable program and the target variable stored in the abnormal vector space according to the compiling tool. And determining the part filled with 0 by the compiler in the abnormal vector space according to the recorded content of the abnormal vector space, and taking the part filled with 0 as a hole space, and sending the hole space together with the target variable to the hole space allocation module 2.
Further, the hole space allocation module 2 generates allocation policies for adding the target variables to the hole space through various allocation algorithms, and sends the allocation policies to the code modification module 3.
The code modification module 3 then modifies the scope of some variables corresponding to the target variables in the source code of the program according to the allocation policy to add these variables to the exception vector space. For example, the variables are originally stored in a memory after the program is run, and are changed into registers corresponding to the abnormal vector space. Thereby generating object code optimized for the program and saving the object code as an object code file.
In some embodiments of the present invention, the code analysis module 1 includes:
the first text search module 11 is configured to determine, in the output file after the program is compiled, a description portion and a target variable corresponding to the abnormal vector space in the output file according to a compiling mode of the program.
As shown in fig. 5, the code analysis module further includes a first text search module 11, where the first text search module mainly searches the content in the output file after compiling the program, and analyzes the content in the compiled output file according to the compiling tool and the hardware platform adopted by the program, to find a description part of the anomaly vector space corresponding to the anomaly processing of the program in the output file. And determining an abnormal vector space of the program based on the description part, acquiring all variable information of the program through the disassembly file and the address mapping table file, and determining a corresponding global variable and a variable which is not changed in the running process of the program, wherein the global variable and the variable are taken as target variables.
In some embodiments of the present invention, the code analysis module 1 further comprises:
a redundant code analysis module 12, the redundant code analysis 12 module being configured to determine redundant data present in the description section based on a preset anomaly vector space template.
In this embodiment, the code analysis module 1 further includes a redundancy code analysis module 12, where the redundancy code analysis module compares the abnormal vector space of the program according to a preset or selected abnormal vector space template based on the determined abnormal vector space, determines redundant data of the abnormal vector space compared with the abnormal vector space module, and uses the redundant data of the abnormal vector space as the redundancy data.
Specifically, as shown in the abnormal vector space reference table in fig. 9, taking IRQ interrupt corresponding to 0x080 as an example, it is assumed that the contents in the abnormal vector space template are only the address of the jump to the abnormal processing flow and the address of the processing flow executed before returning to the abnormality, and the sizes of the two data addresses are 64 bits, i.e., 8 bytes, respectively. In this case, if it is assumed that, in the exception vector space of the program, other data is present in the 128-byte space corresponding to 0x080, in addition to the address of the jump to the exception process and the address of the process flow executed before the return to the exception, the other data and the selected vector space template are redundant data, and it is necessary to mark them.
In some embodiments of the present invention, the code analysis module 1 further comprises:
And a void space confirmation module 13, where the void space confirmation module 13 is configured to analyze the description portion determined by the first text search module 11 and/or the redundant data of the description portion determined by the redundant code analysis module 12, and determine a void space available in an abnormal vector space corresponding to the description portion.
In this embodiment, the code analysis module 1 further includes a hole space confirmation module 13, where the hole space confirmation module 13 analyzes the 0-filled portion and redundant data in the abnormal vector space included in the description portion, and determines the corresponding data address range and uses the corresponding address range as the hole space available in the abnormal vector space of the program.
In some embodiments of the present invention, the code analysis module 1 further comprises:
a ranking module 14, the ranking module 14 configured to rank the target variables based on their data sizes.
In this embodiment, the sorting module in the code analysis module 1 sorts the target variables according to the data sizes of the variables, and sends the sorted target variables to the hole space allocation module.
In some embodiments of the present invention, the void space allocation module 2 includes:
An allocation policy module 21, the allocation policy module 21 being configured to generate an allocation policy for allocating the target variable to a hole space in the anomaly vector space by a plurality of allocation algorithms.
In this embodiment, the allocation policy module 21 allocates the target variable to the void space according to the void space and the target variable sent by the code analysis module through algorithms such as dynamic programming, greedy algorithm, knapsack algorithm, and the like, that is, fills the void space according to the data size of the target variable.
In some embodiments of the present invention, the void space allocation module 2 further includes:
and the hole space management module 22 is configured to save the allocation policy generated by the allocation algorithm corresponding to the allocation policy module, and restore the initial state of the hole space to the next allocation algorithm for allocation operation when the next allocation algorithm runs.
In this embodiment, the void space allocation module 2 is further provided with a void space management module 22, where the void space management module 22 provides initialization work of vector space for each algorithm in the allocation policy module 21, and stores allocation policies given by each algorithm.
In some embodiments of the present invention, the void space allocation module 2 further includes:
and the optimal solution output module 23 is configured to acquire allocation policies generated by a plurality of allocation algorithms from the hole space management module, and determine an optimal solution of the allocation policies according to a predetermined manner based on the allocation policies generated by the plurality of allocation algorithms.
In this embodiment, after the allocation policies are given by the algorithms, the optimal solution output module 23 obtains the allocation policies given by the allocation algorithms and the remaining unallocated target variables from the hole space management module 22, and evaluates the allocation policies according to the number of the remaining unallocated target variables and the target variables allocated to the abnormal vector space and the data size of the target variables allocated to the abnormal vector space to obtain the optimal solution. For example, according to the characteristics of a hardware platform operated by a program and a scheduling mechanism during the operation of the program, a corresponding evaluation tendency is selected, for example, if a storage space of the hardware platform is small, data access is frequent, and a target variable with a large data volume is preferentially allocated to an allocation policy, when the allocation of each algorithm is evaluated, the data size of the remaining unallocated target variable is taken as a main judgment basis, and the smaller the data size of the remaining target variable of the allocation scheme of which algorithm is, the optimal solution is.
In some embodiments of the present invention, the number of times the target variable is used in the program is also used as an evaluation basis for whether the target variable is allocated to the abnormal vector space. If the target variable is frequently called in the program, the smaller the number of unassigned target variables is used as a judgment basis, the smaller the number of the remaining target variables of the allocation scheme of which algorithm is, the better is, and the optimal solution is considered.
In some embodiments of the present invention, the code modification module 3 includes:
a second text lookup module 31 configured to find the location of the variable associated with the allocation policy in the source code of the program according to the allocation policy.
In this embodiment, the code modification module 3 is provided with a second text search module 31, and the second text search module 31 finds the position of the corresponding target variable allocated to the abnormal vector space in the source code according to the optimal allocation scheme given in the hole space allocation module 2.
In some embodiments of the present invention, the code modification module 3 further comprises:
an abnormal vector modification module 32, wherein the abnormal vector modification module 32 is configured to delete the code corresponding to the redundant data in the abnormal vector space analyzed by the code analysis module 1 in the program source code.
In the present embodiment, the abnormal vector modification module 32 clarifies the code corresponding to the abnormal vector space redundancy data given by the code analysis module 1 in the optimal allocation scheme in the program source code.
In some embodiments of the present invention, the code modification module 3 further comprises:
and the data area variable modification module 33 is configured to replace a variable of a target variable in program source code with a corresponding pointer according to an allocation policy, and point the pointer to a corresponding address in an abnormal vector space allocated in the allocation policy.
In this embodiment, the data area variable modification module 33 replaces the variable at the corresponding position by a pointer according to the position of the target variable in the program source code determined by the second text search module 31, and points the pointer to the address of the corresponding abnormal vector space in the allocation policy. In this way, the target variable is added into the hole space of the abnormal vector space after compiling.
In some embodiments of the present invention, the data area variable modification module 33 is further configured to:
and placing the corresponding variable of the target variable in the program source code into the label representing the abnormal vector space in the mode of assembling the label of the code according to the allocation strategy.
In this embodiment, attribute tags are added to corresponding variables in the program source code, and the attribute tags are added to the corresponding exception vector spaces. For example, a corresponding target variable is added to a connection file corresponding to "section name" through "section (" section name ") of the C language.
In some embodiments of the present invention, the code modification module 3 further comprises:
an intermediate result update module 34, said intermediate result update module 34 being configured to save modifications to said program source code by a data area variable modification module and an anomaly vector modification module.
In this embodiment, the code modification module 3 is further provided with an intermediate result update module for saving the source code modification result.
In some embodiments of the present invention, because the object code modified by the code modification module 3 is created in a branching manner, it is necessary to merge into the original branch after modification, and it is necessary to have a user confirm whether to approve the modification at the time of merging. Therefore, the target code file of modification of each time of the code modification module 3 needs to be saved as an intermediate result.
In some embodiments of the invention, the system further comprises:
And the abnormal vector template module 4 is configured to provide a corresponding abnormal vector space template for the code analysis module according to the hardware architecture of the program.
As shown in fig. 8, in the present embodiment, the exception vector template module records the most simplified exception vector space under each architecture, such as the most common ARM architecture, RISCV architecture, MIPS architecture, etc., and is called by the code modification module. And providing a corresponding abnormal vector space template for the code analysis module.
In some embodiments of the invention, the system further comprises:
and the merging module 5 is configured to merge the content allowed by the user in the target code file into the source code of the program according to the operation of the user.
As shown in fig. 8, the merging module 5 is configured to provide the target code modified by the code modification module 3 to a programmer for auditing, and the user confirms which modifications can be merged into the main branch, and which modifications cannot be merged into the main branch.
In some embodiments of the invention, the integration module 5 is further configured to:
judging whether the target code files are all integrated into the source code of the program, and in response to the target code files not being all integrated into the source code of the program, recompiling the integrated source code files of the program according to a preset mode and sending the compiled output files to the code analysis module 1.
Further, in this embodiment, the merging module 5 determines, according to the merging scheme after confirmation by the user (programmer), whether the modified target code in the merged code is completely agreed to be merged into the main branch by the user (if not, it is indicated that there is still a void space in the abnormal vector space.
In some embodiments of the invention, the integration module is further configured to:
and in response to the target code files being completely merged into the source code of the program, compiling the source code of the merged program into an executable file.
In this embodiment, if all object code files are merged into the main branch of the source code of the program with consent, or if the user indicates that the next round of optimization is not performed, the merging module directly sends the source code confirmed by the user to the compiling module 6 to compile the executable file of the program.
Examples:
in this embodiment, the program exception vector space optimization system provided by the invention is implemented by taking the exception vector space of the ARMv8 architecture as an example.
When the ARMv8CPU is in AArch64 state, each EL has 16 independent entries, and the 16 entries are divided into four types of exceptions, namely: IRQ, FIQ, SError, synchronous. The instruction set of AArch64 or AArch32 has four different regions depending on whether an EL level migration would occur when an exception is triggered and whether the use is to occur. Unlike 4 bytes of vector space for each exception in ARMv7, where each entry in ARMv8 is 0x80 bytes, more code can be placed on the vector table. The overall 16 entries classification and offset relationships in the vector table are shown in FIG. 9.
It can be seen from fig. 9 that the entire anomaly vector space has a size of 0x800 bytes, i.e., 2048 bytes; such vector table has 3 under AArch64 architecture, so the total exception vector space has 6144 bytes in total, i.e., 6KB in size.
Specifically, based on the ARMv8CPU platform, the program exception vector space optimization system structure implemented in this embodiment is shown in fig. 8, and includes a code analysis module 1, a hole space allocation module 2, and a code modification module 3.
Compiling module 5: the main function of the module is to select a proper tool chain according to a hardware architecture, call a compiling tool chain to complete the compiling work of codes and generate files required by a subsequent module, such as: symbol table, disassembled file, address mapping table, etc.
Code analysis module 1: and analyzing whether the abnormal vector space has redundant codes according to the generated executable file and the disassembled codes. The exception handling vector mainly operates as follows:
step one, stacking necessary registers, which are often called save sites;
step two, jumping to an exception handling flow;
step three, restoring the register stored in the stack, which is often called a restoration site;
and step four, returning to the execution before the abnormality.
In the conventional implementation, in order to write simplicity and security, in the first step, all registers are stacked, and in the third step, all registers are popped, so that the size of an exception handling vector is increased, meanwhile, the space of a runtime stack is increased, and in order to save more registers, more CPU running time is consumed. Further analyzing the exception handling vector table in the linux kernel, it was found that if the exception handling vector size is less than 0x80 bytes, the insufficient portion will be filled with nop instructions. It can be seen that the anomaly vector space is a lot wasteful of practical application.
Therefore, in the present embodiment, it is considered that the processing flow of the exception vector does not actually need a special parameter transfer, such as interrupt processing flow: that is, in the ARMv8 architecture, the CPU acquires an interrupt number by operating the GIC (Generic Interrupt Controller, general interrupt controller), finds a corresponding interrupt handling function, and then executes. Therefore, in the process of step two from assembly to C language, only the register to be used is needed to be saved theoretically; similarly, for exceptions, the CPU also determines how to handle the exception by reading the exception register.
Following the above principle, the code analysis module 1 analyzes the exception vector to minimize unnecessary operations in the exception handling vector. After the analysis is completed, recording an analysis result in an intermediate process file; at the same time, the actual size of each exception handling vector needs to be recorded.
In addition to the above two main working contents, the code analysis module 1 also needs to use the address mapping table file generated by the compiling module 6 to analyze the space occupied by each variable stored in the data segment, order the information and output the information, so that the subsequent allocation activity can be reasonably performed.
Thus, in summary, the main functions of the code analysis module 1 are as follows:
a) Analyzing whether each abnormal vector in the abnormal vector space has redundant codes or not, and finding out a part in which the abnormal processing is really performed;
b) Recording the original information of the cavity space according to the result after the completion of the A);
c) Analyzing the space occupied by each variable of the data segment;
in this embodiment, the hollow space allocation module 2 allocates the content of the data area to the interrupt vector table space according to the output of the code analysis module 1, for example, according to a preset algorithm such as a dynamic programming or greedy algorithm, and records the information, so as to update the output of the code analysis module, that is, the intermediate result output by the hollow space management module, and output the optimal solution of the present round after completion. And after the completion, the code modification module is called to modify the variable attribute to complete the work of distributing the variable of the data area to the abnormal vector space.
However, since the program design has various requirements and some modifications may have a larger influence, it is possible that the user may not merge the object code file generated by the program exception vector space optimization system into the original code, that is, only select a part of the object code to be merged into the main branch, which needs to continue to recycle the process after the completion of the merging, until the redundant space in the exception vector space is completely allocated, or the data stored in the data area is larger than the residual space of the exception vector space. At this time, an optimal solution is generated, and the content of the data area which is not allocated to the cavity space is recorded for the subsequent merging module.
In this embodiment, the code modification module 3 firstly deletes redundant codes in the abnormal vector space according to the output of the code analysis module 1, then further analyzes according to the abnormal vector space preset in the abnormal vector template, determines whether the abnormal vector space in the abnormal vector template can be used for replacement, and modifies the processing function in the template into the processing function actually called in the program.
In addition, the code modification module 3 also needs to modify the attribute of the variable corresponding code stored in the data area according to the output of the hole space allocation 2 module, so as to complete the operation of really allocating the content of the data area to the abnormal vector space; the global variable can be used in the C code by adding a tag at the assembly code, placing the initial value of the corresponding variable in the space subsequent to the tag, and setting the tag to be of the global type, so that the operation of distributing the variable of the data area to the abnormal vector space can be completed similarly. And after the code modification is finished, the compiling module is called again to compile, and the subsequent flow is started.
In this embodiment, after the above process is completed, the merging module 5 presents the content modified by the code modification module, prompts the user that there may be risk for those modifications according to the modified content, and finally determines whether to merge the modifications into the code main branch by the user. And (5) finishing the merging and running the process again, and checking the result. For the content of the data area which is not finally distributed to the abnormal vector space, the module gives a prompt to inform the user of the reason of the failure to fit and a feasible proposal.
In this embodiment, the exception vector template 4 records the most simplified exception vector space under each architecture, such as the most common ARM architecture, RISCV architecture, MIPS architecture, etc., and is called by the code modification module.
By the program abnormal vector space optimization method provided by the invention, program data is stored by using the abnormal vector space, so that the size of the program mirror image file is reduced, the storage space occupied by the program mirror image file can be effectively reduced, and the program loading time is shortened along with the reduction of the program mirror image file; meanwhile, the invention also avoids the problem that the link address is inconsistent with the running address caused by using the at keyword technology in the link script.
As shown in fig. 2, another aspect of the present invention proposes a program exception vector space optimization method, including:
s1, analyzing an output file compiled by a program to determine a hole space in an abnormal vector space corresponding to the program and a target variable compiled by the program;
s2, generating an allocation strategy for allocating the target variable to the hole space in the abnormal vector space through a preset algorithm;
and step S3, modifying target variables in source codes of the programs based on the allocation strategy to generate target code files.
As shown in fig. 3, a further aspect of the present invention further proposes a computer device, including:
at least one processor 21; and
a memory 22, said memory 22 storing computer instructions 23 executable on said processor 21, said instructions 23 when executed by said processor 21 implementing the steps of any of the methods of the above embodiments.
As shown in fig. 4, a further aspect of the present invention further proposes a computer readable storage medium 401, said computer readable storage medium 401 storing a computer program 402, said computer program 402 implementing the steps of the method according to any of the above embodiments when being executed by a processor.
The foregoing is an exemplary embodiment of the present disclosure, but it should be noted that various changes and modifications could be made herein without departing from the scope of the disclosure as defined by the appended claims. The functions, steps and/or actions of the method claims in accordance with the disclosed embodiments described herein need not be performed in any particular order. Furthermore, although elements of the disclosed embodiments may be described or claimed in the singular, the plural is contemplated unless limitation to the singular is explicitly stated.
It should be understood that as used herein, the singular forms "a", "an", and "the" are intended to include the plural forms as well, unless the context clearly supports the exception. It should also be understood that "and/or" as used herein is meant to include any and all possible combinations of one or more of the associated listed items.
The foregoing embodiment of the present invention has been disclosed with reference to the number of embodiments for the purpose of description only, and does not represent the advantages or disadvantages of the embodiments.
It will be understood by those skilled in the art that all or part of the steps for implementing the above embodiments may be implemented by hardware, or may be implemented by a program for instructing relevant hardware, where the program may be stored in a computer readable storage medium, and the storage medium may be a read-only memory, a magnetic disk or an optical disk, etc.
Those of ordinary skill in the art will appreciate that: the above discussion of any embodiment is merely exemplary and is not intended to imply that the scope of the disclosure of embodiments of the invention, including the claims, is limited to such examples; combinations of features of the above embodiments or in different embodiments are also possible within the idea of an embodiment of the invention, and there are many other variations of the different aspects of the embodiments of the invention as described above, which are not provided in detail for the sake of brevity. Therefore, any omission, modification, equivalent replacement, improvement, etc. of the embodiments should be included in the protection scope of the embodiments of the present invention.

Claims (20)

1. The program anomaly vector space optimization system is characterized by comprising a code analysis module, a hole space allocation module and a code modification module, wherein:
the code analysis module is configured to analyze the output file after the program compiling to determine a hole space in the abnormal vector space corresponding to the program and a target variable after the program compiling;
the hole space allocation module is configured to generate an allocation strategy for allocating a target variable to a hole space in the abnormal vector space through a predetermined algorithm, and send the allocation strategy to the code modification module;
the code modification module is configured to modify a target variable in source code of a program based on the allocation policy to generate a target code file.
2. The system of claim 1, wherein the code analysis module comprises:
and the first text searching module is configured to determine a description part corresponding to the abnormal vector space and a target variable in the output file after the compiling of the program according to the compiling mode of the program.
3. The system of claim 2, wherein the code analysis module further comprises:
And the redundant code analysis module is configured to determine redundant data existing in the description part based on a preset abnormal vector space template.
4. The system of claim 3, wherein the code analysis module further comprises:
and the void space confirmation module is configured to analyze the description part determined by the first text searching module and/or the redundant data of the description part determined by the redundant code analysis module, and determine available void space in the abnormal vector space corresponding to the description part.
5. The system of claim 2, wherein the code analysis module further comprises:
and the sorting module is configured to sort the target variables based on the data sizes of the target variables.
6. The system of claim 1, wherein the void space allocation module comprises:
and the allocation strategy module is configured to generate an allocation strategy for allocating the target variable to the hole space in the abnormal vector space through a plurality of allocation algorithms.
7. The system of claim 6, wherein the void space allocation module further comprises:
and the cavity space management module is configured to store the allocation strategy generated by the allocation algorithm corresponding to the allocation strategy module, and restore the initial state of the cavity space to the next allocation algorithm for allocation operation when the next allocation algorithm runs.
8. The system of claim 7, wherein the void space allocation module further comprises:
and the optimal solution output module is configured to acquire allocation strategies generated by a plurality of allocation algorithms from the cavity space management module, and determine an optimal solution of the allocation strategies according to a preset mode based on the allocation strategies generated by the plurality of allocation algorithms.
9. The system of claim 1, wherein the code modification module comprises:
and the second text searching module is configured to find the position of the variable related to the allocation strategy in the source code of the program according to the allocation strategy.
10. The system of claim 1, wherein the code modification module further comprises:
And the abnormal vector modification module is configured to delete codes corresponding to redundant data in an abnormal vector space analyzed by the code analysis module on the program in the program source code.
11. The system of claim 9, wherein the code modification module further comprises:
and the data area variable modification module is configured to replace a variable of a target variable in program source codes with a corresponding pointer according to an allocation strategy, and point the pointer to a corresponding address in an abnormal vector space allocated in the allocation strategy.
12. The system of claim 11, wherein the data area variable modification module is further configured to:
and placing the corresponding variable of the target variable in the program source code into the label representing the abnormal vector space in the mode of assembling the label of the code according to the allocation strategy.
13. The system of claim 11, wherein the code modification module further comprises:
and the intermediate result updating module is configured to store the modification of the program source code by the data area variable modifying module and the abnormal vector modifying module.
14. The system of claim 1, further comprising:
and the abnormal vector template module is configured to provide a corresponding abnormal vector space template for the code analysis module according to the hardware architecture of the program.
15. The system of claim 1, further comprising:
and the merging module is configured to merge the content allowed by the user in the target code file into the source code of the program according to the operation of the user.
16. The system of claim 15, wherein the merge module is further configured to:
judging whether the target code files are all integrated into the source code of the program, and in response to the fact that the target code files are not all integrated into the source code of the program, recompiling the integrated source code files of the program according to a preset mode and sending the compiled output files to the code analysis module.
17. The system of claim 16, wherein the merge module is further configured to:
and in response to the target code files being completely merged into the source code of the program, compiling the source code of the merged program into an executable file.
18. A method for spatially optimizing a program exception vector, comprising:
analyzing the output file after the program compiling to determine a cavity space in an abnormal vector space corresponding to the program and a target variable after the program compiling;
generating an allocation strategy for allocating the target variable to a hole space in the abnormal vector space through a preset algorithm;
and modifying the target variable in the source code of the program based on the allocation policy to generate a target code file.
19. A computer device, comprising:
at least one processor; and
a memory storing computer instructions executable on the processor, which when executed by the processor, perform the steps of the method of claim 18.
20. A computer readable storage medium storing a computer program which, when executed by a processor, implements the steps of the method of claim 18.
CN202310128388.2A 2023-02-17 2023-02-17 Program exception vector space optimization system, method, equipment and medium Active CN115826946B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310128388.2A CN115826946B (en) 2023-02-17 2023-02-17 Program exception vector space optimization system, method, equipment and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310128388.2A CN115826946B (en) 2023-02-17 2023-02-17 Program exception vector space optimization system, method, equipment and medium

Publications (2)

Publication Number Publication Date
CN115826946A CN115826946A (en) 2023-03-21
CN115826946B true CN115826946B (en) 2023-05-12

Family

ID=85521738

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310128388.2A Active CN115826946B (en) 2023-02-17 2023-02-17 Program exception vector space optimization system, method, equipment and medium

Country Status (1)

Country Link
CN (1) CN115826946B (en)

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113220236A (en) * 2021-05-17 2021-08-06 北京青云科技股份有限公司 Data management method, system and equipment

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102043659A (en) * 2010-12-08 2011-05-04 上海交通大学 Compiling device for eliminating memory access conflict and implementation method thereof
CN104267999B (en) * 2014-09-26 2018-09-18 浙江中控技术股份有限公司 A kind of method and apparatus that control program is compiled
CN106126360B (en) * 2016-06-28 2020-08-25 海信视像科技股份有限公司 Address hole shielding method and device
US11126413B2 (en) * 2017-01-05 2021-09-21 Koninklijke Philips N.V. Compiling device and method
CN109918903B (en) * 2019-03-06 2022-06-21 西安电子科技大学 Program non-control data attack protection method based on LLVM compiler

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113220236A (en) * 2021-05-17 2021-08-06 北京青云科技股份有限公司 Data management method, system and equipment

Also Published As

Publication number Publication date
CN115826946A (en) 2023-03-21

Similar Documents

Publication Publication Date Title
US8196129B2 (en) Adaptive class loading
US7103881B2 (en) Virtual machine to provide compiled code to processing elements embodied on a processor device
CN113872948A (en) Method for executing intelligent contract, block chain node and node equipment
JP3299611B2 (en) Resource allocation device
CN107122216B (en) Dynamic loading method for embedded real-time operating system
US8214812B2 (en) Method of interpreting method bytecode and system operated by the same
US9424004B2 (en) Execution guards in dynamic programming
CN114816417B (en) Cross compiling method, device, computing equipment and storage medium
US7805718B2 (en) Optimisation of a compiler generated program code
CN113296786B (en) Data processing method, device, electronic equipment and storage medium
CN111078279A (en) Processing method, device and equipment of byte code file and storage medium
CN101847096A (en) Optimization method of stack variable-containing function
US7143272B2 (en) Using computation histories to make predictions
US6959430B2 (en) Specialized heaps for creation of objects in object-oriented environments
US5446899A (en) Hint generation in smart recompilation
CN115826946B (en) Program exception vector space optimization system, method, equipment and medium
US6625806B1 (en) Language processing method and language processing system improving use efficiency of cache memory
CN105447285A (en) Method for improving OpenCL hardware execution efficiency
JP2005507103A (en) Framework to realize Java heap
Leupers Register allocation for common subexpressions in DSP data paths
CN114866451B (en) iOS end route communication improvement method, device, storage medium and equipment
US20240134659A1 (en) Java bytecode injection methods and apparatuses, electronic devices, and storage media
Patra et al. Optimizing ast node for javascript compiler a lightweight interpreter for embedded device
CN116932044A (en) Instruction translation method and related equipment thereof
CN116630040A (en) Intelligent contract transaction rapid execution method based on fine-granularity read-write analysis

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant