From 5b535b7e83dc95bec02a4c4e741eb550cb37150b Mon Sep 17 00:00:00 2001 From: Bryce Denney Date: Fri, 11 Oct 2002 16:45:31 +0000 Subject: [PATCH] - test5-execsymbols checks that a module can reach symbols that are defined in the executable. On linux you can. --- .../plugin-test/test5-execsymbols/Makefile | 32 +++++++++++++++++++ .../plugin-test/test5-execsymbols/README | 12 +++++++ .../plugin-test/test5-execsymbols/module1.cc | 11 +++++++ .../plugin-test/test5-execsymbols/module1.h | 19 +++++++++++ .../plugin-test/test5-execsymbols/module2.cc | 16 ++++++++++ .../plugin-test/test5-execsymbols/module2.h | 19 +++++++++++ .../plugin-test/test5-execsymbols/uselib.cc | 25 +++++++++++++++ .../plugin-test/test5-execsymbols/uselib.h | 1 + 8 files changed, 135 insertions(+) create mode 100644 bochs-testing/plugin-test/test5-execsymbols/Makefile create mode 100644 bochs-testing/plugin-test/test5-execsymbols/README create mode 100644 bochs-testing/plugin-test/test5-execsymbols/module1.cc create mode 100644 bochs-testing/plugin-test/test5-execsymbols/module1.h create mode 100644 bochs-testing/plugin-test/test5-execsymbols/module2.cc create mode 100644 bochs-testing/plugin-test/test5-execsymbols/module2.h create mode 100644 bochs-testing/plugin-test/test5-execsymbols/uselib.cc create mode 100644 bochs-testing/plugin-test/test5-execsymbols/uselib.h diff --git a/bochs-testing/plugin-test/test5-execsymbols/Makefile b/bochs-testing/plugin-test/test5-execsymbols/Makefile new file mode 100644 index 000000000..ba64c5993 --- /dev/null +++ b/bochs-testing/plugin-test/test5-execsymbols/Makefile @@ -0,0 +1,32 @@ +CXX=g++ +CXXFLAGS=-Wall -g +LIBTOOL=libtool +RPATH=`pwd`/lib + +all: uselib + +uselib: uselib.cc libmodule1.la libmodule2.la + $(LIBTOOL) $(CXX) $(CXXFLAGS) -o uselib uselib.cc libmodule1.la libmodule2.la + +libmodule1.la: module1.lo libmodule2.la + $(LIBTOOL) $(CXX) -no-undefined -o libmodule1.la module1.lo -rpath ${RPATH} libmodule2.la + mkdir -p lib bin + $(LIBTOOL) cp libmodule1.la ${RPATH} + +libmodule2.la: module2.lo + $(LIBTOOL) $(CXX) -no-undefined -o libmodule2.la module2.lo -rpath ${RPATH} + mkdir -p lib bin + $(LIBTOOL) cp libmodule2.la ${RPATH} + +%.lo: %.cc + $(LIBTOOL) $(CXX) -c $< + +test: + @echo "*** Running test in `pwd`" + -./uselib + @echo "*** Test done in `pwd`" + +clean: + -libtool rm libmodule1.la module1.lo libmodule2.la module2.lo + rm -rf *.o uselib.exe bin lib uselib uselib.exe + rm -rf .libs diff --git a/bochs-testing/plugin-test/test5-execsymbols/README b/bochs-testing/plugin-test/test5-execsymbols/README new file mode 100644 index 000000000..58832ff08 --- /dev/null +++ b/bochs-testing/plugin-test/test5-execsymbols/README @@ -0,0 +1,12 @@ +test5-execsymbols + +Can a module reference symbols in the executable? + +module1 exports module_name and operate(int,int). +module2 exports n_operations and operation_occurred(). + +uselib.cc uses symbols and functions from both modules. +Module1 calls operation_occurred() in module2. + +Module2 calls register_module() in uselib.cc the first time +it is called. diff --git a/bochs-testing/plugin-test/test5-execsymbols/module1.cc b/bochs-testing/plugin-test/test5-execsymbols/module1.cc new file mode 100644 index 000000000..4fada3907 --- /dev/null +++ b/bochs-testing/plugin-test/test5-execsymbols/module1.cc @@ -0,0 +1,11 @@ +#define MODULE1_DLL_EXPORT +#include "module1.h" +#include "module2.h" + +const char *module_name = "AddModule"; + +int operate (int a, int b) +{ + operation_occurred (); + return a + b; +} diff --git a/bochs-testing/plugin-test/test5-execsymbols/module1.h b/bochs-testing/plugin-test/test5-execsymbols/module1.h new file mode 100644 index 000000000..c29250615 --- /dev/null +++ b/bochs-testing/plugin-test/test5-execsymbols/module1.h @@ -0,0 +1,19 @@ +#if defined(WIN32) || defined(__CYGWIN__) +# ifdef MODULE1_DLL_EXPORT +# ifdef DLL_EXPORT +# warning I will export DLL symbols for MODULE1 +# define MODULE1API(type) __declspec(dllexport) type +# endif +# else +# warning I will import DLL symbols for MODULE1 +# define MODULE1API(type) __declspec(dllimport) type +# endif +#endif +#ifndef MODULE1API +# warning No DLL import/export is needed +# define MODULE1API(type) type +#endif + +MODULE1API(extern const char *) module_name; +MODULE1API(extern int) operate (int a, int b); + diff --git a/bochs-testing/plugin-test/test5-execsymbols/module2.cc b/bochs-testing/plugin-test/test5-execsymbols/module2.cc new file mode 100644 index 000000000..9bf15fd1f --- /dev/null +++ b/bochs-testing/plugin-test/test5-execsymbols/module2.cc @@ -0,0 +1,16 @@ +#include +#define MODULE2_DLL_EXPORT +#include "module2.h" +#include "uselib.h" + +int n_operations = 0; + +void operation_occurred () { + static int first_time = 1; + if (first_time) { + register_module ("module2"); + first_time = 0; + } + printf ("module2: operation_occurred\n"); + n_operations++; +} diff --git a/bochs-testing/plugin-test/test5-execsymbols/module2.h b/bochs-testing/plugin-test/test5-execsymbols/module2.h new file mode 100644 index 000000000..cce8b1cae --- /dev/null +++ b/bochs-testing/plugin-test/test5-execsymbols/module2.h @@ -0,0 +1,19 @@ +#if defined(WIN32) || defined(__CYGWIN__) +# ifdef MODULE2_DLL_EXPORT +# ifdef DLL_EXPORT +# warning I will export DLL symbols for MODULE2 +# define MODULE2API(type) __declspec(dllexport) type +# endif +# else +# warning I will import DLL symbols for MODULE2 +# define MODULE2API(type) __declspec(dllimport) type +# endif +#endif +#ifndef MODULE2API +# warning No DLL import/export is needed +# define MODULE2API(type) type +#endif + + +MODULE2API(extern int) n_operations; +MODULE2API(void) operation_occurred (); diff --git a/bochs-testing/plugin-test/test5-execsymbols/uselib.cc b/bochs-testing/plugin-test/test5-execsymbols/uselib.cc new file mode 100644 index 000000000..770c2b4fa --- /dev/null +++ b/bochs-testing/plugin-test/test5-execsymbols/uselib.cc @@ -0,0 +1,25 @@ +#include +#include "module1.h" +#include "module2.h" +#include "uselib.h" + +int register_module (const char *name) +{ + printf ("register_module was called by module '%s'\n", name); + return 0; +} + +int main () +{ + printf ("start\n"); + printf ("at first, n_operations = %d\n", n_operations); + printf ("Module name is '%s'\n", module_name); + int a=5, b=12; + int c = operate (a, b); + printf ("operate(%d,%d) = %d\n", a, b, c); + int d = operate (a, c); + printf ("operate(%d,%d) = %d\n", a, c, d); + printf ("stop\n"); + printf ("at end, n_operations = %d\n", n_operations); + return 0; +} diff --git a/bochs-testing/plugin-test/test5-execsymbols/uselib.h b/bochs-testing/plugin-test/test5-execsymbols/uselib.h new file mode 100644 index 000000000..9a0ae0293 --- /dev/null +++ b/bochs-testing/plugin-test/test5-execsymbols/uselib.h @@ -0,0 +1 @@ +extern int register_module (const char *name);