Home > other >  Several methods of Vxworks dynamic loading
Several methods of Vxworks dynamic loading

Time:11-25



Using dynamic load object module many advantages, such as increase in does not destroy the original environment debugging positioning function,
Equivalent to call system "patch"; Don't need to compile the original code (don't even have the original code) and only need to pay attention to is
Debugging code, so that can reduce the compile time and reduce the load of the image of,
In the object module of dynamic load has many methods, such as on the interface of the host environment by click on the object module
The right mouse button and choose "Download file name"; Can also be achieved by wShell and GDB command line window, this article through
Under tshell use ld (), loadModule (), loadModuleAt () function to do this, of course in the code can also be
To invoke them freely,
Ld command is provided by the user after cut library usrLib a load command, use is the premise of ld in the config. H
Defined INCLUDE_LOADER, such, in usrRoot () function will automatically load module initialization function called
ModuleLibInit (); At the same time, depending on the type of CPU, automatically decide the object module format, if the CPU is MIPS,
PPC, ARM, I80X86, COLDFIRE SIMSPARCSOLARIS, SH, etc., loading the object module format is the elf
Type, is called loadElfInit (); If the CPU is I960 AM29XXX etc., the format of the loaded object module is
Coff type, is called loadCoffInit t () function,
Under the ARM and PPC, Tornado generated by the compiler. O or. Out are the ELF types, open the target file
Saw the ELF file header (45, 4 C, 46) tag, then can via FTP tool to load it to the file system (such as using the copy
Command loaded into RAM disk), and then call the ld () or loadModule () function is loaded into memory,
Ld function prototypes: MOUDLE_ID ld (int syms, BOOL noAbort, char * name); Parameter syms decided to mesh
The file how to deal with the symbol of 0: a global symbol is added to the system in the symbol table; 1: global and local symbol is added to the system
In the symbol table. 1: symbol is not added to the system symbol table, generally choose 1, easy to use the symbol under the shell, parameter
NoAbort indicate whether can be ignored during the loading of the mistakes, to TRUE is ignored, the Name is loaded file Name,
Contains the path to the file,
LoadModule function prototype is MODULE_ID loadModule (int fd, int symFlag); Fd for file description
Symbol, and the need to open the file for fd; Parameter symFlag meaning have LOAD_NO_SYMBOLS (2);
LOAD_LOCAL_SYMBOLS (4); LOAD_GLOBAL_SYMBOLS (8); LOAD_ALL_SYMBOLS
(0 xc),
If have will need to load file demo. O into RAM plate, loaded into memory in the way to have the following kinds:
(1) - & gt; Ld 1, 0, RamDisk: demo. "o"
(2) - & gt; Ld (1) & lt; The RamDisk: demo. O
(3) - & gt; FdT=open (RamDisk: demo. "o", O_RDONLY);
-> LoadModule (fdT, 0 xc);
-> Close (fdT);
Load () function returns the MODULE_ID, this is a sign of the load module, when using the uninstall unldByModuledId
You can use the module ID, check the information load module function is moduleShow (),
-> ModuleShow
The MODULE NAME the MODULE ID GROUP # TEXT START DATA START BSS START
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
The RamDisk: demo. O x3fff4e4 x3fff3e8 x3fff9e8 1 0 0 0 0 x3fff4e4
For some applications, the use of ld or loadModule will appear the following error:
Relocation value does not fit in 24 bits.
Ld error: error loading the file (errno=0 x3d0001).
This is because the function in memory location is beyond the jump of the maximum distance (generally jump instruction is 24 bit address, 32 m),
In order to circumvent this problem, you can use the long jump to complete function calls, which requires the compilation of the target file at compile choose
Items used in the "call" option, as the ARM - mlong - calls; PPC processor - mlongcall,
, of course, also can use loadModuleAt () to solve this problem, the target module is loaded into the specified address, make the required
To function within the jump address, its prototype is:
MODULE_ID loadModuleAt (int fd, int symFlag,
Char * * ppText, char * * ppData, char * * ppBss);
PpText ppData, ppBss is respectively is loaded after the text section, data section, BSS to address, if add
Load demo. The o to 1 m space (ensure that this space is not used) : fdT=open (RamDisk: demo. "o",
O_RDONLY); PText=0 x100000; PData=https://bbs.csdn.net/topics/pBss=0 XFFFFFFFF;/* (LD_NO_ADDRESS) */
LoadModuleAt (fdT, 8, & amp; PText, & amp; PData, & amp; PBss); Close (fdT);
After completion of loading, under the shell can perform the function in the target file the latest, if some function before, press the
Finally load function, can be seen, loaded object module after relocation, symbol resolution and the process of adding,
If the target module use of global variables or functions in this module are not defined in the program, and before the loading when
A similar Undefined symbol errors,
Sometimes downloaded from the host object module will not appear in the target function of symbols in the shell, the reverse is also true,
Target machine shell generated symbol is not visible on the host wShell, appear this kind of circumstance is the main reason of the target and host
Symbols without synchronization, need INCLUDE_SYM_TBL_SYNC during the compilation of image definition,
  • Related