Date: Friday, April 13, 2007 @ 18:07:45
Author: marc
Path: /cvsroot/carob/libmysequoia/ldtest
Added: Makefile (1.1) main.cpp (1.1) orig.c (1.1) override.c (1.1)
plugin.c (1.1) runtest.sh (1.1)
Minimal RTLD_DEEPBIND test - first draft
------------+
Makefile | 29 +++++++++++++++++++++++
main.cpp | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
orig.c | 6 ++++
override.c | 6 ++++
plugin.c | 10 ++++++++
runtest.sh | 5 ++++
6 files changed, 128 insertions(+)
Index: libmysequoia/ldtest/Makefile
diff -u /dev/null libmysequoia/ldtest/Makefile:1.1
--- /dev/null Fri Apr 13 18:07:45 2007
+++ libmysequoia/ldtest/Makefile Fri Apr 13 18:07:45 2007
@@ -0,0 +1,29 @@
+
+
+DOLIB=-shared
+
+
+SOLIBS=liborig.so liboverride.so
+ALL=${SOLIBS} plugin.so main
+
+all: ${ALL} run
+
+
+${SOLIBS}: lib%.so: %.c
+ ${CC} ${DOLIB} $< -o $@
+
+
+plugin.so: plugin.c liborig.so
+ ${CC} ${DOLIB} $< -o $@ -L. -lorig
+
+
+main: main.cpp
+ ${CXX} -L. ${MAINFLAGS} $< -o $@ -ldl
+
+
+run:
+ LD_LIBRARY_PATH=. ./main
+ LD_LIBRARY_PATH=. LD_PRELOAD=./liboverride.so ./main
+
+clean:
+ rm -f ${ALL}
Index: libmysequoia/ldtest/main.cpp
diff -u /dev/null libmysequoia/ldtest/main.cpp:1.1
--- /dev/null Fri Apr 13 18:07:45 2007
+++ libmysequoia/ldtest/main.cpp Fri Apr 13 18:07:45 2007
@@ -0,0 +1,72 @@
+//
+// Sequoia: Database clustering technology.
+// Copyright (C) 2005 Emic Networks
+// Contact: [EMAIL PROTECTED]
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+// Initial developer: Marc Herbert
+// Contributor(s):
+//
+
+
+
+#include <iostream>
+
+#include <dlfcn.h>
+
+
+#define STRINGIFY(x) #x
+#define TOSTRING(x) STRINGIFY(x)
+
+
+
+// collections of nasty flags - PHP- is using all the ones it can
+// find, see ./Zend/zend.h
+
+
+// http://sourceware.org/ml/libc-hacker/2004-09/msg00083.html
+
+#ifndef DEEPBIND_ARG
+#define DEEPBIND_ARG RTLD_DEEPBIND
+#endif
+
+#ifdef NOGLOBAL
+#warning now nullifying RTLD_GLOBAL
+#define RTLD_GLOGAL 0
+#endif
+
+int
+main()
+{
+
+ void *plugin = dlopen("./plugin.so", RTLD_NOW | RTLD_GLOBAL | DEEPBIND_ARG);
+
+ if (!plugin) {
+ std::cerr << "failed to open plugin: " << dlerror() << std::endl;
+ exit(1);
+ }
+
+ char * (*plugin_function)() = ( char* (*)() ) dlsym(plugin,
"plugin_function");
+
+ char *error = dlerror();
+ if (error) {
+ std::cerr << "failed to find plugin function: " << error << std::endl;
+ exit(1);
+ }
+
+ std::cout << "DEEPBIND_ARG=" TOSTRING(DEEPBIND_ARG)
+ " ---> " << (*plugin_function) () << std::endl;
+
+
+}
Index: libmysequoia/ldtest/orig.c
diff -u /dev/null libmysequoia/ldtest/orig.c:1.1
--- /dev/null Fri Apr 13 18:07:45 2007
+++ libmysequoia/ldtest/orig.c Fri Apr 13 18:07:45 2007
@@ -0,0 +1,6 @@
+
+
+char * my_function()
+{
+ return "ORIG";
+}
Index: libmysequoia/ldtest/override.c
diff -u /dev/null libmysequoia/ldtest/override.c:1.1
--- /dev/null Fri Apr 13 18:07:45 2007
+++ libmysequoia/ldtest/override.c Fri Apr 13 18:07:45 2007
@@ -0,0 +1,6 @@
+
+
+char * my_function()
+{
+ return "OVERRIDE";
+}
Index: libmysequoia/ldtest/plugin.c
diff -u /dev/null libmysequoia/ldtest/plugin.c:1.1
--- /dev/null Fri Apr 13 18:07:45 2007
+++ libmysequoia/ldtest/plugin.c Fri Apr 13 18:07:45 2007
@@ -0,0 +1,10 @@
+
+
+char * my_function();
+
+
+char *plugin_function()
+{
+ return my_function();
+}
+
Index: libmysequoia/ldtest/runtest.sh
diff -u /dev/null libmysequoia/ldtest/runtest.sh:1.1
--- /dev/null Fri Apr 13 18:07:45 2007
+++ libmysequoia/ldtest/runtest.sh Fri Apr 13 18:07:45 2007
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+make clean all
+make clean all MAINFLAGS="-DDEEPBIND_ARG=0"
+
_______________________________________________
Carob-commits mailing list
[EMAIL PROTECTED]
https://forge.continuent.org/mailman/listinfo/carob-commits