add size optimization options
authorSzabolcs Nagy <nsz@port70.net>
Wed, 8 Jan 2014 04:07:37 +0000 (05:07 +0100)
committerSzabolcs Nagy <nsz@port70.net>
Wed, 8 Jan 2014 04:07:37 +0000 (05:07 +0100)
Makefile
stress.c
wrap.c

index c0d1a68..a78a1ff 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,5 @@
 CFLAGS=-std=c99 -Os -g
+#CFLAGS+=-fomit-frame-pointer -fno-unwind-tables -fno-asynchronous-unwind-tables
 LDFLAGS=-g
 CC=musl-gcc
 all: wrap.so hello stress
@@ -8,7 +9,7 @@ wrap.o: head.h func.h
 wrap.so: wrap.o
        $(CC) $(LDFLAGS) -shared -o $@ $< -ldl -lm -lrt -lcrypt
 clean:
-       rm -f wrap.so hello *.o
+       rm -f wrap.so hello stress *.o
 test: all
        LD_PRELOAD=./wrap.so ./hello
        LD_PRELOAD=./wrap.so ./stress 2>&1 |wc -l
index 435d009..7170ed9 100644 (file)
--- a/stress.c
+++ b/stress.c
@@ -5,7 +5,7 @@ int main()
        int i, j;
        char * volatile p = "";
        char * volatile q = "";
-       for (i=0; i<10000; i++)
+       for (i=0; i<100000; i++)
                j += strcmp(p,q);
        return j;
 }
diff --git a/wrap.c b/wrap.c
index a4144db..a24b4a2 100644 (file)
--- a/wrap.c
+++ b/wrap.c
@@ -5,10 +5,13 @@
 
 // dprintf and dlsym are not wrapped
 
+//static void print(const char *s) { dprintf(2, "%s\n", s); }
+#define print(s) dprintf(2, s"\n")
+
 #define F(ret,name,args,args2) ret (name)args \
 { \
        static ret (*p__)args; \
-       dprintf(2, #name "\n"); \
+       print(#name); \
        if (!p__) p__ = dlsym(RTLD_NEXT, #name); \
        return p__ args2; \
 }
@@ -16,7 +19,7 @@
 #define V(v,name,args,args2) v (name)args \
 { \
        static v (*p__)args; \
-       dprintf(2, #name "\n"); \
+       print(#name); \
        if (!p__) p__ = dlsym(RTLD_NEXT, #name); \
        p__ args2; \
 }