Commits

Volker Braun committed 02c3601

start a test suite

Comments (0)

Files changed (15)

+Makefile.Linux

research/Makefile.Linux

+
+
+all: main directories
+
+main: main.o libexample.so
+	gcc main.o -L. -lexample -o example -Wl,-R,'$$ORIGIN/../lib'
+	readelf -d ./example  | grep RPATH
+
+main-preload:
+	make clean
+	make libpreload.so
+	GCCWRAP_LDFLAGS=-L.,-lpreload make 
+
+
+directories: 
+	rm -rf local
+	mkdir local
+	mkdir local/bin
+	mkdir local/lib
+	cp example local/bin/example
+	ln -sf libexample.so.1.0 local/lib/libexample.so
+	ln -sf libexample.so.1.0 local/lib/libexample.so.1
+	ln -sf ../../libexample.so.1.0 local/lib/libexample.so.1.0
+	ln -sf libpreload.so.1.0 local/lib/libpreload.so
+	ln -sf libpreload.so.1.0 local/lib/libpreload.so.1
+	ln -sf ../../libpreload.so.1.0 local/lib/libpreload.so.1.0
+
+
+main.o: main.c
+	gcc -Wall -fPIC -c -o main.o $^ 
+
+library.o: library.c
+	gcc -Wall -fPIC -c -o $@ $^ 
+
+libexample.so: library.o
+	gcc -shared -Wl,-soname,libexample.so.1 -L. -o libexample.so.1.0 library.o
+	ln -sf libexample.so.1.0 libexample.so
+	ln -sf libexample.so.1.0 libexample.so.1
+
+preload.o: preload.c
+	gcc -Wall -fPIC -c -o $@ $^ 
+
+libpreload.so: preload.o
+	gcc -shared -Wl,-soname,libpreload.so.1 -L. -o libpreload.so.1.0 preload.o -ldl
+	ln -sf libpreload.so.1.0 libpreload.so
+	ln -sf libpreload.so.1.0 libpreload.so.1
+
+.PHONY: clean all install
+
+clean:
+	rm -rf *~ *.o *.so* local example
+

research/Makefile.OSX

+
+
+all: main directories
+
+main: main.o libexample.dylib 
+	gcc main.o -L. -lexample -o example
+	otool -L ./example
+
+
+main-preload:
+	make clean
+	make libpreload.dylib
+	GCCWRAP_LDFLAGS=-L.,-lpreload make 
+
+
+directories: 
+	rm -rf local
+	mkdir local
+	mkdir local/bin
+	mkdir local/lib
+	ln -sf ../../example local/bin/example
+	ln -sf ../../libexample.dylib local/lib/libexample.dylib
+	ln -sf ../../libexample.1.dylib local/lib/libexample.1.dylib
+	ln -sf ../../libpreload.dylib local/lib/libpreload.dylib
+	ln -sf ../../libpreload.1.dylib local/lib/libpreload.1.dylib
+
+main.o: main.c
+	gcc -Wall -fPIC -c -o main.o $^ 
+
+library.o: library.c
+	gcc -Wall -fPIC -c -o $@ $^ 
+
+libexample.dylib: library.o
+	gcc -dynamiclib -o libexample.1.dylib library.o
+	ln -sf libexample.1.dylib libexample.dylib
+
+preload.o: preload.c
+	gcc -Wall -fPIC -c -o $@ $^ 
+
+libpreload.dylib: preload.o
+	gcc -dynamiclib -o libpreload.1.dylib preload.o -ldl
+	ln -sf libpreload.1.dylib libpreload.dylib
+
+.PHONY: clean all install
+
+clean:
+	rm -rf *~ *.o *.dylib local
+

research/Makefile.Solaris

