⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loadlib.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* loadLib.c - object module loader *//* Copyright 1984-2002 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------06t,08may02,fmk  SPR 77007 - improve common symbol support - port                 loadCommonManage() and loadCommonMatch() from the host loader06s,07mar02,jn   refix SPR # 30588 - return NULL when there are unresolved                 symbols06r,07feb02,jn   documentation - loadModule returns a module id, not NULL,                 when there are unresolved symbols06q,15oct01,pad  changed loadModuleAt() documentation about obsolete		 <filename>_[text | data | bss] symbols.06p,30nov98,dbt  clear seg.flags<xxx> in loadSegmentAllocate (SPR #23553).		 If we are using text protection, do not use file alignment		 if it is inferior to page size (SPR #23553).06o,17jul98,pcn  Fixed SPR #21836: alignment mismatch between sections and		 target.06n,22nov96,elp  Synchronize only valid modules.06m,06nov96,elp  replaced symAdd() calls by symSAdd() calls +		 added symtbls synchro function pointer <syncLoadRtn>.06l,04nov96,dgp  doc: fix for SPR #410806k,14oct95,jdi  doc: fixed unnecessary refs to UNIX.06j,11feb95,jdi  doc tweaks.06i,08dec94,rhp  docn: clarify RELOCATION section in loadModuleAT() (SPR#3769)06h,19sep94,rhp  docn: show new load flags for loadModuleAt() (SPR#2369).06g,16sep94,rhp  docn: deleted obsolete paragraph (SPR#2520)06f,13feb93,kdl  changed cplusLib.h to private/cplusLibP.h (SPR #1917).06e,27nov92,jdi  documentation cleanup.06d,25sep92,jmm  added check of malloc's return value to loadSegmentsAllocate()06c,10sep92,jmm  moved call to moduleLibInit() to usrConfig.c06b,01aug92,srh  added include cplusLib.h.;		 added call to cplusLoadFixup in loadModuleAtSym06a,30jul92,jmm  documentation cleanup05z,23jul92,jmm  loadSegmentsAllocate() created to alloc memory for all loaders05v,18jul92,smb  Changed errno.h to errnoLib.h.05u,16jul92,jmm  moved addSegNames here		 added support for module tracking05t,23jun92,ajm  fixed EXAMPLE that last change mucked05s,18jun92,ajm  separated to be object module independent05r,26may92,rrr  the tree shuffle05q,10dec91,gae  added includes for ANSI.05p,19nov91,rrr  shut up some ansi warnings.05o,05oct91,ajm  changed bad ifdef of CPU==MIPS to CPU_FAMILY in relSegmentR3k05n,04oct91,rrr  passed through the ansification filter		  -changed functions to ansi style		  -changed includes to have absolute path from h/		  -fixed #else and #endif		  -changed TINY and UTINY to INT8 and UINT8		  -changed READ, WRITE and UPDATE to O_RDONLY O_WRONLY and ...		  -changed VOID to void		  -changed copyright notice05m,30aug91,ajm  added MIPS support from 68k 05h, and mips 4.02 05q.05l,28aug91,shl  added cache coherency calls for MC68040 support.05k,05apr91,jdi	 documentation -- removed header parens and x-ref numbers;		 doc review by dnw.05j,31mar91,del  made file null for I960.05i,08feb91,jaa	 documentation cleanup.05h,05oct90,dnw  made loadModuleAtSym() be NOMANUAL.05g,30jul90,dnw  changed pathLastName() to pathLastNamePtr().		 added forward declaration of void routines.05f,11may90,yao  added missing modification history (05e) for the last checkin.05e,09may90,yao  typecasted malloc to (char *).05d,22aug89,jcf  updated to allow for separate symbol tables.		  symbol table type now a SYM_TYPE.05c,06jul89,ecs  updated to track 4.0.2.05b,06jun89,ecs  fixed bug in relSegmentSparc.05a,01may89,ecs  split relSegment into relSegmentSparc & relSegment68k.04g,06jul89,llk  changed call to pathLastName().04f,16jun89,llk  made loadModuleAt add absolute symbols to symbol table.		 created SEG_INFO structure to reduce parameter passing.04e,09jun89,llk  fixed bug so that symbols which reside in segments that have		   been located at a specific address now have the correct		   relocated address entered in the symbol table.04d,01may89,gae  added empty N_ABS case to relSegment to stop useless warnings.04c,02oct88,hin  used correct N_TYPE constant in 04b fix.04b,29sep88,gae  fixed relative relocation bug with Greenhill's a.out,		   sort of introduced in 03y.04a,07sep88,gae  applied dnw's documentation.03z,15aug88,jcf  lint.03y,30jun88,dnw  fixed bug of not relocating relative to data or bss correctly.	    llk03x,05jun88,dnw  changed from ldLib to loadLib.		 removed pathTail.03w,30may88,dnw  changed to v4 names.03v,28may88,dnw  removed ldLoadAt.03u,19nov87,dnw  made ldLoadModule tolerant of 0 length segments, strings, etc.03t,04nov87,rdc  made ldLoadModule not create segment names if NO_SYMBOLS.03s,16oct87,gae  removed ldLoadName, or ldLoadFile, and made ldLoadModule		   determine and add module name to symbol table.		 added pathTail().03r,29jul87,ecs  added ldLoadFile, ldLoadModule.	    rdc  fixed rdSymtab to zero out space malloc'd for common symbols.	    dnw  fixed to require exact match with system symbol table		  instead of allowing matches with or without leading '_'.		 fixed to not link COMM symbols to existing symbols.03q,02jul87,ecs  changed rdSymtab to call symFindType, instead of symFind.03p,02apr87,ecs  added include of strLib.h03o,23mar87,jlf  documentation.03n,20dec86,dnw  changed to not get include files from default directories.03m,24nov86,llk  deleted SYSTEM conditional compiles.03l,09oct86,dnw  fixed handling of "pc relative" relocation commands.		 cleaned up rdSymtab.		 changed to allocate externals table based on size of symbol		   table in object module.03k,04sep86,jlf  minor documentation.03j,27jul86,llk  prints error messages to standard error03i,24jun86,rdc  now throws away stabs and absolute symbols.  Now		 dynamically allocates and frees necessary buffers.		 now searches symbol table before allocating new symbol		 for type N_COMM.03h,04jun86,dnw  changed sstLib calls to symLib.03g,03mar86,jlf  changed ioctrl calls to ioctl.03f,22oct85,dnw  Fixed bug reading 4 bytes too many for BSD4.2 string table.03e,11oct85,jlf  Made the string table buffer and the externals buffer		   be allocated rather than on the stack.		 Made new routine ldInit.		 Got rid of MAX_STRINGS and MAX_SYMBOLS, and replaced them with		   local variables which are initialize by ldInit.		 De-linted.03d,10oct85,jlf  upped MAX_STRINGS form 20000 to 25000.  Made all		 references use the #define, instead of raw numbers.03c,27aug85,rdc  changed MAX_SYM_LEN to MAX_SYS_SYM_LEN.03b,12aug85,jlf  fixed to not try to relocate segments that have already		 been relocated pc-relative in 4.2 version.  Also, made it		 check relocation segment length, and print an error msg if		 it's not a long.03a,07aug85,jlf  combined 4.2 and v7/sys5 version.02b,20jul85,jlf  documentation.02a,24jun85,rdc  modified for 4.2 a.out format.01e,19sep84,jlf  cleaned up comments a little01d,09sep84,jlf  added comments, copyright, got rid of GLOBAL.01c,10aug84,dnw  changed load to not add special module symbols {T,D,B,E}name		   but also changed to add _etext, _edata, and _end as normal		   symbols.		 fixed rdSymtab to not set S_ldLib_UNDEFINED_SYMBOL and		   instead just leave it S_symLib_SYMBOL_NOT_FOUND.		 changed load to continue with relocation even if		   undefined symbols were found.		 changed call to 'fioOpen' to just 'open'.		 replaced 'load' and 'loadat' with 'ldLoad' and 'ldLoadAt',		   which now take an fd instead of filename.01b,02jul84,ecs  changed format strings to be more unixlike.01a,27apr84,dnw  written: some culled from old fioLib*//*DESCRIPTIONThis library provides a generic object module loading facility.  Anysupported format files may be loaded into memory, relocated properly, theirexternal references resolved, and their external definitions added tothe system symbol table for use by other modules and from the shell.Modules may be loaded from any I/O stream which allows repositioning of thepointer.  This includes netDrv, nfs, or local file devices.  It does not include sockets.EXAMPLE.CS    fdX = open ("/devX/objFile", O_RDONLY);    loadModule (fdX, LOAD_ALL_SYMBOLS);    close (fdX);.CEThis code fragment would load the object file "objFile" located ondevice "/devX/" into memory which would be allocated from the systemmemory pool.  All external and static definitions from the file would beadded to the system symbol table.This could also have been accomplished from the shell, by typing:.CS    -> ld (1) </devX/objFile.CEINCLUDE FILE: loadLib.hSEE ALSO: usrLib, symLib, memLib,.pG "Basic OS"*//* defines */#undef INCLUDE_SDA		/* SDA is not supported for the moment *//*  * SYM_BASIC_NOT_COMM_MASK and SYM_BASIC_MASK are temporary masks until * symbol values are harmonized between host and target sides */#define SYM_BASIC_NOT_COMM_MASK   0x0d   /* basic mask but unset bit                                           * two for common symbol */#define SYM_BASIC_MASK            0x0f   /* only basic types are of interest *//* includes */#include "vxWorks.h"#include "sysSymTbl.h"#include "ioLib.h"#include "loadLib.h"#include "fioLib.h"#include "errnoLib.h"#include "stdio.h"#include "moduleLib.h"#include "a_out.h"#include "pathLib.h"#include "private/vmLibP.h"#include "stdlib.h"#include "private/cplusLibP.h"#include "string.h"#include "memLib.h"#include "private/loadLibP.h"/* locals */LOCAL char cantAddSymErrMsg [] =    "loadAoutLib error: can't add '%s' to system symbol table - error = 0x%x.\n";/* define generic load routine */FUNCPTR loadRoutine = (FUNCPTR) NULL;FUNCPTR syncLoadRtn = (FUNCPTR) NULL;/********************************************************************************* loadModule - load an object module into memory** This routine loads an object module from the specified file, and places* the code, data, and BSS into memory allocated from the system memory* pool.** This call is equivalent to loadModuleAt() with NULL for the addresses of* text, data, and BSS segments.  For more details, see the manual entry for* loadModuleAt().** RETURNS:* MODULE_ID, or NULL if the routine cannot read the file, there is not* enough memory, or the file format is illegal.** SEE ALSO: loadModuleAt()*/MODULE_ID loadModule    (    int fd,		/* fd of file to load */    int symFlag		/* symbols to add to table */			/* (LOAD_[NO | LOCAL | GLOBAL | ALL]_SYMBOLS) */    )    {    return (loadModuleAt (fd, symFlag, (char **)NULL, (char **)NULL,			  (char **)NULL));    }/********************************************************************************* loadModuleAt - load an object module into memory** This routine reads an object module from <fd>, and loads the code, data,* and BSS segments at the specified load addresses in memory set aside by* the user using malloc(), or in the system memory partition as described* below.  The module is properly relocated according to the relocation* commands in the file.  Unresolved externals will be linked to symbols* found in the system symbol table.  Symbols in the module being loaded can* optionally be added to the system symbol table.** LINKING UNRESOLVED EXTERNALS * As the module is loaded, any unresolved external references are* resolved by looking up the missing symbols in the the system symbol* table.  If found, those references are correctly linked to the new* module.  If unresolved external references cannot be found in the* system symbol table, then an error message ("undefined symbol: ...")* is printed for the symbol, but the loading/linking continues.  The* partially resolved module is not removed, to enable the user to* examine the module for debugging purposes.  Care should be taken* when executing code from the resulting module.  Executing code which * contains references to unresolved symbols may have unexpected results * and may corrupt the system's memory.* * Even though a module with unresolved symbols remains loaded after this* routine returns, NULL will be returned to enable the caller to detect* the failure programatically.  To unload the module, the caller may* either call the unload routine with the module name, or look up the* module using the module name and then unload the module using the * returned MODULE_ID.  See the library entries for moduleLib and unldLib* for details.  The name of the module is the name of the file loaded with* the path removed.** ADDING SYMBOLS TO THE SYMBOL TABLE* The symbols defined in the module to be loaded may be optionally added* to the system symbol table, depending on the value of <symFlag>:* .iP "LOAD_NO_SYMBOLS" 29* add no symbols to the system symbol table* .iP "LOAD_LOCAL_SYMBOLS"* add only local symbols to the system symbol table* .iP "LOAD_GLOBAL_SYMBOLS"* add only external symbols to the system symbol table* .iP "LOAD_ALL_SYMBOLS"* add both local and external symbols to the system symbol table* .iP "HIDDEN_MODULE"* do not display the module via moduleShow().* .LP** Obsolete symbols:** For backward compatibility with previous releases, the following symbols* are also added to the symbol table to indicate the start of each segment:* <filename>_text, <filename>_data, and <filename>_bss, where <filename> is* the name associated with the fd. Note that these symbols are not available * when the ELF format is used. Also they will disappear with the next VxWorks* release. The moduleLib API should be used instead to get segment information.** RELOCATION* The relocation commands in the object module are used to relocate* the text, data, and BSS segments of the module.  The location of each* segment can be specified explicitly, or left unspecified in which* case memory will be allocated for the segment from the system memory* partition.  This is determined by the parameters <ppText>, <ppData>, and* <ppBss>, each of which can have the following values:* .iP "NULL"* no load address is specified, none will be returned;* .iP "A pointer to LD_NO_ADDRESS"* no load address is specified, the return address is referenced by the pointer;* .iP "A pointer to an address"* the load address is specified.* .LP** The <ppText>, <ppData>, and <ppBss> parameters specify where to load* the text, data, and bss sections respectively.  Each of these* parameters is a pointer to a  pointer; for example, **<ppText>* gives the address where the text segment is to begin.** For any of the three parameters, there are two ways to request that* new memory be allocated, rather than specifying the section's* starting address: you can either specify the parameter itself as* NULL, or you can write the constant LD_NO_ADDRESS in place of an* address.  In the second case, loadModuleAt() routine replaces the* LD_NO_ADDRESS value with the address actually used for each section* (that is, it records the address at *<ppText>, *<ppData>, or* *<ppBss>).

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -