Patchwork Add --with-build-config=bootstrap-asan support

login
register
mail settings
Submitter H.J. Lu
Date Nov. 22, 2012, 8:37 p.m.
Message ID <20121122203747.GA4264@gmail.com>
Download mbox | patch
Permalink /patch/201189/
State New
Headers show

Comments

H.J. Lu - Nov. 22, 2012, 8:37 p.m.
Hi,

This patch adds --with-build-config=bootstrap-asan support.  Tested on
Linux/x86-64.  OK to install?

Thanks.


H.J.
---
2012-11-21  H.J. Lu  <hongjiu.lu@intel.com>

	* Makefile.def (target_modules): Add bootstrap=true and
	raw_cxx=true to libsanitizer.
	* configure.ac (bootstrap_target_libs): Add libsanitizer.
	* Makefile.in: Regenerated.
	* configure: Likewise.

config/

2012-11-21  H.J. Lu  <hongjiu.lu@intel.com>

	* bootstrap-asan.mk: New file.
Jakub Jelinek - Nov. 29, 2012, 3:20 p.m.
On Thu, Nov 22, 2012 at 12:37:47PM -0800, H.J. Lu wrote:
> 2012-11-21  H.J. Lu  <hongjiu.lu@intel.com>
> 
> 	* Makefile.def (target_modules): Add bootstrap=true and
> 	raw_cxx=true to libsanitizer.
> 	* configure.ac (bootstrap_target_libs): Add libsanitizer.
> 	* Makefile.in: Regenerated.
> 	* configure: Likewise.
> 
> config/
> 
> 2012-11-21  H.J. Lu  <hongjiu.lu@intel.com>
> 
> 	* bootstrap-asan.mk: New file.

Ok, thanks.

	Jakub
Tobias Burnus - Nov. 29, 2012, 5:36 p.m.
H.J. Lu wrote:
> This patch adds --with-build-config=bootstrap-asan support.  Tested on
> Linux/x86-64.  OK to install?

I think that patch has broken bootstrap for me. If I do a normal 
bootstrap, Stage1 fails with:

libtool: compile: unrecognized option `-D_GNU_SOURCE'
libtool: compile: Try `libtool --help' for more information.
make[4]: *** [interception_linux.lo] Error 1
make[4]: Leaving directory 
`/home/burnus/gcc/build/x86_64-unknown-linux-gnu/libsanitizer/interception'


Actually, I wonder why it is build in stage 1. Shouldn't it be a target 
library which only built later (except with bootstrap-asan)?

Tobias
H.J. Lu - Nov. 29, 2012, 5:44 p.m.
On Thu, Nov 29, 2012 at 9:36 AM, Tobias Burnus <burnus@net-b.de> wrote:
> H.J. Lu wrote:
>>
>> This patch adds --with-build-config=bootstrap-asan support.  Tested on
>> Linux/x86-64.  OK to install?
>
>
> I think that patch has broken bootstrap for me. If I do a normal bootstrap,
> Stage1 fails with:
>
> libtool: compile: unrecognized option `-D_GNU_SOURCE'
> libtool: compile: Try `libtool --help' for more information.
> make[4]: *** [interception_linux.lo] Error 1
> make[4]: Leaving directory
> `/home/burnus/gcc/build/x86_64-unknown-linux-gnu/libsanitizer/interception'
>
>
> Actually, I wonder why it is build in stage 1. Shouldn't it be a target
> library which only built later (except with bootstrap-asan)?
>

Please try this:

http://gcc.gnu.org/ml/gcc-patches/2012-11/msg01530.html
Tobias Burnus - Nov. 29, 2012, 6:03 p.m.
H.J. Lu wrote:
> Please try this: http://gcc.gnu.org/ml/gcc-patches/2012-11/msg01530.html 

I just did locally "git log -2 -p|patch -p1 -R" - and wait until you 
sort that out with the patch reviewers, which seemingly didn't like that 
patch.


BTW: I am not sure whether it is possible with the current build system, 
but I'd prefer: if libsanitizer is not needed (i.e. no bootstrap-asan is 
used), it is only build as target library in stage2/stage3 and not also 
in stage1 as host library.



Tobias Burnus wrote:
> I think that patch has broken bootstrap for me. If I do a normal 
> bootstrap, Stage1 fails with:

I should have quoted more. Note that the "g++" or similar is missing 
before "-D_GNU_SOURCE":

