git » libfiu » commit 6a7a14a

tests: Add required flags to the stack tests

author Alberto Bertogli
2015-08-15 21:16:37 UTC
committer Alberto Bertogli
2015-08-16 11:21:22 UTC
parent c4ea63fd1684be407c9df9a76c020d0a3961a473

tests: Add required flags to the stack tests

Tests that use the stack need special build flags, as some common
optimizations can cause them to fail.

-rdynamic: Adds all symbols to the dynamic symbol table. This option is needed
   for backtrace() to work properly.

-fno-optimize-sibling-calls: This optimization can turn some calls into direct
   jumps, which leaves caller information out of the stack frame and makes
   functions not appear in the backtrace.
   We disable it inconditionally. It's only enabled at -O2 and above, which
   some users may pass.

This patch adds those flags only to the stack tests.

It also avoids generating the intermediate .o because they're not particularly
useful.

tests/Makefile +13 -5

diff --git a/tests/Makefile b/tests/Makefile
index 5d8ec6e..ad754ac 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -1,5 +1,5 @@
 
-CFLAGS += -std=c99 -pedantic -Wall -rdynamic
+CFLAGS += -std=c99 -pedantic -Wall
 ALL_CFLAGS = -I../libfiu/ -L../libfiu/ \
 	-D_XOPEN_SOURCE=600 -D_GNU_SOURCE -fPIC -DFIU_ENABLE=1 $(CFLAGS)
 
@@ -53,9 +53,20 @@ C_BINS := $(patsubst %.c,%,$(C_SRCS))
 
 c-tests: $(patsubst %.c,c-run-%,$(C_SRCS))
 
-test-%: test-%.o build-flags
+test-%: test-%.c build-flags
 	$(NICE_CC) $(ALL_CFLAGS) $< -lfiu -lpthread -o $@
 
+# Tests that use the stack need special build flags, as some common
+# optimizations can cause them to fail.
+# -rdynamic: Adds all symbols to the dynamic symbol table. This option is
+#    needed for backtrace() to work properly.
+# -fno-optimize-sibling-calls: This optimization can turn some calls into
+#    direct jumps, which leaves caller information out of the stack frame and
+#    makes functions not appear in the backtrace. We disable it.
+test-enable_stac%: test-enable_stac%.c build-flags
+	$(NICE_CC) $(ALL_CFLAGS) -lfiu -lpthread \
+		-rdynamic -fno-optimize-sibling-calls $< -o $@
+
 c-run-%: %
 	$(NICE_RUN) ./$<
 
@@ -69,9 +80,6 @@ build-flags: .force-build-flags
 		echo "$(BF)" > build-flags; \
 	fi
 
-.c.o:
-	$(NICE_CC) $(ALL_CFLAGS) -c $< -o $@
-
 
 #
 # Python tests