diff options
author | tromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-03-28 19:02:25 +0000 |
---|---|---|
committer | tromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-03-28 19:02:25 +0000 |
commit | 6f4b20f8b5d4c214ee3634698e36a542efda3921 (patch) | |
tree | 44928bcc3b5d69ceb886786f3462685287f715f3 /libjava/libltdl/ltdl.c | |
parent | 0d2d352780b6300803d0ce3f7bce78a90fdeba42 (diff) | |
download | gcc-6f4b20f8b5d4c214ee3634698e36a542efda3921.tar.gz |
PR libgcj/26641:
* Merged libltdl 1.5.16 from vendor branch.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@112464 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/libltdl/ltdl.c')
-rw-r--r-- | libjava/libltdl/ltdl.c | 167 |
1 files changed, 93 insertions, 74 deletions
diff --git a/libjava/libltdl/ltdl.c b/libjava/libltdl/ltdl.c index 40ed84d417a..6b5d8890efa 100644 --- a/libjava/libltdl/ltdl.c +++ b/libjava/libltdl/ltdl.c @@ -1,5 +1,5 @@ /* ltdl.c -- system independent dlopen wrapper - Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2000, 2004, 2006 Free Software Foundation, Inc. Originally by Thomas Tanner <tanner@ffii.org> This file is part of GNU Libtool. @@ -20,8 +20,8 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA -02111-1307 USA +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA */ @@ -29,6 +29,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA # include <config.h> #endif +#if HAVE_BOEHM_GC +# include <gc.h> +#endif + #if HAVE_UNISTD_H # include <unistd.h> #endif @@ -37,8 +41,14 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA # include <stdio.h> #endif +/* Include the header defining malloc. On K&R C compilers, + that's <malloc.h>, on ANSI C and ISO C compilers, that's <stdlib.h>. */ #if HAVE_STDLIB_H # include <stdlib.h> +#else +# if HAVE_MALLOC_H +# include <malloc.h> +# endif #endif #if HAVE_STRING_H @@ -53,10 +63,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA # include <ctype.h> #endif -#if HAVE_MALLOC_H -# include <malloc.h> -#endif - #if HAVE_MEMORY_H # include <memory.h> #endif @@ -65,10 +71,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA # include <errno.h> #endif -#if HAVE_BOEHM_GC -#include <gc.h> -#endif - #ifndef __WINDOWS__ # ifdef __WIN32__ @@ -241,7 +243,7 @@ LT_GLOBAL_DATA void (*lt_dlfree) LT_PARAMS((lt_ptr ptr)) #else #define LT_DLMALLOC(tp, n) ((tp *) lt_dlmalloc ((n) * sizeof(tp))) -#define LT_DLREALLOC(tp, p, n) ((tp *) rpl_realloc ((p), (n) * sizeof(tp))) +#define LT_DLREALLOC(tp, p, n) ((tp *) lt_dlrealloc ((p), (n) * sizeof(tp))) #define LT_DLFREE(p) \ LT_STMT_START { if (p) (p) = (lt_dlfree (p), (lt_ptr) 0); } LT_STMT_END @@ -387,11 +389,13 @@ memcpy (dest, src, size) const lt_ptr src; size_t size; { - size_t i = 0; + const char * s = src; + char * d = dest; + size_t i = 0; for (i = 0; i < size; ++i) { - dest[i] = src[i]; + d[i] = s[i]; } return dest; @@ -411,17 +415,21 @@ memmove (dest, src, size) const lt_ptr src; size_t size; { - size_t i; + const char * s = src; + char * d = dest; + size_t i; - if (dest < src) + if (d < s) for (i = 0; i < size; ++i) { - dest[i] = src[i]; + d[i] = s[i]; } - else if (dest > src) - for (i = size -1; i >= 0; --i) + else if (d > s && size > 0) + for (i = size -1; ; --i) { - dest[i] = src[i]; + d[i] = s[i]; + if (i == 0) + break; } return dest; @@ -453,7 +461,9 @@ opendir (path) DIR *entry; assert(path != (char *) NULL); - (void) strncpy(file_specification,path,LT_FILENAME_MAX-1); + /* allow space for: path + '\\' '\\' '*' '.' '*' + '\0' */ + (void) strncpy (file_specification, path, LT_FILENAME_MAX-6); + file_specification[LT_FILENAME_MAX-6] = LT_EOS_CHAR; (void) strcat(file_specification,"\\"); entry = LT_DLMALLOC (DIR,sizeof(DIR)); if (entry != (DIR *) 0) @@ -494,6 +504,7 @@ static struct dirent *readdir(entry) entry->firsttime = FALSE; (void) strncpy(entry->file_info.d_name,entry->Win32FindData.cFileName, LT_FILENAME_MAX-1); + entry->file_info.d_name[LT_FILENAME_MAX - 1] = LT_EOS_CHAR; entry->file_info.d_namlen = strlen(entry->file_info.d_name); return(&entry->file_info); } @@ -686,7 +697,7 @@ argz_insert (pargz, pargz_len, before, entry) /* This probably indicates a programmer error, but to preserve semantics, scan back to the start of an entry if BEFORE points into the middle of it. */ - while ((before >= *pargz) && (before[-1] != LT_EOS_CHAR)) + while ((before > *pargz) && (before[-1] != LT_EOS_CHAR)) --before; { @@ -1020,7 +1031,7 @@ lt_erealloc (addr, size) lt_ptr addr; size_t size; { - lt_ptr mem = realloc (addr, size); + lt_ptr mem = lt_dlrealloc (addr, size); if (size && !mem) LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY)); return mem; @@ -1584,7 +1595,11 @@ static struct lt_user_dlloader sys_dld = { #if HAVE_MACH_O_DYLD_H -# include <mach-o/dyld.h> +#if !defined(__APPLE_CC__) && !defined(__MWERKS__) && !defined(__private_extern__) +/* Is this correct? Does it still function properly? */ +#define __private_extern__ extern +#endif +# include <mach-o/dyld.h> #endif #include <mach-o/getsect.h> @@ -1610,14 +1625,14 @@ static enum DYLD_BOOL (*ltdl_NSIsSymbolNameDefinedInImage)(const struct mach_hea static enum DYLD_BOOL (*ltdl_NSMakePrivateModulePublic)(NSModule module) = 0; #ifndef NSADDIMAGE_OPTION_NONE -#define NSADDIMAGE_OPTION_NONE 0x0 +#define NSADDIMAGE_OPTION_NONE 0x0 #endif #ifndef NSADDIMAGE_OPTION_RETURN_ON_ERROR #define NSADDIMAGE_OPTION_RETURN_ON_ERROR 0x1 -#endif +#endif #ifndef NSADDIMAGE_OPTION_WITH_SEARCHING #define NSADDIMAGE_OPTION_WITH_SEARCHING 0x2 -#endif +#endif #ifndef NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED #define NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED 0x4 #endif @@ -1626,7 +1641,7 @@ static enum DYLD_BOOL (*ltdl_NSMakePrivateModulePublic)(NSModule module) = 0; #endif #ifndef NSLOOKUPSYMBOLINIMAGE_OPTION_BIND #define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND 0x0 -#endif +#endif #ifndef NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW #define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW 0x1 #endif @@ -1647,11 +1662,11 @@ lt_int_dyld_error(othererror) int lerno; const char *errstr; const char *file; - NSLinkEditError(&ler,&lerno,&file,&errstr); + NSLinkEditError(&ler,&lerno,&file,&errstr); if (!errstr || !strlen(errstr)) errstr = othererror; return errstr; } - + static const struct mach_header * lt_int_dyld_get_mach_header_from_nsmodule(module) NSModule module; @@ -1675,7 +1690,7 @@ lt_int_dyld_get_mach_header_from_nsmodule(module) static const char* lt_int_dyld_lib_install_name(mh) const struct mach_header *mh; -{ +{ /* NSAddImage is also used to get the loaded image, but it only works if the lib is installed, for uninstalled libs we need to check the install_names against each other. Note that this is still broken if DYLD_IMAGE_SUFFIX is set and a @@ -1684,14 +1699,13 @@ static const char* lt_int_dyld_lib_install_name(mh) int j; struct load_command *lc; unsigned long offset = sizeof(struct mach_header); - const struct mach_header *mh1; const char* retStr=NULL; for (j = 0; j < mh->ncmds; j++) { lc = (struct load_command*)(((unsigned long)mh) + offset); if (LC_ID_DYLIB == lc->cmd) { - retStr=(char*)(((struct dylib_command*)lc)->dylib.name.offset + + retStr=(char*)(((struct dylib_command*)lc)->dylib.name.offset + (unsigned long)lc); } offset += lc->cmdsize; @@ -1705,7 +1719,7 @@ lt_int_dyld_match_loaded_lib_by_install_name(const char *name) int i=_dyld_image_count(); int j; const struct mach_header *mh=NULL; - const char *id=NULL; + const char *id=NULL; for (j = 0; j < i; j++) { id=lt_int_dyld_lib_install_name(_dyld_get_image_header(j)); @@ -1717,7 +1731,7 @@ lt_int_dyld_match_loaded_lib_by_install_name(const char *name) } return mh; } - + static NSSymbol lt_int_dyld_NSlookupSymbolInLinkedLibs(symbol,mh) const char *symbol; @@ -1736,26 +1750,26 @@ lt_int_dyld_NSlookupSymbolInLinkedLibs(symbol,mh) lc = (struct load_command*)(((unsigned long)mh) + offset); if ((LC_LOAD_DYLIB == lc->cmd) || (LC_LOAD_WEAK_DYLIB == lc->cmd)) { - mh1=lt_int_dyld_match_loaded_lib_by_install_name((char*)(((struct dylib_command*)lc)->dylib.name.offset + + mh1=lt_int_dyld_match_loaded_lib_by_install_name((char*)(((struct dylib_command*)lc)->dylib.name.offset + (unsigned long)lc)); if (!mh1) - { - /* Maybe NSAddImage can find it */ - mh1=ltdl_NSAddImage((char*)(((struct dylib_command*)lc)->dylib.name.offset + + { + /* Maybe NSAddImage can find it */ + mh1=ltdl_NSAddImage((char*)(((struct dylib_command*)lc)->dylib.name.offset + (unsigned long)lc), - NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED + + NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED + NSADDIMAGE_OPTION_WITH_SEARCHING + NSADDIMAGE_OPTION_RETURN_ON_ERROR ); - } + } if (mh1) { retSym = ltdl_NSLookupSymbolInImage(mh1, symbol, - NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW + NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR ); - if (retSym) break; - } + if (retSym) break; + } } offset += lc->cmdsize; } @@ -1768,7 +1782,7 @@ sys_dyld_init() { int retCode = 0; int err = 0; - if (!_dyld_present()) { + if (!_dyld_present()) { retCode=1; } else { @@ -1788,8 +1802,8 @@ sys_dyld_open (loader_data, filename) lt_module module = 0; NSObjectFileImage ofi = 0; NSObjectFileImageReturnCode ofirc; - - if (!filename) + + if (!filename) return (lt_module)-1; ofirc = NSCreateObjectFileImageFromFile(filename, &ofi); switch (ofirc) @@ -1806,9 +1820,9 @@ sys_dyld_open (loader_data, filename) case NSObjectFileImageInappropriateFile: if (ltdl_NSIsSymbolNameDefinedInImage && ltdl_NSLookupSymbolInImage) { - module = (lt_module)ltdl_NSAddImage(filename, NSADDIMAGE_OPTION_RETURN_ON_ERROR); + module = (lt_module)ltdl_NSAddImage(filename, NSADDIMAGE_OPTION_RETURN_ON_ERROR); break; - } + } default: LT_DLMUTEX_SETERROR (lt_int_dyld_error(LT_DLSTRERROR(CANNOT_OPEN))); return 0; @@ -1824,13 +1838,12 @@ sys_dyld_close (loader_data, module) { int retCode = 0; int flags = 0; - unsigned long size=0; if (module == (lt_module)-1) return 0; -#ifdef __BIG_ENDIAN__ +#ifdef __BIG_ENDIAN__ if (((struct mach_header *)module)->magic == MH_MAGIC) -#else +#else if (((struct mach_header *)module)->magic == MH_CIGAM) -#endif +#endif { LT_DLMUTEX_SETERROR("Can not close a dylib"); retCode = 1; @@ -1841,14 +1854,14 @@ sys_dyld_close (loader_data, module) /* Currently, if a module contains c++ static destructors and it is unloaded, we get a segfault in atexit(), due to compiler and dynamic loader differences of opinion, this works around that. -*/ - if ((const struct section *)NULL != +*/ + if ((const struct section *)NULL != getsectbynamefromheader(lt_int_dyld_get_mach_header_from_nsmodule(module), "__DATA","__mod_term_func")) { flags += NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED; - } -#endif + } +#endif #ifdef __ppc__ flags += NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES; #endif @@ -1856,9 +1869,9 @@ sys_dyld_close (loader_data, module) { retCode=1; LT_DLMUTEX_SETERROR (lt_int_dyld_error(LT_DLSTRERROR(CANNOT_CLOSE))); - } + } } - + return retCode; } @@ -1872,44 +1885,47 @@ sys_dyld_sym (loader_data, module, symbol) NSSymbol *nssym = 0; void *unused; const struct mach_header *mh=NULL; + char saveError[256] = "Symbol not found"; if (module == (lt_module)-1) { _dyld_lookup_and_bind(symbol,(unsigned long*)&address,&unused); return address; } -#ifdef __BIG_ENDIAN__ +#ifdef __BIG_ENDIAN__ if (((struct mach_header *)module)->magic == MH_MAGIC) -#else +#else if (((struct mach_header *)module)->magic == MH_CIGAM) -#endif +#endif { if (ltdl_NSIsSymbolNameDefinedInImage && ltdl_NSLookupSymbolInImage) { mh=module; - if (ltdl_NSIsSymbolNameDefinedInImage((struct mach_header*)module,symbol)) + if (ltdl_NSIsSymbolNameDefinedInImage((struct mach_header*)module,symbol)) { nssym = ltdl_NSLookupSymbolInImage((struct mach_header*)module, symbol, - NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW + NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR ); } - } - - } + } + + } else { nssym = NSLookupSymbolInModule(module, symbol); } - if (!nssym) + if (!nssym) { + strncpy(saveError, lt_int_dyld_error(LT_DLSTRERROR(SYMBOL_NOT_FOUND)), 255); + saveError[255] = 0; if (!mh) mh=lt_int_dyld_get_mach_header_from_nsmodule(module); nssym = lt_int_dyld_NSlookupSymbolInLinkedLibs(symbol,mh); - } - if (!nssym) + } + if (!nssym) { - LT_DLMUTEX_SETERROR (lt_int_dyld_error(LT_DLSTRERROR(SYMBOL_NOT_FOUND))); + LT_DLMUTEX_SETERROR (saveError); return NULL; - } + } return NSAddressOfSymbol(nssym); } @@ -2988,6 +3004,9 @@ trim (dest, str) LT_DLFREE (*dest); + if (!end) + return 1; + if (len > 3 && str[0] == '\'') { tmp = LT_EMALLOC (char, end - str); @@ -3092,7 +3111,7 @@ try_dlopen (phandle, filename) ++base_name; } else - LT_DLMEM_REASSIGN (base_name, canonical); + base_name = canonical; assert (base_name && *base_name); @@ -3923,7 +3942,7 @@ lt_dlerror () LT_DLMUTEX_GETERROR (error); LT_DLMUTEX_SETERROR (0); - return error ? error : LT_DLSTRERROR (UNKNOWN); + return error ? error : NULL; } static int |