+
+
+all: main directories
+
+main: main.o libexample.so
+	gcc main.o -L. -lexample -o example -Wl,-R,'$$ORIGIN/../lib'
+	elfdump -d ./example  | grep RPATH
+
+main-preload:
+	make clean
+	make libpreload.so
+	GCCWRAP_LDFLAGS=-L.,-lpreload make 
+
+
+directories: 
+	rm -rf local
+	mkdir local
+	mkdir local/bin
+	mkdir local/lib
+	cp example local/bin/example
+	ln -sf libexample.so.1.0 local/lib/libexample.so
+	ln -sf libexample.so.1.0 local/lib/libexample.so.1
+	ln -sf ../../libexample.so.1.0 local/lib/libexample.so.1.0
+	ln -sf libpreload.so.1.0 local/lib/libpreload.so
+	ln -sf libpreload.so.1.0 local/lib/libpreload.so.1
+	ln -sf ../../libpreload.so.1.0 local/lib/libpreload.so.1.0
+
+
+main.o: main.c
+	gcc -Wall -fPIC -c -o main.o $^ 
+
+library.o: library.c
+	gcc -Wall -fPIC -c -o $@ $^ 
+
+libexample.so: library.o
+	gcc -shared -Wl,-h,libexample.so.1 -L. -o libexample.so.1.0 library.o
+	ln -sf libexample.so.1.0 libexample.so
+	ln -sf libexample.so.1.0 libexample.so.1
+
+preload.o: preload.c
+	gcc -Wall -fPIC -c -o $@ $^ 
+
+libpreload.so: preload.o
+	gcc -shared -Wl,-h,libpreload.so.1 -L. -o libpreload.so.1.0 preload.o -ldl
+	ln -sf libpreload.so.1.0 libpreload.so
+	ln -sf libpreload.so.1.0 libpreload.so.1
+
+.PHONY: clean all install
+
+clean:
+	rm -rf *~ *.o *.so* local
+
+This subproject is just to figure out how to pass the relevant
+compiler options on different platforms.
+#include <stdio.h>
+#include <stdlib.h>
+
+
+void libraryfunction(int *x)
+{
+  printf("libraryfunction()\n");
+   *x = 10;
+
+   printf("malloc() in library.c\n");
+   malloc(42);
+}
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+void libraryfunction(int *);
+
+int main()
+{
+   int x;
+   libraryfunction(&x);
+   printf("main(): x=%d\n",x);
+
+   printf("Enter a number: ");
+   scanf("%d", &x);
+   printf("You entered: %d\n", x);
+
+   printf("malloc() in main.c\n");
+   malloc(42);
+
+   fflush(stdout);
+   return 0;
+}
+      
+#define _GNU_SOURCE
+#include <dlfcn.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <assert.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+
+
+static int (*real_open)(const char *, int, ...);
+ssize_t (*real_write)(int fd, const void *buf, size_t count);
+int (*real_printf)(const char *format, ...);
+int (*real_scanf)(const char *format, ...);
+void* (*real_malloc)(size_t size);
+
+
+void __attribute__ ((constructor)) preload_initialize(void);
+void __attribute__ ((destructor)) preload_finalize(void);
+
+void preload_initialize(void)
+{
+  real_open = dlsym(RTLD_NEXT, "open");
+  real_write = dlsym(RTLD_NEXT, "write");
+  real_printf = dlsym(RTLD_NEXT, "printf");
+  real_scanf = dlsym(RTLD_NEXT, "scanf");
+  real_malloc = dlsym(RTLD_NEXT, "malloc");
+}
+
+
+void preload_finalize(void)
+{
+}
+
+
+
+
+
+int printf(const char *format, ...)
+{
+  real_printf("[printf]  ");
+
+  va_list ap;
+  va_start(ap, format);
+  int rc = vprintf(format, ap);
+  va_end(ap);
+
+  return rc;
+}
+
+
+void *malloc(size_t size)
+{
+  void* ptr = real_malloc(size);
+  real_printf("[malloc] %x\n", ptr);
+  return ptr;
+}
+
+
+int __isoc99_scanf(const char *format, ...)
+{
+  real_printf("[scanf]\n");
+
+  va_list ap;
+  va_start(ap, format);
+  int rc = vscanf(format, ap);
+  va_end(ap);
+
+  return rc;
+}
+
+
+ssize_t write(int fd, const void *buf, size_t count)
+{
+  real_printf("[write]  ");
+
+  ssize_t rc;
+  rc = real_write(fd, buf, count);
+  return rc;
+}
+
+
+int open(const char *pathname, int flags, ...)
+{
+  real_printf("[open]  ");
+
+  int fd;
+  fd = real_open(pathname, flags);
+  return fd;
+}
+

