[go: up one dir, main page]

CN116909656A - Method for realizing embedded dynamic APP loading based on elf file - Google Patents

Method for realizing embedded dynamic APP loading based on elf file Download PDF

Info

Publication number
CN116909656A
CN116909656A CN202311183710.8A CN202311183710A CN116909656A CN 116909656 A CN116909656 A CN 116909656A CN 202311183710 A CN202311183710 A CN 202311183710A CN 116909656 A CN116909656 A CN 116909656A
Authority
CN
China
Prior art keywords
file
elf
dynamic
elf file
executable
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
CN202311183710.8A
Other languages
Chinese (zh)
Other versions
CN116909656B (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 Zhongtian Xingkong Science & Technology Development Co ltd
Original Assignee
Beijing Zhongtian Xingkong Science & Technology Development 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 Beijing Zhongtian Xingkong Science & Technology Development Co ltd filed Critical Beijing Zhongtian Xingkong Science & Technology Development Co ltd
Priority to CN202311183710.8A priority Critical patent/CN116909656B/en
Publication of CN116909656A publication Critical patent/CN116909656A/en
Application granted granted Critical
Publication of CN116909656B publication Critical patent/CN116909656B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; 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
    • G06F9/44521Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Devices For Executing Special Programs (AREA)
  • Stored Programmes (AREA)

Abstract

The invention discloses a method for realizing embedded dynamic APP loading based on an elf file, which comprises the steps of generating an executable elf file by using a linker, converting the elf file into a bin or a hex file by using a format conversion tool, and burning the converted elf image file into a FLASH or a ROM of a chip by using a downloading device; loading the elf file to a handle, inputting the relocatable file and the sharable object file to a link editor, generating the sharable object file or the executable object file and running in a system through a linker; the method comprises the steps of establishing an elf file program header table, wherein the elf file program header table comprises connection attempt and execution attempt, generating a relocated section file from a sharable object file or an executable object file through writing of a linker, and accessing the file through the located section file.

Description

Method for realizing embedded dynamic APP loading based on elf file
Technical Field
The invention belongs to the technical field of embedded systems, and particularly relates to a method for realizing embedded dynamic APP loading based on an orf file.
Background
Along with the rapid development of electronic technology, embedded equipment is more and more widely applied and has higher and higher complexity; the design proportion of hardware and software is greatly changed, and the proportion of software development is greater and greater; however, in the traditional embedded development process, the application and the operating system are required to be compiled and linked into a whole and then downloaded to the target machine for running; if a problem is found in the debugging process, the process of recompilation, linking and then repeating the downloading operation is needed; such development processes are long and cumbersome and have become increasingly inadequate for rapid marketing needs.
In order to accommodate diversified embedded applications and accelerate the rapid development of embedded systems, besides the support of reliable basic software platforms, such as RTOS with file systems and network protocol stacks and matched integrated development environments are needed; what is more important is a system platform that can be dynamically expanded.
In recent years, a new generation of embedded operating systems has begun to use dynamic extension techniques: the basic system comprises an operating system and other shared function call libraries and application program development are processed separately, and the module updating and dynamic loading technology is supported.
In general, an application or a system needs to use the services of a certain module in the running process, so that a specified module is loaded into the system through a series of preset actions, and a caller can continue to work smoothly. The key point of the realization is that the two technologies of interdependence and dynamic link are loaded and have close relation; at present, the dynamic loading technology of some embedded hardware systems is imperfect and immature; the current technology is relatively deficient in terms of realization flexibility, and a host end is required to do a great deal of work to use; belongs to a production mode with lower efficiency; moreover, the method does not have the capability of resetting the memory address, and the requirement of meeting the position independence of the realization of the APP to be dynamically loaded is met; meanwhile, the related implementation mode of the function to be loaded also has corresponding requirements, such as the requirement that the implementation of the APP to be dynamically loaded does not contain library function call, switch statement is not allowed and the like; can not be widely and randomly used, and has more limitations.
Thus, how to realize arbitrary loading and unloading of the application, and dynamically updating the system components; how multiple applications share a global module; the problem of how to use multiple modules simultaneously for one application, etc. needs to be solved.
Disclosure of Invention
The invention aims to overcome the defects of the prior art and provides a method for realizing embedded dynamic APP loading based on an elf file.
The aim of the invention is realized by the following technical scheme:
a method for realizing embedded dynamic APP loading based on an orf file comprises the following steps:
the method includes the steps of burning an elf file, generating an executable elf file by using a linker, and converting the elf file into a bin or a hex file by using a format conversion tool, wherein the elf file is in an executable link format and has three types: the relocatable object file, the compiler or the assembler compiles the generated o file; executable object files, such as exe files; the object files that can be shared are the dynamic link library files.
And burning the converted elf image file into FLASH or ROM of the chip through a downloading device.
Dynamically loading an elf file to a handle, inputting a relocatable file and a sharable object file to a link editor, and processing the relocatable file and the sharable object file by the link editor to generate the sharable object file or the executable object file, wherein the sharable object file or the executable object file runs in a system through a linker;
dynamic loading based on the elf file is realized, and the reasons for selecting the elf file are as follows: special sections exist in the elf file and can be specially used for realizing repositioning operation; the section records all code positions related to the memory address in a form of a table, and the method of writing the memory address into the machine code; the method includes the steps that an elf file program header table is established, and the elf file program header table is mainly used for informing a system how to create a process image; the elf file program header table comprises a connection attempt and an execution attempt, and the object files that can be shared or the executable object files are written by a linker to generate relocatable section files.
Furthermore, the orf file is a dynamic library executable file, and it should be noted that the reason for selecting the dynamic library to execute is as follows: if the static library is used for generating executable programs, a copy of library code exists in each generated executable program; the stored program occupies additional disk space; when the operation scene is a Linux system and the like, the waste of physical memory is caused; therefore, a dynamic library is selected.
Further, the program header table includes file section information that enables data interaction with the linker, including, but not limited to, file size and file offset.
Further, the program header table further includes segment information, and the segment information is used for data loading.
Further, the specific implementation manner of loading the elf file into the handle is as follows:
judging the type of the elf file, calculating the preferred address and the size of the program, and pre-distributing the memory;
initializing RW domain data in a computer program;
acquiring main function addresses in a computer program, and repositioning codes according to the repositioned section files;
and constructing a dynamic symbol table and clearing the Cache.
Further, the specific implementation mode for constructing the dynamic symbol table is as follows:
the address of a function in the elf file is obtained, the source code of the compiled axf file is searched, all functions decorated by the suffix of __ attribute __ (visibility) are collected, and the functions decorated by the suffix are exported to form a dynamic symbol table.
Further, the axf file is an executable elf file type.
The beneficial effects of the invention are as follows:
1) The invention realizes a method for realizing embedded dynamic loading APP, which has wide application range, simpler operation and more flexibility; from a hardware perspective, can be used for embedded platforms without MMU; from a software perspective: the method can be used for developing complex software platforms such as a bare computer platform, a real-time operating system platform or Linux; the dynamic loading implementation has a wider use scenario and is not limited to the currently existing MMU-based approaches.
2) The invention realizes dynamic loading based on the elf file, and can reduce excessive intervention and operation of a host terminal.
3) The invention can be applied to wider embedded software and hardware platforms, and the embedded hardware platforms are not required to be provided with MMUs; and complex technologies such as overlap and the like are not realized by software.
4) The method is simple and flexible to realize, the bottom layer principle relies on the compiling and linking principles of ARM, and is stable and reliable, meanwhile, the realization mode of the app to be dynamically loaded is not limited, and the app to be dynamically loaded is not required to meet the position independence when being realized.
Drawings
FIG. 1 is a flowchart of an elf file loading process according to the present invention;
FIG. 2 is a diagram of an exemplary embodiment of an elf file program header;
FIG. 3 is a diagram illustrating an embedded software compilation process in accordance with an embodiment of the present invention;
FIG. 4 is a flow chart illustrating the generation of a relocatable file using an IDE tool in accordance with an embodiment of the present invention;
FIG. 5 is a schematic diagram of a workflow of dynamic loading of modules according to an embodiment of the present invention;
FIG. 6 is a function call schematic after a module is loaded into the system according to an embodiment of the present invention;
FIG. 7 is a diagram illustrating a two-level repositioning representation in accordance with an embodiment of the present invention.
Detailed Description
The technical solutions of the present invention will be clearly and completely described below with reference to the embodiments, and it is apparent that the described embodiments are only some embodiments of the present invention, but not all embodiments. All other embodiments, which can be made by a person skilled in the art without any inventive effort, are intended to be within the scope of the present invention, based on the embodiments of the present invention.
Referring to fig. 1-7, the present invention provides a technical solution:
a method for realizing embedded dynamic APP loading based on an orf file comprises the following steps:
the method includes the steps of burning an elf file, generating an executable elf file by using a linker, and converting the elf file into a bin or a hex file by using a format conversion tool, wherein the elf file is in an executable link format and has three types: the relocatable object file, the compiler or the assembler compiles the generated o file; executable object files, such as exe files; the object files that can be shared are the dynamic link library files.
And burning the converted elf image file into FLASH or ROM of the chip through a downloading device.
The dynamic loading is realized, and it is to be noted that the dynamic loading is realized in the system, firstly, a module positioning mechanism is needed, so that a caller can conveniently and dynamically position a required module in the system; the secondary energy of the method enables the modules to be dynamically associated with the target program and work in coordination; the method has the advantages that the work of address space positioning of the target machine side module, the realization mechanism of a repositioning table and the like are simplified by specifying the declaration mode of the module; based on these operations, the system can realize dynamic loading relatively smoothly.
Each module must provide a module call library corresponding thereto while providing a module relocation table. Other objects must and only use the services provided by this module by calling the library. Each call library has a pointer variable that stores a local module relocation table. The variable is initialized to the corresponding module relocation table address when the module is first used by the target program. When the module is first used by the target program, i.e., the dynamic loading process begins, it is first run by calling the library initialization code (Library initialcode) of the library, which initializes the module relocation table base address pointer in the library by a specified system call. The function call is then completed by the base address and the specific function offset each time the object program uses the function interface provided by the module.
When a target program uses modules and is loaded correctly and dynamically, the relation is shown in fig. 6; the target program is linked with a call library and comprises a function jump table and a pointer pointing to the base address of the relocation table of the module; the module is linked with an additional library which comprises a function interface address table, namely a module relocation table; when the module function is called, after the process of dynamically loading the module, the base address pointer of the module relocation table of the target program points to the function interface table of the corresponding module, and then the function call can be smoothly performed.
Loading an elf file to a handle, inputting a relocatable file and a sharable object file to a link editor, and processing the relocatable file and the sharable object file by the link editor to generate the sharable object file or an executable object file, wherein the sharable object file or the executable object file runs in a system through a linker;
dynamic loading based on the elf file is realized, and the reasons for selecting the elf file are as follows: special sections exist in the elf file and can be specially used for realizing repositioning operation; the section records all code positions related to the memory address in a form of a table, and the method of writing the memory address into the machine code; the method includes the steps that an elf file program header table is established, and the elf file program header table is mainly used for informing a system how to create a process image; the elf file program header table comprises a connection attempt and an execution attempt, and the object files that can be shared or the executable object files are written by a linker to generate relocatable section files.
Furthermore, the orf file is a dynamic library executable file, and it should be noted that the reason for selecting the dynamic library to execute is as follows: if the static library is used for generating executable programs, a copy of library code exists in each generated executable program; the stored program occupies additional disk space; when the operation scene is a Linux system and the like, the waste of physical memory is caused; therefore, a dynamic library is selected.
Further, the program header table includes file section information that enables data interaction with the linker, including, but not limited to, file size and file offset.
Further, the program header table further includes segment information, and the segment information is used for data loading.
Further, the specific implementation manner of loading the elf file into the handle is as follows:
judging the type of the elf file, calculating the preferred address and the size of the program, and pre-distributing the memory;
initializing RW domain data in a computer program;
acquiring main function addresses in a computer program, and repositioning codes according to the repositioned section files;
and constructing a dynamic symbol table and clearing the Cache.
Further, the specific implementation mode for constructing the dynamic symbol table is as follows:
the address of a function in the elf file is obtained, the source code of the compiled axf file is searched, all functions decorated by the suffix of __ attribute __ (visibility) are collected, and the functions decorated by the suffix are exported to form a dynamic symbol table.
Further, the axf file is an executable elf file type.
For better explanation, in this embodiment, the embedded software of the ARM integrates the development environment, i.e. the MDK of the IDE, and selects a commonly used embedded MCU, such as STM32F407ZGT6 of compatible legal semiconductor company, to implement the embedded dynamic APP loading process based on the elf file, and the specific implementation flow is shown in fig. 4:
starting a basic platform link model of a linker by a base_platform command line to enable the axf generated by the MDK to have dynamic information, namely relocation sections;
setting the entry address of the whole program as dl_main function with entry=dl_main command line, and in the basic platform link model of arm, the MDK outputs a file with axf last, and the embodiment uses the fromlf tool to check file information, so that the generated axf file is still an executable file type, since the file is an executable file, and a new entry is redefined;
reducing the volume of the axf file by a no_comment_section and a no_debug command, and removing the comment section and the debug information;
export_dynamic commands are used to derive dynamic symbols; the axf file generates a dynamic symbol section which is composed of a pair of character strings and offset addresses, and when an external program wants to call a certain function in the output axf file, the address of the corresponding function is found according to a dynamic symbol table, so that the flexibility of the program is improved; in the prior art, this feature is defaulted to an off state;
the MDK creates a scattered loading file of the engineering, wherein the scattered loading file has absolute address information, and the size of each section is fixed; the size of each segment of the newly-built scattered loading file is not fixed, the starting address is set to 0, the memory is allocated without limitation, and whether the memory is enough or not is judged by the dynamic loader.
Thus, the project of outputting the axf file with the repositioning section is established; after the engineering compiling is completed, the linker starts to work; linking the part of the code containing the address to the physical address that is actually present; the file output by the compiler is provided with repositioning information, so that interference is not needed;
combining the specific effects of the elf file and the selected elf file, the loader of the elf file is realized, namely, the function contained in the elf file is called by the loader; there are many scenarios that require the elf file to call some functions in the loader; can be accessed through a fixed function table; the common function used by the elf file and the loader is put into a fixed memory address; the elf file is accessed directly by accessing the function table to obtain the function pointer.
The implementation manner provided by the embodiment shows that the method for embedded dynamic loading of the APP is wide in application range, simpler to operate and more flexible.
From a hardware perspective, can be used for embedded platforms without MMU; from a software perspective: the method can be used for developing complex software platforms such as a bare metal platform, a real-time operating system (RTOS) platform or Linux. The key is that the implementation mode of dynamic loading has wider use scene, is not limited to the existing MMU-based mode, and is different from the dynamic loading for the platform without MMU based mode implemented by the mode of overlap and the like.
It should be noted that, the invention does not limit the embedded development tool for compiling and generating the elf file, and does not limit the specific type of the elf file, and all implementation methods based on the specific type belong to the protection scope of the invention patent.
The foregoing is merely a preferred embodiment of the invention, and it is to be understood that the invention is not limited to the form disclosed herein but is not to be construed as excluding other embodiments, but is capable of numerous other combinations, modifications and environments and is capable of modifications within the scope of the inventive concept, either as taught or as a matter of routine skill or knowledge in the relevant art. And that modifications and variations which do not depart from the spirit and scope of the invention are intended to be within the scope of the appended claims.