/bin/sh ../libtool --tag=CXX   --mode=compile  -D_GNU_SOURCE -D_DEBUG 
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS  
-I. -I../../../../libsanitizer/interception -I 
../../../../libsanitizer/include   -Wall -W -Wno-unused-parameter 
-Wwrite-strings -pedantic -Wno-long-long  -fPIC -fno-builtin 
-fno-exceptions -fomit-frame-pointer -funwind-tables -fvisibility=hidden 
-Wno-variadic-macros -Wno-c99-extensions  -g -O2 -D_GNU_SOURCE -MT 
interception_mac.lo -MD -MP -MF .deps/interception_mac.Tpo -c -o 
interception_mac.lo 
../../../../libsanitizer/interception/interception_mac.cc

Thus, for libsanitizer, the $(CXX) variable is not set, when invoked via 
build root's Makefile. Which gets set via 'CXX=$$(RAW_CXX_FOR_TARGET)'

Tobias
Paolo Carlini - Nov. 29, 2012, 6:24 p.m.
On 11/29/2012 06:36 PM, Tobias Burnus wrote:
> H.J. Lu wrote:
>> This patch adds --with-build-config=bootstrap-asan support.  Tested on
>> Linux/x86-64.  OK to install?
>
> I think that patch has broken bootstrap for me. If I do a normal 
> bootstrap, Stage1 fails with:
>
> libtool: compile: unrecognized option `-D_GNU_SOURCE'
> libtool: compile: Try `libtool --help' for more information.
> make[4]: *** [interception_linux.lo] Error 1
> make[4]: Leaving directory 
> `/home/burnus/gcc/build/x86_64-unknown-linux-gnu/libsanitizer/interception'
Likewise here. Would it be possible to revert the offending commit, in 
the meanwhile?

Thanks,
Paolo.
H.J. Lu - Nov. 29, 2012, 6:32 p.m.
On Thu, Nov 29, 2012 at 10:24 AM, Paolo Carlini
<paolo.carlini@oracle.com> wrote:
> On 11/29/2012 06:36 PM, Tobias Burnus wrote:
>>
>> H.J. Lu wrote:
>>>
>>> This patch adds --with-build-config=bootstrap-asan support.  Tested on
>>> Linux/x86-64.  OK to install?
>>
>>
>> I think that patch has broken bootstrap for me. If I do a normal
>> bootstrap, Stage1 fails with:
>>
>> libtool: compile: unrecognized option `-D_GNU_SOURCE'
>> libtool: compile: Try `libtool --help' for more information.
>> make[4]: *** [interception_linux.lo] Error 1
>> make[4]: Leaving directory
>> `/home/burnus/gcc/build/x86_64-unknown-linux-gnu/libsanitizer/interception'
>
> Likewise here. Would it be possible to revert the offending commit, in the
> meanwhile?
>

This is a known problem.  Please try:

http://gcc.gnu.org/ml/gcc-patches/2012-11/msg02480.html

