[go: up one dir, main page]
More Web Proxy on the site http://driver.im/

CN105224370A - A kind of method and apparatus of loading ELF document - Google Patents

A kind of method and apparatus of loading ELF document Download PDF

Info

Publication number
CN105224370A
CN105224370A CN201510688388.3A CN201510688388A CN105224370A CN 105224370 A CN105224370 A CN 105224370A CN 201510688388 A CN201510688388 A CN 201510688388A CN 105224370 A CN105224370 A CN 105224370A
Authority
CN
China
Prior art keywords
section
address
file
function
reorientation
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN201510688388.3A
Other languages
Chinese (zh)
Other versions
CN105224370B (en
Inventor
秦松
陈鑫
位广军
马家智
桂敬文
王博通
王晓卿
张洪卫
常磊
张治�
李新开
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Baidu Netcom Science and Technology Co Ltd
Original Assignee
Anyi Hengtong Beijing Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Anyi Hengtong Beijing Technology Co Ltd filed Critical Anyi Hengtong Beijing Technology Co Ltd
Priority to CN201510688388.3A priority Critical patent/CN105224370B/en
Publication of CN105224370A publication Critical patent/CN105224370A/en
Priority to PCT/CN2016/084304 priority patent/WO2017067175A1/en
Application granted granted Critical
Publication of CN105224370B publication Critical patent/CN105224370B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention provides a kind of to having the method and apparatus that can perform and link form (ELF) file dynamic load, wherein method comprises: resolve to obtain obj ect file to the static library file in described ELF file; Effective section is extracted from described obj ect file; Load effective section, and set up object map table sum functions mapping table respectively, for carrying out reorientation to the object in the effective section loaded and function for the object in described obj ect file and function.By the method and apparatus of ELF file dynamic load provided by the present invention, embedded system in prior art can be broken away from need to depend on specific instruction set when parsing and loading ELF document, the puzzlement of whole flush bonding processor frameworks cannot be applicable to, achieve the application that simultaneously can run multiple ELF file under par-ticular processor architecture, and can dynamic link be realized, the file size adopting static linkage to produce before substantially reducing, reduces power consumption.

Description

A kind of method and apparatus of loading ELF document
[technical field]
The present invention relates to computer realm, particularly relate to a kind of method and apparatus of loading ELF document.
[background technology]
There is the form that the ELF (ExecutableandLinkingFormat) that can perform and link form is a kind of obj ect file, for defining content in dissimilar obj ect file (Objectfiles) and form thereof.What adopt for the loading of ELF file due to existing embedded OS is that the mode of static linkage generates executable file, and adopt the mode of burning by executable file direct burning in internal memory (Flash), these processing procedures all must complete under ARM instruction set, and the not ARM instruction set that some processor adopts, and do not support that its instruction set adopted is to the switching of ARM instruction set, therefore prior art cannot provide the loading of ELF file for this type of processor.
[summary of the invention]
The present invention proposes a kind of method and apparatus of loading ELF document, so that solve the problem that prior art cannot record ELF file in some embedded systems.
Concrete technical scheme is as follows:
Loading has the method that can perform and link form ELF file, and described method comprises:
Resolve to obtain obj ect file to the static library file in described ELF file;
Effective section is extracted from described obj ect file;
Load effective section, and set up object map table sum functions mapping table respectively, for carrying out reorientation to the object in the effective section loaded and function for the object in described obj ect file and function.
According to one preferred embodiment of the present invention, effective section of extraction comprises: executable code segment, application data section or reorientation section.
According to one preferred embodiment of the present invention, effective section is extracted according to the ELF file header of described obj ect file and segment file head table.
According to one preferred embodiment of the present invention, the effective section of described loading comprises: dissimilar effective section is loaded into different regions respectively.
According to one preferred embodiment of the present invention, describedly dissimilar effective section be loaded into different regions respectively comprise:
According to the segment information of executable code segment and corresponding reorientation section, reorientation is carried out to executable code segment, by the executable code segment write Flash after reorientation; Or
According to the segment information of application data section and corresponding reorientation section, application data section is directly loaded into RAM.
According to one preferred embodiment of the present invention, the described segment information section of comprising sequence number, field offset amount or section size.
According to one preferred embodiment of the present invention, described executable code segment comprises .text section, and described application data section comprises .data section .bss section or .rodata section, and described reorientation section comprises .rel.data section .rel.bss section or .rel.rodata section.
According to one preferred embodiment of the present invention, after the effective section of described loading, at least one mark following is carried out to effective section of described obj ect file: the start address of section, field offset amount, section size.
According to one preferred embodiment of the present invention, the mapping item of described object map table comprises object oriented and object address, and described object address is the derived object by searching in effective section, obtains according to derived object address; The mapping item of described Function Mapping table comprises function name sum functions address, and described function address is the derivative function by searching in effective section, and the address according to derivative function place obtains.
According to one preferred embodiment of the present invention, when carrying out reorientation to the object in effective section, utilize the address of redirect object in literal pool of object described in the address search of existing object in described object map table, and the address of the object of redirect described in literal pool is revised as the address of existing object.
According to one preferred embodiment of the present invention, when carrying out reorientation to the function in effective section, the function address that address when utilizing current function to run and the needs found from Function Mapping table jump to, through calculating jump instruction, the jump instruction calculated is utilized to upgrade jump instruction before, so that jump to the function address that namely will perform according to the jump instruction of described renewal.
A device for loading ELF document, described device comprises:
Resolver, for resolving to obtain obj ect file to the static library file in described ELF file;
Extraction element, for extracting effective section from described obj ect file;
Charger, for loading effective section, for the object in described obj ect file and function set up object map table sum functions mapping table respectively, and for carrying out reorientation to the object in the effective section loaded and function.
According to one preferred embodiment of the present invention, the effective section extracted in described extraction element comprises: executable code segment, application data section or reorientation section.
According to one preferred embodiment of the present invention, described extraction element is used for extracting effective section according to the ELF file header of described obj ect file and segment file head table.
According to one preferred embodiment of the present invention, described charger loads effective section and comprises: dissimilar effective section is loaded into different regions respectively.
According to one preferred embodiment of the present invention, described charger, when dissimilar effective section is loaded into different regions respectively, specifically performs:
According to the segment information of executable code segment and corresponding reorientation section, reorientation is carried out to executable code segment, by the executable code segment write Flash after reorientation; Or
According to the segment information of application data section and corresponding reorientation section, application data section is directly loaded into RAM.
According to one preferred embodiment of the present invention, the described segment information section of comprising sequence number, field offset amount or section size.
According to one preferred embodiment of the present invention, described executable code segment comprises .text section, and described application data section comprises .data section .bss section or .rodata section, and described reorientation section comprises .rel.data section .rel.bss section or .rel.rodata section.
According to one preferred embodiment of the present invention, described charger, after execution described loading effective section, is further used for carrying out at least one mark following to effective section of described obj ect file: the start address of section, field offset amount, section size.
According to one preferred embodiment of the present invention, the mapping item of described object map table comprises object oriented and object address, and described object address is the derived object by searching in effective section, obtains according to derived object address; The mapping item of described Function Mapping table comprises function name sum functions address, and described function address is the derivative function by searching in effective section, and the address according to derivative function place obtains.
According to one preferred embodiment of the present invention, described charger, when carrying out reorientation to the object in effective section, specifically performs:
Utilize the address of redirect object in literal pool of object described in the address search of existing object in described object map table, and the address of the object of redirect described in literal pool is revised as the address of existing object.
According to one preferred embodiment of the present invention, described charger is when carrying out reorientation to the function in effective section, concrete execution: the function address that address when utilizing current function to run and the needs found from Function Mapping table jump to, through calculating jump instruction, the jump instruction calculated is utilized to upgrade jump instruction before, so that jump to the function address that namely will perform according to the jump instruction of described renewal.
As can be seen from the above technical solutions, present invention employs and resolve static library (.a) file and extract effective section, effective section is loaded, set up object and Function Mapping table for carrying out the mode of reorientation respectively to the object sum functions in relocatable section, these processing modes are not limited to particular, instruction set, and therefore solving prior art cannot the problem of loading ELF document in some embedded systems.
[accompanying drawing explanation]
A kind of schematic flow sheet to ELF file dynamic loading method that Fig. 1 provides for the embodiment of the present invention;
The form schematic diagram of the ELFHeader that Fig. 2 provides for the embodiment of the present invention;
The structural representation of the device of a kind of loading ELF document that Fig. 3 provides for the embodiment of the present invention.
[embodiment]
In order to make the object, technical solutions and advantages of the present invention clearly, describe the present invention below in conjunction with the drawings and specific embodiments.
Please refer to Fig. 1, Fig. 1 is the schematic flow sheet that a kind of loading provided by the invention has the embodiment of the method for the ELF file that can perform and link form.As shown in Figure 1, this flow process comprises:
101: resolve to obtain obj ect file (.o) to static library (.a) file in ELF file.
Obj ect file of the present invention (.o) is the retargetable file preserved with ELF form, and the content in obj ect file can comprise the threshold marker to each function, describes, to form the executable instruction of machine.Also need when program will perform to carry out linking (link), link becomes an executable file multiple .o file chain exactly.
ELF file is except can comprising relocatable obj ect file, the obj ect file that can also comprise executable obj ect file and can be shared, above-mentioned three kinds of obj ect file are owing to can represent with the form of obj ect file .o, and multiple .o obj ect file can be filed (archive) and become .a static library file, thus final composition ELF file, the object of therefore resolving static library (.a) file in the present invention is exactly to obtain the obj ect file (.o) forming ELF file.
Particularly, decompression (reduction) process of resolving a compressed package rar in the process of static library file and windows operating system is similar, namely analyze the static library (.a) generated by obj ect file (.o) packing, resolve wherein each obj ect file (.o).
102: from the obj ect file obtained, extract effective section (section).
When after acquisition obj ect file (.o), for each obj ect file, can therefrom extract effective section and information of recorded segments.
Effective section (sections) inside ELF file, in order to the smallest vessel of load content data.
Preferably, can for the obj ect file of each acquisition, extract effective section according to the ELF file header (ELFHeader) of described obj ect file and segment file head table (SHT, SectionHeaderTable) and record each segment information.
The particular type of this effective section can comprise: executable code segment, application data section, or reorientation section.Wherein this executable code segment can specifically comprise .text section etc. again, and this application data section can comprise .data section .bss section or .rodata section etc., and this reorientation section can comprise .rel.data section .rel.bss section or rel.rodata section etc.
Effective segment information of this record includes but not limited to: each section of sequence number, field offset amount or section size etc.
Wherein
1) executable code is loaded with in .text section;
2) data be initialised are loaded with in .data section;
3) data be not initialised are loaded with in .bss section;
4) constant of respective symbols string and definition is loaded with in .rodata section
5) be loaded with relocation entries inside the reorientation section rel.text section of taking the lead with .rel .rel.data section .rel.bss section .rel.rodata section, this reorientation section is the section for helping executable code segment and application data section to carry out reorientation;
Such as: in .rel.text, illustrated in .text section, which place needs to do reorientation.
Below lift an instantiation so that the concrete mode extracting effective section and each segment information from ELFHeader and SHT of obj ect file to be described:
ELFHeader in the present embodiment can represent with the form shown in Fig. 2.
As shown in Figure 2, this ELFHeader illustrates the form of relocatable obj ect file (.o).Corresponding sections and sequence number can be learnt from this ELFHeader, and in an ELF file, have which concrete sections on earth, then be reflected in the SHT in this ELF file.
SHT shows the definition of discal patch object structure:
In SHT, for each section, be all provided with an entry, be used for describing this corresponding section, its content mainly comprises the title of this section, type, size and the byte offset location in whole ELF file etc.
Above-mentioned SHT shows field Off (sh_offset) in discal patch object structure and illustrates the distance that this section leaves top of file position, i.e. side-play amount; Size (sh_size) represents the section size of section.
Thus the relevant section represented according to ELFHeader and SHT thus the information of each effective section can be extracted.
Above 101 and 102 is to the set-up procedure loaded before dynamic load ELF file, its step can or successively perform simultaneously, the present invention does not lay down hard-and-fast rule to the order that it performs, after above-mentioned set-up procedure performs, then by 103 loadings of effective section of realization to obj ect file further.
103: load effective section, and set up object map table sum functions mapping table respectively, for carrying out reorientation to the object in the effective section be loaded into and function for the object in described obj ect file and function.
For 103; can also by its Further Division for loading effective section, setting up mapping table and reorientation three steps; wherein the first two step can or successively perform simultaneously; the present invention does not lay down hard-and-fast rule to the order that it performs; as long as corresponding function can be completed, then all within scope.
Below three steps are described in detail:
The first step: load effective section.
For the effective section extracted 102, comprise executable code segment, application data section and reorientation section three types, wherein executable code segment and application data section belong to effective section that needs load, and reorientation section does not need to load, for effective section that these needs load, corresponding adopting different regions can be loaded in two ways according to the difference of its type.
First kind of way, loads for executable code segment (.text section):
Because the read-write being directed to different its flash of product is inconsistent, therefore for the ease of reorientation amendment .text section content, first can carry out reorientation to .text section, and then be write Flash.
The information that .text section needs reorientation is comprised in the reorientation section (.rel.text section) corresponding to .text section due to extraction, therefore the relocation loading mode before write flash can be: need the part of reorientation to record establishment relocation information the .text section recorded in the .rel.text section identified, reorientation is done to .text, and then .text section is copied and is written in Flash.
The second way, the loading for application data section (.data .bss and .rodata):
For .data, .bss and the load mode of .rodata from slightly different to the load mode of .text section, compared to for .text section be carried in be written to Flash before also comprise repositioning process to .text section, to .data, .bss and being carried in of .rodata be loaded into random access memory (RandomAccessMemory by each section, RAM) do not need to carry out reorientation before, but according to .data, and .rodata and corresponding reorientation section (..rel.data .bss, .rel.bss and .rel.rodata) effective segment information, by .data, .bss and .rodata section be directly loaded into RAM.
After loading effective section by the first and the second way, can carry out corresponding mark to each section of each obj ect file (.o), this mark can the information such as start address, field offset amount, section size of the section of including but not limited to.
The start address in its stage casing obtains according to effective section of initialization after loading, and field offset amount, section size obtain based on effective section of this extraction when extracting effective section.
In a first step, by the .text section being loaded with executable code is separated with the application data of other application data section, and by creating relocation information to the file destination of executable code and be loaded into internal memory, thus generate memory-mapped process, avoid the process repeatedly copying code data when loading ELF document, improve operational efficiency.
Second step, for the object in obj ect file and function set up object map table sum functions mapping table respectively.
In this step, set up object map table (obj_map) and Function Mapping table (func_map) respectively according to the difference of object and function, the mapping table set up is for follow-up reorientation and external call.
Wherein the mapping item of object map table comprises object oriented and object address, and the object address in this mapping table is the derived object by searching in effective section of obj ect file, obtains according to derived object address; The mapping item of Function Mapping table comprises function name sum functions address, and this function address is the derivative function by searching in effective section of obj ect file, and the address according to derivative function place obtains.
About object sum functions, give an example: the major part wherein comprised in .text section is function, and global variable, the functional elements etc. such as .text section .data section .bss section .rodata section file variable, function variable can with object encodings.Be divided into prior art due to object sum functions, do not repeat them here.
3rd step, carries out reorientation to the object in the effective section be loaded into and function.
In this step, use object map table to carry out reorientation to the object in effective section, or use described Function Mapping table to carry out reorientation to the function in effective section.
Particularly, when linking, need to carry out reorientation to the relocatable section of all file destinations, set up symbolic reference rule, be object simultaneously, the allocation address such as function.When program performs, the address space of specifying when code is loaded into link, to ensure program in the process of implementation to object, correctly quoting of the symbols such as function, makes normal program operation.
Based on the difference of the object extracted in obj ect file and type function, the relocation loading mode that two kinds different can be adopted.
First kind of way, reorientation is carried out to object (obj):
The use-pattern of object in .o file is, directly by the true address of object write literal pool.When this object of dynamic load, utilize the address of redirect object in literal pool of object described in the address search of existing object in described object map table, and the address of the object of redirect described in literal pool is revised as the address of existing object.
Particularly, compiler can all be put into literal pool (LiteralPool) region the address of object.Wherein only deposit specific address or constant inside LiteralPool.When needs carry out reorientation, according to the object relocation information that .rel.text .rel.data .rel.bss and .rel.rodata comprise, the specific address of the redirect object recorded in literal pool is obtained by the current address of the object recorded in object map table, specific address is searched from LiteralPool, when dynamic load, specific address in the literal pool at object place is revised as the address at existing object place, thus reorientation is done to the object that .text .data .bss and .rodata section comprises.
The second way, reorientation is carried out to function (func):
For the reorientation of function, the function address that address when current function can be utilized to run and the needs found from Function Mapping table jump to, through calculating jump instruction, the jump instruction calculated is utilized to upgrade jump instruction before, so that jump to the function address that namely will perform according to the jump instruction of described renewal.
Particularly, function call redirect adopts corresponding jump instruction, such as B/BL etc., when function is reorientated, based on the function relocation information that .rel.text etc. comprises, the true address needing the function jumped to is searched from Function Mapping table, the function true address that the needs that find from Function Mapping table jump to is combined according to the current address at place during function operation, jump instruction is obtained through series of computation, obtain correct jump instruction to upgrade jump instruction before, thus the function of reorientation is loaded according to the jump instruction after renewal.
Certainly, not can only search address according to object map table sum functions mapping table, what may quote due to object during dynamic load is that external object or function use dynamic base function, therefore when corresponding address information cannot be found in object or Function Mapping table, what then show object or function reference is external object or dynamic base function, the address of searching object or function dynamically now can be gone to so that reorientation, thus realize dynamic load.
Please refer to Fig. 3, Fig. 3 is the structural representation of the device embodiment of a kind of loading ELF document provided by the invention.As shown in Figure 3, this device comprises: resolver 301, and extraction element 302 and charger 303, be described in detail each device below:
Resolver 301, for resolving to obtain obj ect file (.o) to static library (.a) file in ELF file.
Obj ect file of the present invention (.o) is the retargetable file preserved with ELF form, and the content in obj ect file can comprise the threshold marker to each function, describes, to form the executable instruction of machine.Also need when program will perform to carry out linking (link), link becomes an executable file multiple .o file chain exactly.Multiple .o obj ect file can be filed (archive) and be become .a static library file, and static library file line has become ELF file.
Wherein the object of resolver parsing static library (.a) file is the obj ect file (.o) in order to obtain wherein.
Particularly, decompression (reduction) process of resolving a compressed package rar in the process of static library file and windows operating system is similar, namely analyze the static library (.a) generated by obj ect file (.o) packing, resolve wherein each obj ect file (.o).
Extraction element 302, for extracting effective section (section) from the obj ect file obtained.
When after acquisition obj ect file (.o), for each obj ect file, can therefrom extract effective section and information of recorded segments.
Effective section (sections) inside ELF file, in order to the smallest vessel of load content data.In ELF file, in each sections, have all been loaded the content that attribute is identical.,
Preferably, can for the obj ect file of each acquisition, extract effective section according to the ELF file header (ELFHeader) of described obj ect file and segment file head table (SHT, SectionHeaderTable) and record each segment information.
The particular type of this effective section can comprise: executable code segment, application data section, or reorientation section.Wherein this executable code segment can specifically comprise .text section etc. again, and this application data section can comprise .data section .bss section or .rodata section etc., and this reorientation section can comprise .rel.data section .rel.bss section or rel.rodata section etc.
Effective segment information of this record includes but not limited to: each section of sequence number, field offset amount or section size etc.
Wherein
1) executable code is loaded with in .text section;
2) data be initialised are loaded with in .data section;
3) data be not initialised are loaded with in .bss section;
4) constant of respective symbols string and definition is loaded with in .rodata section
5) be loaded with relocation entries inside the reorientation section rel.text section of taking the lead with .rel .rel.data section .rel.bss section .rel.rodata section, this reorientation section is the section for helping executable code segment and application data section to carry out reorientation;
Such as: in .rel.text, illustrated in .text section, which place needs to do reorientation.
The concrete mode extracting effective section and each segment information from ELFHeader and SHT of obj ect file can be:
From ELFHeader, learn corresponding sections and sequence number, from the content of SHT, obtain the information such as field offset amount, section size according to the field Off (sh_offset) in SHT, Size (sh_size).
Device 301 and 302 for performing the preparation before loading to the ELF file of prestrain before dynamic load ELF file, its set-up procedure can or successively perform simultaneously, the present invention does not lay down hard-and-fast rule to the order that it performs, after above-mentioned set-up procedure performs, then realize the loading of effective section to obj ect file further by device 303.
Charger 303, for loading effective section, for the object in described obj ect file and function set up object map table sum functions mapping table respectively, and for carrying out reorientation to the object in the effective section be loaded into and function.
Can also be effective section loading unit 3031 by charger 303 Further Division, mapping table sets up unit 3032 and reorientation unit 3,033 three unit; wherein the first two unit simultaneously or successively can perform corresponding operating; the present invention does not lay down hard-and-fast rule to the order that it performs; as long as corresponding function can be completed, then all within scope.
Below three unit are described in detail:
Load effective segment unit 3031.
For the effective section extracted by extraction unit 302, comprise executable code segment, application data section and reorientation section three types, wherein executable code segment and application data section belong to effective section that needs load, and reorientation section does not need to load, for effective section that these needs load, corresponding adopting different regions can be loaded in two ways according to the difference of its type.
First kind of way, loads for executable code segment (.text section):
Because the read-write being directed to different its flash of product is inconsistent, therefore for the ease of reorientation amendment .text section content, first can carry out reorientation to .text section, and then be write Flash.
The information that .text section needs reorientation is comprised in the reorientation section (.rel.text section) corresponding to .text section due to extraction, therefore the relocation loading mode before write flash can be: need the part of reorientation to record establishment relocation information the .text section recorded in the .rel.text section identified, reorientation is done to .text, and then .text section is copied and is written in Flash.
The second way, the loading for application data section (.data .bss and .rodata):
For .data, .bss and the load mode of .rodata from slightly different to the load mode of .text section, compared to for .text section be carried in be written to Flash before also comprise repositioning process to .text section, to .data, .bss and being carried in of .rodata be loaded into random access memory (RandomAccessMemory by each section, RAM) do not need to carry out reorientation before, but according to .data, and .rodata and corresponding reorientation section (.rel.data .bss, .rel.bss and .rel.rodata) effective segment information, by .data, .bss and .rodata section be directly loaded into RAM.
After loading effective section by the first and the second way, can carry out corresponding mark to each section of each obj ect file (.o), this mark can the information such as start address, field offset amount, section size of the section of including but not limited to.
The start address in its stage casing obtains according to effective section of initialization after loading, and field offset amount, section size obtain based on effective section of this extraction when extracting effective section.
The present embodiment is by loading the operation of effective segment unit, the .text section being loaded with executable code is separated with the application data of other application data section, and by creating relocation information to the file destination of executable code and be loaded into internal memory, thus generate memory-mapped process, avoid the process repeatedly copying code data when loading ELF document, improve operational efficiency.
Mapping table sets up unit 3032, for setting up object map table sum functions mapping table respectively for the object in obj ect file and function.
This unit is used for setting up object map table (obj_map) and Function Mapping table (func_map) respectively according to the difference of object and function, and the mapping table set up is for follow-up reorientation and external call.
Wherein the mapping item of object map table comprises object oriented and object address, and the object address in this mapping table is the derived object by searching in effective section of obj ect file, obtains according to derived object address; The mapping item of Function Mapping table comprises function name sum functions address, and this function address is the derivative function by searching in effective section of obj ect file, and the address according to derivative function place obtains.
About object sum functions, give an example: the major part wherein comprised in .text section is function, and global variable, the functional elements etc. such as .text section .data section .bss section .rodata section file variable, function variable can with object encodings.Be divided into prior art due to object sum functions, do not repeat them here.
Reorientation unit 3033, for carrying out reorientation to the object in the effective section be loaded into and function.
This unit carries out reorientation for using object map table to the object in effective section, or uses described Function Mapping table to carry out reorientation to the function in effective section.
Particularly, when linking, need to carry out reorientation to the relocatable section of all file destinations, set up symbolic reference rule, be object simultaneously, the allocation address such as function.When program performs, the address space of specifying when code is loaded into link, to ensure program in the process of implementation to object, correctly quoting of the symbols such as function, makes normal program operation.
Based on the difference of the object extracted in obj ect file and type function, the relocation loading mode that two kinds different can be adopted.
First kind of way, reorientation is carried out to object (obj):
The use-pattern of object in .o file is, directly by the true address of object write literal pool.When this object of dynamic load, utilize the address of redirect object in literal pool of object described in the address search of existing object in described object map table, and the address of the object of redirect described in literal pool is revised as the address of existing object.
The second way, reorientation is carried out to function (func):
For the reorientation of function, the function address that address when current function can be utilized to run and the needs found from Function Mapping table jump to, through calculating jump instruction, the jump instruction calculated is utilized to upgrade jump instruction before, so that jump to the function address that namely will perform according to the jump instruction of described renewal.
Certainly, not can only search address according to object map table sum functions mapping table, what may quote due to object during dynamic load is that external object or function use dynamic base function, therefore when corresponding address information cannot be found in object or Function Mapping table, what then show object or function reference is external object or dynamic base function, now can search the address of object or function so that reorientation, thus realize dynamic load.
The mode that ELF file of the present invention is dynamically recorded and device, can be applied in the several scenes such as Set Top Box, intelligent Wearable device, Smart Home cloud.For Set Top Box, when user uses Set Top Box to start or installs ELF file, method and apparatus provided by the present invention can be used, by resolving static library file (.a) and loading and reorientation, thus realize the dynamic load of ELF file.
Method and apparatus provided by the invention can possess lower advantage:
1) present invention employs parsing static library (.a) file and extract effective section, effective section is loaded, set up object and Function Mapping table for carrying out the mode of reorientation respectively to the object sum functions in relocatable section, these processing modes are not limited to particular, instruction set, and therefore solving prior art cannot the problem of loading ELF document in some embedded systems.
Give one example, the present invention is particularly useful for the Cortex-M series processors embedded system supporting to adopt Thumb-2 instruction set.Because embedded MbedOS is based on the operating system designed by ARMCortex-M processor, Mbedos has the advantage of uniqueness as the system specially for embedded development customization.Current Cortex-M series processors can support Mbedos, but Mbedos also cannot provide the ELF file loader (Loader) being applicable to Cortex-M processor, because which limit the use of Mbedos in Cortex-M series processors at present.This is because existing embedded OS adopts the mode of static linkage to generate executable file for the loading of ELF file, and executable file is burned onto Flash, these operations all must complete under ARM instruction set, but due to the employing of Cortex-M series processors instruction set is Thumb-2 instruction set, this instruction set does not support the state being switched to ARM instruction set, and therefore prior art cannot provide the loader of dynamic analysis loading ELF document for this type of processor.
And method and apparatus provided by the invention converted a kind of thinking, not generate executable file by the mode of static linkage and be directly loaded into the mode of internal memory, do not need to be resolved and loading ELF document by specific ARM instruction set yet.But the static library file of ELF file is resolved to obtain effective section of the relocatable obj ect file of ELF and carries out reorientation, to enable the object in ELF file and function in relocatable mode by dynamic load.These processing procedures of the present invention are not limited to specific ARM instruction set, are therefore particularly useful for the Cortex-M series processors embedded system supporting to adopt Thumb-2 instruction set.
2) adopt the mode of static linkage to generate executable file in prior art, and executable file is burned onto Flash, therefore its number of applications run is limited to the executable file quantity of burning in Flash.And the present invention adopts dynamic load mode, can realize dynamic link based on this, the number of applications of operation is no longer limited to burning executable file quantity in Flash.
3) mode of static linkage needs generate executable file and be loaded into Flash, and it is comparatively large that this just causes file size, and power consumption is larger.The dynamic load mode of the application is compared prior art greatly less file size and power consumption.
In several embodiment provided by the present invention, should be understood that, disclosed system, apparatus and method, can realize by another way.Such as, device embodiment described above is only schematic, and such as, the division of described unit, is only a kind of logic function and divides, and actual can have other dividing mode when realizing.
The described unit illustrated as separating component or can may not be and physically separates, and the parts as unit display can be or may not be physical location, namely can be positioned at a place, or also can be distributed in multiple network element.Some or all of unit wherein can be selected according to the actual needs to realize the object of the present embodiment scheme.
In addition, each functional unit in each embodiment of the present invention can be integrated in a processing unit, also can be that the independent physics of unit exists, also can two or more unit in a unit integrated.Above-mentioned integrated unit both can adopt the form of hardware to realize, and the form that hardware also can be adopted to add SFU software functional unit realizes.
The foregoing is only preferred embodiment of the present invention, not in order to limit the present invention, within the spirit and principles in the present invention all, any amendment made, equivalent replacement, improvement etc., all should be included within the scope of protection of the invention.

