WO2014019367A1 - Method and device for redeploying multilevel storage - Google Patents

Method and device for redeploying multilevel storage Download PDF

Info

Publication number
WO2014019367A1
WO2014019367A1 PCT/CN2013/072953 CN2013072953W WO2014019367A1 WO 2014019367 A1 WO2014019367 A1 WO 2014019367A1 CN 2013072953 W CN2013072953 W CN 2013072953W WO 2014019367 A1 WO2014019367 A1 WO 2014019367A1
Authority
WO
WIPO (PCT)
Prior art keywords
symbol
redeployed
section
location information
target
Prior art date
Application number
PCT/CN2013/072953
Other languages
French (fr)
Chinese (zh)
Inventor
周巍
Original Assignee
华为技术有限公司
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 华为技术有限公司 filed Critical 华为技术有限公司
Publication of WO2014019367A1 publication Critical patent/WO2014019367A1/en

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/443Optimisation

Definitions

  • the present invention relates to the field of information technology, and in particular, to a method and apparatus for redeploying multi-level storage.
  • redirect files provided by third parties in the form of libraries.
  • the code in the redirect files is deployed to different levels of memory by means of multi-level storage. These can be directly used in software code development. Oriented files improve the efficiency of code development. Because the purpose of software development is different, the frequency of the symbols provided in the redirect file will be different. Direct use of the redirect file provided by the third party will result in the efficient use of memory at all levels. Therefore, it is usually necessary to redeploy the storage location of each code in the redirect file, so as to fully exploit the advantages of speed, capacity, and cost in each level to achieve optimal cost performance.
  • the redeployment method of the multi-level storage is: First, specify the section attribute for each symbol when the source code is compiled. Multiple symbols can share a node attribute, and then compiled into a re-directable file by the compiler, the mapping relationship between the section and the memory block is written into the link script, and then an image file is generated to complete the symbol deployment. Then, by modifying the mapping relationship between the section and the memory block in the link script, the image file is regenerated to complete the symbol redeployment.
  • Embodiments of the present invention provide a method and apparatus for redeploying multi-level storage, which can implement redeployment of redirected file symbols without modifying source code.
  • the embodiment of the present invention provides a method for re-deploying a multi-level storage, including: acquiring current location information of a symbol to be redeployed from a redirect file; and performing, according to current location information of the symbol to be redeployed.
  • the symbol to be redeployed is redeployed.
  • the embodiment of the present invention provides a multi-level storage re-deployment apparatus, including: a first acquiring unit, configured to acquire current location information of a symbol to be redeployed from a redirect file; and a redeployment unit, configured to The current location information of the symbol to be redeployed redeploys the symbol to be redeployed.
  • the current location information of the symbol to be redeployed is obtained from the redirect file, and the current location information of the symbol to be redeployed is to be redeployed according to the current location information of the symbol to be redeployed.
  • the symbol is redeployed.
  • FIG. 1 is a flowchart of a method for redeploying multi-level storage according to an embodiment of the present invention
  • FIG. 2 is a flowchart of a method for redeploying multi-level storage according to an embodiment of the present invention
  • FIG. 3 is a schematic flowchart of a multi-level storage according to an embodiment of the present invention.
  • FIG. 4 is a schematic diagram of a composition of a redirect file according to an embodiment of the present invention
  • FIG. 5 is a schematic diagram of symbol deployment in a redirect file according to an embodiment of the present invention
  • FIG. 6 is a schematic diagram of a link script according to an embodiment of the present invention
  • FIG. 7 is a schematic diagram of redistribution of symbols in a redirect file according to an embodiment of the present invention.
  • FIG. 8 is a flowchart of another method for redeploying multi-level storage according to an embodiment of the present invention.
  • FIG. 9 is a flowchart of another method for redeploying multi-level storage according to an embodiment of the present invention.
  • FIG. 10 is a schematic structural diagram of another redirect file according to an embodiment of the present invention.
  • FIG. 11 is a schematic diagram of a re-deployment apparatus of a multi-level storage according to an embodiment of the present invention
  • FIG. 12 is a schematic diagram of another multi-level storage re-deployment apparatus according to an embodiment of the present invention
  • Schematic diagram of the composition of the heavy storage device of the level storage
  • An embodiment of the present invention provides a method for redeploying multi-level storage, as shown in FIG. 1, including:
  • the redirect file is a binary object file, which is generated after being compiled by the source code, used to link with other target files, create an executable file or share the code or data of the target file, and any multi-level storage method. After compiling the source code after writing the source code, a redirect file is generated, and the redirect file can be provided by a third party that provides the redirect file.
  • the symbol may be a variable or a function in the source code, etc., and a specific symbol to be re-deployed may be predetermined before redeployment, for example, providing a symbol name corresponding to the symbol to be redeployed.
  • the redirection file that has been stored in the computer hard disk can be opened by reading the current location information of the symbol to be deployed, and the redirection file is read into the memory, and from the redirection file. Get the current location information of the symbol that needs to be redeployed.
  • the symbol to be redeployed according to current location information of the symbol to be redeployed Number for redeployment.
  • the The current location information of the redeployed symbol modifies the storage location information of the symbol to be redeployed in the redirect file to implement redeployment of the symbol to be redeployed.
  • the unused symbol can be used as the symbol to be redeployed, and the symbol to be redeployed is deleted.
  • the redeployment of the symbol to be redeployed, after the link, the symbol to be redeployed is not loaded into the memory occupying memory space, which saves memory space.
  • the method for re-deploying the multi-level storage obtaineds the current location information of the symbol to be redeployed from the redirection file by parsing the redirection file, and according to the current location information of the symbol to be redeployed. Re-deploy the symbols for redeployment. Compared with the attribution section of the symbol in the source code in the prior art, by parsing the redirected file, the current location information of the symbol to be redeployed can be directly obtained, and only the symbol that needs to be redeployed is changed to the storage location.
  • the symbol that does not need to be redeployed does not change the storage location, not only can the multi-level storage redeployment implementation object be granular to the symbol level, and the source code does not need to be modified, thereby reducing the cost of redeployment.
  • An embodiment of the present invention provides another method for redeploying multi-level storage. As shown in FIG. 2, the method includes:
  • the symbol name to be redeployed is a name of a variable or a function that needs to be cropped or changed, and the symbol to be redeployed is defined when the source code is written.
  • the redirection file in this embodiment uses an Executable and Linkable Format (ELF) as an example to illustrate a redeployment method of multi-level storage.
  • ELF Executable and Linkable Format
  • the redirect file is not limited to ELF files. This method can also be used to implement multi-level storage redeployment for the common object file format (COFF) and the executable file format (Portable Execute, PE).
  • Multi-level storage is generally implemented as shown in Figure 3 (a): First, the source code is generated on the code development platform according to the software function, as shown in Figure 3 (b), the source code is completed according to the function, which is based on the function requirements. Symbols are defined. For example, int a defines a variable named a, int funa ( ) defines a function named funa, and so on. As shown in Figure 3 (c), the definition of the section, the definition of the attribute - ((section (".1 1.data”))) is to put the symbol into the section named ll.data In the festival area. Then, as shown in Fig. 3 (d), the relationship between the symbol and the section is mapped in the source code.
  • LI DATA int a indicates that the variable a is placed in the specified section of the section named ll.data. in.
  • the link script By modifying the link script, establish the mapping relationship between the section and the specified memory block. Finally, the file can be redirected.
  • the link script generates an image file through a link to the linker. At this point, as shown in Figure 3 (f), after multi-level storage, each symbol determines the location of the deployed memory.
  • the internal composition of the redirect file is as shown in FIG. 4, and the redirect file includes a file control header, a section area, a symbol table, and a section header table.
  • Each symbol corresponds to an entry in the symbol table, and each symbol table entry includes a start address of the symbol, a symbol length, an offset of the symbol in its corresponding section, and a section index number corresponding to the symbol.
  • Each section corresponds to the control header in the section header table, and also contains the starting address of each section.
  • the starting address Y of the symbol a in the memory and the length M of the memory space occupied by the symbol a in the memory are obtained from the table entry.
  • the starting address of the symbol is the offset of the starting position of the symbol from the file control head, for example, the starting address Y of the symbol a is the offset of the starting position of the symbol a from the file control head.
  • the symbol table of the redirected file may be queried by the symbol name of the symbol to be redeployed, and the section of the section where the symbol to be redeployed is located is named section A (section A).
  • the ending address of the symbol to be redeployed in the embodiment of the present invention is the offset of the end position of the symbol to be redeployed from the file control header, and the start address of the symbol to be redeployed and the The length of the memory space occupied by the symbols to be redeployed is obtained.
  • the starting address of the symbol to be redeployed and the length of the memory space occupied by the symbol can be obtained by the method described in step 201.
  • step 201 After the start address Y of the symbol a to be redeployed and the length M of the symbol a to be redeployed are obtained in step 201, the start address Y is added to the length M, as shown in FIG. 5, to be redeployed.
  • the end address Z of the symbol a is obtained in step 201.
  • the target memory block name is usually a given known condition.
  • the target location of the symbol that has been determined to be redeployed is specifically a memory block named L2TEXT_seg in the memory block.
  • a memory block corresponds to a section.
  • the memory block name L2TEXT_seg is queried, and the connection script is obtained, and the section of the target section to which the symbol is expected to be deployed is named section B (section B).
  • section B section B
  • the link script is a defined file, and a mapping relationship between the section and the specified memory is established in the link script. In the multi-level storage, before the source code is written, the relationship between the symbol and the section is mapped in the source code. , just conceptually bind the symbol to the section.
  • the link script links and generates an image file, and then the specific location where each symbol is deployed in the memory is determined. This specific location is determined by the mapping of the node to the memory.
  • 204 Query a section header table according to the target section name, and obtain the target section. Start address and target segment length.
  • the target section name may be obtained by the method described in step 203, and the length of the section entry corresponding to the target section name in the section header table of the redirect file.
  • the starting address of the target node is the offset of the starting position of the target node from the file control head.
  • the section table entry corresponding to the section name is found in the section header table, and the start address of the section section section B is obtained from the section entry of the sectionB.
  • W and the length of the memory space occupied by the target section section B in the memory, the specific storage location is shown in Figure 5. .
  • the section item corresponding to the section area named sectionA can also be found through the section header table, and is obtained from the section table item of section A.
  • the specific storage location is as shown in FIG. 5.
  • the end address of the target section is the end position of the target section and is controlled by the file.
  • the starting address of the target section and the length of the target section may be obtained by the method described in step 204.
  • the start address W of the target node area is added to the length V to obtain the target section.
  • the end address X of the area is shown in Figure 5.
  • the foregoing steps 201-202 may be performed.
  • the symbols to be redeployed in the redirect file are redeployed.
  • the specific steps are as follows: 206. Move the symbol to be redeployed from a current location to a target location according to current location information and target location information of the symbol to be redeployed.
  • the moving the symbol to be redeployed to the target location may first determine a relative relationship between the target location and the current location. Still taking FIG. 5 as an example, the starting address Y of the symbol a to be redeployed is obtained through step 201, and the starting address W of the target node section B is obtained by step 204, and the relationship between W and Y is compared, if W is greater than Y, it can be determined that the current position is after the target position, and if W is less than Y, it can be determined that the current position is before the target position.
  • step 204 obtaining a starting address W of the target node section B and a starting address E of the section area A where the symbol a to be redeployed is currently, and comparing the relationship between W and E. If W is greater than E, It can also be determined that after the current position is after the target position, if W is less than E, it can also be determined that the current position is before the target position. It can be understood that the relative relationship between the target location and the current location can be obtained by using various methods, which is not limited by the embodiment of the present invention.
  • the method for moving the symbol to be deployed from the current location to the target location may be: changing a starting address of the symbol to be redeployed in the memory space to an ending address of the target node in the memory space, thereby The symbol to be redeployed is redeployed to the last position of the target section.
  • the memory space start address Y of the symbol a to be redeployed is changed to the end address X of the target node section B in the memory space, thereby The symbol a to be redeployed is redeployed to the last position of the target section sectionB, and the symbol a to be redeployed becomes the symbol a after deployment.
  • the association section or symbol includes: a section or a symbol between the start address of the symbol to be redeployed and the end of the target section, or the end address of the symbol to be redeployed A section or symbol between the end addresses of the target section.
  • the specific movement is: when the current position of the symbol to be redeployed is behind the target position, the section or symbol between the start address of the symbol to be redeployed and the end address of the target section is backward (to the section)
  • the area head table direction moves the symbol length of the symbol to be redeployed;
  • the section or symbol between the end address of the symbol to be redeployed and the end address of the target node is forwarded (to the file control head) Direction) Moves the symbol length of the symbol to be redeployed.
  • the symbol or the section between the address X and the address Y in the memory space is sequentially moved backward (toward the section header table).
  • the symbol length size of the symbol to be redeployed For the determination of the relative relationship between the current location and the target location, refer to step 206, and details are not described herein again.
  • steps 206 and 207 do not necessarily follow the sequence described in the embodiment of the present invention.
  • step 207 may also be before step 206 for the convenience of redeployment. That is, adjust the position of the associated section or symbol first, and then adjust the position of the symbol to be redeployed.
  • the related information in the control file of the redirect file can be modified correspondingly, and the modification method is as follows:
  • Modify the section header table according to the re-deployed symbol and the location information of the section modify the length of the current section in the control section of the current section minus the length of the symbol; modify the section header table
  • the length of the target node area in the target node control header increases the length of the symbol; queries the start address of other section areas in the section header table, determines whether other section areas are associated nodes, and repairs accordingly Change the starting address of the associated section. For example, by the relative relationship between the target position and the current position in step 206, if the current position is after the target position, the starting address for the other nodes is greater than or equal to the end address of the target node and less than the start of the symbol a.
  • the address, the length of the symbol a or the start address of the section in the section header table is sequentially increased by the length M of the symbol a; if the current position is before the target position, the starting address of the other section is greater than or equal to the symbol a
  • the start address is smaller than the end address of the target section, and the length of the symbol a is sequentially increased by the conditional symbol or the start address of the section in the section header table.
  • the current position is after the target position, if the starting address of a certain section is greater than or equal to the end address of the target section and is smaller than the starting address of the symbol a, it is determined as the associated section, and the associated section in the file control header is The starting address including the associated symbol in the associated section is sequentially added with the length M of the symbol a; if the current position is before the target position, if the starting address of a certain section is greater than or equal to the starting address of the symbol a and smaller than the target section The end address of the area is determined as the associated node, and the start address of the associated node in the file control header is added to the length M of the symbol a.
  • the modified redirect file is saved, and the modified information is saved to the hard disk.
  • the repair information is saved from the memory to the redirect file, and the modification of the redirect file is completed.
  • the modified redirect file and the link script are passed through the linker. Linking, the symbol to be redeployed is redeployed from the current location to the target location, and the storage location of the deployed symbol in the memory is re-determined.
  • steps 301 and 302 are the same as step 201 and step 202, respectively, and details are not described herein again.
  • Step 303 create a new section.
  • a new section may be newly created to obtain the target position information.
  • sectionB adding the starting address and the section size of the newly added section to the section header.
  • section header entry adds a section header entry.
  • the newly added section has no actual physical memory space.
  • a section rule is added in the link script to establish a mapping between the newly created section and the memory block. relationship.
  • the memory block is a free memory block found by looking at the link script.
  • Step 304 The starting address of the newly created section is used as the target location information.
  • the new node is used as the target node of the symbol, and the starting address of the newly created node is the target location information.
  • Step 305 to step 307 correspond to step 206 to step 208 respectively, and the common technology in the art will not be described herein.
  • Step 401 Query a symbol table in the redirect file according to the symbol name of the symbol to be redeployed, and obtain a start address and a symbol length of the symbol to be redeployed.
  • step 201 For the specific method for obtaining the starting address and the symbol length of the symbol to be re-deployed, refer to step 201 in this embodiment, and details are not described herein again.
  • Step 402 Calculate an end address of the symbol to be redeployed according to a start address and a symbol length of the symbol to be redeployed.
  • step 202 For the specific calculation method of the end address of the symbol to be redeployed, refer to step 202 in this embodiment, and details are not described herein again.
  • the symbol table of the redirected file may be queried by using the symbol name of the symbol to be redeployed, and the name of the section of the node in which the symbol to be redeployed is currently located may be obtained.
  • Step 403 Delete the symbol to be redeployed from the current location according to the current location information of the symbol to be redeployed.
  • the symbol to be redeployed is found according to the symbol name of the symbol to be redeployed, and the symbol to be redeployed is deleted from the memory space.
  • Step 404 Redeploy the associated section or symbol.
  • the associated node or symbol refers to a section or symbol adjacent to the symbol to be redeployed or the symbol to be redeployed adjacent to the symbol to be redeployed.
  • the specific modification method is: subtracting the length of the symbol to be redeployed from all the symbols and the starting address of the node in the memory space whose starting address is greater than or equal to the ending address of the symbol to be redeployed.
  • Step 405 Modify the symbol table, the section header table, and the file control header corresponding to the redirect file according to the location information of the re-deployed symbol and the location information of the section.
  • the symbol to be redeployed may be deleted, and the information about the deleted symbol in the redirected file may be related information in the symbol table, related information in the section header table, and related information in the redirecting file control header.
  • the modification method is as follows:
  • the offset in the section is greater than the offset of the deleted symbol in the section.
  • the offset of the deleted symbol in the section is subtracted; the corresponding symbol table entry in the redirected file is deleted.
  • section header table modify the length of the current section in the section control header where the deleted symbol in the section header table is the current section length minus the length of the deleted symbol; query the section header table The start address of all the sections whose start address is greater than the end address of the deleted symbol is sequentially subtracted from the length of the deleted symbol.
  • the file control header is queried, and the start address of all the sections of the file control header whose start address is greater than the end address of the deleted symbol is sequentially subtracted from the length of the deleted symbol.
  • the method for re-deploying the multi-level storage obtaineds the current location information of the symbol to be redeployed from the redirection file by parsing the redirection file, and according to the current location information of the symbol to be redeployed. Re-deploy the symbols for redeployment.
  • the symbols that will be used in the generated program that need to be redeployed are added to the target location, and the information related to the symbol is modified.
  • the symbol can be added to the scene. Idle destination, complete the link.
  • the embodiment of the present invention further provides a multi-level storage re-deployment device.
  • the first embodiment includes: a first obtaining unit 31 and a redeploying unit 32.
  • the first obtaining unit 31 is configured to obtain current location information of the symbol to be redeployed from the redirect file.
  • the redeployment unit 32 is configured to redeploy the symbol to be redeployed according to the current location information of the symbol to be redeployed acquired by the first acquiring unit.
  • the current location information includes a start address, an end address, and a length of the symbol to be redeployed
  • the first acquiring unit 31 is specifically configured to: according to the symbol name of the symbol to be redeployed Querying a symbol table in the redirect file, obtaining a start address and a symbol length of the symbol to be redeployed; and starting a address and a symbol of the symbol to be redeployed acquired according to the first obtaining unit Length calculating the end address of the symbol to be redeployed
  • the redeploying unit 32 is configured to perform heavy weighting on the symbol to be redeployed according to the current location information of the symbol to be redeployed acquired by the first acquiring unit deploy.
  • the redeployment unit 32 is specifically configured to: delete the symbol to be redeployed from the current location according to current location information of the symbol to be redeployed acquired by the first acquiring unit.
  • the embodiment of the present invention provides another multi-level storage re-deployment apparatus.
  • the multi-level storage re-deployment apparatus may further include: a second acquisition unit 33.
  • the second obtaining unit 33 is configured to obtain, before redeploying the symbol to be redeployed, Taking the target location information to be deployed of the symbol to be redeployed.
  • the redeploying unit 32 is specifically configured to: according to the current location information of the symbol to be redeployed acquired by the first acquiring unit, and the target location information acquired by the second acquiring unit, The redeployed symbol moves from the current location to the target location.
  • the second obtaining unit 33 is specifically configured to: query a link script according to the target memory block name to obtain a target section name; and query the section of the redirect file according to the target section name a header table, obtaining a start address of the target node area and a target node area length; calculating an end address of the target node area as the target location information according to the start address of the target node area and the target node area length .
  • the second obtaining unit 33 is specifically configured to: create a new section; and use the starting address of the newly created section obtained by the new module as the target location information.
  • the redeployment unit 32 is further configured to: redeploy the associated node or symbol, where the associated node or symbol includes: a start address of the symbol to be redeployed and an end address of the target node An internode or symbol, or a section or symbol between the end address of the symbol to be redeployed and the end address of the target section.
  • An embodiment of the present invention provides another multi-level storage re-deployment apparatus.
  • the multi-level storage apparatus further includes: a modifying unit 34, configured to: according to the location information of the re-deployed symbol and the node area The location information modifies the symbol table, the section header table, and the file control header included in the redirect file.
  • the format of the redirect file includes: an executable link file format ELF, a common object file format COFF, or an executable file format PE.
  • the method for re-deploying the multi-level storage obtaineds the current location information of the symbol to be redeployed from the redirection file by parsing the redirection file, and according to the current location information of the symbol to be redeployed. Re-deploy the symbols for redeployment.
  • the symbols that will be used in the generated program that need to be redeployed are added to the target location, and the information related to the symbol is modified.
  • the symbol can be added to the scene. Idle destination, complete the link.
  • the present invention can be implemented by means of software plus necessary general hardware, and of course, by hardware, but in many cases, the former is a better implementation. .
  • the technical solution of the present invention which is essential or contributes to the prior art, may be embodied in the form of a software product stored in a readable storage medium, such as a floppy disk of a computer.
  • a hard disk or optical disk or the like includes instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to perform the methods described in various embodiments of the present invention.

Abstract

Embodiments of the invention disclose a method and a device for redeploying multilevel storage, and relates to the technical field of information. Redeployment of a redirection file symbol can be implemented without modifying a source code. The implementing method of the present invention comprises: acquiring current location information of a to-be-redeployed symbol from a redirection file; and redeploying the to-be-redeployed symbol according to the current location information of the to-be-redeployed symbol. The embodiments of the invention are mainly used for a redeploying process of a multilevel storage.

Description

多级存储的重部署方法及装置 技术领域  Multi-level storage redeployment method and device
本发明涉及信息技术领域,尤其涉及一种多级存储的重部署方法及装 置。  The present invention relates to the field of information technology, and in particular, to a method and apparatus for redeploying multi-level storage.
背景技术 Background technique
在软件代码开发中, 存在大量第三方以库形式提供的重定向文件, 采 用多级存储的方式将重定向文件中的代码部署到不同级别的内存上,在软 件代码开发中可以直接使用这些重定向文件提高代码开发效率,由于软件 开发目的不同, 对重定向文件中提供的符号使用的频率也会不同, 直接使 用第三方提供的重定向文件, 会造成各级内存不能得到高效利用。 因此, 通常需要重新部署重定向文件中各代码的存储位置,从而充分发挥各级内 存在速度、 容量、 成本方面的优势, 达到最优性价比。  In software code development, there are a large number of redirect files provided by third parties in the form of libraries. The code in the redirect files is deployed to different levels of memory by means of multi-level storage. These can be directly used in software code development. Oriented files improve the efficiency of code development. Because the purpose of software development is different, the frequency of the symbols provided in the redirect file will be different. Direct use of the redirect file provided by the third party will result in the efficient use of memory at all levels. Therefore, it is usually necessary to redeploy the storage location of each code in the redirect file, so as to fully exploit the advantages of speed, capacity, and cost in each level to achieve optimal cost performance.
为了提高多级存储的性价比,需要调整重定向文件中各符号的存储位 置, 现有技术提供的多级存储的重部署方法为: 首先, 在源代码编译时为 每个符号指定节区属性, 多个符号可以共用一个节区属性, 再通过编译器 编译成可重定向文件, 将节区与内存块的映射关系写入链接脚本, 然后生 成镜像文件, 完成符号的部署。 然后, 通过修改链接脚本中节区与内存块 的映射关系, 重新生成镜像文件, 完成符号重部署。  In order to improve the cost performance of the multi-level storage, it is necessary to adjust the storage location of each symbol in the redirect file. The redeployment method of the multi-level storage provided by the prior art is: First, specify the section attribute for each symbol when the source code is compiled. Multiple symbols can share a node attribute, and then compiled into a re-directable file by the compiler, the mapping relationship between the section and the memory block is written into the link script, and then an image file is generated to complete the symbol deployment. Then, by modifying the mapping relationship between the section and the memory block in the link script, the image file is regenerated to complete the symbol redeployment.
在实现上述多级存储的重部署方法时,发明人发现现有技术至少存在 如下问题: 由于所述重定向文件中符号与节区已绑定, 修改链接脚本中节 区与内存块的映射关系只能在节区一级做调整,无法对单个符号进行重部 署。 在编译时为每个符号指定一个不同的节区属性, 可以修改单个符号的 存储位置, 但是需要获取到源代码, 并且对源代码的编译需要花费大量人 工成本。 发明内容 In the implementation of the above-described multi-level storage redeployment method, the inventor has found that at least the following problems exist in the prior art: Since the symbol and the section are bound in the redirect file, the mapping relationship between the section and the memory block in the link script is modified. Adjustments can only be made at the section level, and individual symbols cannot be redeployed. By assigning a different section attribute to each symbol at compile time, you can modify the storage location of a single symbol, but you need to get the source code, and the compilation of the source code requires a lot of labor costs. Summary of the invention
本发明的实施例提供一种多级存储的重部署方法及装置,可以无需修 改源代码实现对重定向文件符号的重部署。  Embodiments of the present invention provide a method and apparatus for redeploying multi-level storage, which can implement redeployment of redirected file symbols without modifying source code.
为达到上述目的, 本发明的实施例采用如下技术方案:  In order to achieve the above object, the embodiment of the present invention adopts the following technical solutions:
一方面, 本发明实施例提供一种多级存储的重部署方法, 包括: 从重 定向文件中获取待重部署的符号的当前位置信息;根据所述待重部署的符 号的当前位置信息对所述待重部署的符号进行重部署。  In an aspect, the embodiment of the present invention provides a method for re-deploying a multi-level storage, including: acquiring current location information of a symbol to be redeployed from a redirect file; and performing, according to current location information of the symbol to be redeployed. The symbol to be redeployed is redeployed.
另一方面, 本发明实施例提供一种多级存储的重部署装置, 包括: 第 一获取单元, 用于从重定向文件中获取待重部署的符号的当前位置信息; 重部署单元,用于根据所述待重部署的符号的当前位置信息对所述待重部 署的符号进行重部署。  In another aspect, the embodiment of the present invention provides a multi-level storage re-deployment apparatus, including: a first acquiring unit, configured to acquire current location information of a symbol to be redeployed from a redirect file; and a redeployment unit, configured to The current location information of the symbol to be redeployed redeploys the symbol to be redeployed.
本发明实施例提供的多级存储的重部署方法及装置,通过从重定向文 件中获取待重部署的符号的当前位置信息,根据所述待重部署的符号的当 前位置信息对所述待重部署的符号进行重部署,与现有技术中只能在节区 一级进行重部署的方法相比, 在重定向文件中只剪裁了需要重部署的符 号, 不需要通过修改源代码删除指定的符号, 即可将多级存储重部署的实 施对象粒度到符号级别, 降低成本。  The method and device for re-deploying the multi-level storage provided by the embodiment of the present invention, the current location information of the symbol to be redeployed is obtained from the redirect file, and the current location information of the symbol to be redeployed is to be redeployed according to the current location information of the symbol to be redeployed. The symbol is redeployed. Compared with the prior art method of redeploying only at the node level, only the symbols that need to be redeployed are trimmed in the redirect file, and the specified symbol is not deleted by modifying the source code. , you can granularize the implementation of multi-level storage redeployment to the symbol level, reducing costs.
附图说明  DRAWINGS
为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对 实施例或现有技术描述中所需要使用的附图作筒单地介绍, 显而易见地, 下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员 来讲, 在不付出创造性劳动的前提下, 还可以根据这些附图获得其他的附 图。  In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings to be used in the embodiments or the description of the prior art will be briefly described below. Obviously, the drawings in the following description It is merely some embodiments of the present invention, and those skilled in the art can obtain other drawings according to these drawings without any creative work.
图 1为本发明实施例一种多级存储的重部署方法流程图;  1 is a flowchart of a method for redeploying multi-level storage according to an embodiment of the present invention;
图 2为本发明实施例一种多级存储的重部署方法流程图;  2 is a flowchart of a method for redeploying multi-level storage according to an embodiment of the present invention;
图 3为本发明实施例一种多级存储的流程示意图;  3 is a schematic flowchart of a multi-level storage according to an embodiment of the present invention;
图 4为本发明实施例一种重定向文件的组成示意图; 图 5为本发明实施例一种重定向文件中符号部署的示意图; 图 6为本发明实施例一种链接脚本的示意图; 4 is a schematic diagram of a composition of a redirect file according to an embodiment of the present invention; FIG. 5 is a schematic diagram of symbol deployment in a redirect file according to an embodiment of the present invention; FIG. 6 is a schematic diagram of a link script according to an embodiment of the present invention;
图 7为本发明实施例一种重定向文件中符号的重部署示意图  FIG. 7 is a schematic diagram of redistribution of symbols in a redirect file according to an embodiment of the present invention;
图 8为本发明实施例另一种多级存储的重部署方法流程图;  8 is a flowchart of another method for redeploying multi-level storage according to an embodiment of the present invention;
图 9为本发明实施例另一种多级存储的重部署方法流程图;  FIG. 9 is a flowchart of another method for redeploying multi-level storage according to an embodiment of the present invention;
图 10为本发明实施例另一种重定向文件的组成示意图;  FIG. 10 is a schematic structural diagram of another redirect file according to an embodiment of the present invention;
图 11为本发明实施例一种多级存储的重部署装置组成示意图; 图 12 为本发明实施例另一种多级存储的重部署装置组成示意图; 图 13为本发明实施例再一种多级存储的重部署装置组成示意图。 具体实施方式  FIG. 11 is a schematic diagram of a re-deployment apparatus of a multi-level storage according to an embodiment of the present invention; FIG. 12 is a schematic diagram of another multi-level storage re-deployment apparatus according to an embodiment of the present invention; Schematic diagram of the composition of the heavy storage device of the level storage. detailed description
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进 行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例, 而不是全部的实施例。 基于本发明中的实施例, 本领域普通技术人员在没 有作出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的 范围。  The technical solutions in the embodiments of the present invention are clearly and completely described in conjunction with the drawings in the embodiments of the present invention. It is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative efforts are within the scope of the present invention.
本发明的实施例提供一种多级存储的重部署方法,如图 1所示,包括: An embodiment of the present invention provides a method for redeploying multi-level storage, as shown in FIG. 1, including:
101、 从重定向文件中获取待重部署的符号的当前位置信息。 101. Obtain current location information of the symbol to be redeployed from the redirect file.
其中, 所述重定向文件是一种二进制的目标文件, 由源代码编译后生 成, 用于与其他目标文件链接, 创建可执行文件或者共享目标文件的代码 或数据, 任一种多级存储方法, 编写源码之后对源代码进行编译, 都会生 成重定向文件, 所述重定向文件可以由提供重定向文件的第三方提供。 所 述符号可以为源代码中的变量或函数等,在重部署之前可以预先确定待重 部署的特定符号, 例如提供待重部署的符号对应的符号名。 通过所述重定 向文件按获取待部署的符号的当前位置信息,可以将已存入电脑硬盘中的 重定向文件打开, 将所述重定向文件读入内存中, 并从所述重定向文件中 获取到需要重部署的符号的当前位置信息。  The redirect file is a binary object file, which is generated after being compiled by the source code, used to link with other target files, create an executable file or share the code or data of the target file, and any multi-level storage method. After compiling the source code after writing the source code, a redirect file is generated, and the redirect file can be provided by a third party that provides the redirect file. The symbol may be a variable or a function in the source code, etc., and a specific symbol to be re-deployed may be predetermined before redeployment, for example, providing a symbol name corresponding to the symbol to be redeployed. The redirection file that has been stored in the computer hard disk can be opened by reading the current location information of the symbol to be deployed, and the redirection file is read into the memory, and from the redirection file. Get the current location information of the symbol that needs to be redeployed.
102、 根据所述待重部署的符号的当前位置信息对所述待重部署的符 号进行重部署。 102. The symbol to be redeployed according to current location information of the symbol to be redeployed Number for redeployment.
其中, 当所述重定向文件中的符号在生成的程序中没有使用到的时 候,或是需要将所述待重部署的符号从当前的存储位置移动到其他存储位 置,都可以根据所述待重部署的符号的当前位置信息修改所述待重部署的 符号在重定向文件中的存储位置信息,实现对所述待重部署的符号的重部 署。  Wherein, when the symbol in the redirect file is not used in the generated program, or the symbol to be redeployed needs to be moved from the current storage location to another storage location, the The current location information of the redeployed symbol modifies the storage location information of the symbol to be redeployed in the redirect file to implement redeployment of the symbol to be redeployed.
可以理解的是, 若在重定向文件中有符号在生成的程序中没有使用 到, 则可以将所述没有使用到的符号作为待重部署的符号, 通过删除所述 待重部署的符号实现对所述待重部署的符号的重部署, 则在链接之后, 所 述待重部署的符号就不会被加载到内存中占用内存空间, 节约了内存空 间。  It can be understood that if the symbol in the redirect file is not used in the generated program, the unused symbol can be used as the symbol to be redeployed, and the symbol to be redeployed is deleted. The redeployment of the symbol to be redeployed, after the link, the symbol to be redeployed is not loaded into the memory occupying memory space, which saves memory space.
本发明实施例提供的多级存储的重部署方法, 通过解析重定向文件, 从重定向文件中获取待重部署的符号的当前位置信息,并根据所述待重部 署的符号的当前位置信息对所述待重部署的符号进行重部署。与现有技术 中重新修改源代码中符号的归属节区相比, 通过解析重定向文件, 可直接 获取到待重部署的符号的当前位置信息,并且只将需要重部署的符号改变 存储位置, 对不需要重部署的符号不改变存储位置, 不仅能将多级存储的 重部署的实施对象粒度到符号级别, 而且不需要修改源代码, 从而降低了 重部署的成本。  The method for re-deploying the multi-level storage provided by the embodiment of the present invention obtains the current location information of the symbol to be redeployed from the redirection file by parsing the redirection file, and according to the current location information of the symbol to be redeployed. Re-deploy the symbols for redeployment. Compared with the attribution section of the symbol in the source code in the prior art, by parsing the redirected file, the current location information of the symbol to be redeployed can be directly obtained, and only the symbol that needs to be redeployed is changed to the storage location. The symbol that does not need to be redeployed does not change the storage location, not only can the multi-level storage redeployment implementation object be granular to the symbol level, and the source code does not need to be modified, thereby reducing the cost of redeployment.
本发明的实施例提供另一种多级存储的重部署方法, 如图 2所示, 包 括:  An embodiment of the present invention provides another method for redeploying multi-level storage. As shown in FIG. 2, the method includes:
201、 根据待重部署的符号的符号名, 查询所述重定向文件中的符号 表, 获取所述待重部署的符号的起始地址和符号长度。  201. Query a symbol table in the redirect file according to a symbol name of the symbol to be redeployed, and obtain a start address and a symbol length of the symbol to be redeployed.
其中,所述待重部署的符号名是需要裁剪或改变存储位置的变量或函 数的名称, 所述待重部署的符号是在编写源代码时定义的。 本实施例的重 定向文件以可执行链接文件格式( Executable and Linkable Format ,ELF)为 例说明多级存储的重部署方法。 但所述重定向文件不仅限用于 E L F文件, 对于通用对象文件格式 ( Common Object File Format, COFF ) 及可执行 文件格式( Portable Execute , PE )的重定向文件也都可以采用本方法实现 多级存储的重部署。 The symbol name to be redeployed is a name of a variable or a function that needs to be cropped or changed, and the symbol to be redeployed is defined when the source code is written. The redirection file in this embodiment uses an Executable and Linkable Format (ELF) as an example to illustrate a redeployment method of multi-level storage. However, the redirect file is not limited to ELF files. This method can also be used to implement multi-level storage redeployment for the common object file format (COFF) and the executable file format (Portable Execute, PE).
多级存储一般采用如图 3 ( a ) 所示的方式实现: 首先按照软件功能 在代码开发平台上生成源代码, 如图 3 ( b ) 所示为按照功能完成的源代 码, 其中根据功能需要定义了符号, 例如图中 int a定义了名为 a的变量, int funa ( ) 定义了名为 funa的函数等。 如图 3 ( c ) 所示为定义节区, 图 中定义的— attribute„„((section(" .1 1.data")))的作用是将符号放入节区名为 ll .data的节区中 。 再如图 3 ( d ) 所示符号映射, 将符号与节区的关系在 源代码中进行映射, 图中 LI DATA int a表示将变量 a放入指定的节区名 为 ll .data的节区中。 将上述所写代码编译成二进制格式的可重定向文件, 并如图 3 ( e ) 所示内存映射, 通过修改链接脚本, 建立节区与指定内存 块的映射关系; 最后将可重定向文件与链接脚本通过连接器链接, 生成镜 像文件。 此时, 如图 3 ( f ) 所示, 多级存储之后, 各个符号都确定了部 署的内存位置。  Multi-level storage is generally implemented as shown in Figure 3 (a): First, the source code is generated on the code development platform according to the software function, as shown in Figure 3 (b), the source code is completed according to the function, which is based on the function requirements. Symbols are defined. For example, int a defines a variable named a, int funa ( ) defines a function named funa, and so on. As shown in Figure 3 (c), the definition of the section, the definition of the attribute - ((section (".1 1.data"))) is to put the symbol into the section named ll.data In the festival area. Then, as shown in Fig. 3 (d), the relationship between the symbol and the section is mapped in the source code. In the figure, LI DATA int a indicates that the variable a is placed in the specified section of the section named ll.data. in. Compile the above code into a resizable file in binary format, and store the memory map as shown in Figure 3 (e). By modifying the link script, establish the mapping relationship between the section and the specified memory block. Finally, the file can be redirected. The link script generates an image file through a link to the linker. At this point, as shown in Figure 3 (f), after multi-level storage, each symbol determines the location of the deployed memory.
其中, 重定向文件的内部组成如图 4所示, 所述重定向文件中包含文 件控制头、 节区部分、 符号表、 节区头部表。 每个符号对应符号表中的一 个表项, 每一个符号表项中包含符号的起始地址、 符号长度、 符号在其对 应节区内的偏移量及符号对应的节区索引号。每个节区对应节区头部表中 控制头中, 也包含每个节区的起始地址。 所述根据已知的符号名, 查询所 述重定向文件中的符号表, 例如, 假设需要重部署的符号名为 a, 在符号 表中找到待重部署的符号的符号名为 a的表项, 如图 5所示, 从所述表项 中获取到所述符号 a在内存中的起始地址 Y和符号 a在内存中所占内存 空间的长度 M。 在本发明实施例中, 符号的起始地址为符号的起始位置 距离文件控制头的偏移量, 例如符号 a的起始地址 Y为符号 a的起始位 置距离文件控制头的偏移量。 另外,还可以通过所述待重部署的符号的符号名查询所述重定向文件 的符号表, 获取所述待重部署的符号当前所在节区的节区名为节区 A ( sectionA )。 The internal composition of the redirect file is as shown in FIG. 4, and the redirect file includes a file control header, a section area, a symbol table, and a section header table. Each symbol corresponds to an entry in the symbol table, and each symbol table entry includes a start address of the symbol, a symbol length, an offset of the symbol in its corresponding section, and a section index number corresponding to the symbol. Each section corresponds to the control header in the section header table, and also contains the starting address of each section. The querying the symbol table in the redirect file according to the known symbol name, for example, assuming that the symbol name to be redeployed is a, and finding the symbol named a of the symbol to be redeployed in the symbol table As shown in FIG. 5, the starting address Y of the symbol a in the memory and the length M of the memory space occupied by the symbol a in the memory are obtained from the table entry. In the embodiment of the present invention, the starting address of the symbol is the offset of the starting position of the symbol from the file control head, for example, the starting address Y of the symbol a is the offset of the starting position of the symbol a from the file control head. . In addition, the symbol table of the redirected file may be queried by the symbol name of the symbol to be redeployed, and the section of the section where the symbol to be redeployed is located is named section A (section A).
202、 根据所述待重部署的符号的起始地址和符号长度计算所述待重 部署的符号的结束地址。  202. Calculate, according to a start address and a symbol length of the symbol to be redeployed, an end address of the symbol to be re-deployed.
其中,本发明实施例中所述待重部署的符号的结束地址是待重部署的 符号的结束位置距离文件控制头的偏移量,通过所述待重部署的符号的起 始地址与所述待重部署的符号所占内存空间长度相加得到。所述待重部署 的符号的起始地址与符号所占内存空间长度可以通过步骤 201 所述的方 法获取。  The ending address of the symbol to be redeployed in the embodiment of the present invention is the offset of the end position of the symbol to be redeployed from the file control header, and the start address of the symbol to be redeployed and the The length of the memory space occupied by the symbols to be redeployed is obtained. The starting address of the symbol to be redeployed and the length of the memory space occupied by the symbol can be obtained by the method described in step 201.
例如, 通过步骤 201得到待重部署的符号 a的起始地址 Y和待重部 署的符号 a的长度 M后, 将起始地址 Y与长度 M相加, 如图 5所示, 得 到待重部署的符号 a的结束地址 Z。  For example, after the start address Y of the symbol a to be redeployed and the length M of the symbol a to be redeployed are obtained in step 201, the start address Y is added to the length M, as shown in FIG. 5, to be redeployed. The end address Z of the symbol a.
203、 根据目标内存块名查询链接脚本, 获取目标节区名。  203. Query the link script according to the target memory block name to obtain the target section name.
其中, 所述目标内存块名通常为给出的已知条件, 例如, 已经确定需 要重部署的符号的目标位置具体是内存块中的名为 L2TEXT_seg 的内存 块。 一个内存块对应一个节区。 如图 6所示, 居内存块名 L2TEXT_seg, 查询连接脚本, 获取所述符号期待部署的目标节区的节区名为节区 B ( sectionB )。 所述链接脚本是已定义的文件, 链接脚本中建立了所述节区 与指定内存的映射关系, 在多级存储中, 编写源代码前, 对符号与节区的 关系在源代码中进行映射, 只是在概念上将符号与节区绑定。 通过编译源 代码, 生成重定向文件, 为符号分配内存空间, 这种内存空间是逻辑上的 内存空间, 并未将变量放到实际物理内存中, 需要通过链接器, 将所述重 定向文件与所述链接脚本进行链接 , 生成镜像文件, 此时便确定了各个 符号部署在内存中的具体位置,这种具体位置是通过节区与内存的映射确 定的。  The target memory block name is usually a given known condition. For example, the target location of the symbol that has been determined to be redeployed is specifically a memory block named L2TEXT_seg in the memory block. A memory block corresponds to a section. As shown in FIG. 6, the memory block name L2TEXT_seg is queried, and the connection script is obtained, and the section of the target section to which the symbol is expected to be deployed is named section B (section B). The link script is a defined file, and a mapping relationship between the section and the specified memory is established in the link script. In the multi-level storage, before the source code is written, the relationship between the symbol and the section is mapped in the source code. , just conceptually bind the symbol to the section. By compiling the source code, generating a redirect file, allocating memory space for the symbol, this memory space is a logical memory space, and the variable is not put into the actual physical memory, and the redirect file needs to be The link script links and generates an image file, and then the specific location where each symbol is deployed in the memory is determined. This specific location is determined by the mapping of the node to the memory.
204、 根据所述目标节区名查询节区头部表, 获取所述目标节区的起 始地址和目标节区长度。 204. Query a section header table according to the target section name, and obtain the target section. Start address and target segment length.
其中, 所述目标节区名可以通过步骤 203所述的方法获取, 并且, 在 所述重定向文件的节区头部表中的与所述目标节区名相对应的节区表项 长度。所述目标节区的起始地址为目标节区起始位置距离所述文件控制头 的偏移量。  The target section name may be obtained by the method described in step 203, and the length of the section entry corresponding to the target section name in the section header table of the redirect file. The starting address of the target node is the offset of the starting position of the target node from the file control head.
例如, 根据步骤 203获取的节区名 sectionB , 在节区头部表中找到节 区名为 sectionB对应的节区表项,从 sectionB的节区表项中获取到目标节 区 sectionB的起始地址 W和目标节区 sectionB在内存中所占内存空间的 长度 V , 具体存储位置如图 5所示。。  For example, according to the section name sectionB obtained in step 203, the section table entry corresponding to the section name is found in the section header table, and the start address of the section section section B is obtained from the section entry of the sectionB. W and the length of the memory space occupied by the target section section B in the memory, the specific storage location is shown in Figure 5. .
相应的,根据步骤 201所得到的符号当前所在节区的节区名 sectionA , 也可以通过节区头部表找到节区名为 sectionA 对应的节区表项, 从 sectionA的节区表项中获取到所述符号 a当前所在节区 sectionA的起始地 址 E, 具体存储位置如图 5所示。  Correspondingly, according to the section name section A of the section where the symbol currently located in step 201 is located, the section item corresponding to the section area named sectionA can also be found through the section header table, and is obtained from the section table item of section A. To the start address E of the section area A where the symbol a is currently located, the specific storage location is as shown in FIG. 5.
205、 根据所述目标节区的起始地址和目标节区长度, 计算所述目标 节区的结束地址, 作为目标位置信息。  205. Calculate, as the target location information, an end address of the target node according to a start address of the target node and a target segment length.
其中,所述目标节区的结束地址为目标节区的结束位置距离文件控制 到。所述目标节区的起始地址和目标节区长度可以通过步骤 204所述的方 法获取。  The end address of the target section is the end position of the target section and is controlled by the file. The starting address of the target section and the length of the target section may be obtained by the method described in step 204.
例如, 通过步骤 204获取目标节区的起始地址 W和目标节区在内存 中所占内存空间的长度 V后, 将目标节区的起始地址 W与长度 V相加, 得到所述目标节区的结束地址 X, 具体存储位置如图 5所示。  For example, after obtaining the start address W of the target node area and the length V of the memory space occupied by the target node area in the step 204, the start address W of the target node area is added to the length V to obtain the target section. The end address X of the area, the specific storage location is shown in Figure 5.
在本发明实施例中,通过以上步骤 201-202确定了所述待重部署的符 号的当前位置信息和通过步骤 203-205 确定了所述待重部署的符号的目 标位置信息之后,便可以对重定向文件中的所述待重部署的符号进行重部 署了, 具体步骤如下: 206、 根据所述待重部署的符号的当前位置信息及目标位置信息, 将 所述待重部署的符号从当前位置移至目标位置。 In the embodiment of the present invention, after determining the current location information of the symbol to be redeployed and determining the target location information of the symbol to be redeployed through steps 203-205, the foregoing steps 201-202 may be performed. The symbols to be redeployed in the redirect file are redeployed. The specific steps are as follows: 206. Move the symbol to be redeployed from a current location to a target location according to current location information and target location information of the symbol to be redeployed.
其中, 所述将所述待重部署的符号移至所述目标位置, 可以先确定所 述目标位置与所述当前位置的相对关系。 仍以图 5 为例, 通过步骤 201 获得待重部署的符号 a的起始地址 Y , 通过步骤 204获得所述目标节区 sectionB的起始地址 W,比较 W与 Y的大小关系, 如果 W大于 Y,则可判 断出所述当前位置在目标位置之后, 如果 W小于 Y,则可判断出所述当前 位置在目标位置之前。或者通过步骤 204获得所述目标节区 sectionB的起 始地址 W与所述待重部署的符号 a当前所在节区 sectionA的起始地址 E, 比较 W与 E的大小关系,如果 W大于 E,则也可判断出所述当前位置在目 标位置之后,如果 W小于 E,则也可判断出所述当前位置在目标位置之前。 可以理解的是, 目标位置与所述当前位置的相对关系, 可以通过多种方法 获取, 本发明实施例对此不做限定。  The moving the symbol to be redeployed to the target location may first determine a relative relationship between the target location and the current location. Still taking FIG. 5 as an example, the starting address Y of the symbol a to be redeployed is obtained through step 201, and the starting address W of the target node section B is obtained by step 204, and the relationship between W and Y is compared, if W is greater than Y, it can be determined that the current position is after the target position, and if W is less than Y, it can be determined that the current position is before the target position. Or, by step 204, obtaining a starting address W of the target node section B and a starting address E of the section area A where the symbol a to be redeployed is currently, and comparing the relationship between W and E. If W is greater than E, It can also be determined that after the current position is after the target position, if W is less than E, it can also be determined that the current position is before the target position. It can be understood that the relative relationship between the target location and the current location can be obtained by using various methods, which is not limited by the embodiment of the present invention.
其中, 将所述待部署的符号从当前位置移至目标位置的方法可以为: 待重部署的符号的在内存空间的起始地址改成目标节区在内存空间的结 束地址,从而将所述待重部署的符号重部署至目标节区的最后位置。例如, 如图 7所示, 假设所述目标位置在所述当前位置之后, 将待重部署的符号 a所在内存空间起始地址 Y改成目标节区 sectionB在内存空间中的结束地 址 X ,从而将待重部署的符号 a就重部署至目标节区 sectionB的最后位置, 待重部署的符号 a成为部署后的符号 a。  The method for moving the symbol to be deployed from the current location to the target location may be: changing a starting address of the symbol to be redeployed in the memory space to an ending address of the target node in the memory space, thereby The symbol to be redeployed is redeployed to the last position of the target section. For example, as shown in FIG. 7, after the target location is after the current location, the memory space start address Y of the symbol a to be redeployed is changed to the end address X of the target node section B in the memory space, thereby The symbol a to be redeployed is redeployed to the last position of the target section sectionB, and the symbol a to be redeployed becomes the symbol a after deployment.
207、 对关联节区或符号进行重部署。  207. Redeploy the associated section or symbol.
其中, 所述关联节区或符号包括: 所述待重部署符号的起始地址与所 述目标节区结束地址之间的节区或符号, 或者, 所述待重部署的符号的结 束地址与所述目标节区的结束地址之间的节区或符号。  The association section or symbol includes: a section or a symbol between the start address of the symbol to be redeployed and the end of the target section, or the end address of the symbol to be redeployed A section or symbol between the end addresses of the target section.
具体移动为: 当所述待重部署的符号的当前位置在目标位置之后时, 将所述待重部署符号的起始地址与目标节区结束地址之间的节区或符号 向后(向节区头部表方向)移动所述待重部署的符号的符号长度大小; 当 所述待重部署的符号的当前位置在目标位置之前时,将所述待重部署的符 号的结束地址与所述目标节区的结束地址之间的节区或符号向前(向文件 控制头方向) 移动所述待重部署的符号的符号长度大小。 The specific movement is: when the current position of the symbol to be redeployed is behind the target position, the section or symbol between the start address of the symbol to be redeployed and the end address of the target section is backward (to the section) The area head table direction) moves the symbol length of the symbol to be redeployed; When the current position of the symbol to be redeployed is before the target position, the section or symbol between the end address of the symbol to be redeployed and the end address of the target node is forwarded (to the file control head) Direction) Moves the symbol length of the symbol to be redeployed.
例如, 如图 7所示, 由于当前位置在目标位置之后, 于是将在内存空 间中地址 X与地址 Y之间的符号或节区的依次向后(向节区头部表方向 ) 移动所述待重部署的符号的符号长度大小。所述当前位置与目标位置的相 对关系的判断参见步骤 206所述, 此处不再赘述。  For example, as shown in FIG. 7, since the current position is after the target position, the symbol or the section between the address X and the address Y in the memory space is sequentially moved backward (toward the section header table). The symbol length size of the symbol to be redeployed. For the determination of the relative relationship between the current location and the target location, refer to step 206, and details are not described herein again.
需说明的是, 本领域技术人员可以理解, 步骤 206与步骤 207并不是 一定要遵循本发明实施例所述顺序, 在特定情况下, 为了重部署的方便, 步骤 207也可以在步骤 206之前, 即先调整关联节区或符号的位置, 再调 整待重部署的符号的位置。  It should be noted that those skilled in the art can understand that steps 206 and 207 do not necessarily follow the sequence described in the embodiment of the present invention. In a specific case, step 207 may also be before step 206 for the convenience of redeployment. That is, adjust the position of the associated section or symbol first, and then adjust the position of the symbol to be redeployed.
208、 依据重部署后的符号的位置信息及节区的位置信息修改所述重 定向文件对应的符号表、 节区头部表、 文件控制头。  208. Modify a symbol table, a section header table, and a file control header corresponding to the redirected file according to the location information of the re-deployed symbol and the location information of the node.
其中, 由于重部署符号 a后符号 a的位置改变, 所述重定向文件中重 部署后的符号 a在符号表中相关信息、 目标节区与当前节区在节区头部表 中相关信息及所述重定向文件控制头中相关信息都可以对应修改,修改方 法如下:  The information of the symbol a after the redeployment symbol a is changed in the symbol table, the related information in the symbol table, the target node area, and the related information in the section header table of the current section and The related information in the control file of the redirect file can be modified correspondingly, and the modification method is as follows:
• 依据重部署后的符号及节区的位置信息修改符号表: 查询符号表, 对与符号 a的原节区索引号相同的符号(即与符号 a原先属于同一节区的 符号), 对这些符号中在该节区内的偏移量大于符号 a在该节区内的偏移 量的全部减去符号 a在节区内的偏移量; 修改符号表中符号 a的当前节 区索引号为指向所述目标节区的索引号;修改符号表中符号 a在当前节区 内的偏移量的值为所述目标节区原占有的内存空间大小。  • Modify the symbol table according to the symbol after re-deployment and the position information of the section: Query the symbol table, the same symbol as the index number of the original node of the symbol a (that is, the symbol originally belonging to the same section as the symbol a), The offset in the symbol in the symbol is greater than the offset of the symbol a in the section minus the offset of the symbol a in the section; modifying the current section index number of the symbol a in the symbol table An index number that points to the target section; the value of the offset of the symbol a in the current section in the modified symbol table is the size of the memory space originally occupied by the target section.
• 依据重部署后的符号及节区的位置信息修改节区头部表: 修改所 述当前节区的控制头中当前节区的长度减去所述符号的长度;修改节区头 部表中目标节区控制头中目标节区的长度增加所述符号的长度;查询节区 头部表中其他节区的起始地址, 判断其他节区是否为关联节区, 并相应修 改关联节区的起始地址。 例如, 通过步骤 206中所述目标位置与所述当前 位置的相对关系, 若当前位置在目标位置之后, 对于其他节区的起始地址 大于等于目标节区的结束地址并且小于符号 a的起始地址,将节区头部表 中符合条件的符号或节区的起始地址顺次增加符号 a的长度 M;若当前位 置在目标位置之前,对于其他节区的起始地址大于等于符号 a的起始地址 并且小于目标节区的结束地址,将节区头部表中符合条件的符号或节区的 起始地址顺次增加符号 a的长度 M。 • Modify the section header table according to the re-deployed symbol and the location information of the section: modify the length of the current section in the control section of the current section minus the length of the symbol; modify the section header table The length of the target node area in the target node control header increases the length of the symbol; queries the start address of other section areas in the section header table, determines whether other section areas are associated nodes, and repairs accordingly Change the starting address of the associated section. For example, by the relative relationship between the target position and the current position in step 206, if the current position is after the target position, the starting address for the other nodes is greater than or equal to the end address of the target node and less than the start of the symbol a. The address, the length of the symbol a or the start address of the section in the section header table is sequentially increased by the length M of the symbol a; if the current position is before the target position, the starting address of the other section is greater than or equal to the symbol a The start address is smaller than the end address of the target section, and the length of the symbol a is sequentially increased by the conditional symbol or the start address of the section in the section header table.
• 依据重部署后的符号及节区的位置信息修改文件控制头: 查询文 件控制头中其他节区的起始地址,通过步骤 206中目标位置与当前位置的 相对关系, 判断其他节区是否为关联节区。 若当前位置在目标位置之后, 若某节区的起始地址大于等于目标节区的结束地址并且小于符号 a 起始 地址时, 将其确定为关联节区, 将文件控制头中关联节区 (包括关联节区 中的关联符号)的起始地址顺次加上符号 a的长度 M; 若当前位置在目标 位置之前,若某节区的起始地址大于等于符号 a起始地址并且小于目标节 区的结束地址, 则将其确定为关联节区, 将文件控制头中关联节区的起始 地址加上所述符号 a的长度 M。  • Modify the file control header according to the symbol after re-deployment and the location information of the section: Query the start address of other sections in the file control header, and determine whether other sections are determined by the relative relationship between the target location and the current location in step 206. Associated sections. If the current position is after the target position, if the starting address of a certain section is greater than or equal to the end address of the target section and is smaller than the starting address of the symbol a, it is determined as the associated section, and the associated section in the file control header is The starting address including the associated symbol in the associated section is sequentially added with the length M of the symbol a; if the current position is before the target position, if the starting address of a certain section is greater than or equal to the starting address of the symbol a and smaller than the target section The end address of the area is determined as the associated node, and the start address of the associated node in the file control header is added to the length M of the symbol a.
在本实施例中, 修改完所述重定向文件对应的符号表、 节区头部表、 文件控制头之后, 将所述修改过的重定向文件保存, 则修改后的信息保存 到所述硬盘中, 即所述修该信息从内存保存至所述重定向文件中, 完成了 重定向文件的修改, 如图 3所示, 将所述修改后的重定向文件与所述链接 脚本通过链接器链接,则所述待重部署的符号从所述当前位置重部署到了 所述目标位置上, 重新确定了所部署符号在内存的存储位置。  In this embodiment, after the symbol table, the section header table, and the file control header corresponding to the redirect file are modified, the modified redirect file is saved, and the modified information is saved to the hard disk. The repair information is saved from the memory to the redirect file, and the modification of the redirect file is completed. As shown in FIG. 3, the modified redirect file and the link script are passed through the linker. Linking, the symbol to be redeployed is redeployed from the current location to the target location, and the storage location of the deployed symbol in the memory is re-determined.
在本发明实施例的另一种应用场景中, 如图 8所示, 步骤 301和 302 分别与步骤 201和步骤 202相同, 在此不再赘述。  In another application scenario of the embodiment of the present invention, as shown in FIG. 8, steps 301 and 302 are the same as step 201 and step 202, respectively, and details are not described herein again.
步骤 303、 新建一个节区。  Step 303, create a new section.
其中,对于无法确定目标节区位置的场景或者不规定所述符号目标节 区位置的场景, 可以新建一个节区获得所述目标位置信息。 如图 10所示, 在重定向文件中所有节区的最后, 添加一个新的节区, 假设新添加的节区 名为 sectionB,将所述新添加的节区的起始地 址与节区大小添加至节区头 部表中, 增加一个节区头部表项。 此时的新添加的节区并没有实际的物理 内存空间, 要修改所述链接脚本, 如图 6所示, 在链接脚本中添加一条节 区规则, 建立所述新建节区 与内存块的映射关系。 所述内存块是通过查 看所述链接脚本找到的空闲内存块。 Wherein, for a scene in which the target node position cannot be determined or a scene in which the symbol target node position is not specified, a new section may be newly created to obtain the target position information. As shown in Figure 10, At the end of all the sections in the redirect file, add a new section, assuming that the newly added section is named sectionB, adding the starting address and the section size of the newly added section to the section header. In the table, add a section header entry. At this time, the newly added section has no actual physical memory space. To modify the link script, as shown in FIG. 6, a section rule is added in the link script to establish a mapping between the newly created section and the memory block. relationship. The memory block is a free memory block found by looking at the link script.
步骤 304、 并将新建节区的起始地址作为目标位置信息。  Step 304: The starting address of the newly created section is used as the target location information.
其中, 将所述新建节区作为所述符号的目标节区, 所述新建节区的起 始地址作即为目标位置信息。  The new node is used as the target node of the symbol, and the starting address of the newly created node is the target location information.
步骤 305至步骤 307与步骤 206至步骤 208分别对应,本领域普通技 在此不再赘述。  Step 305 to step 307 correspond to step 206 to step 208 respectively, and the common technology in the art will not be described herein.
在本发明的另一种场景应用场景中, 如图 9所示, 若待重部署的符号 在生成的程序中没有使用到, 则可以将所述待重部署的符号删除, 节约内 存空间, 具体包括:  In another scenario application scenario of the present invention, as shown in FIG. 9, if the symbol to be redeployed is not used in the generated program, the symbol to be redeployed may be deleted, thereby saving memory space. Includes:
步骤 401、 根据所述待重部署的符号的符号名, 查询所述重定向文件 中的符号表, 获取所述待重部署的符号的起始地址和符号长度。  Step 401: Query a symbol table in the redirect file according to the symbol name of the symbol to be redeployed, and obtain a start address and a symbol length of the symbol to be redeployed.
其中,所述待重部署符号的起始地址和符号长度的具体获取方法参考 本实施例步骤 201所述, 此处不再赘述。  For the specific method for obtaining the starting address and the symbol length of the symbol to be re-deployed, refer to step 201 in this embodiment, and details are not described herein again.
步骤 402、 根据所述待重部署的符号的起始地址和符号长度计算所述 待重部署的符号的结束地址。  Step 402: Calculate an end address of the symbol to be redeployed according to a start address and a symbol length of the symbol to be redeployed.
其中,所述待重部署的符号的结束地址的具体计算方法参考本实施例 步骤 202所述, 此处不再赘述。  For the specific calculation method of the end address of the symbol to be redeployed, refer to step 202 in this embodiment, and details are not described herein again.
另外,还可以通过所述待重部署符号的符号名查询所述重定向文件的 符号表, 获取所述待重部署的符号当前所在节区的节区名。  In addition, the symbol table of the redirected file may be queried by using the symbol name of the symbol to be redeployed, and the name of the section of the node in which the symbol to be redeployed is currently located may be obtained.
需要说明的是,将所述通过步骤 201-202获得所述待重部署的符号的 起始地址、 结束地址及长度作为所述待重部署的符号的当前位置信息。 步骤 403、 根据所述待重部署的符号的当前位置信息将所述待重部署 的符号从当前位置删除。 It should be noted that the start address, the end address, and the length of the symbol to be redeployed are obtained as the current location information of the symbol to be redeployed through the steps 201-202. Step 403: Delete the symbol to be redeployed from the current location according to the current location information of the symbol to be redeployed.
其中,根据所述待重部署的符号的符号名,找到所述待重部署的符号, 并将所述待重部署的符号从内存空间中删除。  The symbol to be redeployed is found according to the symbol name of the symbol to be redeployed, and the symbol to be redeployed is deleted from the memory space.
步骤 404、 对关联节区或符号进行重部署。  Step 404: Redeploy the associated section or symbol.
其中,所述关联节区或符号指与所述待重部署的符号相邻的在所述待 重部署符号之前或所述待重部署的符号之后的节区或符号。具体修改方法 为:将在内存空间中起始地址大于或等于所述待重部署的符号的结束地址 的所有符号及节区的起始地址减去所述待重部署符号的长度。  The associated node or symbol refers to a section or symbol adjacent to the symbol to be redeployed or the symbol to be redeployed adjacent to the symbol to be redeployed. The specific modification method is: subtracting the length of the symbol to be redeployed from all the symbols and the starting address of the node in the memory space whose starting address is greater than or equal to the ending address of the symbol to be redeployed.
步骤 405、 依据重部署后的符号的位置信息及节区的位置信息修改所 述重定向文件对应的符号表、 节区头部表、 文件控制头。  Step 405: Modify the symbol table, the section header table, and the file control header corresponding to the redirect file according to the location information of the re-deployed symbol and the location information of the section.
其中, 由于待重部署的符号已被删除, 所述重定向文件中被删除的符 号在符号表中相关信息、节区头部表中相关信息及所述重定向文件控制头 中相关信息都可以对应修改, 修改方法如下:  The symbol to be redeployed may be deleted, and the information about the deleted symbol in the redirected file may be related information in the symbol table, related information in the section header table, and related information in the redirecting file control header. Corresponding to the modification, the modification method is as follows:
查询符号表,修改符号表中与已删除的符号的节区索引号相同的表项 中的所有其他符号在节区内的偏移量大于已删除的符号在节区内的偏移 量的全部减去已删除符号在节区内的偏移量;删除所述已删除的符号在重 定向文件中对应的符号表项。  Query the symbol table, and modify all the symbols in the symbol table that have the same section index number as the deleted symbol in the symbol table. The offset in the section is greater than the offset of the deleted symbol in the section. The offset of the deleted symbol in the section is subtracted; the corresponding symbol table entry in the redirected file is deleted.
查询节区头部表,修改节区头部表中已删除的符号所在的节区控制头 中当前节区的长度为当前节区长度减去已删除符号的长度;查询节区头部 表中起始地址大于已删除符号的结束地址的所有节区的起始地址都顺次 减去已删除符号的长度。  Query the section header table, modify the length of the current section in the section control header where the deleted symbol in the section header table is the current section length minus the length of the deleted symbol; query the section header table The start address of all the sections whose start address is greater than the end address of the deleted symbol is sequentially subtracted from the length of the deleted symbol.
查询文件控制头,将文件控制头中起始地址大于已删除符号的结束地 址的所有节区的起始地址都顺次减去已删除符号的长度。  The file control header is queried, and the start address of all the sections of the file control header whose start address is greater than the end address of the deleted symbol is sequentially subtracted from the length of the deleted symbol.
本发明实施例提供的多级存储的重部署方法, 通过解析重定向文件, 从重定向文件中获取待重部署的符号的当前位置信息,并根据所述待重部 署的符号的当前位置信息对所述待重部署的符号进行重部署。与现有技术 中重新修改源代码中符号的归属节区相比, 通过解析重定向文件, 可直接 获取到待重部署的符号的当前位置信息,并且只将需要重部署的符号改变 存储位置, 对不需要重部署的符号不改变存储位置, 不仅能将多级存储的 重部署的实施对象粒度到符号级别, 而且不需要修改源代码, 从而降低了 重部署的成本。 The method for re-deploying the multi-level storage provided by the embodiment of the present invention obtains the current location information of the symbol to be redeployed from the redirection file by parsing the redirection file, and according to the current location information of the symbol to be redeployed. Re-deploy the symbols for redeployment. And prior art Compared with the attribution section of the symbol in the source code, by resolving the redirected file, the current location information of the symbol to be redeployed can be directly obtained, and only the symbol that needs to be redeployed is changed to the storage location, The deployed symbols do not change the storage location, not only can granularize the redeployed implementation objects of multi-level storage to the symbol level, and do not need to modify the source code, thereby reducing the cost of redeployment.
并且, 将需要重部署的在生成的程序中会用到的符号添加到目标位 置, 修改与符号有关的信息, 对于链接过程中, 内存空间不够而无法链接 的场景, 可以将所述符号添加至空闲目标位置, 完成链接。  And, the symbols that will be used in the generated program that need to be redeployed are added to the target location, and the information related to the symbol is modified. For the scene in which the memory space is insufficient and cannot be linked during the linking process, the symbol can be added to the scene. Idle destination, complete the link.
本发明实施例还提供一种多级存储的重部署装置, 如图 11所示, 包 括: 第一获取单元 31、 重部署单元 32。  The embodiment of the present invention further provides a multi-level storage re-deployment device. As shown in FIG. 11, the first embodiment includes: a first obtaining unit 31 and a redeploying unit 32.
第一获取单元 31 , 用于从重定向文件中获取待重部署的符号的当前 位置信息。  The first obtaining unit 31 is configured to obtain current location information of the symbol to be redeployed from the redirect file.
重部署单元 32 , 用于根据所述第一获取单元获取的所述待重部署的 符号的当前位置信息对所述待重部署的符号进行重部署。  The redeployment unit 32 is configured to redeploy the symbol to be redeployed according to the current location information of the symbol to be redeployed acquired by the first acquiring unit.
在一种实现方式下,所述当前位置信息包括待重部署的符号的起始地 址、 结束地址及长度, 所述第一获取单元 31具体用于: 根据所述待重部 署的符号的符号名, 查询所述重定向文件中的符号表, 获取所述待重部署 的符号的起始地址和符号长度;根据所述第一获取单元获取的所述待重部 署的符号的起始地址和符号长度计算所述待重部署的符号的结束地址,重 部署单元 32 , 用于根据所述第一获取单元获取的所述待重部署的符号的 当前位置信息对所述待重部署的符号进行重部署。  In an implementation manner, the current location information includes a start address, an end address, and a length of the symbol to be redeployed, and the first acquiring unit 31 is specifically configured to: according to the symbol name of the symbol to be redeployed Querying a symbol table in the redirect file, obtaining a start address and a symbol length of the symbol to be redeployed; and starting a address and a symbol of the symbol to be redeployed acquired according to the first obtaining unit Length calculating the end address of the symbol to be redeployed, and the redeploying unit 32 is configured to perform heavy weighting on the symbol to be redeployed according to the current location information of the symbol to be redeployed acquired by the first acquiring unit deploy.
在另一种实现方式下, 重部署单元 32具体用于: 根据所述第一获取 单元获取的所述待重部署的符号的当前位置信息将所述待重部署的符号 从当前位置删除。  In another implementation, the redeployment unit 32 is specifically configured to: delete the symbol to be redeployed from the current location according to current location information of the symbol to be redeployed acquired by the first acquiring unit.
本发明的实施例提供另一种多级存储的重部署装置, 如图 12所示, 该多级存储的重部署装置还可以包括: 第二获取单元 33。  The embodiment of the present invention provides another multi-level storage re-deployment apparatus. As shown in FIG. 12, the multi-level storage re-deployment apparatus may further include: a second acquisition unit 33.
第二获取单元 33 , 用于对所述待重部署的符号进行重部署之前, 获 取所述待重部署的符号待部署的目标位置信息。 The second obtaining unit 33 is configured to obtain, before redeploying the symbol to be redeployed, Taking the target location information to be deployed of the symbol to be redeployed.
相应的, 重部署单元 32具体用于: 根据所述第一获取单元获取的所 述待重部署的符号的当前位置信息及所述第二获取单元获取的所述目标 位置信息, 将所述待重部署的符号从当前位置移至目标位置。  Correspondingly, the redeploying unit 32 is specifically configured to: according to the current location information of the symbol to be redeployed acquired by the first acquiring unit, and the target location information acquired by the second acquiring unit, The redeployed symbol moves from the current location to the target location.
进一步的, 在一种实现方式下, 第二获取单元 33具体用于: 根据目 标内存块名查询链接脚本, 获取目标节区名; 根据所述目标节区名查询所 述重定向文件的节区头部表,获取所述目标节区的起始地址和目标节区长 度; 根据所述目标节区的起始地址和目标节区长度, 计算所述目标节区的 结束地址, 作为目标位置信息。 在另一种实现方式下, 第二获取单元 33 具体用于: 新建一个节区; 将所述新建模块获取的所述新建节区的起始地 址作为目标位置信息。  Further, in an implementation manner, the second obtaining unit 33 is specifically configured to: query a link script according to the target memory block name to obtain a target section name; and query the section of the redirect file according to the target section name a header table, obtaining a start address of the target node area and a target node area length; calculating an end address of the target node area as the target location information according to the start address of the target node area and the target node area length . In another implementation manner, the second obtaining unit 33 is specifically configured to: create a new section; and use the starting address of the newly created section obtained by the new module as the target location information.
进一步的, 重部署单元 32还用于: 对关联节区或符号进行重部署, 所述关联节区或符号包括:所述待重部署符号的起始地址与所述目标节区 的结束地址之间的节区或符号, 或者, 所述待重部署的符号的结束地址与 所述目标节区的结束地址之间的节区或符号。  Further, the redeployment unit 32 is further configured to: redeploy the associated node or symbol, where the associated node or symbol includes: a start address of the symbol to be redeployed and an end address of the target node An internode or symbol, or a section or symbol between the end address of the symbol to be redeployed and the end address of the target section.
本发明的实施例提供另一种多级存储的重部署装置, 如图 13所示, 该多级存储装置还包括: 修改单元 34 , 用于依据重部署后的符号的位置 信息及节区的位置信息修改所述重定向文件中包含的符号表、 节区头部 表、 文件控制头。  An embodiment of the present invention provides another multi-level storage re-deployment apparatus. As shown in FIG. 13, the multi-level storage apparatus further includes: a modifying unit 34, configured to: according to the location information of the re-deployed symbol and the node area The location information modifies the symbol table, the section header table, and the file control header included in the redirect file.
在以上装置实施例中, 所述重定向文件的格式包括: 可执行链接文件 格式 ELF、 通用对象文件格式 COFF或可执行文件格式 PE。  In the above device embodiment, the format of the redirect file includes: an executable link file format ELF, a common object file format COFF, or an executable file format PE.
需要理解的是,本实施例中全部步骤的具体描述可以参考方法实施例 中对应的内容, 在此不再——赘述。  It should be understood that the specific description of all the steps in this embodiment may refer to the corresponding content in the method embodiment, and is not described again here.
本发明实施例提供的多级存储的重部署方法, 通过解析重定向文件, 从重定向文件中获取待重部署的符号的当前位置信息,并根据所述待重部 署的符号的当前位置信息对所述待重部署的符号进行重部署。与现有技术 中重新修改源代码中符号的归属节区相比, 通过解析重定向文件, 可直接 获取到待重部署的符号的当前位置信息,并且只将需要重部署的符号改变 存储位置, 对不需要重部署的符号不改变存储位置, 不仅能将多级存储的 重部署的实施对象粒度到符号级别, 而且不需要修改源代码, 从而降低了 重部署的成本。 The method for re-deploying the multi-level storage provided by the embodiment of the present invention obtains the current location information of the symbol to be redeployed from the redirection file by parsing the redirection file, and according to the current location information of the symbol to be redeployed. Re-deploy the symbols for redeployment. Compared with the attribution section of the symbol in the source code in the prior art, by parsing the redirect file, Obtain the current location information of the symbol to be redeployed, and change the storage location only for the symbol that needs to be redeployed, and change the storage location for the symbol that does not need to be redeployed, not only can the implementation object of the redeployment of the multi-level storage be granular to Symbol level, and no need to modify the source code, thus reducing the cost of redeployment.
并且, 将需要重部署的在生成的程序中会用到的符号添加到目标位 置, 修改与符号有关的信息, 对于链接过程中, 内存空间不够而无法链接 的场景, 可以将所述符号添加至空闲目标位置, 完成链接。  And, the symbols that will be used in the generated program that need to be redeployed are added to the target location, and the information related to the symbol is modified. For the scene in which the memory space is insufficient and cannot be linked during the linking process, the symbol can be added to the scene. Idle destination, complete the link.
通过以上的实施方式的描述,所属领域的技术人员可以清楚地了解到 本发明可借助软件加必需的通用硬件的方式来实现, 当然也可以通过硬 件, 但很多情况下前者是更佳的实施方式。 基于这样的理解, 本发明的技 术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式 体现出来, 该计算机软件产品存储在可读取的存储介质中, 如计算机的软 盘, 硬盘或光盘等, 包括若干指令用以使得一台计算机设备(可以是个人 计算机, 服务器, 或者网络设备等) 执行本发明各个实施例所述的方法。  Through the description of the above embodiments, those skilled in the art can clearly understand that the present invention can be implemented by means of software plus necessary general hardware, and of course, by hardware, but in many cases, the former is a better implementation. . Based on such understanding, the technical solution of the present invention, which is essential or contributes to the prior art, may be embodied in the form of a software product stored in a readable storage medium, such as a floppy disk of a computer. A hard disk or optical disk or the like includes instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to perform the methods described in various embodiments of the present invention.
以上所述, 仅为本发明的具体实施方式, 但本发明的保护范围并不局 限于此, 任何熟悉本技术领域的技术人员在本发明揭露的技术范围内, 可 轻易想到变化或替换, 都应涵盖在本发明的保护范围之内。 因此, 本发明 的保护范围应以所述权利要求的保护范围为准。  The above is only the specific embodiment of the present invention, but the scope of the present invention is not limited thereto, and any person skilled in the art can easily think of changes or substitutions within the technical scope of the present invention. It should be covered by the scope of the present invention. Therefore, the scope of the invention should be determined by the scope of the appended claims.