I updated my patch for the newly added tsan.  It fixed
bootstrap on Linux/ia32.
H.J. Lu - Nov. 29, 2012, 7:03 p.m.
On Thu, Nov 29, 2012 at 10:32 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Thu, Nov 29, 2012 at 10:24 AM, Paolo Carlini
> <paolo.carlini@oracle.com> wrote:
>> On 11/29/2012 06:36 PM, Tobias Burnus wrote:
>>>
>>> H.J. Lu wrote:
>>>>
>>>> This patch adds --with-build-config=bootstrap-asan support.  Tested on
>>>> Linux/x86-64.  OK to install?
>>>
>>>
>>> I think that patch has broken bootstrap for me. If I do a normal
>>> bootstrap, Stage1 fails with:
>>>
>>> libtool: compile: unrecognized option `-D_GNU_SOURCE'
>>> libtool: compile: Try `libtool --help' for more information.
>>> make[4]: *** [interception_linux.lo] Error 1
>>> make[4]: Leaving directory
>>> `/home/burnus/gcc/build/x86_64-unknown-linux-gnu/libsanitizer/interception'
>>
>> Likewise here. Would it be possible to revert the offending commit, in the
>> meanwhile?
>>
>
> This is a known problem.  Please try:
>
> http://gcc.gnu.org/ml/gcc-patches/2012-11/msg02480.html
>
> I updated my patch for the newly added tsan.  It fixed
> bootstrap on Linux/ia32.
>

I checked in my patch to restore bootstrap after tested
on Linux/ia32 and Linux/x86-64.  I will revert both patches
if my fix is incorrect.
Andrew Pinski - Nov. 29, 2012, 7:05 p.m.
On Thu, Nov 29, 2012 at 11:03 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Thu, Nov 29, 2012 at 10:32 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Thu, Nov 29, 2012 at 10:24 AM, Paolo Carlini
>> <paolo.carlini@oracle.com> wrote:
>>> On 11/29/2012 06:36 PM, Tobias Burnus wrote:
>>>>
>>>> H.J. Lu wrote:
>>>>>
>>>>> This patch adds --with-build-config=bootstrap-asan support.  Tested on
>>>>> Linux/x86-64.  OK to install?
>>>>
>>>>
>>>> I think that patch has broken bootstrap for me. If I do a normal
>>>> bootstrap, Stage1 fails with:
>>>>
>>>> libtool: compile: unrecognized option `-D_GNU_SOURCE'
>>>> libtool: compile: Try `libtool --help' for more information.
>>>> make[4]: *** [interception_linux.lo] Error 1
>>>> make[4]: Leaving directory
>>>> `/home/burnus/gcc/build/x86_64-unknown-linux-gnu/libsanitizer/interception'
>>>
>>> Likewise here. Would it be possible to revert the offending commit, in the
>>> meanwhile?
>>>
>>
>> This is a known problem.  Please try:
>>
>> http://gcc.gnu.org/ml/gcc-patches/2012-11/msg02480.html
>>
>> I updated my patch for the newly added tsan.  It fixed
>> bootstrap on Linux/ia32.
>>
>
> I checked in my patch to restore bootstrap after tested
> on Linux/ia32 and Linux/x86-64.  I will revert both patches
> if my fix is incorrect.

This is not how patch review is supposed to work.

Thanks,
Andrew
Jakub Jelinek - Nov. 29, 2012, 7:06 p.m.
On Thu, Nov 29, 2012 at 07:24:38PM +0100, Paolo Carlini wrote:
> On 11/29/2012 06:36 PM, Tobias Burnus wrote:
> >H.J. Lu wrote:
> >>This patch adds --with-build-config=bootstrap-asan support.  Tested on
> >>Linux/x86-64.  OK to install?
> >
> >I think that patch has broken bootstrap for me. If I do a normal
> >bootstrap, Stage1 fails with:
> >
> >libtool: compile: unrecognized option `-D_GNU_SOURCE'
> >libtool: compile: Try `libtool --help' for more information.
> >make[4]: *** [interception_linux.lo] Error 1
> >make[4]: Leaving directory `/home/burnus/gcc/build/x86_64-unknown-linux-gnu/libsanitizer/interception'
> Likewise here. Would it be possible to revert the offending commit,
> in the meanwhile?

Yes, H.J., please revert the patch, I thought you have tested it alone
without any further patches.  For the -I patch, I really would prefer if
libsanitizer just had a dependency on libstdc++ at toplevel
(configure-target-sanitizer depending on all-target-libstdc++-v3),
then you can (and similarly for host variants if we need host sanitizer at
all).  Then you should be able to use scripts/testsuite_flags
--build-includes just fine.

	Jakub
H.J. Lu - Nov. 29, 2012, 7:26 p.m.
On Thu, Nov 29, 2012 at 11:06 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Thu, Nov 29, 2012 at 07:24:38PM +0100, Paolo Carlini wrote:
>> On 11/29/2012 06:36 PM, Tobias Burnus wrote:
>> >H.J. Lu wrote:
>> >>This patch adds --with-build-config=bootstrap-asan support.  Tested on
>> >>Linux/x86-64.  OK to install?
>> >
>> >I think that patch has broken bootstrap for me. If I do a normal
>> >bootstrap, Stage1 fails with:
>> >
>> >libtool: compile: unrecognized option `-D_GNU_SOURCE'
>> >libtool: compile: Try `libtool --help' for more information.
>> >make[4]: *** [interception_linux.lo] Error 1
>> >make[4]: Leaving directory `/home/burnus/gcc/build/x86_64-unknown-linux-gnu/libsanitizer/interception'
>> Likewise here. Would it be possible to revert the offending commit,
>> in the meanwhile?
>
> Yes, H.J., please revert the patch, I thought you have tested it alone