Claims (7)

1. A method for realizing embedded dynamic APP loading based on an orf file is characterized by comprising the following steps: the method comprises the following steps:
burning an elf file, generating an executable elf file using a linker, converting the elf file into a. Bin or. Hex file by a format conversion tool, and
burning the converted elf image file into FLASH or ROM of the chip through a downloading device;
dynamic loading, loading of the elf file to the handle, inputting of the relocatable file and the shareable object file to the link editor, and
the link editor processes the relocatable file and the sharable object file to generate the sharable object file or the executable object file, and the sharable object file or the executable object file runs in the system through the linker;
dynamic loading based on an elf file is realized, an elf file program header table is established, the elf file program header table comprises a connection attempt and an execution attempt, and
generating a relocated section file from the sharable object file or the executable object file by writing a linker;
the loader is used for calling the functions contained in the elf file, and the file is accessed through the located section file.
2. The method for realizing embedded dynamic APP loading based on the elf file according to claim 1, wherein the method is characterized in that: the elf file is a dynamic library executable file.
3. The method for realizing embedded dynamic APP loading based on the elf file according to claim 1, wherein the method is characterized in that: the program header table includes file section information that enables data interaction with the linker, including but not limited to file size and file offset.
4. A method for implementing embedded dynamic APP loading based on an orf file as defined in claim 3, wherein: the program header table also includes segment information for data loading.
5. The method for realizing embedded dynamic APP loading based on the elf file according to claim 1, wherein the method is characterized in that: the specific implementation of loading the elf file into the handle is as follows:
judging the type of the elf file, calculating the preferred address and the size of the program, and pre-distributing the memory;
initializing RW domain data in a computer program;
acquiring main function addresses in a computer program, and repositioning codes according to the repositioned section files;
and constructing a dynamic symbol table and clearing the Cache.
6. The method for realizing embedded dynamic APP loading based on the orf file according to claim 5, wherein the method is characterized in that: the specific implementation mode for constructing the dynamic symbol table is as follows:
the address of a function in the elf file is obtained, the source code of the compiled axf file is searched, all functions decorated by the suffix of __ attribute __ (visibility) are collected, and the functions decorated by the suffix are exported to form a dynamic symbol table.
7. The method for realizing embedded dynamic APP loading based on the elf file according to claim 6, wherein the method is characterized in that: the axf file is an executable type of the elf file.
CN202311183710.8A 2023-09-14 2023-09-14 Method for realizing embedded dynamic APP loading based on elf file Active CN116909656B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311183710.8A CN116909656B (en) 2023-09-14 2023-09-14 Method for realizing embedded dynamic APP loading based on elf file

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311183710.8A CN116909656B (en) 2023-09-14 2023-09-14 Method for realizing embedded dynamic APP loading based on elf file

