summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathieu Malaterre <mathieu.malaterre@gmail.com>2006-03-10 13:34:03 -0500
committerMathieu Malaterre <mathieu.malaterre@gmail.com>2006-03-10 13:34:03 -0500
commitf90e7541008116d22209e5e1ffc0d9b4e6bc1a87 (patch)
tree3ade01051786b12754534a61f37036172e396870
parent5623ef913fc4120f8d0e9bca92597f4ad9fd9d91 (diff)
downloadcmake-f90e7541008116d22209e5e1ffc0d9b4e6bc1a87.tar.gz
BUG: Fix DynamicLoader implementation on MacOSX (using old API)
-rw-r--r--Source/kwsys/CMakeLists.txt2
-rw-r--r--Source/kwsys/DynamicLoader.cxx52
2 files changed, 35 insertions, 19 deletions
diff --git a/Source/kwsys/CMakeLists.txt b/Source/kwsys/CMakeLists.txt
index 1008792a94..6771d26d08 100644
--- a/Source/kwsys/CMakeLists.txt
+++ b/Source/kwsys/CMakeLists.txt
@@ -515,7 +515,7 @@ IF(KWSYS_C_SRCS OR KWSYS_CXX_SRCS)
# If kwsys contains the DynamicLoader, need extra library
IF(KWSYS_USE_DynamicLoader)
- ADD_LIBRARY(testDynload SHARED testDynload.c)
+ ADD_LIBRARY(testDynload MODULE testDynload.c)
IF(UNIX)
TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} ${CMAKE_DL_LIBS})
ENDIF(UNIX)
diff --git a/Source/kwsys/DynamicLoader.cxx b/Source/kwsys/DynamicLoader.cxx
index 2bf2a0d9d0..07df87a437 100644
--- a/Source/kwsys/DynamicLoader.cxx
+++ b/Source/kwsys/DynamicLoader.cxx
@@ -16,6 +16,12 @@
#include KWSYS_HEADER(Configure.hxx)
+#ifdef __APPLE__
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1030
+#include <string.h> // for strlen
+#endif //MAC_OS_X_VERSION_MIN_REQUIRED < 1030
+#endif // __APPLE__
+
// Work-around CMake dependency scanning limitation. This must
// duplicate the above list of headers.
#if 0
@@ -70,20 +76,20 @@ int DynamicLoader::CloseLibrary(LibHandle lib)
//----------------------------------------------------------------------------
DynamicLoaderFunction
DynamicLoader::GetSymbolAddress(LibHandle lib, const char* sym)
-{
+{
void* addr;
int status;
-
+
status = shl_findsym (&lib, sym, TYPE_PROCEDURE, &addr);
void* result = (status < 0) ? (void*)0 : addr;
-
+
// Hack to cast pointer-to-data to pointer-to-function.
return *reinterpret_cast<DynamicLoaderFunction*>(&result);
}
//----------------------------------------------------------------------------
const char* DynamicLoader::LibPrefix()
-{
+{
return "lib";
}
@@ -97,9 +103,9 @@ const char* DynamicLoader::LibExtension()
const char* DynamicLoader::LastError()
{
// TODO: Need implementation with errno/strerror
- /* If successful, shl_findsym returns an integer (int) value zero. If
- * shl_findsym cannot find sym, it returns -1 and sets errno to zero.
- * If any other errors occur, shl_findsym returns -1 and sets errno to one
+ /* If successful, shl_findsym returns an integer (int) value zero. If
+ * shl_findsym cannot find sym, it returns -1 and sets errno to zero.
+ * If any other errors occur, shl_findsym returns -1 and sets errno to one
* of these values (defined in <errno.h>):
* ENOEXEC
* A format error was detected in the specified library.
@@ -134,11 +140,13 @@ LibHandle DynamicLoader::OpenLibrary(const char* libname )
NSObjectFileImage image = 0;
rc = NSCreateObjectFileImageFromFile(libname, &image);
- if(!image)
+ // rc == NSObjectFileImageInappropriateFile when trying to load a dylib file
+ if( rc != NSObjectFileImageSuccess )
{
return 0;
}
- return NSLinkModule(image, libname, NSLINKMODULE_OPTION_BINDNOW);
+ return NSLinkModule(image, libname,
+ NSLINKMODULE_OPTION_PRIVATE|NSLINKMODULE_OPTION_BINDNOW);
}
//----------------------------------------------------------------------------
@@ -149,17 +157,22 @@ int DynamicLoader::CloseLibrary( LibHandle lib)
}
//----------------------------------------------------------------------------
-DynamicLoaderFunction DynamicLoader::GetSymbolAddress(LibHandle /* lib */, const char* sym)
+DynamicLoaderFunction DynamicLoader::GetSymbolAddress(LibHandle lib, const char* sym)
{
void *result=0;
- if(NSIsSymbolNameDefined(sym))
+ // Need to prepend symbols with '_' on Apple-gcc compilers
+ size_t len = strlen(sym);
+ char *rsym = new char[len + 1 + 1];
+ strcpy(rsym, "_");
+ strcat(rsym+1, sym);
+
+ NSSymbol symbol = NSLookupSymbolInModule(lib, rsym);
+ if(symbol)
{
- NSSymbol symbol= NSLookupAndBindSymbol(sym);
- if(symbol)
- {
- result = NSAddressOfSymbol(symbol);
- }
+ result = NSAddressOfSymbol(symbol);
}
+
+ delete[] rsym;
// Hack to cast pointer-to-data to pointer-to-function.
return *reinterpret_cast<DynamicLoaderFunction*>(&result);
}
@@ -167,13 +180,16 @@ DynamicLoaderFunction DynamicLoader::GetSymbolAddress(LibHandle /* lib */, const
//----------------------------------------------------------------------------
const char* DynamicLoader::LibPrefix()
{
- return "";
+ return "lib";
}
//----------------------------------------------------------------------------
const char* DynamicLoader::LibExtension()
{
- return ".dylib";
+ // NSCreateObjectFileImageFromFile fail when dealing with dylib image
+ // it returns NSObjectFileImageInappropriateFile
+ //return ".dylib";
+ return ".so";
}
//----------------------------------------------------------------------------