Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
forgot the test file
authorMartin Quinson <martin.quinson@loria.fr>
Wed, 19 Dec 2012 18:41:07 +0000 (19:41 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Wed, 19 Dec 2012 18:41:07 +0000 (19:41 +0100)
buildtools/Cmake/DefinePackages.cmake
buildtools/Cmake/test_prog/prog_gnu_dynlinker.c [new file with mode: 0644]

index 2f074b3..32264f5 100644 (file)
@@ -755,6 +755,7 @@ set(CMAKE_SOURCE_FILES
   buildtools/Cmake/test_prog/prog_thread_storage.c
   buildtools/Cmake/test_prog/prog_va_copy.c
   buildtools/Cmake/test_prog/prog_vsnprintf.c
   buildtools/Cmake/test_prog/prog_thread_storage.c
   buildtools/Cmake/test_prog/prog_va_copy.c
   buildtools/Cmake/test_prog/prog_vsnprintf.c
+  buildtools/Cmake/test_prog/prog_gnu_dynlinker.c
   )
 
 set(PLATFORMS_EXAMPLES
   )
 
 set(PLATFORMS_EXAMPLES
diff --git a/buildtools/Cmake/test_prog/prog_gnu_dynlinker.c b/buildtools/Cmake/test_prog/prog_gnu_dynlinker.c
new file mode 100644 (file)
index 0000000..d48b891
--- /dev/null
@@ -0,0 +1,32 @@
+/* prog_gnu_dynlinker.c -- check that RTLD_NEXT is defined as in GNU linker */
+/* Copyright (c) 2012. The SimGrid Team. All rights reserved.               */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#define _GNU_SOURCE 1
+#include <dlfcn.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+static void * (*real_malloc) (size_t);
+
+int main(void) {
+   char *error;
+   dlerror(); // clear any previous error
+   real_malloc = (void * (*) (size_t)) dlsym(RTLD_NEXT, "malloc");
+   error = dlerror();
+   if (!error && real_malloc) {
+      char *A = real_malloc(20);
+      strcpy(A,"epic success");
+      free(A);
+      return 0; // SUCCESS
+   } else {
+      if (error)
+        printf("Error while checking for dlsym: %s\n",error);
+      else
+        printf("dlsym did not return any error, but failed to find malloc()\n",error);
+      return 1; // FAILED
+   }
+}