aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcnlohr <lohr85@gmail.com>2017-03-14 21:25:53 -0400
committercnlohr <lohr85@gmail.com>2017-03-14 21:25:53 -0400
commit99b615ba75f24e48b713e9b23ae596d7ddf1c59b (patch)
tree5fb377265e9e38e441dd469043da88d3f237cd92
parent9aabbe7720b3c315048f977642e4bb8e387b572a (diff)
downloadlibsurvive-99b615ba75f24e48b713e9b23ae596d7ddf1c59b.tar.gz
libsurvive-99b615ba75f24e48b713e9b23ae596d7ddf1c59b.tar.bz2
Handle autoregistration of startup functions.
-rw-r--r--Makefile6
-rw-r--r--redist/symbol_enumerator.c4
-rwxr-xr-xsrc/survive.c23
3 files changed, 28 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index 29b2164..19f7c40 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ all : lib data_recorder test calibrate calibrate_client
CC:=gcc
-CFLAGS:=-Iinclude/libsurvive -I. -fPIC -g -O0 -Iredist -flto -DUSE_DOUBLE -std=gnu99
+CFLAGS:=-Iinclude/libsurvive -I. -fPIC -g -O0 -Iredist -flto -DUSE_DOUBLE -std=gnu99 -rdynamic
LDFLAGS:=-lpthread -lusb-1.0 -lz -lX11 -lm -flto -g
POSERS:=src/poser_dummy.o src/poser_daveortho.o src/poser_charlesslow.o
@@ -37,6 +37,10 @@ lib:
lib/libsurvive.so : $(LIBSURVIVE_O)
$(CC) -o $@ $^ $(LDFLAGS) -shared
+
+calibrate_tcc : $(LIBSURVIVE_C)
+ tcc -DRUNTIME_SYMNUM $(CFLAGS) -o $@ $^ $(LDFLAGS) calibrate.c redist/XDriver.c redist/os_generic.c redist/DrawFunctions.c redist/symbol_enumerator.c
+
clean :
rm -rf *.o src/*.o *~ src/*~ test data_recorder lib/libsurvive.so redist/*.o redist/*~
diff --git a/redist/symbol_enumerator.c b/redist/symbol_enumerator.c
index 756a1ca..eddddb9 100644
--- a/redist/symbol_enumerator.c
+++ b/redist/symbol_enumerator.c
@@ -87,8 +87,6 @@ int EnumerateSymbols( SymEnumeratorCallback cb )
#include <limits.h>
#include <string.h>
-#include "elf_enum.h"
-
#ifndef __GNUC__
#define __int128_t long long long
#endif
@@ -240,4 +238,4 @@ int EnumerateSymbols( SymEnumeratorCallback cb )
-#endif \ No newline at end of file
+#endif
diff --git a/src/survive.c b/src/survive.c
index d786d3d..0e567ad 100755
--- a/src/survive.c
+++ b/src/survive.c
@@ -9,6 +9,23 @@
#include "survive_config.h"
+#ifdef RUNTIME_SYMNUM
+#include <symbol_enumerator.h>
+static int did_runtime_symnum;
+int SymnumCheck( const char * path, const char * name, void * location, long size )
+{
+ printf( "--->%s\n", name );
+ if( strncmp( name, "REGISTER", 8 ) == 0 )
+ {
+ typedef void (*sf)();
+ sf fn = (sf)location;
+ fn();
+ }
+ return 0;
+}
+
+#endif
+
static void survivefault( struct SurviveContext * ctx, const char * fault )
{
fprintf( stderr, "Error: %s\n", fault );
@@ -23,6 +40,10 @@ static void survivenote( struct SurviveContext * ctx, const char * fault )
SurviveContext * survive_init( int headless )
{
+#ifdef RUNTIME_SYMNUM
+ EnumerateSymbols( SymnumCheck );
+#endif
+
int r = 0;
int i = 0;
SurviveContext * ctx = calloc( 1, sizeof( SurviveContext ) );
@@ -266,4 +287,4 @@ int survive_simple_inflate( struct SurviveContext * ctx, const char * input, int
return len;
}
-#endif \ No newline at end of file
+#endif