Claims (22)

1. loading has the method that can perform and link form ELF file, and it is characterized in that, described method comprises:
Resolve to obtain obj ect file to the static library file in described ELF file;
Effective section is extracted from described obj ect file;
Load effective section, and set up object map table sum functions mapping table respectively, for carrying out reorientation to the object in the effective section loaded and function for the object in described obj ect file and function.
2. method according to claim 1, is characterized in that, effective section of extraction comprises: executable code segment, application data section or reorientation section.
3. method according to claim 1 and 2, is characterized in that, extracts effective section according to the ELF file header of described obj ect file and segment file head table.
4. method according to claim 1 and 2, is characterized in that, the effective section of described loading comprises: dissimilar effective section is loaded into different regions respectively.
5. method according to claim 4, is characterized in that, describedly dissimilar effective section is loaded into different regions respectively comprises:
According to the segment information of executable code segment and corresponding reorientation section, reorientation is carried out to executable code segment, by the executable code segment write Flash after reorientation; Or
According to the segment information of application data section and corresponding reorientation section, application data section is directly loaded into RAM.
6. method according to claim 5, is characterized in that, the described segment information section of comprising sequence number, field offset amount or section size.
7. method according to claim 5, it is characterized in that, described executable code segment comprises .text section, and described application data section comprises .data section .bss section or .rodata section, and described reorientation section comprises .rel.data section .rel.bss section or .rel.rodata section.
8. method according to claim 1 and 2, is characterized in that, after the effective section of described loading, carries out at least one mark following: the start address of section, field offset amount, section size to effective section of described obj ect file.
9. method according to claim 1, is characterized in that:
The mapping item of described object map table comprises object oriented and object address, and described object address is the derived object by searching in effective section, obtains according to derived object address;
The mapping item of described Function Mapping table comprises function name sum functions address, and described function address is the derivative function by searching in effective section, and the address according to derivative function place obtains.
10. method according to claim 1, it is characterized in that, when carrying out reorientation to the object in effective section, utilize the address of redirect object in literal pool of object described in the address search of existing object in described object map table, and the address of the object of redirect described in literal pool is revised as the address of existing object.
11. methods according to claim 1, it is characterized in that, when carrying out reorientation to the function in effective section, the function address that address when utilizing current function to run and the needs found from Function Mapping table jump to, through calculating jump instruction, the jump instruction calculated is utilized to upgrade jump instruction before, so that jump to the function address that namely will perform according to the jump instruction of described renewal.
The device of 12. 1 kinds of loading ELF documents, is characterized in that, described device comprises:
Resolver, for resolving to obtain obj ect file to the static library file in described ELF file;
Extraction element, for extracting effective section from described obj ect file;
Charger, for loading effective section, for the object in described obj ect file and function set up object map table sum functions mapping table respectively, and for carrying out reorientation to the object in the effective section loaded and function.
The device of 13. loading ELF documents according to claim 12, is characterized in that, the effective section extracted in described extraction element comprises: executable code segment, application data section or reorientation section.
The device of 14. loading ELF documents according to claim 12 or 13, is characterized in that, described extraction element is used for extracting effective section according to the ELF file header of described obj ect file and segment file head table.
The device of 15. loading ELF documents according to claim 12 or 13, it is characterized in that, described charger loads effective section and comprises: dissimilar effective section is loaded into different regions respectively.
The device of 16. loading ELF documents according to claim 15, is characterized in that, described charger, when dissimilar effective section is loaded into different regions respectively, specifically performs:
According to the segment information of executable code segment and corresponding reorientation section, reorientation is carried out to executable code segment, by the executable code segment write Flash after reorientation; Or
According to the segment information of application data section and corresponding reorientation section, application data section is directly loaded into RAM.
The device of 17. loading ELF documents according to claim 16, is characterized in that, the described segment information section of comprising sequence number, field offset amount or section size.
The device of 18. loading ELF documents according to claim 16, it is characterized in that, described executable code segment comprises .text section, described application data section comprises .data section .bss section or .rodata section, and described reorientation section comprises .rel.data section .rel.bss section or .rel.rodata section.
The device of 19. loading ELF documents according to claim 12 or 13, it is characterized in that, described charger, after execution described loading effective section, is further used for carrying out at least one mark following to effective section of described obj ect file: the start address of section, field offset amount, section size.
The device of 20. loading ELF documents according to claim 12, is characterized in that:
The mapping item of described object map table comprises object oriented and object address, and described object address is the derived object by searching in effective section, obtains according to derived object address;
The mapping item of described Function Mapping table comprises function name sum functions address, and described function address is the derivative function by searching in effective section, and the address according to derivative function place obtains.
The device of 21. loading ELF documents according to claim 12, is characterized in that, described charger, when carrying out reorientation to the object in effective section, specifically performs:
Utilize the address of redirect object in literal pool of object described in the address search of existing object in described object map table, and the address of the object of redirect described in literal pool is revised as the address of existing object.
The device of 22. loading ELF documents according to claim 12, it is characterized in that, described charger is when carrying out reorientation to the function in effective section, concrete execution: the function address that address when utilizing current function to run and the needs found from Function Mapping table jump to, through calculating jump instruction, the jump instruction calculated is utilized to upgrade jump instruction before, so that jump to the function address that namely will perform according to the jump instruction of described renewal.
CN201510688388.3A 2015-10-21 2015-10-21 A kind of method and apparatus of loading ELF document Active CN105224370B (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN201510688388.3A CN105224370B (en) 2015-10-21 2015-10-21 A kind of method and apparatus of loading ELF document
PCT/CN2016/084304 WO2017067175A1 (en) 2015-10-21 2016-06-01 Method, apparatus and device for loading elf file, and computer storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510688388.3A CN105224370B (en) 2015-10-21 2015-10-21 A kind of method and apparatus of loading ELF document

Publications (2)

Publication Number Publication Date
CN105224370A true CN105224370A (en) 2016-01-06
CN105224370B CN105224370B (en) 2019-03-08

Family

ID=54993362

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510688388.3A Active CN105224370B (en) 2015-10-21 2015-10-21 A kind of method and apparatus of loading ELF document

Country Status (2)

Country Link
CN (1) CN105224370B (en)
WO (1) WO2017067175A1 (en)

Cited By (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106354536A (en) * 2016-08-31 2017-01-25 北京奇虎科技有限公司 Method and device of loading ELF file of Linux system in Windows system
CN106598674A (en) * 2016-12-16 2017-04-26 中南大学 Relocatable ELF file-based software quick loading method
WO2017067175A1 (en) * 2015-10-21 2017-04-27 百度在线网络技术(北京)有限公司 Method, apparatus and device for loading elf file, and computer storage medium
CN107247579A (en) * 2016-08-19 2017-10-13 北京金山安全管理系统技术有限公司 The computational methods and device of a kind of ELF file maps base address
CN107315599A (en) * 2016-04-27 2017-11-03 龙芯中科技术有限公司 Shape library extracting method and device
CN107450960A (en) * 2017-09-18 2017-12-08 珠海亿智电子科技有限公司 A kind of method for linking and loading again to can perform ELF files
CN108874468A (en) * 2018-06-20 2018-11-23 深圳市腾讯网络信息技术有限公司 Loading method, device, computer equipment and the storage medium of application program
CN109324838A (en) * 2018-08-31 2019-02-12 深圳市元征科技股份有限公司 Execution method, executive device and the terminal of SCM program
CN110673850A (en) * 2019-08-28 2020-01-10 五八有限公司 Method and device for obtaining size of static library
CN111856989A (en) * 2020-06-19 2020-10-30 中电科航空电子有限公司 Dynamic linking method for single chip microcomputer
CN113010186A (en) * 2021-02-05 2021-06-22 武汉联特科技股份有限公司 Firmware and application data integration method and system applied to optical module
WO2021218756A1 (en) * 2020-04-30 2021-11-04 华为技术有限公司 Executable file processing method and device
CN114546515A (en) * 2022-01-20 2022-05-27 上海合宙通信科技有限公司 Module, firmware and equipment for dynamically loading static library and method for converting C library into Lua library
CN115658275A (en) * 2022-11-21 2023-01-31 统信软件技术有限公司 Executable program migration method and device and computing equipment

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111488557B (en) * 2019-01-28 2024-01-12 中国移动通信有限公司研究院 Encryption and decryption method and device, electronic equipment and readable storage medium
CN113672238B (en) * 2021-09-07 2024-03-12 广东九联开鸿科技发展有限公司 Operation method, device and equipment based on real-time operating system modularized management
CN116909656B (en) * 2023-09-14 2023-12-08 北京中天星控科技开发有限公司 Method for realizing embedded dynamic APP loading based on elf file
CN117075960B (en) * 2023-10-17 2024-01-23 统信软件技术有限公司 Program reconstruction method, application cross-platform migration method, device and computing equipment

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101697131A (en) * 2009-11-04 2010-04-21 中兴通讯股份有限公司 Method and device for dynamically loading relocatable file

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6298479B1 (en) * 1998-05-29 2001-10-02 Sun Microsystems, Inc. Method and system for compiling and linking source files
CN100359472C (en) * 2005-07-01 2008-01-02 中国科学院计算技术研究所 Method for processing library function call in binary translation
CN101470619A (en) * 2007-12-29 2009-07-01 安凯(广州)软件技术有限公司 Application program dynamic loading method based on microkernel operating system
CN105224370B (en) * 2015-10-21 2019-03-08 安一恒通(北京)科技有限公司 A kind of method and apparatus of loading ELF document

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101697131A (en) * 2009-11-04 2010-04-21 中兴通讯股份有限公司 Method and device for dynamically loading relocatable file

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
EMMOBLIN: "《http//:www.blog.chinaunix.net/uid-20778443-id-99714.html》", 23 January 2011 *
陈赜 主编: "《ARM嵌入式技术原理与应用》", 31 January 2011 *

Cited By (19)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2017067175A1 (en) * 2015-10-21 2017-04-27 百度在线网络技术(北京)有限公司 Method, apparatus and device for loading elf file, and computer storage medium
CN107315599A (en) * 2016-04-27 2017-11-03 龙芯中科技术有限公司 Shape library extracting method and device
CN107247579B (en) * 2016-08-19 2020-09-11 北京金山安全管理系统技术有限公司 Method and device for calculating ELF file mapping base address
CN107247579A (en) * 2016-08-19 2017-10-13 北京金山安全管理系统技术有限公司 The computational methods and device of a kind of ELF file maps base address
WO2018040270A1 (en) * 2016-08-31 2018-03-08 北京奇虎科技有限公司 Method and device for loading linux-system elf file in windows system
CN106354536A (en) * 2016-08-31 2017-01-25 北京奇虎科技有限公司 Method and device of loading ELF file of Linux system in Windows system
CN106598674A (en) * 2016-12-16 2017-04-26 中南大学 Relocatable ELF file-based software quick loading method
CN107450960A (en) * 2017-09-18 2017-12-08 珠海亿智电子科技有限公司 A kind of method for linking and loading again to can perform ELF files
CN108874468B (en) * 2018-06-20 2021-03-26 深圳市腾讯网络信息技术有限公司 Application program loading method and device, computer equipment and storage medium
CN108874468A (en) * 2018-06-20 2018-11-23 深圳市腾讯网络信息技术有限公司 Loading method, device, computer equipment and the storage medium of application program
CN109324838A (en) * 2018-08-31 2019-02-12 深圳市元征科技股份有限公司 Execution method, executive device and the terminal of SCM program
CN110673850A (en) * 2019-08-28 2020-01-10 五八有限公司 Method and device for obtaining size of static library
WO2021218756A1 (en) * 2020-04-30 2021-11-04 华为技术有限公司 Executable file processing method and device
CN111856989A (en) * 2020-06-19 2020-10-30 中电科航空电子有限公司 Dynamic linking method for single chip microcomputer
CN113010186A (en) * 2021-02-05 2021-06-22 武汉联特科技股份有限公司 Firmware and application data integration method and system applied to optical module
CN113010186B (en) * 2021-02-05 2023-03-21 武汉联特科技股份有限公司 Firmware and application data integration method and system applied to optical module
CN114546515A (en) * 2022-01-20 2022-05-27 上海合宙通信科技有限公司 Module, firmware and equipment for dynamically loading static library and method for converting C library into Lua library
CN114546515B (en) * 2022-01-20 2023-09-12 上海合宙通信科技有限公司 Module, firmware and equipment for dynamically loading static library and method for converting C library into Lua library
CN115658275A (en) * 2022-11-21 2023-01-31 统信软件技术有限公司 Executable program migration method and device and computing equipment

Also Published As

Publication number Publication date
WO2017067175A1 (en) 2017-04-27
CN105224370B (en) 2019-03-08

Similar Documents

Publication Publication Date Title
CN105224370A (en) A kind of method and apparatus of loading ELF document
US8566372B2 (en) Method and device for dynamically loading relocatable file
JP6267711B2 (en) Modernization of legacy software systems based on modeled dependencies
CN108139891B (en) Method and system for generating suggestions to correct undefined token errors
US20230117105A1 (en) On-demand loading of dynamic scripting language code for reduced memory usage
CN109032631B (en) Application program patch package obtaining method and device, computer equipment and storage medium
CN104714788A (en) Method and device for automatically generating software installation package
CN112099800A (en) Code data processing method and device and server
CN103019787A (en) Function call relation determining method, hotfix updating method and hotfix updating device
CN101251799B (en) Apparatus and method for implementing management
CN102364433B (en) Method for realizing Wine construction tool transplanting on ARM (Advanced RISC Machines) processor
EP2321734B1 (en) Type descriptor management for frozen objects
CN103761107A (en) Software package customizing device and method
CN101334737A (en) Embedded equipment start-up or reset method
US20090217022A1 (en) Method and apparatus for loading classes and re-organizing class archives
CN103645888A (en) System and method for automatically building operation system
KR102141749B1 (en) APP program execution method and device
CN102147734A (en) Runtime class extracting method and system
US20170228243A1 (en) Non-transitory computer-readable recording medium storing control program, control device and control method
CN102880461A (en) Compiling and linking method and device
CN103235745B (en) A kind of address conflict detecting method and device
JP5427802B2 (en) Library conversion method and program between programming languages
CN102760212B (en) Virtual desktop malicious code detecting method based on storage mirroring cloning mechanism
CN106202523A (en) Page authoring method and device
CN103677851B (en) A kind of method and apparatus generating embedded program operation symbol table

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
TR01 Transfer of patent right
TR01 Transfer of patent right

Effective date of registration: 20190807

Address after: 100085 Beijing, Haidian District, No. ten on the ground floor, No. 10 Baidu building, layer 2

Patentee after: BEIJING BAIDU NETCOM SCIENCE AND TECHNOLOGY Co.,Ltd.

Address before: 100193 room 1-01, 1-03, 1-04, block C, software Plaza, building 4, No. 8, Mong West Road, Beijing, Haidian District

Patentee before: Pacify a Heng Tong (Beijing) Science and Technology Ltd.