Done.

> without any further patches.  For the -I patch, I really would prefer if
> libsanitizer just had a dependency on libstdc++ at toplevel
> (configure-target-sanitizer depending on all-target-libstdc++-v3),
> then you can (and similarly for host variants if we need host sanitizer at
> all).  Then you should be able to use scripts/testsuite_flags
> --build-includes just fine.
>

From Makefile.tpl:

@if target-libstdc++-v3
# CXX_FOR_TARGET is tricky to get right for target libs that require a
# functional C++ compiler.  When we recurse, if we expand
# CXX_FOR_TARGET before configuring libstdc++-v3, we won't get
# libstdc++ include flags from the script.  Instead, we get an
# -funconfigured-* word, so that we'll get errors if this invalid C++
# command line is used for anything, but also so that we can use the
# word to decide whether or not to pass on this CXX_FOR_TARGET.  If we
# don't pass it on, sub-make will use the default definition, that
# re-expands it at the time of use, so we'll get it right when we need
# it.  One potential exception is the expansion of CXX_FOR_TARGET
# passed down as part of CXX within TARGET_FLAGS, but this wouldn't
# really work, for C++ host programs can't depend on the current-stage
# C++ target library.
CXX_FOR_TARGET_FLAG_TO_PASS = \
        $(shell if echo "$(CXX_FOR_TARGET)" | grep " -funconfigured-"
> /dev/null; then :; else echo '"CXX_FOR_TARGET=$(CXX_FOR_TARGET)"';
fi)
@endif target-libstdc++-v3

bootstrap library in C++ has raw_cxx=true and

CXX_FOR_TARGET=$(STAGE_CC_WRAPPER) $$r/$(HOST_SUBDIR)/gcc/g++
-B$$r/$(HOST_SUBDIR)/gcc/ -nostdinc++ `if test -f
$$r/$(TARGET_SUBDIR)/libstdc++-v3/scripts/testsuite_flags; then
$(SHELL) $$r/$(TARGET_SUBDIR)/libstdc++-v3/scripts/testsuite_flags
--build-includes; else echo -funconfigured-libstdc++-v3 ; fi`
-L$$r/$(TARGET_SUBDIR)/libstdc++-v3/src
-L$$r/$(TARGET_SUBDIR)/libstdc++-v3/src/.libs
RAW_CXX_FOR_TARGET=$(STAGE_CC_WRAPPER) $$r/$(HOST_SUBDIR)/gcc/xgcc
-shared-libgcc -B$$r/$(HOST_SUBDIR)/gcc -nostdinc++
-L$$r/$(TARGET_SUBDIR)/libstdc++-v3/src
-L$$r/$(TARGET_SUBDIR)/libstdc++-v3/src/.libs

