From 098e185ebea0c023e9b42ca15b607ef156b5deba Mon Sep 17 00:00:00 2001 From: Dain Date: Mon, 28 Jan 2008 13:24:32 -0700 Subject: [PATCH 1/4] fixed compile error, function in vm namespace needed to call function in the anonymous namespace --- src/process.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/process.cpp b/src/process.cpp index 6ab36f49ca..8f2d5e62ac 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -170,7 +170,7 @@ resolveNativeMethod2(Thread* t, object method) snprintf(decorated + decoratedSize - 1, 5, "@%d", footprint * BytesPerWord); - p = resolveNativeMethod(t, undecorated, decorated); + p = ::resolveNativeMethod(t, undecorated, decorated); if (p) { return p; } From c1f3d28d2464974190050c24f66ac8496ec83e05 Mon Sep 17 00:00:00 2001 From: Eric Scharff Date: Mon, 28 Jan 2008 16:17:22 -0700 Subject: [PATCH 2/4] Fixes dynamic symbol loading bug on Mac OS X. On OS X, when you call dlopen() on a null library, and then call dlsym(), the most recently loaded symbols are always used, no matter what flags we seem to pass to dlopen(). The solution is to explicitly find the name of the running executable, and open that as a library. --- makefile | 2 +- src/posix.cpp | 32 ++++++++++++++++++++++++++++++++ src/system.h | 1 + 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/makefile b/makefile index 9cdd151cdb..e4d31bfe01 100644 --- a/makefile +++ b/makefile @@ -82,7 +82,7 @@ endif ifeq ($(platform),darwin) build-cflags = $(common-cflags) -fPIC -fvisibility=hidden \ -I$(JAVA_HOME)/include/linux -I$(src) - lflags = $(common-lflags) -ldl + lflags = $(common-lflags) -ldl -framework CoreFoundation strip-all = -S -x binaryToMacho = $(native-build)/binaryToMacho endif diff --git a/src/posix.cpp b/src/posix.cpp index 4f3b46857a..dbc4bd5886 100644 --- a/src/posix.cpp +++ b/src/posix.cpp @@ -1,3 +1,6 @@ +#ifdef __APPLE__ +#include "CoreFoundation/CoreFoundation.h" +#endif #include "sys/mman.h" #include "sys/types.h" #include "sys/stat.h" @@ -116,6 +119,27 @@ allocate(System* s, unsigned size) return p; } +void +pathOfExecutable(System* s, const char** retBuf, unsigned* size) +{ +#ifdef __APPLE__ + CFBundleRef bundle = CFBundleGetMainBundle(); + CFURLRef url = CFBundleCopyExecutableURL(bundle); + CFStringRef path = CFURLCopyPath(url); + CFIndex pathSize = CFStringGetMaximumSizeOfFileSystemRepresentation(path); + char* buffer = reinterpret_cast(allocate(s, pathSize)); + if (CFStringGetFileSystemRepresentation(path, buffer, pathSize)) { + *size = pathSize; + *retBuf = buffer; + } else { + abort(); + } +#else + *size = 0; + *retBuf = NULL; +#endif +} + const bool Verbose = false; const unsigned Waiting = 1 << 0; @@ -646,6 +670,7 @@ class MySystem: public System { bool mapName) { void* p; + bool alreadyAllocated = false; unsigned nameLength = (name ? strlen(name) : 0); if (mapName) { unsigned size = nameLength + 3 + sizeof(SO_SUFFIX); @@ -653,6 +678,10 @@ class MySystem: public System { snprintf(buffer, size, "lib%s" SO_SUFFIX, name); p = dlopen(buffer, RTLD_LAZY); } else { + if (!name) { + pathOfExecutable(this, &name, &nameLength); + alreadyAllocated = true; + } p = dlopen(name, RTLD_LAZY); } @@ -665,6 +694,9 @@ class MySystem: public System { if (name) { n = static_cast(allocate(this, nameLength + 1)); memcpy(n, name, nameLength + 1); + if (alreadyAllocated) { + free(name, nameLength, false); + } } else { n = 0; } diff --git a/src/system.h b/src/system.h index 2f06357cbf..bb53cdc407 100644 --- a/src/system.h +++ b/src/system.h @@ -134,6 +134,7 @@ expect(System* s, bool v) #ifdef NDEBUG +# undef assert # define assert(a, b) #else // not NDEBUG From e5f95ae89d1279e7987ff17cd6d61fb392760a94 Mon Sep 17 00:00:00 2001 From: Eric Scharff Date: Mon, 28 Jan 2008 16:22:16 -0700 Subject: [PATCH 3/4] Fix pesky compiler warning on unused variable in linux. --- src/posix.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/posix.cpp b/src/posix.cpp index dbc4bd5886..c0773a46df 100644 --- a/src/posix.cpp +++ b/src/posix.cpp @@ -135,7 +135,8 @@ pathOfExecutable(System* s, const char** retBuf, unsigned* size) abort(); } #else - *size = 0; + if (s) + *size = 0; *retBuf = NULL; #endif } From 2363d6e8eb35df8da196f178cc50c200e590fa07 Mon Sep 17 00:00:00 2001 From: Eric Scharff Date: Mon, 28 Jan 2008 16:35:23 -0700 Subject: [PATCH 4/4] Fix debug build for Mac OS X --- src/posix.cpp | 1 + src/system.h | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/posix.cpp b/src/posix.cpp index c0773a46df..635c7c088d 100644 --- a/src/posix.cpp +++ b/src/posix.cpp @@ -1,5 +1,6 @@ #ifdef __APPLE__ #include "CoreFoundation/CoreFoundation.h" +#undef assert #endif #include "sys/mman.h" #include "sys/types.h" diff --git a/src/system.h b/src/system.h index bb53cdc407..2f06357cbf 100644 --- a/src/system.h +++ b/src/system.h @@ -134,7 +134,6 @@ expect(System* s, bool v) #ifdef NDEBUG -# undef assert # define assert(a, b) #else // not NDEBUG