diff options
author | Leon Brocard <acme@astray.com> | 2004-01-25 08:53:17 +0000 |
---|---|---|
committer | Leon Brocard <acme@astray.com> | 2004-01-25 08:53:17 +0000 |
commit | ee2a00f3e3efa02e950161a9fb453e0a7cfdf6f4 (patch) | |
tree | 8d4b4235cccf7b224b69c4667801fe8b89fbf59c | |
parent | d69abffa14dcf095e5ca7397f5e1b00667547d9a (diff) | |
download | perl-ee2a00f3e3efa02e950161a9fb453e0a7cfdf6f4.tar.gz |
Applied patch from Jarkko Hietaniemi to add support for Mac OS X
p4raw-id: //depot/maint-5.005/perl@22213
-rw-r--r-- | MANIFEST | 2 | ||||
-rw-r--r-- | ext/DynaLoader/dl_dyld.xs | 226 | ||||
-rw-r--r-- | hints/darwin.sh | 230 |
3 files changed, 458 insertions, 0 deletions
@@ -225,6 +225,7 @@ ext/DynaLoader/dl_beos.xs BeOS implementation ext/DynaLoader/dl_cygwin32.xs Cygwin32 implementation ext/DynaLoader/dl_dld.xs GNU dld style implementation ext/DynaLoader/dl_dlopen.xs BSD/SunOS4&5 dlopen() style implementation +ext/DynaLoader/dl_dyld.xs NeXT/Apple dyld implementation ext/DynaLoader/dl_hpux.xs HP-UX implementation ext/DynaLoader/dl_mpeix.xs MPE/iX implementation ext/DynaLoader/dl_next.xs Next implementation @@ -399,6 +400,7 @@ hints/bsdos.sh Hints for named architecture hints/convexos.sh Hints for named architecture hints/cxux.sh Hints for named architecture hints/cygwin32.sh Hints for named architecture +hints/darwin.sh Hints for named architecture hints/dcosx.sh Hints for named architecture hints/dec_osf.sh Hints for named architecture hints/dgux.sh Hints for named architecture diff --git a/ext/DynaLoader/dl_dyld.xs b/ext/DynaLoader/dl_dyld.xs new file mode 100644 index 0000000000..e5e068d5a2 --- /dev/null +++ b/ext/DynaLoader/dl_dyld.xs @@ -0,0 +1,226 @@ +/* dl_dyld.xs + * + * Platform: Darwin (Mac OS) + * Author: Wilfredo Sanchez <wsanchez@apple.com> + * Based on: dl_next.xs by Paul Marquess + * Based on: dl_dlopen.xs by Anno Siegel + * Created: Aug 15th, 1994 + * + */ + +/* + And Gandalf said: 'Many folk like to know beforehand what is to + be set on the table; but those who have laboured to prepare the + feast like to keep their secret; for wonder makes the words of + praise louder.' +*/ + +/* Porting notes: + +dl_dyld.xs is based on dl_next.xs by Anno Siegel. + +dl_next.xs is in turn a port from dl_dlopen.xs by Paul Marquess. It +should not be used as a base for further ports though it may be used +as an example for how dl_dlopen.xs can be ported to other platforms. + +The method used here is just to supply the sun style dlopen etc. +functions in terms of NeXT's/Apple's dyld. The xs code proper is +unchanged from Paul's original. + +The port could use some streamlining. For one, error handling could +be simplified. + +This should be useable as a replacement for dl_next.xs, but it has not +been tested on NeXT platforms. + + Wilfredo Sanchez + +*/ + +#include "EXTERN.h" +#include "perl.h" +#include "XSUB.h" + +#include "dlutils.c" /* for SaveError() etc */ + +#undef environ +#undef bool +#import <mach-o/dyld.h> + +char *dl_last_error; + +static char *dlerror() +{ + return dl_last_error; +} + +static int dlclose(handle) /* stub only */ +void *handle; +{ + return 0; +} + +enum dyldErrorSource +{ + OFImage, +}; + +static void TranslateError + (const char *path, enum dyldErrorSource type, int number) +{ + char *error; + unsigned int index; + static char *OFIErrorStrings[] = + { + "%s(%d): Object Image Load Failure\n", + "%s(%d): Object Image Load Success\n", + "%s(%d): Not a recognisable object file\n", + "%s(%d): No valid architecture\n", + "%s(%d): Object image has an invalid format\n", + "%s(%d): Invalid access (permissions?)\n", + "%s(%d): Unknown error code from NSCreateObjectFileImageFromFile\n", + }; +#define NUM_OFI_ERRORS (sizeof(OFIErrorStrings) / sizeof(OFIErrorStrings[0])) + + error = malloc(1024); + + switch (type) + { + case OFImage: + index = number; + if (index > NUM_OFI_ERRORS - 1) + index = NUM_OFI_ERRORS - 1; + snprintf(error, 1024, OFIErrorStrings[index], path, number); + break; + + default: + snprintf(error, 1024, "%s(%d): Totally unknown error type %d\n", + path, number, type); + break; + } + safefree(dl_last_error); + dl_last_error = savepv(error); +} + +static char *dlopen(char *path, int mode /* mode is ignored */) +{ + int dyld_result; + NSObjectFileImage ofile; + NSModule handle = NULL; + + dyld_result = NSCreateObjectFileImageFromFile(path, &ofile); + if (dyld_result != NSObjectFileImageSuccess) + TranslateError(path, OFImage, dyld_result); + else + { + // NSLinkModule will cause the run to abort on any link error's + // not very friendly but the error recovery functionality is limited. + handle = NSLinkModule(ofile, path, TRUE); + NSDestroyObjectFileImage(ofile); + } + + return handle; +} + +static void * +dlsym(handle, symbol) +void *handle; +char *symbol; +{ + void *addr; + + if (NSIsSymbolNameDefined(symbol)) + addr = NSAddressOfSymbol(NSLookupAndBindSymbol(symbol)); + else + addr = NULL; + + return addr; +} + + + +/* ----- code from dl_dlopen.xs below here ----- */ + + +static void +dl_private_init() +{ + (void)dl_generic_private_init(); +} + +MODULE = DynaLoader PACKAGE = DynaLoader + +BOOT: + (void)dl_private_init(); + + + +void * +dl_load_file(filename, flags=0) + char * filename + int flags + PREINIT: + int mode = 1; + CODE: + DLDEBUG(1,PerlIO_printf(Perl_debug_log, "dl_load_file(%s,%x):\n", filename,flags)); + if (flags & 0x01) + Perl_warn("Can't make loaded symbols global on this platform while loading %s",filename); + RETVAL = dlopen(filename, mode) ; + DLDEBUG(2,PerlIO_printf(Perl_debug_log, " libref=%x\n", RETVAL)); + ST(0) = sv_newmortal() ; + if (RETVAL == NULL) + SaveError("%s",dlerror()) ; + else + sv_setiv( ST(0), (IV)RETVAL ); + + +void * +dl_find_symbol(libhandle, symbolname) + void * libhandle + char * symbolname + CODE: + char *buffer = malloc(1024); + snprintf(buffer, 1024, "_%s", symbolname); + DLDEBUG(2, PerlIO_printf(Perl_debug_log, + "dl_find_symbol(handle=%lx, symbol=%s)\n", + (unsigned long) libhandle, buffer)); + RETVAL = dlsym(libhandle, buffer); + DLDEBUG(2, PerlIO_printf(Perl_debug_log, + " symbolref = %lx\n", (unsigned long) RETVAL)); + safefree(buffer); + ST(0) = sv_newmortal() ; + if (RETVAL == NULL) + SaveError("%s",dlerror()) ; + else + sv_setiv( ST(0), (IV)RETVAL ); + + +void +dl_undef_symbols() + PPCODE: + + + +# These functions should not need changing on any platform: + +void +dl_install_xsub(perl_name, symref, filename="$Package") + char * perl_name + void * symref + char * filename + CODE: + DLDEBUG(2,PerlIO_printf(Perl_debug_log, "dl_install_xsub(name=%s, symref=%x)\n", + perl_name, symref)); + ST(0) = sv_2mortal(newRV((SV*)newXS(perl_name, + (void(*)(CV *))symref, + filename))); + + +char * +dl_error() + CODE: + RETVAL = dl_last_error ; + OUTPUT: + RETVAL + +# end. diff --git a/hints/darwin.sh b/hints/darwin.sh new file mode 100644 index 0000000000..3620d943fd --- /dev/null +++ b/hints/darwin.sh @@ -0,0 +1,230 @@ +## +# Darwin (Mac OS) hints +# Wilfredo Sanchez <wsanchez@wsanchez.net> +## + +## +# Paths +## + +# Configure hasn't figured out the version number yet. Bummer. +perl_revision=`awk '/define[ ]+PERL_REVISION/ {print $3}' $src/patchlevel.h` +perl_version=`awk '/define[ ]+PERL_VERSION/ {print $3}' $src/patchlevel.h` +perl_subversion=`awk '/define[ ]+PERL_SUBVERSION/ {print $3}' $src/patchlevel.h` +version="${perl_revision}.${perl_version}.${perl_subversion}" + +# Pretend that Darwin doesn't know about those system calls [perl #24122] +d_setregid='undef' +d_setreuid='undef' +d_setrgid='undef' +d_setruid='undef' + +# This was previously used in all but causes three cases +# (no -Ddprefix=, -Dprefix=/usr, -Dprefix=/some/thing/else) +# but that caused too much grief. +# vendorlib="/System/Library/Perl/${version}"; # Apple-supplied modules + +# BSD paths +case "$prefix" in +'') # Default install; use non-system directories + prefix='/usr/local'; + siteprefix='/usr/local'; + ;; +'/usr') # We are building/replacing the built-in perl + prefix='/'; + installprefix='/'; + bin='/usr/bin'; + siteprefix='/usr/local'; + # We don't want /usr/bin/HEAD issues. + sitebin='/usr/local/bin'; + sitescript='/usr/local/bin'; + installusrbinperl='define'; # You knew what you were doing. + privlib="/System/Library/Perl/${version}"; + sitelib="/Library/Perl/${version}"; + vendorprefix='/'; + usevendorprefix='define'; + vendorbin='/usr/bin'; + vendorscript='/usr/bin'; + vendorlib="/Network/Library/Perl/${version}"; + # 4BSD uses ${prefix}/share/man, not ${prefix}/man. + man1dir='/usr/share/man/man1'; + man3dir='/usr/share/man/man3'; + # But users' installs shouldn't touch the system man pages. + # Transient obsoleted style. + siteman1='/usr/local/share/man/man1'; + siteman3='/usr/local/share/man/man3'; + # New style. + siteman1dir='/usr/local/share/man/man1'; + siteman3dir='/usr/local/share/man/man3'; + ;; + *) # Anything else; use non-system directories, use Configure defaults + ;; +esac + +## +# Tool chain settings +## + +# Since we can build fat, the archname doesn't need the processor type +archname='darwin'; + +# nm works. +usenm='true'; + +case "$optimize" in +'') +# Optimizing for size also mean less resident memory usage on the part +# of Perl. Apple asserts that this is a more important optimization than +# saving on CPU cycles. Given that memory speed has not increased at +# pace with CPU speed over time (on any platform), this is probably a +# reasonable assertion. +if [ -z "${optimize}" ]; then + case "`${cc:-gcc} -v 2>&1`" in + *"gcc version 3."*) optimize='-Os' ;; + *) optimize='-O3' ;; + esac +else + optimize='-O3' +fi +;; +esac + +# -pipe: makes compilation go faster. +# -fno-common because common symbols are not allowed in MH_DYLIB +# -DPERL_DARWIN: apparently the __APPLE__ is not sanctioned by Apple +# as the way to differentiate Mac OS X. (The official line is that +# *no* cpp symbol does differentiate Mac OS X.) +ccflags="${ccflags} -pipe -fno-common -DPERL_DARWIN" + +# At least on Darwin 1.3.x: +# +# # define INT32_MIN -2147483648 +# int main () { +# double a = INT32_MIN; +# printf ("INT32_MIN=%g\n", a); +# return 0; +# } +# will output: +# INT32_MIN=2.14748e+09 +# Note that the INT32_MIN has become positive. +# INT32_MIN is set in /usr/include/stdint.h by: +# #define INT32_MIN -2147483648 +# which seems to break the gcc. Defining INT32_MIN as (-2147483647-1) +# seems to work. INT64_MIN seems to be similarly broken. +# -- Nicholas Clark, Ken Williams, and Edward Moy +# +# This seems to have been fixed since at least Mac OS X 10.1.3, +# stdint.h defining INT32_MIN as (-INT32_MAX-1) +# -- Edward Moy +# +case "$(grep '^#define INT32_MIN' /usr/include/stdint.h)" in + *-2147483648) ccflags="${ccflags} -DINT32_MIN_BROKEN -DINT64_MIN_BROKEN" ;; +esac + +# Avoid Apple's cpp precompiler, better for extensions +cppflags="${cppflags} -no-cpp-precomp" + +# This is necessary because perl's build system doesn't +# apply cppflags to cc compile lines as it should. +ccflags="${ccflags} ${cppflags}" + +# Known optimizer problems. +case "`cc -v 2>&1`" in + *"3.1 20020105"*) toke_cflags='optimize=""' ;; +esac + +# Shared library extension is .dylib. +# Bundle extension is .bundle. +ld='cc'; +so='dylib'; +dlext='bundle'; +dlsrc='dl_dyld.xs'; usedl='define'; +cccdlflags=' '; # space, not empty, because otherwise we get -fpic +# Perl bundles do not expect two-level namespace, added in Darwin 1.4. +# But starting from perl 5.8.1/Darwin 7 the default is the two-level. +case "$osvers" in +1.[0-3].*) + lddlflags="${ldflags} -bundle -undefined suppress" + ;; +1.*) + ldflags="${ldflags} -flat_namespace" + lddlflags="${ldflags} -bundle -undefined suppress" + ;; +[2-6].*) + ldflags="${ldflags} -flat_namespace" + lddlflags="${ldflags} -bundle -undefined suppress" + ;; +*) lddlflags="${ldflags} -bundle -undefined dynamic_lookup" + case "$ld" in + *MACOSX_DEVELOPMENT_TARGET*) ;; + *) ld="env MACOSX_DEPLOYMENT_TARGET=10.3 ${ld}" ;; + esac + ;; +esac +ldlibpthname='DYLD_LIBRARY_PATH'; + +# useshrplib=true results in much slower startup times. +# 'false' is the default value. Use Configure -Duseshrplib to override. + +cat > UU/archname.cbu <<'EOCBU' +# This script UU/archname.cbu will get 'called-back' by Configure +# after it has otherwise determined the architecture name. +case "$ldflags" in +*"-flat_namespace"*) ;; # Backward compat, be flat. +# If we are using two-level namespace, we will munge the archname to show it. +*) archname="${archname}-2level" ;; +esac +EOCBU + +## +# System libraries +## + +# vfork works +usevfork='true'; + +# our malloc works (but allow users to override) +case "$usemymalloc" in +'') usemymalloc='n' ;; +esac + +# Locales aren't feeling well. +LC_ALL=C; export LC_ALL; +LANG=C; export LANG; + +# +# The libraries are not threadsafe as of OS X 10.1. +# +# Fix when Apple fixes libc. +# +case "$usethreads$useithreads$use5005threads" in + *define*) + case "$osvers" in + [12345].*) cat <<EOM >&4 + + + +*** Warning, there might be problems with your libraries with +*** regards to threading. The test ext/threads/t/libc.t is likely +*** to fail. + +EOM + ;; + *) usereentrant='define';; + esac + +esac + +# Fink can install a GDBM library that claims to have the ODBM interfaces +# but Perl dynaloader cannot for some reason use that library. We don't +# really need ODBM_FIle, though, so let's just hint ODBM away. +i_dbm=undef; + +## +# Build process +## + +# Case-insensitive filesystems don't get along with Makefile and +# makefile in the same place. Since Darwin uses GNU make, this dodges +# the problem. +firstmakefile=GNUmakefile; |