Publications (2)

Publication Number Publication Date
CN116909656A true CN116909656A (en) 2023-10-20
CN116909656B CN116909656B (en) 2023-12-08

Family

ID=88360715

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311183710.8A Active CN116909656B (en) 2023-09-14 2023-09-14 Method for realizing embedded dynamic APP loading based on elf file

Country Status (1)

Country Link
CN (1) CN116909656B (en)

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103246524A (en) * 2012-02-01 2013-08-14 上海野火网络科技有限公司 Dynamic loading method for simultaneous operation of a plurality of program segments on basis of advanced reduced instruction set computer (RISC) machine (ARM) chip
WO2017067175A1 (en) * 2015-10-21 2017-04-27 百度在线网络技术(北京)有限公司 Method, apparatus and device for loading elf file, and computer storage medium
CN109828758A (en) * 2018-12-05 2019-05-31 苏州蜗牛数字科技股份有限公司 A kind of analytic method of SO file
CN111124550A (en) * 2020-03-26 2020-05-08 北京翼辉信息技术有限公司 Program dynamic loading method and device and storage medium
CN112328319A (en) * 2020-09-30 2021-02-05 北京空间飞行器总体设计部 Satellite-borne APP dynamic loading method supporting RAM file system
CN115700470A (en) * 2021-07-22 2023-02-07 阿里云计算有限公司 File loading processing method and device, computer storage medium and electronic equipment
WO2023034586A1 (en) * 2021-09-03 2023-03-09 Dover Microsystems, Inc. Systems and methods for on-demand loading of metadata
CN115878213A (en) * 2022-11-28 2023-03-31 苏州赫里奥网络技术有限公司 Dynamic loading method for Internet of things equipment driver

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103246524A (en) * 2012-02-01 2013-08-14 上海野火网络科技有限公司 Dynamic loading method for simultaneous operation of a plurality of program segments on basis of advanced reduced instruction set computer (RISC) machine (ARM) chip
WO2017067175A1 (en) * 2015-10-21 2017-04-27 百度在线网络技术(北京)有限公司 Method, apparatus and device for loading elf file, and computer storage medium
CN109828758A (en) * 2018-12-05 2019-05-31 苏州蜗牛数字科技股份有限公司 A kind of analytic method of SO file
CN111124550A (en) * 2020-03-26 2020-05-08 北京翼辉信息技术有限公司 Program dynamic loading method and device and storage medium
CN112328319A (en) * 2020-09-30 2021-02-05 北京空间飞行器总体设计部 Satellite-borne APP dynamic loading method supporting RAM file system
CN115700470A (en) * 2021-07-22 2023-02-07 阿里云计算有限公司 File loading processing method and device, computer storage medium and electronic equipment
WO2023034586A1 (en) * 2021-09-03 2023-03-09 Dover Microsystems, Inc. Systems and methods for on-demand loading of metadata
CN115878213A (en) * 2022-11-28 2023-03-31 苏州赫里奥网络技术有限公司 Dynamic loading method for Internet of things equipment driver

