diff mbox

Fix --with-build-config=bootstrap-ubsan bootstrap of lto-plugin (PR sanitizer/56781)

Message ID 20140325192856.GW1817@tucnak.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek March 25, 2014, 7:28 p.m. UTC
Hi!

lto-plugin is another problematic directory in asan/ubsan bootstraps.

Unlike fixincludes, it is bootstrapped, and like fixincludes it is also
linked against host libiberty.  The problem for lto-plugin is that the
-static-libubsan -fsanitize=undefined -B/some/path/to/libsanitizer/ -B/some/path/to/libsanitizer/ubsan/.libs/
switches are eaten by libtool, which throws them away on the floor.

We apparently have libtool-ldflags which is used by other libraries
to filter some options so that libtool doesn't eat them, but even after
applying the lto-plugin/Makefile.am changes I got failures, because
while -fsanitize=undefined now made it through, the rest of the options
didn't.  So, this patch also tweaks libtool-ldflags to handle some more
options.

Bootstrapped/regtested on x86_64-linux (normally) and i686-linux
(--with-build-config=bootstrap-ubsan).  Ok for trunk?

2014-03-25  Jakub Jelinek  <jakub@redhat.com>

	PR sanitizer/56781
	* libtool-ldflags: Also prefix -static-lib*, -shared-lib*
	and -B* options with -Xcompiler.
lto-plugin/
	* Makefile.am (LTLDFLAGS, liblto_plugin_la_LINK): New variables.
	* Makefile.in: Regenerated.



	Jakub

Comments

H.J. Lu March 25, 2014, 7:44 p.m. UTC | #1
On Tue, Mar 25, 2014 at 12:28 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> lto-plugin is another problematic directory in asan/ubsan bootstraps.
>
> Unlike fixincludes, it is bootstrapped, and like fixincludes it is also
> linked against host libiberty.  The problem for lto-plugin is that the
> -static-libubsan -fsanitize=undefined -B/some/path/to/libsanitizer/ -B/some/path/to/libsanitizer/ubsan/.libs/
> switches are eaten by libtool, which throws them away on the floor.
>
> We apparently have libtool-ldflags which is used by other libraries
> to filter some options so that libtool doesn't eat them, but even after
> applying the lto-plugin/Makefile.am changes I got failures, because
> while -fsanitize=undefined now made it through, the rest of the options
> didn't.  So, this patch also tweaks libtool-ldflags to handle some more
> options.
>

lto-plugin is dlopened by ld.  How does asan work in lto-plugin
when ld isn't compiled with asan?
Jakub Jelinek March 25, 2014, 7:57 p.m. UTC | #2
On Tue, Mar 25, 2014 at 12:44:58PM -0700, H.J. Lu wrote:
> On Tue, Mar 25, 2014 at 12:28 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> > lto-plugin is another problematic directory in asan/ubsan bootstraps.
> >
> > Unlike fixincludes, it is bootstrapped, and like fixincludes it is also
> > linked against host libiberty.  The problem for lto-plugin is that the
> > -static-libubsan -fsanitize=undefined -B/some/path/to/libsanitizer/ -B/some/path/to/libsanitizer/ubsan/.libs/
> > switches are eaten by libtool, which throws them away on the floor.
> >
> > We apparently have libtool-ldflags which is used by other libraries
> > to filter some options so that libtool doesn't eat them, but even after
> > applying the lto-plugin/Makefile.am changes I got failures, because
> > while -fsanitize=undefined now made it through, the rest of the options
> > didn't.  So, this patch also tweaks libtool-ldflags to handle some more
> > options.
> >
> 
> lto-plugin is dlopened by ld.  How does asan work in lto-plugin
> when ld isn't compiled with asan?

It works fine for ubsan, and your fix is not the right thing to do,
e.g. bootstrap-ubsan reveals some bugs in libiberty which would be otherwise
unnoticed if you always filter away the sanitizing options from libiberty.

So, I think my patch is the right thing to do for ubsan bootstraps, and for
asan bootstraps we'll need something different (build libiberty twice, or
build selected libiberty objects inside lto-plugin/ directory again, or
something similar).  You do want the libiberty parts in cc1, cc1plus, xgcc
etc. instrumented.

	Jakub
Jakub Jelinek March 25, 2014, 8:17 p.m. UTC | #3
On Tue, Mar 25, 2014 at 08:57:21PM +0100, Jakub Jelinek wrote:
> It works fine for ubsan, and your fix is not the right thing to do,
> e.g. bootstrap-ubsan reveals some bugs in libiberty which would be otherwise
> unnoticed if you always filter away the sanitizing options from libiberty.
> 
> So, I think my patch is the right thing to do for ubsan bootstraps, and for
> asan bootstraps we'll need something different (build libiberty twice, or
> build selected libiberty objects inside lto-plugin/ directory again, or
> something similar).  You do want the libiberty parts in cc1, cc1plus, xgcc
> etc. instrumented.