test/Makefile

-Makefile.Linux

test/Makefile.Linux

-
-
-all: main directories
-
-main: main.o libexample.so
-	gcc main.o -L. -lexample -o example -Wl,-R,'$$ORIGIN/../lib'
-	readelf -d ./example  | grep RPATH
-
-main-preload:
-	make clean
-	make libpreload.so
-	GCCWRAP_LDFLAGS=-L.,-lpreload make 
-
-
-directories: 
-	rm -rf local
-	mkdir local
-	mkdir local/bin
-	mkdir local/lib
-	cp example local/bin/example
-	ln -sf libexample.so.1.0 local/lib/libexample.so
-	ln -sf libexample.so.1.0 local/lib/libexample.so.1
-	ln -sf ../../libexample.so.1.0 local/lib/libexample.so.1.0
-	ln -sf libpreload.so.1.0 local/lib/libpreload.so
-	ln -sf libpreload.so.1.0 local/lib/libpreload.so.1
-	ln -sf ../../libpreload.so.1.0 local/lib/libpreload.so.1.0
-
-
-main.o: main.c
-	gcc -Wall -fPIC -c -o main.o $^ 
-
-library.o: library.c
-	gcc -Wall -fPIC -c -o $@ $^ 
-
-libexample.so: library.o
-	gcc -shared -Wl,-soname,libexample.so.1 -L. -o libexample.so.1.0 library.o
-	ln -sf libexample.so.1.0 libexample.so
-	ln -sf libexample.so.1.0 libexample.so.1
-
-preload.o: preload.c
-	gcc -Wall -fPIC -c -o $@ $^ 
-
-libpreload.so: preload.o
-	gcc -shared -Wl,-soname,libpreload.so.1 -L. -o libpreload.so.1.0 preload.o -ldl
-	ln -sf libpreload.so.1.0 libpreload.so
-	ln -sf libpreload.so.1.0 libpreload.so.1
-
-.PHONY: clean all install
-
-clean:
-	rm -rf *~ *.o *.so* local
-

test/Makefile.OSX

-
-
-all: main directories
-
-main: main.o libexample.dylib 
-	gcc main.o -L. -lexample -o example
-	otool -L ./example
-
-
-main-preload:
-	make clean
-	make libpreload.dylib
-	GCCWRAP_LDFLAGS=-L.,-lpreload make 
-
-
-directories: 
-	rm -rf local
-	mkdir local
-	mkdir local/bin
-	mkdir local/lib
-	ln -sf ../../example local/bin/example
-	ln -sf ../../libexample.dylib local/lib/libexample.dylib
-	ln -sf ../../libexample.1.dylib local/lib/libexample.1.dylib
-	ln -sf ../../libpreload.dylib local/lib/libpreload.dylib
-	ln -sf ../../libpreload.1.dylib local/lib/libpreload.1.dylib
-
-main.o: main.c
-	gcc -Wall -fPIC -c -o main.o $^ 
-
-library.o: library.c
-	gcc -Wall -fPIC -c -o $@ $^ 
-
-libexample.dylib: library.o
-	gcc -dynamiclib -o libexample.1.dylib library.o
-	ln -sf libexample.1.dylib libexample.dylib
-
-preload.o: preload.c
-	gcc -Wall -fPIC -c -o $@ $^ 
-
-libpreload.dylib: preload.o
-	gcc -dynamiclib -o libpreload.1.dylib preload.o -ldl
-	ln -sf libpreload.1.dylib libpreload.dylib
-
-.PHONY: clean all install
-
-clean:
-	rm -rf *~ *.o *.dylib local
-

test/Makefile.Solaris

