From 35814b034651b543b2521f9bd028c35f1fcaac1a Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 29 Nov 2013 13:30:36 +0100 Subject: [PATCH] re PR sanitizer/59063 (ASAN: segfault in __interceptor_clock_gettime) gcc/ 2013-11-29 Jakub Jelinek Yury Gribov PR sanitizer/59063 * config/gnu-user.h: Removed old code for setting up sanitizer libs. * gcc.c: Using libsanitizer spec instead of explicit libs. gcc/testsuite/ 2013-11-29 Jakub Jelinek Yury Gribov PR sanitizer/59063 * c-c++-common/asan/pr59063-1.c: New test. * c-c++-common/asan/pr59063-2.c: Likewise. * lib/asan-dg.exp: Add path to libsanitizer.spec to cflags. * lib/ubsan-dg.exp: Likewise. libsanitizer/ 2013-11-29 Jakub Jelinek Yury Gribov PR sanitizer/59063 * libsanitizer.spec.in: Add spec file to hold link flags for various sanitizer libs. * configure.ac: Check whether clock_* routines come from librt. * asan/Makefile.am (libasan_la_LDFLAGS): Libs now come from configure.ac. * tsan/Makefile.am (libtsan_la_LDFLAGS): Likewise. * ubsan/Makefile.am (libubsan_la_LDFLAGS): Likewise. * lsan/Makefile.am (liblsan_la_LDFLAGS): Likewise. * asan/Makefile.in: Regenerate. * interception/Makefile.in: Regenerate. * lsan/Makefile.in: Regenerate. * sanitizer_common/Makefile.in: Regenerate. * tsan/Makefile.in: Regenerate. * ubsan/Makefile.in: Regenerate. * Makefile.in: Regenerate. * configure: Regenerate. Co-Authored-By: Yury Gribov From-SVN: r205524 --- gcc/ChangeLog | 8 ++ gcc/config/gnu-user.h | 16 ---- gcc/gcc.c | 52 ++++-------- gcc/testsuite/ChangeLog | 9 ++ gcc/testsuite/c-c++-common/asan/pr59063-1.c | 11 +++ gcc/testsuite/c-c++-common/asan/pr59063-2.c | 12 +++ gcc/testsuite/lib/asan-dg.exp | 2 +- gcc/testsuite/lib/ubsan-dg.exp | 2 +- libsanitizer/ChangeLog | 21 +++++ libsanitizer/Makefile.am | 2 + libsanitizer/Makefile.in | 78 ++++++++++++++--- libsanitizer/asan/Makefile.am | 2 +- libsanitizer/asan/Makefile.in | 6 +- libsanitizer/configure | 94 ++++++++++++++++++++- libsanitizer/configure.ac | 35 +++++++- libsanitizer/interception/Makefile.in | 4 + libsanitizer/libsanitizer.spec.in | 11 +++ libsanitizer/lsan/Makefile.am | 2 +- libsanitizer/lsan/Makefile.in | 6 +- libsanitizer/sanitizer_common/Makefile.in | 4 + libsanitizer/tsan/Makefile.am | 2 +- libsanitizer/tsan/Makefile.in | 6 +- libsanitizer/ubsan/Makefile.am | 2 +- libsanitizer/ubsan/Makefile.in | 6 +- 24 files changed, 318 insertions(+), 75 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/asan/pr59063-1.c create mode 100644 gcc/testsuite/c-c++-common/asan/pr59063-2.c create mode 100644 libsanitizer/libsanitizer.spec.in diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b40ff365aea..33fa1590e64 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2013-11-29 Jakub Jelinek + Yury Gribov + + PR sanitizer/59063 + * config/gnu-user.h: Removed old code for setting up sanitizer + libs. + * gcc.c: Using libsanitizer spec instead of explicit libs. + 2013-11-29 Ilya Enkovich Reverted: diff --git a/gcc/config/gnu-user.h b/gcc/config/gnu-user.h index 157e147b188..60eb30dd127 100644 --- a/gcc/config/gnu-user.h +++ b/gcc/config/gnu-user.h @@ -126,19 +126,3 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see LD_STATIC_OPTION " --whole-archive -ltsan --no-whole-archive " \ LD_DYNAMIC_OPTION "}}%{!static-libtsan:-ltsan}" #endif - -/* Additional libraries needed by -static-libasan. */ -#undef STATIC_LIBASAN_LIBS -#define STATIC_LIBASAN_LIBS "-ldl -lpthread" - -/* Additional libraries needed by -static-libtsan. */ -#undef STATIC_LIBTSAN_LIBS -#define STATIC_LIBTSAN_LIBS "-ldl -lpthread" - -/* Additional libraries needed by -static-liblsan. */ -#undef STATIC_LIBLSAN_LIBS -#define STATIC_LIBLSAN_LIBS "-ldl -lpthread" - -/* Additional libraries needed by -static-libubsan. */ -#undef STATIC_LIBUBSAN_LIBS -#define STATIC_LIBUBSAN_LIBS "-ldl -lpthread" diff --git a/gcc/gcc.c b/gcc/gcc.c index 4edf6771c4f..b895f226ad0 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -535,20 +535,16 @@ proper position among the other output files. */ #define STACK_SPLIT_SPEC " %{fsplit-stack: --wrap=pthread_create}" #ifndef LIBASAN_SPEC -#ifdef STATIC_LIBASAN_LIBS -#define ADD_STATIC_LIBASAN_LIBS \ - " %{static-libasan:" STATIC_LIBASAN_LIBS "}" -#else -#define ADD_STATIC_LIBASAN_LIBS -#endif +#define STATIC_LIBASAN_LIBS \ + " %{static-libasan:%:include(libsanitizer.spec)%(link_libasan)}" #ifdef LIBASAN_EARLY_SPEC -#define LIBASAN_SPEC ADD_STATIC_LIBASAN_LIBS +#define LIBASAN_SPEC STATIC_LIBASAN_LIBS #elif defined(HAVE_LD_STATIC_DYNAMIC) #define LIBASAN_SPEC "%{static-libasan:" LD_STATIC_OPTION \ "} -lasan %{static-libasan:" LD_DYNAMIC_OPTION "}" \ - ADD_STATIC_LIBASAN_LIBS + STATIC_LIBASAN_LIBS #else -#define LIBASAN_SPEC "-lasan" ADD_STATIC_LIBASAN_LIBS +#define LIBASAN_SPEC "-lasan" STATIC_LIBASAN_LIBS #endif #endif @@ -557,20 +553,16 @@ proper position among the other output files. */ #endif #ifndef LIBTSAN_SPEC -#ifdef STATIC_LIBTSAN_LIBS -#define ADD_STATIC_LIBTSAN_LIBS \ - " %{static-libtsan:" STATIC_LIBTSAN_LIBS "}" -#else -#define ADD_STATIC_LIBTSAN_LIBS -#endif +#define STATIC_LIBTSAN_LIBS \ + " %{static-libtsan:%:include(libsanitizer.spec)%(link_libtsan)}" #ifdef LIBTSAN_EARLY_SPEC -#define LIBTSAN_SPEC ADD_STATIC_LIBTSAN_LIBS +#define LIBTSAN_SPEC STATIC_LIBTSAN_LIBS #elif defined(HAVE_LD_STATIC_DYNAMIC) #define LIBTSAN_SPEC "%{static-libtsan:" LD_STATIC_OPTION \ "} -ltsan %{static-libtsan:" LD_DYNAMIC_OPTION "}" \ - ADD_STATIC_LIBTSAN_LIBS + STATIC_LIBTSAN_LIBS #else -#define LIBTSAN_SPEC "-ltsan" ADD_STATIC_LIBTSAN_LIBS +#define LIBTSAN_SPEC "-ltsan" STATIC_LIBTSAN_LIBS #endif #endif @@ -579,34 +571,26 @@ proper position among the other output files. */ #endif #ifndef LIBLSAN_SPEC -#ifdef STATIC_LIBLSAN_LIBS -#define ADD_STATIC_LIBLSAN_LIBS \ - " %{static-liblsan:" STATIC_LIBLSAN_LIBS "}" -#else -#define ADD_STATIC_LIBLSAN_LIBS -#endif +#define STATIC_LIBLSAN_LIBS \ + " %{static-liblsan:%:include(libsanitizer.spec)%(link_liblsan)}" #ifdef HAVE_LD_STATIC_DYNAMIC #define LIBLSAN_SPEC "%{!shared:%{static-liblsan:" LD_STATIC_OPTION \ "} -llsan %{static-liblsan:" LD_DYNAMIC_OPTION "}" \ - ADD_STATIC_LIBLSAN_LIBS "}" + STATIC_LIBLSAN_LIBS "}" #else -#define LIBLSAN_SPEC "%{!shared:-llsan" ADD_STATIC_LIBLSAN_LIBS "}" +#define LIBLSAN_SPEC "%{!shared:-llsan" STATIC_LIBLSAN_LIBS "}" #endif #endif #ifndef LIBUBSAN_SPEC -#ifdef STATIC_LIBUBSAN_LIBS -#define ADD_STATIC_LIBUBSAN_LIBS \ - " %{static-libubsan:" STATIC_LIBUBSAN_LIBS "}" -#else -#define ADD_STATIC_LIBUBSAN_LIBS -#endif +#define STATIC_LIBUBSAN_LIBS \ + " %{static-libubsan:%:include(libsanitizer.spec)%(link_libubsan)}" #ifdef HAVE_LD_STATIC_DYNAMIC #define LIBUBSAN_SPEC "%{static-libubsan:" LD_STATIC_OPTION \ "} -lubsan %{static-libubsan:" LD_DYNAMIC_OPTION "}" \ - ADD_STATIC_LIBUBSAN_LIBS + STATIC_LIBUBSAN_LIBS #else -#define LIBUBSAN_SPEC "-lubsan" ADD_STATIC_LIBUBSAN_LIBS +#define LIBUBSAN_SPEC "-lubsan" STATIC_LIBUBSAN_LIBS #endif #endif diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 713980f5328..75ccd013808 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2013-11-29 Jakub Jelinek + Yury Gribov + + PR sanitizer/59063 + * c-c++-common/asan/pr59063-1.c: New test. + * c-c++-common/asan/pr59063-2.c: Likewise. + * lib/asan-dg.exp: Add path to libsanitizer.spec to cflags. + * lib/ubsan-dg.exp: Likewise. + 2013-11-29 Eric Botcazou * gnat.dg/opt29.ad[sb]: New test. diff --git a/gcc/testsuite/c-c++-common/asan/pr59063-1.c b/gcc/testsuite/c-c++-common/asan/pr59063-1.c new file mode 100644 index 00000000000..a4e01f76f3a --- /dev/null +++ b/gcc/testsuite/c-c++-common/asan/pr59063-1.c @@ -0,0 +1,11 @@ +/* { dg-do run } */ + +#include +static int weak_gettime (clockid_t clk_id, struct timespec *tp) + __attribute__((__weakref__("clock_gettime"))); +int main() { + if (!clock_gettime) + return 0; + struct timespec ts; + return weak_gettime(CLOCK_MONOTONIC, &ts); +} diff --git a/gcc/testsuite/c-c++-common/asan/pr59063-2.c b/gcc/testsuite/c-c++-common/asan/pr59063-2.c new file mode 100644 index 00000000000..64354ea7831 --- /dev/null +++ b/gcc/testsuite/c-c++-common/asan/pr59063-2.c @@ -0,0 +1,12 @@ +/* { dg-do run } */ +/* { dg-options "-static-libasan" } */ + +#include +static int weak_gettime (clockid_t clk_id, struct timespec *tp) + __attribute__((__weakref__("clock_gettime"))); +int main() { + if (!clock_gettime) + return 0; + struct timespec ts; + return weak_gettime(CLOCK_MONOTONIC, &ts); +} diff --git a/gcc/testsuite/lib/asan-dg.exp b/gcc/testsuite/lib/asan-dg.exp index e0bf2da2e78..823265ccb84 100644 --- a/gcc/testsuite/lib/asan-dg.exp +++ b/gcc/testsuite/lib/asan-dg.exp @@ -39,9 +39,9 @@ proc asan_link_flags { paths } { set shlib_ext [get_shlib_extension] if { $gccpath != "" } { + append flags " -B${gccpath}/libsanitizer/asan/ " if { [file exists "${gccpath}/libsanitizer/asan/.libs/libasan.a"] || [file exists "${gccpath}/libsanitizer/asan/.libs/libasan.${shlib_ext}"] } { - append flags " -B${gccpath}/libsanitizer/asan/ " append flags " -L${gccpath}/libsanitizer/asan/.libs " append ld_library_path ":${gccpath}/libsanitizer/asan/.libs" } diff --git a/gcc/testsuite/lib/ubsan-dg.exp b/gcc/testsuite/lib/ubsan-dg.exp index 4ec5fdfad67..2e6b272822d 100644 --- a/gcc/testsuite/lib/ubsan-dg.exp +++ b/gcc/testsuite/lib/ubsan-dg.exp @@ -30,9 +30,9 @@ proc ubsan_link_flags { paths } { set shlib_ext [get_shlib_extension] if { $gccpath != "" } { + append flags " -B${gccpath}/libsanitizer/ubsan/ " if { [file exists "${gccpath}/libsanitizer/ubsan/.libs/libubsan.a"] || [file exists "${gccpath}/libsanitizer/ubsan/.libs/libubsan.${shlib_ext}"] } { - append flags " -B${gccpath}/libsanitizer/ubsan/ " append flags " -L${gccpath}/libsanitizer/ubsan/.libs" append ld_library_path ":${gccpath}/libsanitizer/ubsan/.libs" } diff --git a/libsanitizer/ChangeLog b/libsanitizer/ChangeLog index 028c52122df..8404d51a053 100644 --- a/libsanitizer/ChangeLog +++ b/libsanitizer/ChangeLog @@ -1,3 +1,24 @@ +2013-11-29 Jakub Jelinek + Yury Gribov + + PR sanitizer/59063 + * libsanitizer.spec.in: Add spec file to hold link flags for + various sanitizer libs. + * configure.ac: Check whether clock_* routines come from librt. + * asan/Makefile.am (libasan_la_LDFLAGS): Libs now come from + configure.ac. + * tsan/Makefile.am (libtsan_la_LDFLAGS): Likewise. + * ubsan/Makefile.am (libubsan_la_LDFLAGS): Likewise. + * lsan/Makefile.am (liblsan_la_LDFLAGS): Likewise. + * asan/Makefile.in: Regenerate. + * interception/Makefile.in: Regenerate. + * lsan/Makefile.in: Regenerate. + * sanitizer_common/Makefile.in: Regenerate. + * tsan/Makefile.in: Regenerate. + * ubsan/Makefile.in: Regenerate. + * Makefile.in: Regenerate. + * configure: Regenerate. + 2013-11-28 Jakub Jelinek Yury Gribov diff --git a/libsanitizer/Makefile.am b/libsanitizer/Makefile.am index 15c11ecb2d7..6c3e5b053a2 100644 --- a/libsanitizer/Makefile.am +++ b/libsanitizer/Makefile.am @@ -50,5 +50,7 @@ AM_MAKEFLAGS = \ MAKEOVERRIDES= +nodist_toolexeclib_HEADERS = libsanitizer.spec + ## ################################################################ diff --git a/libsanitizer/Makefile.in b/libsanitizer/Makefile.in index 47a8771c783..9424c59fe37 100644 --- a/libsanitizer/Makefile.in +++ b/libsanitizer/Makefile.in @@ -14,6 +14,7 @@ # PARTICULAR PURPOSE. @SET_MAKE@ + VPATH = @srcdir@ pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ @@ -37,7 +38,7 @@ target_triplet = @target@ subdir = . DIST_COMMON = ChangeLog $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ $(top_srcdir)/configure $(am__configure_deps) \ - $(srcdir)/../mkinstalldirs + $(srcdir)/../mkinstalldirs $(srcdir)/libsanitizer.spec.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \ $(top_srcdir)/../config/depstand.m4 \ @@ -54,7 +55,7 @@ am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \ configure.lineno config.status.lineno mkinstalldirs = $(SHELL) $(top_srcdir)/../mkinstalldirs -CONFIG_CLEAN_FILES = +CONFIG_CLEAN_FILES = libsanitizer.spec CONFIG_CLEAN_VPATH_FILES = SOURCES = MULTISRCTOP = @@ -70,6 +71,29 @@ RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \ install-pdf-recursive install-ps-recursive install-recursive \ installcheck-recursive installdirs-recursive pdf-recursive \ ps-recursive uninstall-recursive +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__installdirs = "$(DESTDIR)$(toolexeclibdir)" +HEADERS = $(nodist_toolexeclib_HEADERS) RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ distclean-recursive maintainer-clean-recursive AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \ @@ -183,6 +207,10 @@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ +link_libasan = @link_libasan@ +link_liblsan = @link_liblsan@ +link_libtsan = @link_libtsan@ +link_libubsan = @link_libubsan@ localedir = @localedir@ localstatedir = @localstatedir@ mandir = @mandir@ @@ -252,6 +280,7 @@ AM_MAKEFLAGS = \ "DESTDIR=$(DESTDIR)" MAKEOVERRIDES = +nodist_toolexeclib_HEADERS = libsanitizer.spec all: all-recursive .SUFFIXES: @@ -289,6 +318,8 @@ $(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) $(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS) $(am__aclocal_m4_deps): +libsanitizer.spec: $(top_builddir)/config.status $(srcdir)/libsanitizer.spec.in + cd $(top_builddir) && $(SHELL) ./config.status $@ mostlyclean-libtool: -rm -f *.lo @@ -315,6 +346,26 @@ distclean-multi: $(MULTICLEAN) $(AM_MAKEFLAGS) DO=distclean multi-clean # $(MAKE) maintainer-clean-multi: $(MULTICLEAN) $(AM_MAKEFLAGS) DO=maintainer-clean multi-clean # $(MAKE) +install-nodist_toolexeclibHEADERS: $(nodist_toolexeclib_HEADERS) + @$(NORMAL_INSTALL) + test -z "$(toolexeclibdir)" || $(MKDIR_P) "$(DESTDIR)$(toolexeclibdir)" + @list='$(nodist_toolexeclib_HEADERS)'; test -n "$(toolexeclibdir)" || list=; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + echo "$$d$$p"; \ + done | $(am__base_list) | \ + while read files; do \ + echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(toolexeclibdir)'"; \ + $(INSTALL_HEADER) $$files "$(DESTDIR)$(toolexeclibdir)" || exit $$?; \ + done + +uninstall-nodist_toolexeclibHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(nodist_toolexeclib_HEADERS)'; test -n "$(toolexeclibdir)" || list=; \ + files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ + test -n "$$files" || exit 0; \ + echo " ( cd '$(DESTDIR)$(toolexeclibdir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(toolexeclibdir)" && rm -f $$files # This directory's subdirectories are mostly independent; you can cd # into them and run `make' without going through this Makefile. @@ -452,9 +503,12 @@ distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags check-am: all-am check: check-recursive -all-am: Makefile all-multi +all-am: Makefile all-multi $(HEADERS) installdirs: installdirs-recursive installdirs-am: + for dir in "$(DESTDIR)$(toolexeclibdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done install: install-recursive install-exec: install-exec-recursive install-data: install-data-recursive @@ -508,7 +562,7 @@ install-dvi: install-dvi-recursive install-dvi-am: -install-exec-am: install-multi +install-exec-am: install-multi install-nodist_toolexeclibHEADERS install-html: install-html-recursive @@ -548,7 +602,7 @@ ps: ps-recursive ps-am: -uninstall-am: +uninstall-am: uninstall-nodist_toolexeclibHEADERS .MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) all-multi \ clean-multi ctags-recursive distclean-multi install-am \ @@ -563,12 +617,14 @@ uninstall-am: install-am install-data install-data-am install-dvi \ install-dvi-am install-exec install-exec-am install-html \ install-html-am install-info install-info-am install-man \ - install-multi install-pdf install-pdf-am install-ps \ - install-ps-am install-strip installcheck installcheck-am \ - installdirs installdirs-am maintainer-clean \ - maintainer-clean-generic maintainer-clean-multi mostlyclean \ - mostlyclean-generic mostlyclean-libtool mostlyclean-multi pdf \ - pdf-am ps ps-am tags tags-recursive uninstall uninstall-am + install-multi install-nodist_toolexeclibHEADERS install-pdf \ + install-pdf-am install-ps install-ps-am install-strip \ + installcheck installcheck-am installdirs installdirs-am \ + maintainer-clean maintainer-clean-generic \ + maintainer-clean-multi mostlyclean mostlyclean-generic \ + mostlyclean-libtool mostlyclean-multi pdf pdf-am ps ps-am tags \ + tags-recursive uninstall uninstall-am \ + uninstall-nodist_toolexeclibHEADERS # Tell versions [3.59,3.63) of GNU make to not export all variables. diff --git a/libsanitizer/asan/Makefile.am b/libsanitizer/asan/Makefile.am index 0e1ee111a79..58defae04b7 100644 --- a/libsanitizer/asan/Makefile.am +++ b/libsanitizer/asan/Makefile.am @@ -43,7 +43,7 @@ libasan_la_LIBADD = $(top_builddir)/sanitizer_common/libsanitizer_common.la $(to endif libasan_la_LIBADD += $(LIBSTDCXX_RAW_CXX_LDFLAGS) -libasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` -lpthread -ldl +libasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libasan) libasan_preinit.o: asan_preinit.o cp $< $@ diff --git a/libsanitizer/asan/Makefile.in b/libsanitizer/asan/Makefile.in index c6044744e1d..e86d7b5b34b 100644 --- a/libsanitizer/asan/Makefile.in +++ b/libsanitizer/asan/Makefile.in @@ -224,6 +224,10 @@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ +link_libasan = @link_libasan@ +link_liblsan = @link_liblsan@ +link_libtsan = @link_libtsan@ +link_libubsan = @link_libubsan@ localedir = @localedir@ localstatedir = @localstatedir@ mandir = @mandir@ @@ -289,7 +293,7 @@ libasan_la_SOURCES = $(asan_files) @USING_MAC_INTERPOSE_TRUE@libasan_la_LIBADD = $(top_builddir)/sanitizer_common/libsanitizer_common.la \ @USING_MAC_INTERPOSE_TRUE@ $(top_builddir)/lsan/libsanitizer_lsan.la \ @USING_MAC_INTERPOSE_TRUE@ $(LIBSTDCXX_RAW_CXX_LDFLAGS) -libasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` -lpthread -ldl +libasan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libasan) # Work around what appears to be a GNU make bug handling MAKEFLAGS # values defined in terms of make variables, as is the case for CC and diff --git a/libsanitizer/configure b/libsanitizer/configure index 22f7fee9156..e5c320604d3 100755 --- a/libsanitizer/configure +++ b/libsanitizer/configure @@ -606,6 +606,10 @@ LTLIBOBJS LIBOBJS USING_MAC_INTERPOSE_FALSE USING_MAC_INTERPOSE_TRUE +link_liblsan +link_libubsan +link_libtsan +link_libasan LSAN_SUPPORTED_FALSE LSAN_SUPPORTED_TRUE TSAN_SUPPORTED_FALSE @@ -11119,7 +11123,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 11122 "configure" +#line 11126 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -11225,7 +11229,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 11228 "configure" +#line 11232 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -14544,6 +14548,89 @@ else fi +# Check for functions needed. +for ac_func in clock_getres clock_gettime clock_settime +do : + as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` +ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" +eval as_val=\$$as_ac_var + if test "x$as_val" = x""yes; then : + cat >>confdefs.h <<_ACEOF +#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done + + +# Common libraries that we need to link against for all sanitizer libs. +link_sanitizer_common='-lpthread -ldl' + +# Set up the set of additional libraries that we need to link against for libasan. +link_libasan=$link_sanitizer_common + + +# Set up the set of additional libraries that we need to link against for libtsan. +link_libtsan=$link_sanitizer_common + + +# Set up the set of additional libraries that we need to link against for libubsan. +link_libubsan=$link_sanitizer_common + + +# Set up the set of additional libraries that we need to link against for liblsan. +link_liblsan=$link_sanitizer_common + + +# At least for glibc, clock_gettime is in librt. But don't pull that +# in if it still doesn't give us the function we want. This +# test is copied from libgomp. +if test $ac_cv_func_clock_gettime = no; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for clock_gettime in -lrt" >&5 +$as_echo_n "checking for clock_gettime in -lrt... " >&6; } +if test "${ac_cv_lib_rt_clock_gettime+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lrt $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char clock_gettime (); +int +main () +{ +return clock_gettime (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + ac_cv_lib_rt_clock_gettime=yes +else + ac_cv_lib_rt_clock_gettime=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_rt_clock_gettime" >&5 +$as_echo "$ac_cv_lib_rt_clock_gettime" >&6; } +if test "x$ac_cv_lib_rt_clock_gettime" = x""yes; then : + link_libasan="-lrt $link_libasan" +link_libtsan="-lrt $link_libtsan" +# Other sanitizers do not override clock_* API + +fi + +fi + case "$host" in *-*-darwin*) MAC_INTERPOSE=true ; enable_static=no ;; *) MAC_INTERPOSE=false ;; @@ -14557,7 +14644,7 @@ else fi -ac_config_files="$ac_config_files Makefile" +ac_config_files="$ac_config_files Makefile libsanitizer.spec" ac_config_files="$ac_config_files interception/Makefile sanitizer_common/Makefile lsan/Makefile asan/Makefile ubsan/Makefile" @@ -15692,6 +15779,7 @@ do "depfiles") CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;; "libtool") CONFIG_COMMANDS="$CONFIG_COMMANDS libtool" ;; "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; + "libsanitizer.spec") CONFIG_FILES="$CONFIG_FILES libsanitizer.spec" ;; "interception/Makefile") CONFIG_FILES="$CONFIG_FILES interception/Makefile" ;; "sanitizer_common/Makefile") CONFIG_FILES="$CONFIG_FILES sanitizer_common/Makefile" ;; "lsan/Makefile") CONFIG_FILES="$CONFIG_FILES lsan/Makefile" ;; diff --git a/libsanitizer/configure.ac b/libsanitizer/configure.ac index f769fdb030c..7f9327904da 100644 --- a/libsanitizer/configure.ac +++ b/libsanitizer/configure.ac @@ -83,13 +83,46 @@ unset LSAN_SUPPORTED AM_CONDITIONAL(TSAN_SUPPORTED, [test "x$TSAN_SUPPORTED" = "xyes"]) AM_CONDITIONAL(LSAN_SUPPORTED, [test "x$LSAN_SUPPORTED" = "xyes"]) +# Check for functions needed. +AC_CHECK_FUNCS(clock_getres clock_gettime clock_settime) + +# Common libraries that we need to link against for all sanitizer libs. +link_sanitizer_common='-lpthread -ldl' + +# Set up the set of additional libraries that we need to link against for libasan. +link_libasan=$link_sanitizer_common +AC_SUBST(link_libasan) + +# Set up the set of additional libraries that we need to link against for libtsan. +link_libtsan=$link_sanitizer_common +AC_SUBST(link_libtsan) + +# Set up the set of additional libraries that we need to link against for libubsan. +link_libubsan=$link_sanitizer_common +AC_SUBST(link_libubsan) + +# Set up the set of additional libraries that we need to link against for liblsan. +link_liblsan=$link_sanitizer_common +AC_SUBST(link_liblsan) + +# At least for glibc, clock_gettime is in librt. But don't pull that +# in if it still doesn't give us the function we want. This +# test is copied from libgomp. +if test $ac_cv_func_clock_gettime = no; then + AC_CHECK_LIB(rt, clock_gettime, + [link_libasan="-lrt $link_libasan" +link_libtsan="-lrt $link_libtsan" +# Other sanitizers do not override clock_* API +]) +fi + case "$host" in *-*-darwin*) MAC_INTERPOSE=true ; enable_static=no ;; *) MAC_INTERPOSE=false ;; esac AM_CONDITIONAL(USING_MAC_INTERPOSE, $MAC_INTERPOSE) -AC_CONFIG_FILES([Makefile]) +AC_CONFIG_FILES([Makefile libsanitizer.spec]) AC_CONFIG_FILES(AC_FOREACH([DIR], [interception sanitizer_common lsan asan ubsan], [DIR/Makefile ]), [cat > vpsed$$ << \_EOF diff --git a/libsanitizer/interception/Makefile.in b/libsanitizer/interception/Makefile.in index f3a2f41c033..52a06d63458 100644 --- a/libsanitizer/interception/Makefile.in +++ b/libsanitizer/interception/Makefile.in @@ -181,6 +181,10 @@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ +link_libasan = @link_libasan@ +link_liblsan = @link_liblsan@ +link_libtsan = @link_libtsan@ +link_libubsan = @link_libubsan@ localedir = @localedir@ localstatedir = @localstatedir@ mandir = @mandir@ diff --git a/libsanitizer/libsanitizer.spec.in b/libsanitizer/libsanitizer.spec.in new file mode 100644 index 00000000000..a4fa87d8dfc --- /dev/null +++ b/libsanitizer/libsanitizer.spec.in @@ -0,0 +1,11 @@ +# This spec file is read by gcc when linking. It is used to specify the +# standard libraries we need in order to link with various sanitizer libs. + +*link_libasan: @link_libasan@ + +*link_libtsan: @link_libtsan@ + +*link_libubsan: @link_libubsan@ + +*link_liblsan: @link_liblsan@ + diff --git a/libsanitizer/lsan/Makefile.am b/libsanitizer/lsan/Makefile.am index a312c1c262e..36fd6058841 100644 --- a/libsanitizer/lsan/Makefile.am +++ b/libsanitizer/lsan/Makefile.am @@ -28,7 +28,7 @@ libsanitizer_lsan_la_SOURCES = $(sanitizer_lsan_files) liblsan_la_SOURCES = $(lsan_files) liblsan_la_LIBADD = $(top_builddir)/sanitizer_common/libsanitizer_common.la $(top_builddir)/interception/libinterception.la $(LIBSTDCXX_RAW_CXX_LDFLAGS) -liblsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` -lpthread -ldl +liblsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_liblsan) # Work around what appears to be a GNU make bug handling MAKEFLAGS # values defined in terms of make variables, as is the case for CC and diff --git a/libsanitizer/lsan/Makefile.in b/libsanitizer/lsan/Makefile.in index f0946618eb2..9296b7048ab 100644 --- a/libsanitizer/lsan/Makefile.in +++ b/libsanitizer/lsan/Makefile.in @@ -215,6 +215,10 @@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ +link_libasan = @link_libasan@ +link_liblsan = @link_liblsan@ +link_libtsan = @link_libtsan@ +link_libubsan = @link_libubsan@ localedir = @localedir@ localstatedir = @localstatedir@ mandir = @mandir@ @@ -265,7 +269,7 @@ lsan_files = \ libsanitizer_lsan_la_SOURCES = $(sanitizer_lsan_files) liblsan_la_SOURCES = $(lsan_files) liblsan_la_LIBADD = $(top_builddir)/sanitizer_common/libsanitizer_common.la $(top_builddir)/interception/libinterception.la $(LIBSTDCXX_RAW_CXX_LDFLAGS) -liblsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` -lpthread -ldl +liblsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_liblsan) # Work around what appears to be a GNU make bug handling MAKEFLAGS # values defined in terms of make variables, as is the case for CC and diff --git a/libsanitizer/sanitizer_common/Makefile.in b/libsanitizer/sanitizer_common/Makefile.in index b54465388ce..9bbdfd6acfe 100644 --- a/libsanitizer/sanitizer_common/Makefile.in +++ b/libsanitizer/sanitizer_common/Makefile.in @@ -192,6 +192,10 @@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ +link_libasan = @link_libasan@ +link_liblsan = @link_liblsan@ +link_libtsan = @link_libtsan@ +link_libubsan = @link_libubsan@ localedir = @localedir@ localstatedir = @localstatedir@ mandir = @mandir@ diff --git a/libsanitizer/tsan/Makefile.am b/libsanitizer/tsan/Makefile.am index 6fc4d0ea0ff..9b039d229d7 100644 --- a/libsanitizer/tsan/Makefile.am +++ b/libsanitizer/tsan/Makefile.am @@ -39,7 +39,7 @@ tsan_files = \ libtsan_la_SOURCES = $(tsan_files) libtsan_la_LIBADD = $(top_builddir)/sanitizer_common/libsanitizer_common.la $(top_builddir)/interception/libinterception.la $(LIBSTDCXX_RAW_CXX_LDFLAGS) -libtsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` -lpthread -ldl +libtsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libtsan) # Work around what appears to be a GNU make bug handling MAKEFLAGS # values defined in terms of make variables, as is the case for CC and diff --git a/libsanitizer/tsan/Makefile.in b/libsanitizer/tsan/Makefile.in index bac430be35d..eb5c7e7a84b 100644 --- a/libsanitizer/tsan/Makefile.in +++ b/libsanitizer/tsan/Makefile.in @@ -231,6 +231,10 @@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ +link_libasan = @link_libasan@ +link_liblsan = @link_liblsan@ +link_libtsan = @link_libtsan@ +link_libubsan = @link_libubsan@ localedir = @localedir@ localstatedir = @localstatedir@ mandir = @mandir@ @@ -295,7 +299,7 @@ tsan_files = \ libtsan_la_SOURCES = $(tsan_files) libtsan_la_LIBADD = $(top_builddir)/sanitizer_common/libsanitizer_common.la $(top_builddir)/interception/libinterception.la $(LIBSTDCXX_RAW_CXX_LDFLAGS) -libtsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` -lpthread -ldl +libtsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libtsan) # Work around what appears to be a GNU make bug handling MAKEFLAGS # values defined in terms of make variables, as is the case for CC and diff --git a/libsanitizer/ubsan/Makefile.am b/libsanitizer/ubsan/Makefile.am index ce94eaacbde..24e405bd146 100644 --- a/libsanitizer/ubsan/Makefile.am +++ b/libsanitizer/ubsan/Makefile.am @@ -23,7 +23,7 @@ if !USING_MAC_INTERPOSE libubsan_la_LIBADD += $(top_builddir)/interception/libinterception.la endif libubsan_la_LIBADD += $(LIBSTDCXX_RAW_CXX_LDFLAGS) -libubsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` -lpthread -ldl +libubsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libubsan) # Use special rules for files that require RTTI support. ubsan_handlers_cxx.% ubsan_type_hash.% : AM_CXXFLAGS += -frtti diff --git a/libsanitizer/ubsan/Makefile.in b/libsanitizer/ubsan/Makefile.in index 314835885ff..dcb04c72d4d 100644 --- a/libsanitizer/ubsan/Makefile.in +++ b/libsanitizer/ubsan/Makefile.in @@ -210,6 +210,10 @@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ +link_libasan = @link_libasan@ +link_liblsan = @link_liblsan@ +link_libtsan = @link_libtsan@ +link_libubsan = @link_libubsan@ localedir = @localedir@ localstatedir = @localstatedir@ mandir = @mandir@ @@ -256,7 +260,7 @@ libubsan_la_SOURCES = $(ubsan_files) libubsan_la_LIBADD = \ $(top_builddir)/sanitizer_common/libsanitizer_common.la \ $(am__append_1) $(LIBSTDCXX_RAW_CXX_LDFLAGS) -libubsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` -lpthread -ldl +libubsan_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version` $(link_libubsan) # Work around what appears to be a GNU make bug handling MAKEFLAGS # values defined in terms of make variables, as is the case for CC and