Seems libiberty builds (optionally) everything also into pic/ subdirectory,
I think best would be if it in case it found -fsanitize=address in CFLAGS
also built everything into noasan/ subdirectory with additional
-fno-sanitize=address, and filter out -fsanitize=address just in lto-plugin
Makefile and use noasan/libiberty.a preferrably over pic/libiberty.a over
libiberty.a.
I guess I can cook up a patch tomorrow for that, though probably won't have
cycles to fully test that.

	Jakub
diff mbox

Patch

--- libtool-ldflags.jj	2008-09-05 12:59:51.000000000 +0200
+++ libtool-ldflags	2014-03-25 15:43:36.726185093 +0100
@@ -2,7 +2,7 @@ 
 
 # Script to translate LDFLAGS into a form suitable for use with libtool.
 
-# Copyright (C) 2005 Free Software Foundation, Inc.
+# Copyright (C) 2005-2014 Free Software Foundation, Inc.
 #
 # This file is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -36,14 +36,15 @@  prev_arg=
 for arg
 do
     case $arg in
-	-f*|--*)
+	-f*|--*|-static-lib*|-shared-lib*|-B*)
 	    # Libtool does not ascribe any special meaning options
 	    # that begin with -f or with a double-dash.  So, it will
 	    # think these options are linker options, and prefix them
 	    # with "-Wl,".  Then, the compiler driver will ignore the
 	    # options.  So, we prefix these options with -Xcompiler to
 	    # make clear to libtool that they are in fact compiler
-	    # options.
+	    # options.  Similarly for e.g. -static-libstdc++, or
+	    # -B/some/path.
 	    case $prev_arg in
 		-Xpreprocessor|-Xcompiler|-Xlinker)
 		    # This option is already prefixed; don't prefix it again.
--- lto-plugin/Makefile.am.jj	2014-03-17 20:01:54.000000000 +0100
+++ lto-plugin/Makefile.am	2014-03-25 15:46:26.832294118 +0100
@@ -18,6 +18,7 @@  in_gcc_libs = $(foreach lib, $(libexecsu
 
 # Can be removed when libiberty becomes a normal convenience library
 Wc=-Wc,
+LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/../libtool-ldflags $(LDFLAGS))
 
 liblto_plugin_la_SOURCES = lto-plugin.c
 liblto_plugin_la_LIBADD = \
@@ -28,6 +29,9 @@  liblto_plugin_la_LDFLAGS = $(AM_LDFLAGS)
 	$(if $(wildcard ../libiberty/pic/libiberty.a),,-Wc,../libiberty/libiberty.a)
 liblto_plugin_la_DEPENDENCIES = $(if $(wildcard \
 	../libiberty/pic/libiberty.a),../libiberty/pic/libiberty.a,)
+liblto_plugin_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+	$(liblto_plugin_la_LDFLAGS) $(LTLDFLAGS) -o $@
 
 all-local: $(in_gcc_libs)
 
--- lto-plugin/Makefile.in.jj	2014-03-17 20:01:54.000000000 +0100
+++ lto-plugin/Makefile.in	2014-03-25 15:47:10.059071353 +0100
@@ -84,9 +84,6 @@  am__installdirs = "$(DESTDIR)$(libexecsu
 LTLIBRARIES = $(libexecsub_LTLIBRARIES)
 am_liblto_plugin_la_OBJECTS = lto-plugin.lo
 liblto_plugin_la_OBJECTS = $(am_liblto_plugin_la_OBJECTS)
-liblto_plugin_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
-	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
-	$(liblto_plugin_la_LDFLAGS) $(LDFLAGS) -o $@
 DEFAULT_INCLUDES = -I.@am__isrc@
 depcomp =
 am__depfiles_maybe =
@@ -239,6 +236,7 @@  in_gcc_libs = $(foreach lib, $(libexecsu
 
 # Can be removed when libiberty becomes a normal convenience library
 Wc = -Wc,
+LTLDFLAGS = $(shell $(SHELL) $(top_srcdir)/../libtool-ldflags $(LDFLAGS))
 liblto_plugin_la_SOURCES = lto-plugin.c
 liblto_plugin_la_LIBADD = \
 	$(if $(wildcard ../libiberty/pic/libiberty.a),$(Wc)../libiberty/pic/libiberty.a,)
@@ -251,6 +249,10 @@  liblto_plugin_la_LDFLAGS = $(AM_LDFLAGS)
 liblto_plugin_la_DEPENDENCIES = $(if $(wildcard \
 	../libiberty/pic/libiberty.a),../libiberty/pic/libiberty.a,)
 
+liblto_plugin_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+	$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+	$(liblto_plugin_la_LDFLAGS) $(LTLDFLAGS) -o $@
+
 all: config.h
 	$(MAKE) $(AM_MAKEFLAGS) all-am