diff --git a/libstdc++-v3/scripts/testsuite_flags.in b/libstdc++-v3/scripts/testsuite_flags.in
index cf7f0f7411e..40dd3d3465e 100755
--- a/libstdc++-v3/scripts/testsuite_flags.in
+++ b/libstdc++-v3/scripts/testsuite_flags.in
@@ -78,7 +78,8 @@ case ${query} in
       ;;
     --cxxldflags)
       SECTIONLDFLAGS="@SECTION_LDFLAGS@ @LIBICONV@
-                      -L${BUILD_DIR}/src/filesystem/.libs"
+                      -L${BUILD_DIR}/src/filesystem/.libs
+                      -L${BUILD_DIR}/src/libbacktrace/.libs"
       echo ${SECTIONLDFLAGS}
       ;;
     *)
diff --git a/libstdc++-v3/src/Makefile.am b/libstdc++-v3/src/Makefile.am
index 71a0da2cd93..18f57632c3d 100644
--- a/libstdc++-v3/src/Makefile.am
+++ b/libstdc++-v3/src/Makefile.am
@@ -30,8 +30,10 @@ endif
 
 if ENABLE_BACKTRACE
 backtrace_dir = libbacktrace
+backtrace_supported_h = $(backtrace_dir)/backtrace-supported.h
 else
 backtrace_dir =
+backtrace_supported_h =
 endif
 
 ## Keep this list sync'd with acinclude.m4:GLIBCXX_CONFIGURE.
@@ -402,7 +404,15 @@ stamp-debug: Makefile $(foreach dir,$(SUBDIRS),$(dir)/Makefile)
 	fi; \
 	echo `date` > stamp-debug;
 
-build-debug: stamp-debug
+if ENABLE_BACKTRACE
+${debugdir}/$(backtrace_supported_h): $(backtrace_supported_h) stamp-debug
+	cp $< $@
+debug_backtrace_supported_h = ${debugdir}/$(backtrace_supported_h)
+else
+debug_backtrace_supported_h =
+endif
+
+build-debug: stamp-debug $(debug_backtrace_supported_h)
 	  (cd ${debugdir}; \
 	  mv Makefile Makefile.tmp; \
 	  sed -e 's,all-local: all-once,all-local:,' \
diff --git a/libstdc++-v3/src/libbacktrace/Makefile.am b/libstdc++-v3/src/libbacktrace/Makefile.am
index 3a3195167b2..0f1143507f3 100644
--- a/libstdc++-v3/src/libbacktrace/Makefile.am
+++ b/libstdc++-v3/src/libbacktrace/Makefile.am
@@ -35,9 +35,12 @@ toolexeclib_LTLIBRARIES = libstdc++_libbacktrace.la
 
 ACLOCAL_AMFLAGS = -I ../.. -I ../../config
 
-AM_CPPFLAGS = -I $(top_srcdir)/../include -I $(top_srcdir)/../libgcc \
+# This will be used instead of the common AM_CPPFLAGS from fragment.am
+libstdc___libbacktrace_la_CPPFLAGS = \
+	-I $(top_srcdir)/../include -I $(top_srcdir)/../libgcc \
 	-I ../../../libgcc -I .. -I $(top_srcdir) \
 	-I $(top_srcdir)/../libbacktrace \
+	-I $(top_srcdir)/../libiberty \
 	-include $(top_srcdir)/src/libbacktrace/backtrace-rename.h \
 	$(BACKTRACE_CPPFLAGS)
 
@@ -50,42 +53,55 @@ AM_CFLAGS += $(EXTRA_CFLAGS)
 AM_CXXFLAGS = $(CXX_WARN_FLAGS) -fno-rtti -fno-exceptions
 AM_CXXFLAGS += $(EXTRA_CXXFLAGS)
 
+obj_prefix = std_stacktrace
+
+# Each FILE.c in SOURCES will be compiled to SHORTNAME-FILE.o
+libstdc___libbacktrace_la_SHORTNAME = $(obj_prefix)
+
 libstdc___libbacktrace_la_SOURCES = \
-	../../../libbacktrace/backtrace.h \
-	../../../libbacktrace/atomic.c \
-	../../../libbacktrace/dwarf.c \
-	../../../libbacktrace/fileline.c \
-	../../../libbacktrace/internal.h \
-	../../../libbacktrace/posix.c \
-	../../../libbacktrace/sort.c \
-	../../../libbacktrace/simple.c \
-	../../../libbacktrace/state.c \
-	../../../libiberty/cp-demangle.c
+	atomic.c \
+	dwarf.c \
+	fileline.c \
+	posix.c \
+	sort.c \
+	simple.c \
+	state.c \
+	cp-demangle.c
 
 FORMAT_FILES = \
-	../../../libbacktrace/elf.c \
-	../../../libbacktrace/unknown.c
+	elf.c \
+	unknown.c
 
 VIEW_FILES = \
-	../../../libbacktrace/read.c \
-	../../../libbacktrace/mmapio.c
+	read.c \
+	mmapio.c
 
 ALLOC_FILES = \
-	../../../libbacktrace/alloc.c \
-	../../../libbacktrace/mmap.c
+	alloc.c \
+	mmap.c
 
 EXTRA_libstdc___libbacktrace_la_SOURCES = \
 	$(FORMAT_FILES) \
 	$(VIEW_FILES) \
 	$(ALLOC_FILES)
 
+# These three files are chosen by configure and added to the link.
+# We need the SHORTNAME- prefix so that they use the custom CPPFLAGS above.
 libstdc___libbacktrace_la_LIBADD = \
-	$(FORMAT_FILE) \
-	$(VIEW_FILE) \
-	$(ALLOC_FILE)
+	$(obj_prefix)-$(FORMAT_FILE) \
+	$(obj_prefix)-$(VIEW_FILE) \
+	$(obj_prefix)-$(ALLOC_FILE)
 
 libstdc___libbacktrace_la_DEPENDENCIES = $(libstdc___libbacktrace_la_LIBADD)
 
+# Use symlinks for the sources
+
+%.c: ../../../libbacktrace/%.c
+	$(LN_S) $< $@
+
+cp-demangle.c: ../../../libiberty/cp-demangle.c
+	$(LN_S) $< $@
+
 LTCOMPILE = \
 	$(LIBTOOL) --tag CC --tag disable-shared \
 	$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