Also Published As

Publication number Publication date
CN116909656B (en) 2023-12-08

Similar Documents

Publication Publication Date Title
JP6122493B2 (en) Adaptively portable library
CN100485620C (en) Programme code translating and compiling method in integrated development environment
US11768757B2 (en) Kernel debugging system and method
CN106415495B (en) Programming system and language for application development
CN110659031B (en) Application compilation method, device, electronic device and storage medium
CN100403258C (en) Embedded device integrated development system and using method thereof
CN1105802A (en) Incremental build system
WO2019005228A1 (en) Automated source code adaption to inject features between platform versions
CN107273176B (en) Compiling method and device adaptive to hardware architecture
WO2000045260A1 (en) Compiler, compiling method, and storage medium stored with program therefor
KR19980080502A (en) System and method for optimizing template object files
CN111880801A (en) Application program dynamic method and device and electronic equipment
CN107832059A (en) Code static analysis method and device based on Makefile
CN111399840A (en) Module development method and device
CN109670299A (en) A kind of method and electronic equipment creating Python sandbox environment
US20140157247A1 (en) Enabling Symbol Resolution of Private Symbols in Legacy Programs and Optimizing Access to the Private Symbols
WO2016094258A1 (en) Inter-procedural type propagation for devirtualization
CN110659088B (en) Method and system for expanding program under embedded environment
CN102364433B (en) Method for realizing Wine construction tool transplanting on ARM (Advanced RISC Machines) processor
CN101030241A (en) Method and system based on Keil C51 software protecting development
CN113590127A (en) Compiled data processing method and device, electronic equipment and storage medium
US7689979B1 (en) Methods and apparatus to improve application launch time
US7503040B2 (en) Configuring a shared library to accommodate relocatable data in a pervasive device
CN116909656B (en) Method for realizing embedded dynamic APP loading based on elf file
CN114443052A (en) A dynamic specialization method and device for IL instruction runtime

Legal Events

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