Claims

权 利 要 求 书 claims
1、 一种多级存储的重部署方法, 其特征在于, 包括: 1. A multi-level storage redeployment method, characterized by including:
从重定向文件中获取待重部署的符号的当前位置信息; Obtain the current location information of the symbol to be redeployed from the redirection file;
根据所述待重部署的符号的当前位置信息对所述待重部署的符号进行 重部署。 The symbols to be redeployed are redeployed according to the current location information of the symbols to be redeployed.
2、 根据权利要求 1所述的方法, 其特征在于, 所述当前位置信息包括 待重部署的符号的起始地址、 结束地址及符号长度, 所述从重定向文件中 获取待重部署的符号的当前位置信息, 具体包括: 2. The method according to claim 1, characterized in that, the current location information includes the start address, end address and symbol length of the symbol to be redeployed, and the information of the symbol to be redeployed is obtained from the redirection file. Current location information, specifically including:
根据所述待重部署的符号的符号名,查询所述重定向文件中的符号表, 获取所述待重部署的符号的起始地址和符号长度; Query the symbol table in the redirection file according to the symbol name of the symbol to be redeployed, and obtain the starting address and symbol length of the symbol to be redeployed;
根据所述待重部署的符号的起始地址和符号长度计算所述待重部署的 符号的结束地址。 The end address of the symbol to be redeployed is calculated based on the start address and symbol length of the symbol to be redeployed.
3、 根据权利要求 1或 2所述的方法, 其特征在于, 在对所述待重部署 的符号进行重部署之前, 所述方法还包括: 3. The method according to claim 1 or 2, characterized in that, before redeploying the symbols to be redeployed, the method further includes:
获取所述待重部署的符号待部署的目标位置信息; Obtain the target location information to be deployed of the symbol to be redeployed;
所述根据所述待重部署的符号的当前位置信息对所述待重部署的符号 进行重部署, 具体包括: The redeployment of the symbols to be redeployed according to the current location information of the symbols to be redeployed specifically includes:
根据所述待重部署的符号的当前位置信息及目标位置信息, 将所述待 重部署的符号从当前位置移至目标位置。 According to the current position information and target position information of the symbol to be redeployed, the symbol to be redeployed is moved from the current position to the target position.
4、 根据权利要求 3所述的方法, 其特征在于, 所述获取所述待重部署 的符号待部署的目标位置信息, 具体包括: 4. The method according to claim 3, characterized in that said obtaining the target location information to be deployed of the symbol to be redeployed specifically includes:
根据目标内存块名查询链接脚本, 获取目标节区名; Query the link script according to the target memory block name and obtain the target section name;
根据所述目标节区名查询所述重定向文件的节区头部表, 获取所述目 标节区的起始地址和目标节区长度; Query the section header table of the redirected file according to the target section name, and obtain the starting address and target section length of the target section;
根据所述目标节区的起始地址和目标节区长度, 计算所述目标节区的 结束地址, 作为目标位置信息。 According to the start address of the target section and the length of the target section, the end address of the target section is calculated as the target location information.
5、 根据权利要求 3所述的方法, 其特征在于, 所述获取所述待重部署 的符号待部署的目标位置信息, 包括: 5. The method according to claim 3, characterized in that: obtaining the to-be-redeployed The target location information of the symbol to be deployed includes:
新建一个节区; Create a new section;
并将所述新建的节区的起始地址作为目标位置信息。 And the starting address of the newly created section is used as the target location information.
6、 根据权利要求 1所述的方法, 其特征在于, 所述根据所述待重部署 的符号的当前位置信息对所述待重部署的符号进行重部署, 具体包括: 根据所述待重部署的符号的当前位置信息将所述待重部署的符号从当 前位置删除。 6. The method according to claim 1, characterized in that: redeploying the symbols to be redeployed according to the current location information of the symbols to be redeployed specifically includes: redeploying the symbols according to the current location information of the symbols to be redeployed. The symbol to be redeployed is deleted from the current location according to the current location information of the symbol.
7、 根据权利要求 4所述的方法, 其特征在于, 在根据所述重部署的符 号的当前位置信息及目标位置信息对所述待重部署的符号进行重部署之 后, 所述方法还包括: 7. The method according to claim 4, characterized in that, after redeploying the symbols to be redeployed according to the current location information and target location information of the redeployed symbols, the method further includes:
对关联节区或符号进行重部署, 所述关联节区或符号包括: 所述待重 部署符号的起始地址与所述目标节区的结束地址之间的节区或符号,或者, 所述待重部署的符号的结束地址与所述目标节区的结束地址之间的节区或 符号。 Redeploy associated sections or symbols, and the associated sections or symbols include: sections or symbols between the starting address of the symbol to be redeployed and the end address of the target section, or, the The section or symbol between the end address of the symbol to be redeployed and the end address of the target section.
8、 根据权利要求 1-7中任一项所述的方法, 其特征在于, 在根据所述 待重部署的符号的当前位置信息对所述待重部署的符号进行重部署之后, 所述方法还包括: 8. The method according to any one of claims 1 to 7, characterized in that, after redeploying the symbols to be redeployed according to the current location information of the symbols to be redeployed, the method Also includes:
依据重部署后的符号的位置信息及节区的位置信息修改所述重定向文 件中包含的符号表、 节区头部表、 文件控制头。 Modify the symbol table, section header table, and file control header contained in the redirection file according to the location information of the redeployed symbol and the location information of the section.
9、 根据权利要求 1-8中任一项所述的方法, 其特征在于, 所述重定向 文件的格式包括: 可执行链接文件格式 ELF、 通用对象文件格式 COFF或 可执行文件格式 PE。 9. The method according to any one of claims 1 to 8, characterized in that the format of the redirection file includes: executable link file format ELF, common object file format COFF or executable file format PE.
10、 一种多级存储的重部署装置, 其特征在于, 包括: 10. A multi-level storage redeployment device, characterized by including:
第一获取单元, 用于从重定向文件中获取待重部署的符号的当前位置 信息; The first acquisition unit is used to obtain the current location information of the symbol to be redeployed from the redirection file;
重部署单元, 用于根据所述第一获取单元获取的所述待重部署的符号 的当前位置信息对所述待重部署的符号进行重部署。 A redeployment unit, configured to redeploy the symbols to be redeployed according to the current location information of the symbols to be redeployed acquired by the first acquisition unit.
11、 根据权利要求 10所述的装置, 其特征在于, 所述当前位置信息包 括待重部署的符号的起始地址、 结束地址及长度, 所述第一获取单元具体 用于: 根据所述待重部署的符号的符号名, 查询所述重定向文件中的符号 表, 获取所述待重部署的符号的起始地址和符号长度; 根据所述第一获取 单元获取的所述待重部署的符号的起始地址和符号长度计算所述待重部署 的符号的结束地址。 11. The device according to claim 10, wherein the current location information includes the start address, end address and length of the symbol to be redeployed, and the first acquisition unit is specifically configured to: according to the to-be-redeployed symbol The symbol name of the symbol to be redeployed, query the symbol table in the redirection file, and obtain the starting address and symbol length of the symbol to be redeployed; according to the symbol to be redeployed obtained by the first acquisition unit The starting address of the symbol and the symbol length are used to calculate the ending address of the symbol to be redeployed.
12、 根据权利要求 10或 11所述的装置, 其特征在于, 还包括: 第二获取单元, 用于在对所述待重部署的符号进行重部署之前, 获取 所述待重部署的符号待部署的目标位置信息; 12. The device according to claim 10 or 11, further comprising: a second acquisition unit, configured to acquire the symbols to be redeployed before redeploying the symbols to be redeployed. Deployment target location information;
所述重部署单元具体用于: 根据所述第一获取单元获取的所述待重部 署的符号的当前位置信息及所述第二获取单元获取的所述目标位置信息, 将所述待重部署的符号从当前位置移至目标位置。 The redeployment unit is specifically configured to: according to the current location information of the symbol to be redeployed acquired by the first acquisition unit and the target location information acquired by the second acquisition unit, symbol is moved from the current position to the target position.
13、 根据权利要求 12所述的装置, 其特征在于, 所述第二获取单元具 体用于: 根据目标内存块名查询链接脚本, 获取目标节区名; 根据所述目 标节区名查询所述重定向文件的节区头部表, 获取所述目标节区的起始地 址和目标节区长度; 根据所述目标节区的起始地址和目标节区长度, 计算 所述目标节区的结束地址, 作为目标位置信息。 13. The device according to claim 12, wherein the second acquisition unit is specifically configured to: query the link script according to the target memory block name, and obtain the target section name; query the target section name according to the target section name. Redirect the file's section header table to obtain the starting address and target section length of the target section; calculate the end of the target section based on the starting address and target section length of the target section Address, as target location information.
14、 根据权利要求 12所述的装置, 其特征在于, 所述第二获取单元具 体用于: 新建一个节区; 将所述新建模块获取的所述新建节区的起始地址 作为目标位置信息。 14. The device according to claim 12, characterized in that, the second acquisition unit is specifically configured to: create a new section; use the starting address of the new section obtained by the new module as the target location information .
15、 根据权利要求 10所述的装置, 其特征在于, 所述重部署单元具体 用于: 15. The device according to claim 10, characterized in that the redeployment unit is specifically used for:
根据所述第一获取单元获取的所述待重部署的符号的当前位置信息将所述 待重部署的符号从当前位置删除。 The symbol to be redeployed is deleted from the current location according to the current location information of the symbol to be redeployed acquired by the first acquisition unit.
16、 根据权利要求 13所述的装置, 其特征在于, 所述重部署单元还用 于: 对关联节区或符号进行重部署, 所述关联节区或符号包括: 所述待重 部署符号的起始地址与所述目标节区的结束地址之间的节区或符号,或者, 所述待重部署的符号的结束地址与所述目标节区的结束地址之间的节区或 符号。 16. The device according to claim 13, wherein the redeployment unit is further configured to: redeploy associated sections or symbols, where the associated sections or symbols include: the symbols to be redeployed The section or symbol between the start address and the end address of the target section, or, The section or symbol between the end address of the symbol to be redeployed and the end address of the target section.
17、 根据权利要求 10-16中任一项所述的装置, 其特征在于, 还包括: 修改单元, 用于依据重部署后的符号的位置信息及节区的位置信息修 改所述重定向文件中包含的符号表、 节区头部表、 文件控制头。 17. The device according to any one of claims 10 to 16, further comprising: a modification unit, configured to modify the redirection file according to the location information of the redeployed symbol and the location information of the section. It contains the symbol table, section header table, and file control header.
18、 根据权利要求 10-17 中任一项所述的装置, 其特征在于, 所述重 定向文件的格式包括以: 可执行链接文件格式 ELF、 通用对象文件格式 COFF或可执行文件格式 PE。 18. The device according to any one of claims 10 to 17, characterized in that the format of the redirection file includes: executable link file format ELF, common object file format COFF or executable file format PE.
PCT/CN2013/072953 2012-07-30 2013-03-20 Method and device for redeploying multilevel storage WO2014019367A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201210268364.9 2012-07-30
CN201210268364.9A CN102831178B (en) 2012-07-30 2012-07-30 Heavy dispositions method and the device of multistage storage

