Index: tests/Makefile.am
===================================================================
--- tests/Makefile.am	(revision 2aa25cc246cb459caed9ef2620e76d91b5dca91d)
+++ tests/Makefile.am	(revision 673eb7a23c93903af14453c0bbf51106c4b15ca2)
@@ -60,4 +60,5 @@
 # adjusted CC but without the actual distcc call
 CFACCLOCAL = $(if $(DISTCC_CFA_PATH),$(DISTCC_CFA_PATH) ${ARCH_FLAGS},$(TARGET_CFA) ${DEBUG_FLAGS} ${ARCH_FLAGS})
+CFACCLINK = $(CFACCLOCAL) $(if $(test), 2> $(test), ) $($(shell echo "${@}_FLAGSLD" | sed 's/-\|\//_/g'))
 
 PRETTY_PATH=mkdir -p $(dir $(abspath ${@})) && cd ${srcdir} &&
@@ -112,5 +113,5 @@
 % : %.cfa $(CFACCBIN)
 	$(CFACOMPILETEST) -c -o $(abspath ${@}).o
-	$(CFACCLOCAL) $(if $(test), 2> $(test), ) $($(shell echo "${@}_FLAGSLD" | sed 's/-\|\//_/g')) ${@}.o -o $(abspath ${@})
+	$(CFACCLINK) ${@}.o -o $(abspath ${@})
 
 # implicit rule for c++ test
@@ -176,4 +177,10 @@
 	$(CFACCLOCAL) $($(shell echo "${@}_FLAGSLD" | sed 's/-\|\//_/g')) $(abspath ${@}).o -o $(abspath ${@})
 
+# Linking tests
+# Meta tests to make sure we see linking errors (can't compile with -O2 since it may multiply number of calls)
+linking/linkerror : linking/linkerror.cfa $(CFACCBIN)
+	$(CFACOMPILETEST) -O0 -c -o $(abspath ${@}).o
+	$(CFACCLINK)  -O0 ${@}.o -o $(abspath ${@})
+
 #------------------------------------------------------------------------------
 # Other targets