-
-
-all: main directories
-
-main: main.o libexample.so
-	gcc main.o -L. -lexample -o example -Wl,-R,'$$ORIGIN/../lib'
-	elfdump -d ./example  | grep RPATH
-
-main-preload:
-	make clean
-	make libpreload.so
-	GCCWRAP_LDFLAGS=-L.,-lpreload make 
-
-
-directories: 
-	rm -rf local
-	mkdir local
-	mkdir local/bin
-	mkdir local/lib
-	cp example local/bin/example
-	ln -sf libexample.so.1.0 local/lib/libexample.so
-	ln -sf libexample.so.1.0 local/lib/libexample.so.1
-	ln -sf ../../libexample.so.1.0 local/lib/libexample.so.1.0
-	ln -sf libpreload.so.1.0 local/lib/libpreload.so
-	ln -sf libpreload.so.1.0 local/lib/libpreload.so.1
-	ln -sf ../../libpreload.so.1.0 local/lib/libpreload.so.1.0
-
-
-main.o: main.c
-	gcc -Wall -fPIC -c -o main.o $^ 
-
-library.o: library.c
-	gcc -Wall -fPIC -c -o $@ $^ 
-
-libexample.so: library.o
-	gcc -shared -Wl,-h,libexample.so.1 -L. -o libexample.so.1.0 library.o
-	ln -sf libexample.so.1.0 libexample.so
-	ln -sf libexample.so.1.0 libexample.so.1
-
-preload.o: preload.c
-	gcc -Wall -fPIC -c -o $@ $^ 
-
-libpreload.so: preload.o
-	gcc -shared -Wl,-h,libpreload.so.1 -L. -o libpreload.so.1.0 preload.o -ldl
-	ln -sf libpreload.so.1.0 libpreload.so
-	ln -sf libpreload.so.1.0 libpreload.so.1
-
-.PHONY: clean all install
-
-clean:
-	rm -rf *~ *.o *.so* local
-

test/library.c

-#include <stdio.h>
-#include <stdlib.h>
-
-
-void libraryfunction(int *x)
-{
-  printf("libraryfunction()\n");
-   *x = 10;
-
-   printf("malloc() in library.c\n");
-   malloc(42);
-}
-

test/main.c

-#include <stdio.h>
-#include <unistd.h>
-#include <stdlib.h>
-
-void libraryfunction(int *);
-
-int main()
-{
-   int x;
-   libraryfunction(&x);
-   printf("main(): x=%d\n",x);
-
-   printf("Enter a number: ");
-   scanf("%d", &x);
-   printf("You entered: %d\n", x);
-
-   printf("malloc() in main.c\n");
-   malloc(42);
-
-   fflush(stdout);
-   return 0;
-}
-      

test/preload.c

-#define _GNU_SOURCE
-#include <dlfcn.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <assert.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <stdlib.h>
-
-
-static int (*real_open)(const char *, int, ...);
-ssize_t (*real_write)(int fd, const void *buf, size_t count);
-int (*real_printf)(const char *format, ...);
-int (*real_scanf)(const char *format, ...);
-void* (*real_malloc)(size_t size);
-
-
-void __attribute__ ((constructor)) preload_initialize(void);
-void __attribute__ ((destructor)) preload_finalize(void);
-
-void preload_initialize(void)
-{
-  real_open = dlsym(RTLD_NEXT, "open");
-  real_write = dlsym(RTLD_NEXT, "write");
-  real_printf = dlsym(RTLD_NEXT, "printf");
-  real_scanf = dlsym(RTLD_NEXT, "scanf");
-  real_malloc = dlsym(RTLD_NEXT, "malloc");
-}
-
-
-void preload_finalize(void)
-{
-}
-
-
-
-
-
-int printf(const char *format, ...)
-{
-  real_printf("[printf]  ");
-
-  va_list ap;
-  va_start(ap, format);
-  int rc = vprintf(format, ap);
-  va_end(ap);
-
-  return rc;
-}
-
-
-void *malloc(size_t size)
-{
-  void* ptr = real_malloc(size);
-  real_printf("[malloc] %x\n", ptr);
-  return ptr;
-}
-
-
-int __isoc99_scanf(const char *format, ...)
-{
-  real_printf("[scanf]\n");
-
-  va_list ap;
-  va_start(ap, format);
-  int rc = vscanf(format, ap);
-  va_end(ap);
-
-  return rc;
-}
-
-
-ssize_t write(int fd, const void *buf, size_t count)
-{
-  real_printf("[write]  ");
-
-  ssize_t rc;
-  rc = real_write(fd, buf, count);
-  return rc;
-}
-
-
-int open(const char *pathname, int flags, ...)
-{
-  real_printf("[open]  ");
-
-  int fd;
-  fd = real_open(pathname, flags);
-  return fd;
-}
-