diff options
author | das <das> | 2005-11-27 02:34:41 (GMT) |
---|---|---|
committer | das <das> | 2005-11-27 02:34:41 (GMT) |
commit | ba70aa95d3d6bd4d0fd9fdd2292fdf970a08c1ae (patch) | |
tree | 50da2d930b34642a460752f68a389c77baa00323 /unix/tclLoadDyld.c | |
parent | 6ac7a57e2334ef01629b511af9388158bb0d1034 (diff) | |
download | tcl-ba70aa95d3d6bd4d0fd9fdd2292fdf970a08c1ae.zip tcl-ba70aa95d3d6bd4d0fd9fdd2292fdf970a08c1ae.tar.gz tcl-ba70aa95d3d6bd4d0fd9fdd2292fdf970a08c1ae.tar.bz2 |
* unix/tcl.m4 (Darwin): add 64bit support, check for Tiger copyfile(),
add CFLAGS to SHLIB_LD to support passing -isysroot in env(CFLAGS) to
configure (flag can't be present twice, so can't be in both CFLAGS and
LDFLAGS during configure), don't use -prebind when deploying on 10.4,
define TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING (rdar://3171542).
(SC_ENABLE_LANGINFO, SC_TIME_HANDLER): add/fix caching, fix obsolete
autoconf macros. Sync with tk/unix/tcl.m4, sync whitespace with HEAD.
* unix/configure.in: fix obsolete autoconf macros, sync gratuitous
formatting/ordering differences with tk/unix/configure.in.
* unix/Makefile.in: add CFLAGS to tclsh/tcltest link to make executable
linking the same as during configure (needed to avoid loosing any linker
relevant flags in CFLAGS, in particular flags that can't be in LDFLAGS).
Avoid concurrent linking of tclsh and compiling of tclTestInit.o or
xtTestInit.o during parallel make.
(checkstubs, checkdoc, checkexports): dependency and Darwin fixes
* unix/tclLoadDyld.c (TclpDlopen): use NSADDIMAGE_OPTION_WITH_SEARCHING
on second NSAddImage only. [Bug 1204237]
(TclGuessPackageName): should not be MODULE_SCOPE.
(TclpLoadMemory): ppc64 and endian (i386) fixes, add support for loading
universal (fat) bundles from memory.
* unix/tclUnixPort.h:
* unix/tclUnixFCmd.c: add support for new Tiger copyfile() API to enable
copying of xattrs & ACLs by [file copy].
* generic/tcl.h: add Darwin specifc configure overrides for TCL_WIDE
defines to support fat compiles of ppc and ppc64 at the same time,
(replaces Darwin CVS fix by emoy, rdar://3693001).
add/correct location of version numbers in macosx files.
* generic/tclInt.h: clarify fat compile comment.
* unix/tclUnixPort.h: add Darwin specifc configure overrides to support
fat compiles, where configure runs only once for multiple architectures
(replaces Darwin CVS fix by emoy, rdar://3693001).
* macosx/tclMacOSXBundle.c:
* macosx/tclMacOSXNotify.c:
* unix/tclUnixNotfy.c:
* unix/tclUnixPort.h: fix #include order to support compile time
override of HAVE_COREFOUNDATION in tclUnixPort.h when building for ppc64
* macosx/Tcl.pbproj/default.pbxuser (new file):
* macosx/Tcl.pbproj/jingham.pbxuser:
* macosx/Tcl.pbproj/project.pbxproj: sync with HEAD.
* macosx/README: clarification/cleanup, sync with HEAD, document
universal (fat) builds via CFLAGS (i.e. all of ppc ppc64 i386 at once).
* macosx/Makefile: add support for reusing configure cache, build target
fixes, remove GENERIC_FLAGS override now handled by tcl.m4.
* generic/tclIOUtil.c:
* generic/tclRegexp.c:
* generic/tclVar.c: declare globals used only in own file as static
(sync with HEAD).
* generic/rege_dfa.c (getvacant):
* generic/regexec.c (cfind):
* generic/tclCompExpr.c (CompileSubExpr):
* unix/tclUnixChan.c (TclUnixWaitForFile): initialise variables to
silence gcc 4 warnings.
* generic/regguts.h: only #define NDEBUG if not already #defined.
* macosx/tclMacOSXNotify.c: sync whitespace & comments with HEAD
* unix/configure: regen.
Diffstat (limited to 'unix/tclLoadDyld.c')
-rw-r--r-- | unix/tclLoadDyld.c | 67 |
1 files changed, 56 insertions, 11 deletions
diff --git a/unix/tclLoadDyld.c b/unix/tclLoadDyld.c index 1796307..3e05bf3 100644 --- a/unix/tclLoadDyld.c +++ b/unix/tclLoadDyld.c @@ -12,12 +12,15 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclLoadDyld.c,v 1.14.2.4 2005/07/30 07:58:16 das Exp $ + * RCS: @(#) $Id: tclLoadDyld.c,v 1.14.2.5 2005/11/27 02:34:42 das Exp $ */ #include "tclInt.h" #include "tclPort.h" #include <mach-o/dyld.h> +#include <mach-o/fat.h> +#include <mach-o/swap.h> +#include <mach-o/arch.h> #undef panic #include <mach/mach.h> @@ -120,8 +123,7 @@ TclpDlopen(interp, pathPtr, loadHandle, unloadProcPtr) */ native = Tcl_FSGetNativePath(pathPtr); - dyldLibHeader = NSAddImage(native, NSADDIMAGE_OPTION_WITH_SEARCHING | - NSADDIMAGE_OPTION_RETURN_ON_ERROR); + dyldLibHeader = NSAddImage(native, NSADDIMAGE_OPTION_RETURN_ON_ERROR); if (!dyldLibHeader) { NSLinkEditErrors editError; @@ -148,7 +150,8 @@ TclpDlopen(interp, pathPtr, loadHandle, unloadProcPtr) if (!dyldLibHeader) { NSLinkEditError(&editError, &errorNumber, &name, &msg); } - } else if ((editError==NSLinkEditFileFormatError && errorNumber==EBADMACHO) + } else if ((editError == NSLinkEditFileFormatError + && errorNumber == EBADMACHO) || editError == NSLinkEditOtherError){ /* * The requested file was found but was not of type MH_DYLIB, @@ -232,7 +235,7 @@ TclpFindSymbol(interp, loadHandle, symbol) NSSymbol nsSymbol; CONST char *native; Tcl_DString newName, ds; - Tcl_PackageInitProc* proc = NULL; + Tcl_PackageInitProc *proc = NULL; Tcl_DyldLoadHandle *dyldLoadHandle = (Tcl_DyldLoadHandle *) loadHandle; /* @@ -464,15 +467,57 @@ TclpLoadMemory(interp, buffer, size, codeSize, loadHandle, unloadProcPtr) if (codeSize >= 0) { NSObjectFileImageReturnCode err = NSObjectFileImageSuccess; - + CONST struct fat_header *fh = buffer; + uint32_t ms = 0; #ifndef __LP64__ - struct mach_header *mh = buffer; - if (codeSize < sizeof(struct mach_header) || mh->magic != MH_MAGIC + CONST struct mach_header *mh = NULL; + #define mh_magic OSSwapHostToBigInt32(MH_MAGIC) + #define mh_size sizeof(struct mach_header) #else - struct mach_header_64 *mh = buffer; - if (codeSize < sizeof(struct mach_header_64) || mh->magic != MH_MAGIC_64 + CONST struct mach_header_64 *mh = NULL; + #define mh_magic OSSwapHostToBigInt32(MH_MAGIC_64) + #define mh_size sizeof(struct mach_header_64) #endif - || mh->filetype != MH_BUNDLE) { + + if (codeSize >= sizeof(struct fat_header) + && fh->magic == OSSwapHostToBigInt32(FAT_MAGIC)) { + /* + * Fat binary, try to find mach_header for our architecture + */ + uint32_t fh_nfat_arch = OSSwapBigToHostInt32(fh->nfat_arch); + + if (codeSize >= sizeof(struct fat_header) + + fh_nfat_arch * sizeof(struct fat_arch)) { + void *fatarchs = buffer + sizeof(struct fat_header); + CONST NXArchInfo *arch = NXGetLocalArchInfo(); + struct fat_arch *fa; + + if (fh->magic != FAT_MAGIC) { + swap_fat_arch(fatarchs, fh_nfat_arch, arch->byteorder); + } + fa = NXFindBestFatArch(arch->cputype, arch->cpusubtype, + fatarchs, fh_nfat_arch); + if (fa) { + mh = buffer + fa->offset; + ms = fa->size; + } else { + err = NSObjectFileImageInappropriateFile; + } + if (fh->magic != FAT_MAGIC) { + swap_fat_arch(fatarchs, fh_nfat_arch, arch->byteorder); + } + } else { + err = NSObjectFileImageInappropriateFile; + } + } else { + /* + * Thin binary + */ + mh = buffer; + ms = codeSize; + } + if (ms && !(ms >= mh_size && mh->magic == mh_magic && + mh->filetype == OSSwapHostToBigInt32(MH_BUNDLE))) { err = NSObjectFileImageInappropriateFile; } if (err == NSObjectFileImageSuccess) { |