That is why we need to explicit -I for libstdc++ header files.
If we remove raw_cxx=true from bootstrap C++ library, which
include libstdc++ and libjava, they won't compile for multitib.
scripts/testsuite_flags can not be used to compile bootstrap library
in C++.
H.J. Lu - Nov. 29, 2012, 8:20 p.m.
On Thu, Nov 29, 2012 at 11:06 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Thu, Nov 29, 2012 at 07:24:38PM +0100, Paolo Carlini wrote:
>> On 11/29/2012 06:36 PM, Tobias Burnus wrote:
>> >H.J. Lu wrote:
>> >>This patch adds --with-build-config=bootstrap-asan support.  Tested on
>> >>Linux/x86-64.  OK to install?
>> >
>> >I think that patch has broken bootstrap for me. If I do a normal
>> >bootstrap, Stage1 fails with:
>> >
>> >libtool: compile: unrecognized option `-D_GNU_SOURCE'
>> >libtool: compile: Try `libtool --help' for more information.
>> >make[4]: *** [interception_linux.lo] Error 1
>> >make[4]: Leaving directory `/home/burnus/gcc/build/x86_64-unknown-linux-gnu/libsanitizer/interception'
>> Likewise here. Would it be possible to revert the offending commit,
>> in the meanwhile?
>
> Yes, H.J., please revert the patch, I thought you have tested it alone
> without any further patches.  For the -I patch, I really would prefer if
> libsanitizer just had a dependency on libstdc++ at toplevel
> (configure-target-sanitizer depending on all-target-libstdc++-v3),
> then you can (and similarly for host variants if we need host sanitizer at
> all).  Then you should be able to use scripts/testsuite_flags
> --build-includes just fine.

I opened:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55533

to explain why scripts/testsuite_flags doesn't work when
bootstrapping libsanitizer.
Jakub Jelinek - Dec. 3, 2012, 11:52 a.m.
Hi!

On Thu, Nov 29, 2012 at 12:20:39PM -0800, H.J. Lu wrote:
> On Thu, Nov 29, 2012 at 11:06 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> > On Thu, Nov 29, 2012 at 07:24:38PM +0100, Paolo Carlini wrote:
> >> On 11/29/2012 06:36 PM, Tobias Burnus wrote:
> >> >H.J. Lu wrote:
> >> >>This patch adds --with-build-config=bootstrap-asan support.  Tested on
> >> >>Linux/x86-64.  OK to install?
> >> >
> >> >I think that patch has broken bootstrap for me. If I do a normal
> >> >bootstrap, Stage1 fails with:
> >> >
> >> >libtool: compile: unrecognized option `-D_GNU_SOURCE'
> >> >libtool: compile: Try `libtool --help' for more information.
> >> >make[4]: *** [interception_linux.lo] Error 1
> >> >make[4]: Leaving directory `/home/burnus/gcc/build/x86_64-unknown-linux-gnu/libsanitizer/interception'
> >> Likewise here. Would it be possible to revert the offending commit,
> >> in the meanwhile?
> >
> > Yes, H.J., please revert the patch, I thought you have tested it alone
> > without any further patches.  For the -I patch, I really would prefer if
> > libsanitizer just had a dependency on libstdc++ at toplevel
> > (configure-target-sanitizer depending on all-target-libstdc++-v3),
> > then you can (and similarly for host variants if we need host sanitizer at
> > all).  Then you should be able to use scripts/testsuite_flags
> > --build-includes just fine.
> 
> I opened:
> 
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55533
> 
> to explain why scripts/testsuite_flags doesn't work when
> bootstrapping libsanitizer.

CCing Paolo and Alex as build maintainers on this, using the script
is just my preference and not sure whether it is feasible or not, though
IMHO if there is a dependency on libstdc++-v3 being built before
libsanitizer is configured (or perhaps just configure when it has been
configured and build when it has been built), I don't see why it couldn't
be used in theory.  I'll defer this to them.

	Jakub
