From patchwork Tue Aug 26 22:27:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kostya Serebryany X-Patchwork-Id: 2547 Received: (qmail 23134 invoked by alias); 26 Aug 2014 22:27:50 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 23118 invoked by uid 89); 26 Aug 2014 22:27:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-yk0-f171.google.com X-Received: by 10.220.79.68 with SMTP id o4mr13041936vck.38.1409092057669; Tue, 26 Aug 2014 15:27:37 -0700 (PDT) MIME-Version: 1.0 From: Konstantin Serebryany Date: Tue, 26 Aug 2014 15:27:17 -0700 Message-ID: Subject: building GLIBC with -fsanitize=address To: GNU C Library , Roland McGrath , "Carlos O'Donell" Hello, I want to ask some assistance with building the GLIBC with AddressSanitizer (aka asan, GCC's -fsanitize=address flag). The end goal is to have libc-asan.so, a shared libc library with code instrumented by asan. Simply doing CFLAGS='-g -O1 -fsanitize=address' ../glibc/configure .. does not work -- it fails at configure time with configure: error: Need linker with .init_array/.fini_array support. Even if we bypass this error there will be others and, finally, we don't want to instrument every file we build (e.g. there are object files that go into the ld.so which we don't want to instrument). One of the things we discussed at the Cauldron was to add a configure option (e.g. --enable-asan) similar to the existing --enable-profile which adds the -pg build flag. This is indeed similar with one major difference: --enable-profile builds a static libc and for asan we need a DSO. I've managed to make a patch that builds libc-asan.a (attached) but I don't see how to get libc-asan.so from it. Thoughts? Thanks, --kcc diff --git a/Makeconfig b/Makeconfig index cef0f06..d2f4506 100644 --- a/Makeconfig +++ b/Makeconfig @@ -846,7 +846,7 @@ endif # The compilation rules use $(CPPFLAGS-${SUFFIX}) and $(CFLAGS-${SUFFIX}) # to pass different flags for each flavor. libtypes = $(foreach o,$(object-suffixes-for-libc),$(libtype$o)) -all-object-suffixes := .o .os .op .og .oS +all-object-suffixes := .o .os .op .og .oS .oasan object-suffixes := CPPFLAGS-.o = $(pic-default) CFLAGS-.o = $(filter %frame-pointer,$(+cflags)) @@ -877,6 +877,15 @@ CFLAGS-.op = -pg libtype.op = lib%_p.a endif +ifeq (yes,$(build-asan)) +# Under --enable-asan, TODO. +object-suffixes += .op +CPPFLAGS-.op = $(pic-default) +CFLAGS-.op = -fsanitize=address +libtype.op = lib%_asan.a +endif + + # Convenience variable for when we want to treat shared-library cases # differently from the rest. object-suffixes-noshared := $(filter-out .os,$(object-suffixes)) diff --git a/config.make.in b/config.make.in index 6bcab8a..eef62a9 100644 --- a/config.make.in +++ b/config.make.in @@ -82,6 +82,7 @@ nss-crypt = @libc_cv_nss_crypt@ build-shared = @shared@ build-pic-default= @libc_cv_pic_default@ build-profile = @profile@ +build-asan = @asan@ build-static-nss = @static_nss@ add-ons = @add_ons@ add-on-subdirs = @add_on_subdirs@ diff --git a/configure b/configure index c8d2967..c928def 100755 --- a/configure +++ b/configure @@ -576,6 +576,7 @@ mach_interface_list DEFINES static_nss profile +asan libc_cv_pic_default shared static @@ -737,6 +738,7 @@ with_default_link enable_sanity_checks enable_shared enable_profile +enable_asan enable_oldest_abi enable_hardcoded_path_in_tests enable_stackguard_randomization @@ -1390,6 +1392,8 @@ Optional Features: in special situations) [default=yes] --enable-shared build shared library [default=yes if GNU ld] --enable-profile build profiled library [default=no] + --enable-asan build library instrumented with AddressSanitizer + (ASan) [default=no] --enable-oldest-abi=ABI configure the oldest ABI supported [e.g. 2.2] [default=glibc default] --enable-hardcoded-path-in-tests @@ -3431,6 +3435,13 @@ else profile=no fi +# Check whether --enable-asan was given. +if test "${enable_asan+set}" = set; then : + enableval=$enable_asan; asan=$enableval +else + asan=no +fi + # Check whether --enable-oldest-abi was given. if test "${enable_oldest_abi+set}" = set; then : diff --git a/configure.ac b/configure.ac index 566ecb2..cb4bae4 100644 --- a/configure.ac +++ b/configure.ac @@ -150,6 +150,11 @@ AC_ARG_ENABLE([profile], [build profiled library @<:@default=no@:>@]), [profile=$enableval], [profile=no]) +AC_ARG_ENABLE([asan], + AC_HELP_STRING([--enable-asan], + [build library instrumented with AddressSanitizer (ASan) @<:@default=no@:>@]), + [asan=$enableval], + [asan=no]) AC_ARG_ENABLE([oldest-abi], AC_HELP_STRING([--enable-oldest-abi=ABI], @@ -1996,6 +2001,7 @@ rm -f conftest.*]) AC_SUBST(libc_cv_pic_default) AC_SUBST(profile) +AC_SUBST(asan) AC_SUBST(static_nss) AC_SUBST(DEFINES)