Publications (1)

Publication Number Publication Date
WO2014019367A1 true WO2014019367A1 (en) 2014-02-06

Family

ID=47334315

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2013/072953 WO2014019367A1 (en) 2012-07-30 2013-03-20 Method and device for redeploying multilevel storage

Country Status (2)

Country Link
CN (1) CN102831178B (en)
WO (1) WO2014019367A1 (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102831178B (en) * 2012-07-30 2016-05-25 华为技术有限公司 Heavy dispositions method and the device of multistage storage
CN103942078B (en) * 2014-04-30 2017-11-17 华为技术有限公司 The method and embedded device of a kind of load driver program
CN105700861A (en) * 2014-11-27 2016-06-22 迈普通信技术股份有限公司 Embedded program run symbol table generation method and apparatus

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5291601A (en) * 1989-06-01 1994-03-01 Hewlett-Packard Company Shared libraries implemented with linking program loader
CN1841329A (en) * 2005-03-28 2006-10-04 华为技术有限公司 Method and apparatus for positioning target file
KR20080013424A (en) * 2006-08-08 2008-02-13 삼성전자주식회사 Method of incremental linking for embedded system
CN101470619A (en) * 2007-12-29 2009-07-01 安凯(广州)软件技术有限公司 Application program dynamic loading method based on microkernel operating system
CN101697131A (en) * 2009-11-04 2010-04-21 中兴通讯股份有限公司 Method and device for dynamically loading relocatable file
CN102831178A (en) * 2012-07-30 2012-12-19 华为技术有限公司 Method and device for redeploying multilevel storage

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5291601A (en) * 1989-06-01 1994-03-01 Hewlett-Packard Company Shared libraries implemented with linking program loader
CN1841329A (en) * 2005-03-28 2006-10-04 华为技术有限公司 Method and apparatus for positioning target file
KR20080013424A (en) * 2006-08-08 2008-02-13 삼성전자주식회사 Method of incremental linking for embedded system
CN101470619A (en) * 2007-12-29 2009-07-01 安凯(广州)软件技术有限公司 Application program dynamic loading method based on microkernel operating system
CN101697131A (en) * 2009-11-04 2010-04-21 中兴通讯股份有限公司 Method and device for dynamically loading relocatable file
CN102831178A (en) * 2012-07-30 2012-12-19 华为技术有限公司 Method and device for redeploying multilevel storage

Also Published As

Publication number Publication date
CN102831178B (en) 2016-05-25
CN102831178A (en) 2012-12-19

Similar Documents

Publication Publication Date Title
EP3588285B1 (en) Sequence optimizations in a high-performance computing environment
KR101994021B1 (en) File manipulation method and apparatus
CN109766341B (en) Method, device and storage medium for establishing Hash mapping
US9811321B1 (en) Script compilation
US11086638B2 (en) Method and apparatus for loading application
JP5674634B2 (en) Controller, storage device and program
US20230117105A1 (en) On-demand loading of dynamic scripting language code for reduced memory usage
CN109739823A (en) A kind of method and device for building parallel file system
CN103838572A (en) System and method for packing Android SDK
CN111176654B (en) Internet of things application online compiling method based on multi-user cache
US8209662B2 (en) Application retargeting
WO2014019367A1 (en) Method and device for redeploying multilevel storage
CN109460406B (en) Data processing method and device
CN103369002A (en) A resource downloading method and system
CN103514004A (en) Method and device for managing system environment under Windows system
CN112463055B (en) Method, system, equipment and medium for optimizing and using L2P table of solid state disk
JP2006011533A (en) Memory card, semiconductor device, and control method of semiconductor memory
US8689200B1 (en) Method and system for optimizing an executable program by generating special operations for identical program entities
JP2016515258A (en) File aggregation for optimized file operation
CN109918059B (en) Application function expansion method and device, terminal equipment and storage medium
WO2012171363A1 (en) Method and equipment for data operation in distributed cache system
WO2013189177A1 (en) Storage space mapping method and device
JP6119327B2 (en) Duplicate data management device, data transfer control device, data transfer control system, duplicate data management method, data transfer control method, and computer program
CN105279195A (en) Method and apparatus for webpage application to call browser function
US8683455B1 (en) Method and system for optimizing an executable program by selectively merging identical program entities

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 13825161

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 13825161

Country of ref document: EP

Kind code of ref document: A1