CN105224370B - A kind of method and apparatus of loading ELF document - Google Patents
A kind of method and apparatus of loading ELF document Download PDFInfo
- Publication number
- CN105224370B CN105224370B CN201510688388.3A CN201510688388A CN105224370B CN 105224370 B CN105224370 B CN 105224370B CN 201510688388 A CN201510688388 A CN 201510688388A CN 105224370 B CN105224370 B CN 105224370B
- Authority
- CN
- China
- Prior art keywords
- section
- function
- address
- file
- effective
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements 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/44—Arrangements for executing specific programs
- G06F9/445—Program loading or initiating
Abstract
The present invention provides one kind to having executable and link format (ELF) file dynamically load method and apparatus, and wherein method includes: to be parsed the static library file in the ELF file to obtain obj ect file;Effective section is extracted from the obj ect file;Load effective section, and in the obj ect file object and function establish object mapping table and Function Mapping table respectively, in effective section to load object and function relocate.The method and apparatus of provided ELF file dynamically load through the invention, embedded system in the prior art can be got rid of to need to rely on specific instruction set in parsing and when loading ELF document, it can not be suitable for the puzzlement of whole embeded processor frameworks, realize the application that can run multiple ELF files simultaneously under par-ticular processor architecture, and it can be realized dynamic link, the file size generated before substantially reducing using static linkage, reduces power consumption.
Description
[technical field]
The present invention relates to computer field more particularly to a kind of method and apparatus of loading ELF document.
[background technique]
It is a kind of object text with executable and link format ELF (Executable and Linking Format)
The format of part, for defining content and its format in different types of obj ect file (Object files).Due to existing
Embedded OS generates executable file using the mode of static linkage for the load of ELF file, and using burning
For the mode of record by executable file direct burning to memory (Flash), these treatment processes all must be complete under ARM instruction set
At, and the not ARM instruction set that some processors use, and its used instruction set cutting to ARM instruction set is not supported
It changes, therefore the prior art can not provide the load of ELF file for such processor.
[summary of the invention]
The invention proposes a kind of method and apparatus of loading ELF document, in order to solve the prior art in some insertions
The problem of ELF file can not be recorded in formula system.
Specific technical solution is as follows:
A method of being loaded with executable and link format ELF file, which comprises
Static library file in the ELF file is parsed to obtain obj ect file;
Effective section is extracted from the obj ect file;
Load effective section, and in the obj ect file object and function establish object mapping table and Function Mapping respectively
Table, in effective section to load object and function relocate.
According to one preferred embodiment of the present invention, effective section of extraction includes: executable code segment, application data section or resets
Position section.
According to one preferred embodiment of the present invention, it is extracted according to the ELF file header of the obj ect file and segment file head table
Effective section.
According to one preferred embodiment of the present invention, the effective section of load includes: to load different types of effective section respectively
To different regions.
According to one preferred embodiment of the present invention, described that different types of effective section is loaded into different region packets respectively
It includes:
According to the segment information of executable code segment and corresponding reorientation section, executable code segment is relocated, will be weighed
Flash is written in executable code segment after positioning;Or
According to the segment information of application data section and corresponding reorientation section, application data section is loaded directly into RAM.
According to one preferred embodiment of the present invention, the segment information includes section serial number, field offset amount or Duan great little.
According to one preferred embodiment of the present invention, the executable code segment includes .text sections, the application data section packet
Include .data sections .bss sections or .rodata sections, the reorientation section include .rel.data sections .rel.bss sections or
.rel.rodata section.
According to one preferred embodiment of the present invention, after the effective section of the load, to effective section of the obj ect file into
The label of at least one below row: initial address, the field offset amount, Duan great little of section.
According to one preferred embodiment of the present invention, the mapping item of the object mapping table includes object oriented and object
Location, the object address are by searching for the derived object in effective section, according to obtained from derived object address;It is described
The mapping item of Function Mapping table includes function name and function address, and the function address is by searching for leading in effective section
Function out, according to obtained from the address where export function.
According to one preferred embodiment of the present invention, when being relocated to the object in effective section, existed using existing object
Object described in address search in the object mapping table jumps address of the object in literal pool, and will be described in literal pool
It is revised as the address of existing object in the address for jumping object.
According to one preferred embodiment of the present invention, it when being relocated to the function in effective section, is transported using current function
The function address that address when row and the needs found from Function Mapping table jump to, jumps finger by being calculated
It enables, calculated jump instruction is updated jump instruction before, in order to jump finger according to the update
Order jumps to function address i.e. to be executed.
A kind of device of loading ELF document, described device include:
Resolver, for being parsed the static library file in the ELF file to obtain obj ect file;
Extraction element, for extracting effective section from the obj ect file;
Loading device is that the object and function in the obj ect file establish object mapping respectively for loading effective section
Table and Function Mapping table, and for in effective section of load object and function relocate.
According to one preferred embodiment of the present invention, the effective section extracted in the extraction element includes: executable code segment, answers
With data segment or reorientation section.
According to one preferred embodiment of the present invention, the extraction element be used for according to the ELF file header of the obj ect file and
Segment file head table extracts effective section.
According to one preferred embodiment of the present invention, it includes: by different types of effective section that the loading device, which loads effective section,
It is loaded into different regions respectively.
According to one preferred embodiment of the present invention, different types of effective section is being loaded into difference by the loading device respectively
Region when, it is specific to execute:
According to the segment information of executable code segment and corresponding reorientation section, executable code segment is relocated, will be weighed
Flash is written in executable code segment after positioning;Or
According to the segment information of application data section and corresponding reorientation section, application data section is loaded directly into RAM.
According to one preferred embodiment of the present invention, the segment information includes section serial number, field offset amount or Duan great little.
According to one preferred embodiment of the present invention, the executable code segment includes .text sections, the application data section packet
Include .data sections .bss sections or .rodata sections, the reorientation section include .rel.data sections .rel.bss sections or
.rel.rodata section.
According to one preferred embodiment of the present invention, the loading device is further used after executing the effective section of load
The label of at least one below effective section to the obj ect file carries out: initial address, the field offset amount, Duan great little of section.
According to one preferred embodiment of the present invention, the mapping item of the object mapping table includes object oriented and object
Location, the object address are by searching for the derived object in effective section, according to obtained from derived object address;It is described
The mapping item of Function Mapping table includes function name and function address, and the function address is by searching for leading in effective section
Function out, according to obtained from the address where export function.
According to one preferred embodiment of the present invention, the loading device is when relocating the object in effective section, tool
Body executes:
Object is jumped in literal pool using existing object object described in the address search in the object mapping table
Address, and the address that object is jumped described in literal pool is revised as to the address of existing object.
According to one preferred embodiment of the present invention, the loading device is when relocating the function in effective section, tool
Body executes: the function that address when being run using current function and the needs found from Function Mapping table are jumped to
Location, by jump instruction is calculated, calculated jump instruction is updated jump instruction before, in order to
Function address i.e. to be executed is jumped to according to the jump instruction of the update.
As can be seen from the above technical solutions, present invention employs parsing static library (.a) file and effective section is extracted,
Effective section is loaded, establish object and Function Mapping table be used for in relocatable section object and function carry out weight respectively
The mode of positioning, these processing modes are not limited to particular, instruction set, therefore solve the prior art in some embedded systems
In system can not loading ELF document the problem of.
[Detailed description of the invention]
Fig. 1 is the flow diagram of a kind of couple of ELF file dynamic loading method provided in an embodiment of the present invention;
Fig. 2 is the form schematic diagram of ELF Header provided in an embodiment of the present invention;
Fig. 3 is a kind of structural schematic diagram of the device of loading ELF document provided in an embodiment of the present invention.
[specific embodiment]
To make the objectives, technical solutions, and advantages of the present invention clearer, right in the following with reference to the drawings and specific embodiments
The present invention is described in detail.
Referring to FIG. 1, Fig. 1 is a kind of side for being loaded with executable and link format ELF file provided by the invention
The flow diagram of method embodiment.As shown in Figure 1, the process includes:
101: static library (.a) file in ELF file is parsed to obtain obj ect file (.o).
Obj ect file (.o) of the invention is the retargetable file saved with ELF format, and the content in obj ect file can
To include the threshold marker to each function, description, to form the executable instruction of machine.Also needed when program will execute into
Row link (link), link is exactly multiple .o file chains into an executable file.
ELF file other than the obj ect file that may include relocatable, can also comprising executable obj ect file and
The obj ect file that can be shared, above-mentioned three kinds of obj ect files in the form of obj ect file .o due to that can be indicated, and multiple .o
Obj ect file can file (archive) into .a static state library file, to finally form ELF file, therefore parse in the present invention
The purpose of static library (.a) file is exactly the obj ect file (.o) in order to obtain composition ELF file.
Specifically, the decompression of a compressed package rar in the process and windows operating system of static library file is parsed
(reduction) process is similar, that is, analysis is packaged the static library (.a) generated by obj ect file (.o), parses wherein each object
File (.o).
102: effective section (section) is extracted from the obj ect file of acquisition.
After obtaining obj ect file (.o), it can be directed to each obj ect file, therefrom extract effective section and record segment
Information.
Effective smallest vessel of the section (sections) inside ELF file, to load contents data.
Preferably, it can be directed to the obj ect file of each acquisition, according to the ELF file header (ELF of the obj ect file
Header it) extracts effective section with segment file head table (SHT, Section Header Table) and records each segment information.
Effective section of the concrete type may include: executable code segment, application data section, or reorientation section.Wherein should
Executable code segment can specifically include .text sections etc. again, the application data section may include .data sections .bss sections or
.rodata section etc., the reorientation section may include .rel.data sections .rel.bss sections or rel.rodata sections etc..
Effective segment information of the record includes but is not limited to: each section of serial number, field offset amount or section size etc..
Wherein
1) executable code is loaded in .text sections;
2) data being initialised are loaded in .data sections;
3) data not being initialised are loaded in .bss sections;
4) constant of respective symbols string and definition is loaded in .rodata sections
5) rel.text sections .rel.data sections .rel.bss sections .rel.rodata sections of reorientation section to be taken the lead with .rel
The inside is loaded with relocation entries, which is used to help executable code segment and application data section is relocated
Section;
Such as: show which place in .text sections needs to relocate in .rel.text.
Lift a specific example below to illustrate to extract effective section and each section of letter from the ELF Header and SHT of obj ect file
The concrete mode of breath:
ELF Header in the present embodiment can be indicated with format shown in Fig. 2.
As shown in Fig. 2, the ELF Header illustrates the format of relocatable obj ect file (.o).It can be from the ELF
Corresponding sections and serial number are learnt in Header, and has which specific sections in an ELF file on earth, then instead
It reflects in the SHT in this ELF file.
The definition of target structure can be in SHT table are as follows:
In SHT, for each section, it is both provided with an entry, for describing this corresponding section,
Its content mainly includes title, type, size and byte offset location in entire ELF file of the section etc..
Field Off (sh_offset) illustrates that the section leaves top of file in target structure in above-mentioned SHT table
The distance of position, i.e. offset;The section size of Size (sh_size) expression section.
Related section to be indicated according to ELF Header and SHT is so as to extracting each effective section of information.
101 above and 102 are the preparation processes before dynamically load ELF file to load, and step can be simultaneously
Or successively execute, the sequence that the present invention executes it does not lay down hard-and-fast rule, and after above-mentioned preparation process executes, then passes through
103 further realize the load to effective section of obj ect file.
103: load effective section, and in the obj ect file object and function establish object mapping table and function respectively
Mapping table, for in the effective section being loaded into object and function relocate.
For 103, the effective section of load can also be further divided into, establish mapping table and three steps of reorientation
Suddenly, wherein the first two steps can simultaneously or successively execute, the sequence that the present invention executes it does not lay down hard-and-fast rule, as long as
Corresponding function can be completed, then within that scope of the present invention.
Three steps are described in detail below:
Step 1: loading effective section.
For in 102 extracted effective sections, including executable code segment, application data section and reorientation three type of section
Type, wherein executable code segment and application data section, which belong to, needs effective section to be loaded, and relocates section and do not need to load, for
This needs effective section to be loaded, can according to its type it is different corresponding can be loaded into using two ways it is different
Region.
First way loads (.text sections) of executable code segment:
Since the read-write for being directed to different its flash of product is inconsistent, for the ease of .text sections of reorientation modification
Content can first relocate .text sections, then be written into Flash again.
It needs to relocate due to including .text sections in the reorientation section (.rel.text sections) corresponding with .text sections of extraction
Information, therefore the relocation loading mode before flash is written can be with are as follows: records in the .rel.text section that will identify that
.text section needs the part relocated to record creation relocation information, relocates to .text, then again by .text sections
It copies and is written in Flash.
The second way, the load for application data section (.data .bss and .rodata):
The loading method and the loading method to .text sections of .data .bss and .rodata are slightly different, compared to
It further include for .text sections of repositioning process, to .data .bss before being written to Flash to .text sections of loads
And the load of .rodata is being loaded into random access memory (Random Access Memory, RAM) before not for each section
It is relocated, but according to .data .bss and .rodata and accordingly relocates section (..rel.data .rel.bss
And .rel.rodata) effective segment information, be loaded directly into RAM for .data .bss and .rodata sections.
After through the first and the effective section of second way load, each section of each object file (.o) can be done
Good corresponding label, the label can include but is not limited to the information such as the initial address of section, field offset amount, section size.
The initial address in its middle section is obtained according to effective section initialization after load, and field offset amount, Duan great little are
What effective section when extracting effective section based on the extraction obtained.
In the first step, by the way that the .text section of executable code and the application number of other application data sections will be loaded with
According to separation, and relocation information is created by the file destination to executable code and is loaded into memory, to generate memory mapping
Process avoids the process for repeatedly copying code data in loading ELF document, improves operational efficiency.
Second step is that the object and function in obj ect file establish object mapping table and Function Mapping table respectively.
In this step, object mapping table (obj_map) and Function Mapping are established respectively according to the difference of object and function
Table (func_map), the mapping table established are used for subsequent reorientation and external call.
Wherein the mapping item of object mapping table includes object oriented and object address, and the object address in the mapping table is
By searching for the derived object in effective section of obj ect file, according to obtained from derived object address;Function Mapping table
Mapping item include function name and function address, which is the export in effective section by searching for obj ect file
Function, according to obtained from the address where export function.
About object and function, for example: the major part for wherein including in .text sections is function, and .text sections,
.data global variables, the functional element such as file variable, function variable etc. can be with objects in section .bss sections .rodata sections
It indicates.The prior art is divided into due to object and function, details are not described herein.
Third step, in the effective section being loaded into object and function relocate.
In this step, the object in effective section is relocated using object mapping table, or is reflected using the function
Firing table relocates the function in effective section.
Specifically, it in link, needs to relocate the relocatable section of all file destinations, establishes symbolic reference
Rule, while being object, function etc. distributes address.When program executes, code is loaded into the address space specified when link, with
Guarantee program in the process of implementation to object, the correct reference of the symbols such as function makes normal program operation.
Based on the difference of the object and type function that extract in obj ect file, two different reorientation sides can be used
Formula.
First way relocates object (obj):
Usage mode of the object in .o file is that literal pool directly is written in the true address of object.In dynamically load
When this object, object is jumped in literal pool using existing object object described in the address search in the object mapping table
Address, and the address that object is jumped described in literal pool is revised as to the address of existing object.
Specifically, compiler can all be put into the address of object the region literal pool (Literal Pool).Wherein Literal
Absolute address or constant are only stored inside Pool.When being relocated, according to .rel.text .rel.data,
.rel.bss and the .rel.rodata object relocation information that is included, pass through working as object recorded in object mapping table
Preceding address obtains the absolute address that object is jumped recorded in literal pool, searches absolute address from Literal Pool,
When dynamically load, the absolute address in the literal pool where object is revised as to the address where existing object, thus right
.text .data, the .bss and .rodata sections of objects for including relocate.
The second way relocates function (func):
Reorientation for function can use address when current function is run and find from Function Mapping table
The function address that jumps to of needs, by jump instruction is calculated, calculated jump instruction is to jump before
Turn instruction to be updated, in order to jump to function address i.e. to be executed according to the jump instruction of the update.
Specifically, function call is jumped using corresponding jump instruction, such as B/BL etc. relocates function
When, based on the function relocation information that .rel.text etc. is included, the function for needing to jump to is searched from Function Mapping table
True address, the letter for combining the needs found from Function Mapping table to jump to according to the current address where when function operation
Number true address, obtains jump instruction by series of computation, obtains correct jump instruction and carries out to jump instruction before
It updates, thus according to the function of updated jump instruction load reorientation.
Certainly, not address can only be searched according to object mapping table and Function Mapping table, object when due to dynamically load
What may be quoted is that external object or function use dynamic library function, therefore working as can not in object or Function Mapping table
When finding corresponding address information, then show object or function reference is external object or dynamic library function, at this time can be with
Go to the address for dynamically searching object or function to relocate, to realize dynamically load.
Referring to FIG. 3, Fig. 3 is a kind of structural schematic diagram of the Installation practice of loading ELF document provided by the invention.Such as
Shown in Fig. 3, which includes: resolver 301, extraction element 302 and loading device 303, is carried out below to each device detailed
Description:
Resolver 301, for being parsed static library (.a) file in ELF file to obtain obj ect file
(.o)。
Obj ect file (.o) of the invention is the retargetable file saved with ELF format, and the content in obj ect file can
To include the threshold marker to each function, description, to form the executable instruction of machine.Also needed when program will execute into
Row link (link), link is exactly multiple .o file chains into an executable file.Multiple .o obj ect files can file
(archive) at .a static state library file, and static library file line is at ELF file.
Wherein the purpose of resolver parsing static library (.a) file is to obtain obj ect file therein (.o).
Specifically, the decompression of a compressed package rar in the process and windows operating system of static library file is parsed
(reduction) process is similar, that is, analysis is packaged the static library (.a) generated by obj ect file (.o), parses wherein each object
File (.o).
Extraction element 302, for extracting effective section (section) from the obj ect file of acquisition.
After obtaining obj ect file (.o), it can be directed to each obj ect file, therefrom extract effective section and record segment
Information.
Effective smallest vessel of the section (sections) inside ELF file, to load contents data.In ELF file,
The identical content of attribute has all been loaded in each sections.,
Preferably, it can be directed to the obj ect file of each acquisition, according to the ELF file header (ELF of the obj ect file
Header it) extracts effective section with segment file head table (SHT, Section Header Table) and records each segment information.
Effective section of the concrete type may include: executable code segment, application data section, or reorientation section.Wherein should
Executable code segment can specifically include .text sections etc. again, the application data section may include .data sections .bss sections or
.rodata section etc., the reorientation section may include .rel.data sections .rel.bss sections or rel.rodata sections etc..
Effective segment information of the record includes but is not limited to: each section of serial number, field offset amount or section size etc..
Wherein
1) executable code is loaded in .text sections;
2) data being initialised are loaded in .data sections;
3) data not being initialised are loaded in .bss sections;
4) constant of respective symbols string and definition is loaded in .rodata sections
5) rel.text sections .rel.data sections .rel.bss sections .rel.rodata sections of reorientation section to be taken the lead with .rel
The inside is loaded with relocation entries, which is used to help executable code segment and application data section is relocated
Section;
Such as: show which place in .text sections needs to relocate in .rel.text.
The concrete mode that effective section and each segment information are extracted from the ELF Header and SHT of obj ect file can be with are as follows:
Corresponding sections and serial number are learnt from ELF Header, from the content of SHT, according to the field in SHT
Off (sh_offset), Size (sh_size) obtain the information such as field offset amount, section size.
Device 301 and 302 is for executing the standard before load to the ELF file of preloading before dynamically load ELF file
It is standby, preparation process can simultaneously or successively execute, the sequence that the present invention executes it does not lay down hard-and-fast rule, when above-mentioned standard
After standby process executes, then the load to effective section of obj ect file is further realized by device 303.
Loading device 303, for loading effective section, in the obj ect file object and function establish object respectively and reflect
Firing table and Function Mapping table, and for in the effective section being loaded into object and function relocate.
Loading device 303 can also be further divided into effective section loading unit 3031, mapping table establishes unit 3032
And 3,033 3 units of bit location are reset, wherein the first two unit can execute simultaneously or successively corresponding operating, this hair
The bright sequence executed to it does not lay down hard-and-fast rule, as long as corresponding function can be completed, within that scope of the present invention.
Three units are described in detail below:
Load effective segment unit 3031.
For by the extracted effective section of extraction unit 302, including executable code segment, application data section and reorientation
Section three types, wherein executable code segment and application data section, which belong to, needs effective section to be loaded, and relocates section and do not need
Load needs effective section to be loaded for this, corresponding can be added using two ways according to the difference of its type
It is downloaded to different regions.
First way loads (.text sections) of executable code segment:
Since the read-write for being directed to different its flash of product is inconsistent, for the ease of .text sections of reorientation modification
Content can first relocate .text sections, then be written into Flash again.
It needs to relocate due to including .text sections in the reorientation section (.rel.text sections) corresponding with .text sections of extraction
Information, therefore the relocation loading mode before flash is written can be with are as follows: records in the .rel.text section that will identify that
.text section needs the part relocated to record creation relocation information, relocates to .text, then again by .text sections
It copies and is written in Flash.
The second way, the load for application data section (.data .bss and .rodata):
The loading method and the loading method to .text sections of .data .bss and .rodata are slightly different, compared to
It further include for .text sections of repositioning process, to .data .bss before being written to Flash to .text sections of loads
And the load of .rodata is being loaded into random access memory (Random Access Memory, RAM) before not for each section
It is relocated, but according to .data .bss and .rodata and accordingly relocates section (.rel.data .rel.bss
And .rel.rodata) effective segment information, be loaded directly into RAM for .data .bss and .rodata sections.
After through the first and the effective section of second way load, each section of each object file (.o) can be done
Good corresponding label, the label can include but is not limited to the information such as the initial address of section, field offset amount, section size.
The initial address in its middle section is obtained according to effective section initialization after load, and field offset amount, Duan great little are
What effective section when extracting effective section based on the extraction obtained.
The present embodiment will be loaded with the .text section and others of executable code by the operation of the effective segment unit of load
The application data separating of application data section, and created in relocation information and loading by the file destination to executable code
It deposits, to generate memory mapping process, avoids the process for repeatedly copying code data in loading ELF document, improve fortune
Line efficiency.
Mapping table establishes unit 3032, for in obj ect file object and function establish object mapping table and letter respectively
Number mapping table.
This unit is used to establish object mapping table (obj_map) and Function Mapping table respectively according to the difference of object and function
(func_map), the mapping table established is used for subsequent reorientation and external call.
Wherein the mapping item of object mapping table includes object oriented and object address, and the object address in the mapping table is
By searching for the derived object in effective section of obj ect file, according to obtained from derived object address;Function Mapping table
Mapping item include function name and function address, which is the export in effective section by searching for obj ect file
Function, according to obtained from the address where export function.
About object and function, for example: the major part for wherein including in .text sections is function, and .text sections,
.data global variables, the functional element such as file variable, function variable etc. can be with objects in section .bss sections .rodata sections
It indicates.The prior art is divided into due to object and function, details are not described herein.
Reset bit location 3033, for in the effective section being loaded into object and function relocate.
This unit is used to relocate the object in effective section using object mapping table, or uses the Function Mapping
Table relocates the function in effective section.
Specifically, it in link, needs to relocate the relocatable section of all file destinations, establishes symbolic reference
Rule, while being object, function etc. distributes address.When program executes, code is loaded into the address space specified when link, with
Guarantee program in the process of implementation to object, the correct reference of the symbols such as function makes normal program operation.
Based on the difference of the object and type function that extract in obj ect file, two different reorientation sides can be used
Formula.
First way relocates object (obj):
Usage mode of the object in .o file is that literal pool directly is written in the true address of object.In dynamically load
When this object, object is jumped in literal pool using existing object object described in the address search in the object mapping table
Address, and the address that object is jumped described in literal pool is revised as to the address of existing object.
The second way relocates function (func):
Reorientation for function can use address when current function is run and find from Function Mapping table
The function address that jumps to of needs, by jump instruction is calculated, calculated jump instruction is to jump before
Turn instruction to be updated, in order to jump to function address i.e. to be executed according to the jump instruction of the update.
Certainly, not address can only be searched according to object mapping table and Function Mapping table, object when due to dynamically load
What may be quoted is that external object or function use dynamic library function, therefore working as can not in object or Function Mapping table
When finding corresponding address information, then show object or function reference is external object or dynamic library function, at this time can be with
The address of object or function is searched to relocate, to realize dynamically load.
The mode and device that ELF file dynamic of the invention is recorded, can be applied to that set-top box, intelligence is wearable sets
In the several scenes such as standby, smart home cloud.By taking set-top box as an example, when user is started using set-top box or installs ELF file,
Method and apparatus provided by the present invention can be used, by being parsed to static library file (.a) and being loaded and reset
Position, to realize the dynamically load of ELF file.
Method and apparatus provided by the invention can have lower advantage:
1) present invention employs parsing static library (.a) file and extracting effective section, effective section is loaded, is established
Object and Function Mapping table are used for the object and the mode that is relocated respectively of function in relocatable section, these processing sides
Formula is not limited to particular, instruction set, therefore solving the prior art can not loading ELF document in some embedded systems
Problem.
It gives one example, present invention is particularly suitable for the Cortex-M series processors supported using Thumb-2 instruction set
Embedded system.Since embedded Mbed OS is based on operating system designed by ARM Cortex-M processor, Mbed os
There is unique advantage as the system customized exclusively for embedded development.Cortex-M series processors have been able to prop up at present
Mbed os is held, but Mbed os can not also provide the ELF file loader (Loader) suitable for Cortex-M processor at present,
Therefore use of the Mbed os in Cortex-M series processors is limited.This is because existing embedded OS pair
Executable file is generated by the way of static linkage in the load of ELF file, and executable file is burned onto Flash, this
A little operations must all be completed under ARM instruction set, but since Cortex-M series processors instruction set is using Thumb-2
Instruction set, the instruction set do not support the state for being switched to ARM instruction set, thus the prior art can not be provided for such processor it is dynamic
The loader of state parsing loading ELF document.
And method and apparatus provided by the invention converted a kind of thinking, not be to generate to hold by way of static linkage
Style of writing part is simultaneously directly loaded into the mode of memory, does not also need to parse by specific ARM instruction set and loading ELF document.And
It is to be parsed to the static library file of ELF file to obtain effective section of the obj ect file of ELF relocatable and reset
Position, to enable object in ELF file and function to be loaded dynamically in a manner of relocatable.These processing of the invention
Process is not limited to specific ARM instruction set, therefore is particularly suitable for the Cortex-M system for supporting to use Thumb-2 instruction set
Column processor embedded system.
2) executable file is generated by the way of static linkage in the prior art, and executable file is burned onto
Flash, therefore the number of applications of its operation is limited to the executable file quantity of burning in Flash.And the present invention is using dynamic
Loading method can be realized dynamic link based on this, and the number of applications of operation is no longer limited by burning executable file in Flash
Quantity.
3) mode of static linkage needs to generate executable file and is loaded into Flash, and it is larger that this has resulted in file size,
Power consumption is larger.The dynamically load mode of the application compares the prior art significantly smaller file size and power consumption.
In several embodiments provided by the present invention, it should be understood that disclosed system, device and method can be with
It realizes by another way.For example, the apparatus embodiments described above are merely exemplary, for example, the unit
It divides, only a kind of logical function partition, there may be another division manner in actual implementation.
The unit as illustrated by the separation member may or may not be physically separated, aobvious as unit
The component shown may or may not be physical unit, it can and it is in one place, or may be distributed over multiple
In network unit.It can select some or all of unit therein according to the actual needs to realize the mesh of this embodiment scheme
's.
It, can also be in addition, the functional units in various embodiments of the present invention may be integrated into one processing unit
It is that each unit physically exists alone, can also be integrated in one unit with two or more units.Above-mentioned integrated list
Member both can take the form of hardware realization, can also realize in the form of hardware adds SFU software functional unit.
The foregoing is merely illustrative of the preferred embodiments of the present invention, is not intended to limit the invention, all in essence of the invention
Within mind and principle, any modification, equivalent substitution, improvement and etc. done be should be included within the scope of the present invention.
Claims (18)
1. a kind of be loaded with executable and link format ELF file method, which is characterized in that the described method includes:
Static library file in the ELF file is parsed to obtain obj ect file;
Effective section is extracted from the obj ect file;
Different types of effective section is loaded into different regions respectively, and in the obj ect file object and function build respectively
Vertical object mapping table and Function Mapping table, in effective section to load object and function relocate;Wherein,
It includes according to executable code segment and accordingly relocating section that different types of effective section is loaded into different regions respectively
Segment information, executable code segment is relocated, by after reorientation executable code segment be written Flash;Or according to
The segment information of application data section and corresponding reorientation section, is loaded directly into RAM for application data section.
2. the method according to claim 1, wherein the effective section extracted includes: executable code segment, using number
According to section or reorientation section.
3. method according to claim 1 or 2, which is characterized in that according to the ELF file header and Duan Wen of the obj ect file
Part head table extracts effective section.
4. the method according to claim 1, wherein the segment information includes that section serial number, field offset amount or section are big
It is small.
5. according to the method described in claim 4, it is characterized in that, the executable code segment includes .text sections, the application
Data segment includes .data sections .bss sections or .rodata sections, the reorientation section include .rel.data sections .rel.bss sections or
.rel.rodata section.
6. method according to claim 1 or 2, which is characterized in that after the effective section of load, to the object text
The label of at least one below effective section progress of part: initial address, the field offset amount, Duan great little of section.
7. according to the method described in claim 1, it is characterized by:
The mapping item of the object mapping table includes object oriented and object address, and the object address is by searching for effective
Derived object in section, according to obtained from derived object address;
The mapping item of the Function Mapping table includes function name and function address, and the function address is by searching for effective
Export function in section, according to obtained from the address where export function.
8. the method according to claim 1, wherein being utilized when being relocated to the object in effective section
Existing object object described in the address search in the object mapping table jumps address of the object in literal pool, and will be literary
It is revised as the address of existing object in the address that object is jumped described in word pond.
9. the method according to claim 1, wherein being utilized when being relocated to the function in effective section
The function address that address and the needs that find from Function Mapping table when current function is run jump to, by calculating
To jump instruction, calculated jump instruction is updated jump instruction before, in order to according to the update
Jump instruction jump to function address i.e. to be executed.
10. a kind of device of loading ELF document, which is characterized in that described device includes:
Resolver, for being parsed the static library file in the ELF file to obtain obj ect file;
Extraction element, for extracting effective section from the obj ect file;
Loading device is pair in the obj ect file for different types of effective section to be loaded into different regions respectively
As and function establish object mapping table and Function Mapping table respectively, and for in effective section of load object and function into
Row reorientation;Wherein,
The loading device is specific to execute according to executable when different types of effective section is loaded into different regions respectively
The segment information of code segment and corresponding reorientation section, relocates executable code segment, by the executable code after reorientation
Section write-in Flash;Or the segment information according to application data section and corresponding reorientation section, application data section is loaded directly into
RAM。
11. the device of loading ELF document according to claim 10, which is characterized in that extracted in the extraction element
Effective section includes: executable code segment, application data section or reorientation section.
12. the device of loading ELF document described in 0 or 11 according to claim 1, which is characterized in that the extraction element is used for
Effective section is extracted according to the ELF file header of the obj ect file and segment file head table.
13. the device of loading ELF document according to claim 10, which is characterized in that the segment information include section serial number,
Field offset amount or Duan great little.
14. the device of loading ELF document according to claim 13, which is characterized in that the executable code segment includes
.text section, the application data section include .data sections .bss sections or .rodata sections, and the reorientation section includes .rel.data
Section .rel.bss sections or .rel.rodata sections.
15. the device of loading ELF document described in 0 or 11 according to claim 1, which is characterized in that the loading device is being held
After the effective section of the row load, it is further used for carrying out effective section of the obj ect file at least one following label:
Initial address, the field offset amount, Duan great little of section.
16. the device of loading ELF document according to claim 10, it is characterised in that:
The mapping item of the object mapping table includes object oriented and object address, and the object address is by searching for effective
Derived object in section, according to obtained from derived object address;
The mapping item of the Function Mapping table includes function name and function address, and the function address is by searching for effective
Export function in section, according to obtained from the address where export function.
17. the device of loading ELF document according to claim 10, which is characterized in that the loading device is to effective
It is specific to execute when object in section is relocated:
Ground of the object in literal pool is jumped using existing object object described in the address search in the object mapping table
Location, and the address that object is jumped described in literal pool is revised as to the address of existing object.
18. the device of loading ELF document according to claim 10, which is characterized in that the loading device is to effective
Function in section is specific to execute when being relocated: address when being run using current function and looking into from Function Mapping table
The function address that the needs found jump to, by jump instruction is calculated, calculated jump instruction is to before
Jump instruction be updated, in order to jump to function address i.e. to be executed according to the jump instruction of the update.
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 CN105224370A (en) | 2016-01-06 |
CN105224370B true 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) |
Families Citing this family (18)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105224370B (en) * | 2015-10-21 | 2019-03-08 | 安一恒通(北京)科技有限公司 | A kind of method and apparatus of loading ELF document |
CN107315599B (en) * | 2016-04-27 | 2020-09-01 | 龙芯中科技术有限公司 | Method and device for extracting graphic library |
CN107247579B (en) * | 2016-08-19 | 2020-09-11 | 北京金山安全管理系统技术有限公司 | Method and device for calculating ELF file mapping base address |
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 |
CN109324838B (en) * | 2018-08-31 | 2022-05-10 | 深圳市元征科技股份有限公司 | Execution method and execution device of single chip microcomputer program and terminal |
CN111488557B (en) * | 2019-01-28 | 2024-01-12 | 中国移动通信有限公司研究院 | Encryption and decryption method and device, electronic equipment and readable storage medium |
CN110673850A (en) * | 2019-08-28 | 2020-01-10 | 五八有限公司 | Method and device for obtaining size of static library |
CN113590138A (en) * | 2020-04-30 | 2021-11-02 | 华为技术有限公司 | Executable file processing method and device |
CN111856989A (en) * | 2020-06-19 | 2020-10-30 | 中电科航空电子有限公司 | Dynamic linking method for single chip microcomputer |
CN113010186B (en) * | 2021-02-05 | 2023-03-21 | 武汉联特科技股份有限公司 | Firmware and application data integration method and system applied to optical module |
CN113672238B (en) * | 2021-09-07 | 2024-03-12 | 广东九联开鸿科技发展有限公司 | Operation method, device and equipment based on real-time operating system modularized management |
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 |
CN115658275B (en) * | 2022-11-21 | 2023-03-28 | 统信软件技术有限公司 | Executable program migration method and device and computing equipment |
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)
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)
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 |
-
2015
- 2015-10-21 CN CN201510688388.3A patent/CN105224370B/en active Active
-
2016
- 2016-06-01 WO PCT/CN2016/084304 patent/WO2017067175A1/en active Application Filing
Patent Citations (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101697131A (en) * | 2009-11-04 | 2010-04-21 | 中兴通讯股份有限公司 | Method and device for dynamically loading relocatable file |
Also Published As
Publication number | Publication date |
---|---|
WO2017067175A1 (en) | 2017-04-27 |
CN105224370A (en) | 2016-01-06 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN105224370B (en) | A kind of method and apparatus of loading ELF document | |
US8977626B2 (en) | Indexing and searching a data collection | |
CN106843842B (en) | Method and device for updating application program configuration file | |
CN106796525B (en) | On-demand loading dynamic script language codes are to reduce memory use | |
CN103019787A (en) | Function call relation determining method, hotfix updating method and hotfix updating device | |
US8983908B2 (en) | File link migration for decommisioning a storage server | |
KR20170007521A (en) | Optimized browser rendering process | |
WO2017014318A1 (en) | Instruction set simulator and simulator generation method therefor | |
CN104978394A (en) | Webpage tag data organization and update method for multi-language display | |
CN106354536A (en) | Method and device of loading ELF file of Linux system in Windows system | |
CN105094941B (en) | It is a kind of to realize multilingual method and device | |
CN106202158A (en) | The using method of a kind of graphics file format and device | |
KR20210057176A (en) | Function jump implementation method, device, and computer storage medium | |
US9477496B2 (en) | Method and apparatus for loading classes and re-organizing class archives | |
WO2015057457A1 (en) | Systems and methods to segment text for layout and rendering | |
US9027008B2 (en) | Method, computer, and computer program for speculatively optimizing code | |
Juričić | Detecting source code similarity using low-level languages | |
US8914350B2 (en) | Flexible metadata composition | |
CN107544811A (en) | Ios platform hides method, storage medium, electronic equipment and the system of dylib files | |
CN105160001A (en) | Physical memory mirror image document analysis method of Linux system | |
US20120284279A1 (en) | Code string search apparatus, search method, and program | |
US11194885B1 (en) | Incremental document object model updating | |
CN114610364A (en) | Application program updating method, application program developing method, application program updating device, application program developing device and computer equipment | |
CN108153530A (en) | Optimization method, device, storage medium, processor and the terminal of bytecode | |
US10365937B2 (en) | Entropy increase by executable loader |
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. |