H.J. Lu - Dec. 3, 2012, 6:02 p.m.
On Mon, Dec 3, 2012 at 3:52 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> On Thu, Nov 29, 2012 at 12:20:39PM -0800, H.J. Lu wrote:
>> On Thu, Nov 29, 2012 at 11:06 AM, Jakub Jelinek <jakub@redhat.com> wrote:
>> > On Thu, Nov 29, 2012 at 07:24:38PM +0100, Paolo Carlini wrote:
>> >> On 11/29/2012 06:36 PM, Tobias Burnus wrote:
>> >> >H.J. Lu wrote:
>> >> >>This patch adds --with-build-config=bootstrap-asan support.  Tested on
>> >> >>Linux/x86-64.  OK to install?
>> >> >
>> >> >I think that patch has broken bootstrap for me. If I do a normal
>> >> >bootstrap, Stage1 fails with:
>> >> >
>> >> >libtool: compile: unrecognized option `-D_GNU_SOURCE'
>> >> >libtool: compile: Try `libtool --help' for more information.
>> >> >make[4]: *** [interception_linux.lo] Error 1
>> >> >make[4]: Leaving directory `/home/burnus/gcc/build/x86_64-unknown-linux-gnu/libsanitizer/interception'
>> >> Likewise here. Would it be possible to revert the offending commit,
>> >> in the meanwhile?
>> >
>> > Yes, H.J., please revert the patch, I thought you have tested it alone
>> > without any further patches.  For the -I patch, I really would prefer if
>> > libsanitizer just had a dependency on libstdc++ at toplevel
>> > (configure-target-sanitizer depending on all-target-libstdc++-v3),
>> > then you can (and similarly for host variants if we need host sanitizer at
>> > all).  Then you should be able to use scripts/testsuite_flags
>> > --build-includes just fine.
>>
>> I opened:
>>
>> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55533
>>
>> to explain why scripts/testsuite_flags doesn't work when
>> bootstrapping libsanitizer.
>
> CCing Paolo and Alex as build maintainers on this, using the script
> is just my preference and not sure whether it is feasible or not, though
> IMHO if there is a dependency on libstdc++-v3 being built before
> libsanitizer is configured (or perhaps just configure when it has been
> configured and build when it has been built), I don't see why it couldn't
> be used in theory.  I'll defer this to them.
>

Hi Alex, Paolo,

This is related to

http://gcc.gnu.org/ml/gcc-patches/2010-11/msg01430.html
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46026

The problem is CXX_FOR_TARGET used to configure libsanitizer
was expanded before libstdc++-v3 is configured when we are
bootstrapping libsanitizer.  I opened:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55533

with a fix at

http://gcc.gnu.org/ml/gcc-patches/2012-11/msg02480.html

Can you take a look at it?

Thanks.
Markus Trippelsdorf - Dec. 6, 2012, 12:06 p.m.
On 2012.11.29 at 11:26 -0800, H.J. Lu wrote:
> On Thu, Nov 29, 2012 at 11:06 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> > On Thu, Nov 29, 2012 at 07:24:38PM +0100, Paolo Carlini wrote:
> >> On 11/29/2012 06:36 PM, Tobias Burnus wrote:
> >> >H.J. Lu wrote:
> >> >>This patch adds --with-build-config=bootstrap-asan support.  Tested on
> >> >>Linux/x86-64.  OK to install?
> >> >
> >> >I think that patch has broken bootstrap for me. If I do a normal
> >> >bootstrap, Stage1 fails with:
> >> >
> >> >libtool: compile: unrecognized option `-D_GNU_SOURCE'
> >> >libtool: compile: Try `libtool --help' for more information.
> >> >make[4]: *** [interception_linux.lo] Error 1
> >> >make[4]: Leaving directory `/home/burnus/gcc/build/x86_64-unknown-linux-gnu/libsanitizer/interception'
> >> Likewise here. Would it be possible to revert the offending commit,
> >> in the meanwhile?
> >
> > Yes, H.J., please revert the patch, I thought you have tested it alone
> 
> Done.

There is still a stale, non-working config/bootstrap-asan.mk in the tree.

Patch

diff --git a/Makefile.def b/Makefile.def
index 1ea63ac..8d8af23 100644
--- a/Makefile.def
+++ b/Makefile.def
@@ -119,7 +119,10 @@  target_modules = { module= libstdc++-v3;
 		   lib_path=src/.libs;
 		   raw_cxx=true; };
 target_modules = { module= libmudflap; lib_path=.libs; };
-target_modules = { module= libsanitizer; lib_path=.libs; };
+target_modules = { module= libsanitizer;
+		   bootstrap=true;
+		   lib_path=.libs;
+		   raw_cxx=true; };
 target_modules = { module= libssp; lib_path=.libs; };
 target_modules = { module= newlib; };
 target_modules = { module= libgcc; bootstrap=true; no_check=true; };
diff --git a/config/bootstrap-asan.mk b/config/bootstrap-asan.mk
new file mode 100644
index 0000000..d37a9da
--- /dev/null
+++ b/config/bootstrap-asan.mk
@@ -0,0 +1,6 @@ 
+# This option enables -fsanitize=address for stage2 and stage3.
+
+STAGE2_CFLAGS += -fsanitize=address
+STAGE3_CFLAGS += -fsanitize=address
+POSTSTAGE1_LDFLAGS += -fsanitize=address -static-libasan \
+		      -B$$r/prev-$(TARGET_SUBDIR)/libsanitizer/asan/.libs
diff --git a/configure.ac b/configure.ac
index 24ea7e5..64e0387 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2433,6 +2433,11 @@  if echo " ${target_configdirs} " | grep " libgomp " > /dev/null 2>&1 ; then
   bootstrap_target_libs=${bootstrap_target_libs}target-libgomp,
 fi
 
+# If we are building libsanitizer, bootstrap it.
+if echo " ${target_configdirs} " | grep " libsanitizer " > /dev/null 2>&1 ; then
+  bootstrap_target_libs=${bootstrap_target_libs}target-libsanitizer,
+fi
+
 # Determine whether gdb needs tk/tcl or not.
 # Use 'maybe' since enable_gdbtk might be true even if tk isn't available
 # and in that case we want gdb to be built without tk.  Ugh!