From patchwork Wed Dec 2 10:42:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashutosh Pandey X-Patchwork-Id: 41253 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A7CE1395B803; Wed, 2 Dec 2020 10:42:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A7CE1395B803 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1606905771; bh=6S67XRUAnJGwDDh4TjU+ui4ntU4voILAj7PXGdeUtiE=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Wq+Zeg9jM8HfSmEVKloYJMyxs9RMh6gtgcNT0RCaaQQIIcgcl2AdDo+5EbpTG9xOC lr0j1O+7PBg2xjO9B9vZkDuJIaLtC+CDe38Q38IjfVKWj7hbBoS3+ikFScR/sYXM9P FjGjVyMOkCPP3WeUOhrK8FMhHbEfl/WHnFaZZ6Z8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id CBBA3395B454 for ; Wed, 2 Dec 2020 10:42:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CBBA3395B454 Received: by mail-wm1-x32b.google.com with SMTP id e25so6574610wme.0 for ; Wed, 02 Dec 2020 02:42:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=9wEgGDQulwx6PN2L162XP3aP8loq4GFzjmlURMTwWkA=; b=DeRB4d4D378owCnarxZum3tYvnrMhv8mdMKnKsl3H7MIpsM2CMMLbW0thEfbwSSOhk y+V7HwWBK91dhdw6oOom3jdR3z8m4FQwvSveKJXbP+uEJ23io5tv6wjwHdQVco0HLGhd XJMKXnta0v0cJ5JghnReMUFgSc4uLK+nPcRXilKREcH7K4SZpRvkkfHwO/30oXkbgVhF JDdfGI3hvj/3X40zUoX/0utVl2UqZtc7ylsiz45W+w4+nHymF/pI9zuUfkDmA7u1CRG6 KDBAdYwBf276dBB/nnFYAgZRdD3uVjNPATez73sERzWUKGBtLtVa9JxPTjqxgstfe0KS JXKA== X-Gm-Message-State: AOAM530LV/jcCQ4R/xWBZlfogpTBrXqywt4J1TpMIyu6PSb2g7nmkQol /bFVmnyAiT89AqPqqV1UBlzVaD/y1CK2ukoCzHpC9vGywYv7LGY= X-Google-Smtp-Source: ABdhPJwsf0wplvpD30QyB2mtuaovb1V3tfT4NkunphrlYGWGhX8LSA80wGoRzKqkUaKui1PWYZlo57UlF0qFYEwxMx8= X-Received: by 2002:a1c:4b0f:: with SMTP id y15mr2482915wma.10.1606905764265; Wed, 02 Dec 2020 02:42:44 -0800 (PST) MIME-Version: 1.0 Date: Wed, 2 Dec 2020 16:12:32 +0530 Message-ID: Subject: [PATCH] glibc code coverage To: libc-alpha@sourceware.org X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ashutosh Pandey via Libc-alpha From: Ashutosh Pandey Reply-To: Ashutosh Pandey Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" I am a new contributor. I have applied for copyright papers and signed them. Enable building glibc with instrumentation for code coverage. For + individual files '--coverage' can be used, but this fails + when it is used as an option with '../configure' command to build glibc. + To successfully build glibc with coverage, you must first build and install glibc + with shared libraries enabled. This will allow some files such as + 'libc-modules.h' to be generated which are needed for code coverage to + work. + The command '../configure --disable-shared --enable-gcov --without-selinux + --disable-nscd --prefix=/path/to/install' + will build glibc with code coverage. Note that not including a prefix, + or setting the prefix to usr/lib can affect the system glibc and can + render the system unusable. The command to make is 'make CXX=', without + which you will get a error 'cannot find -lgcc_s'. From 3297a01fd688d35d5e242819688ba7e6150e77f2 Mon Sep 17 00:00:00 2001 From: Ashutosh Pandey Date: Tue, 24 Nov 2020 00:20:03 +0530 Subject: [PATCH] glibc code coverage --- INSTALL | 15 +++++++++++++++ Makeconfig | 7 +++++++ config.make.in | 1 + configure | 28 +++++++++++++++++++++++++++- configure.ac | 8 ++++++++ manual/install.texi | 15 +++++++++++++++ 6 files changed, 73 insertions(+), 1 deletion(-) diff --git a/INSTALL b/INSTALL index 2b00f80df5..56923fbc8b 100644 --- a/INSTALL +++ b/INSTALL @@ -111,6 +111,21 @@ if 'CFLAGS' is specified it must enable optimization. For example: systems support shared libraries; you need ELF support and (currently) the GNU linker. +'--enable-gcov' + Enable building glibc with instrumentation for code coverage. For + individual files '--coverage' can be used, but this fails + when it is used as an option with '../configure' command to build glibc. + To successfully build glibc with coverage, you must first build and install glibc + with shared libraries enabled. This will allow some files such as + 'libc-modules.h' to be generated which are needed for code coverage to + work. + The command '../configure --disable-shared --enable-gcov --without-selinux + --disable-nscd --prefix=/path/to/install' + will build glibc with code coverage. Note that not including a prefix, + or setting the prefix to usr/lib can affect the system glibc and can + render the system unusable. The command to make is 'make CXX=', without + which you will get a error 'cannot find -lgcc_s'. + '--enable-static-pie' Enable static position independent executable (static PIE) support. Static PIE is similar to static executable, but can be loaded at diff --git a/Makeconfig b/Makeconfig index 8074613b85..5956de9d44 100644 --- a/Makeconfig +++ b/Makeconfig @@ -610,6 +610,13 @@ endif link-libc-static = -Wl,--start-group $(common-objpfx)libc.a $(static-gnulib) -Wl,--end-group link-libc-static-tests = -Wl,--start-group $(common-objpfx)libc.a $(static-gnulib-tests) -Wl,--end-group +# support for code coverage with gcov +ifeq (yes,$(build-gcov)) ++cflags += -fprofile-arcs -ftest-coverage -O2 +link-libc-static = -Wl,--start-group -lgcov $(common-objpfx)libc.a $(static-gnulib) -Wl,--end-group +link-libc-static-tests = -Wl,--start-group -lgcov $(common-objpfx)libc.a $(static-gnulib-tests) -Wl,--end-group +endif + # How to link against libgcc. Some libgcc functions, such as those # for "long long" arithmetic or software floating point, can always be # built without use of C library headers and do not have any global diff --git a/config.make.in b/config.make.in index 1ac9417245..463e9d808c 100644 --- a/config.make.in +++ b/config.make.in @@ -92,6 +92,7 @@ build-shared = @shared@ build-pic-default= @libc_cv_pic_default@ build-pie-default= @libc_cv_pie_default@ cc-pie-default= @libc_cv_cc_pie_default@ +build-gcov = @gcov@ build-profile = @profile@ build-static-nss = @static_nss@ cross-compiling = @cross_compiling@ diff --git a/configure b/configure index 4795e721e5..21f8582e16 100755 --- a/configure +++ b/configure @@ -683,6 +683,7 @@ force_install bindnow hardcoded_path_in_tests enable_timezone_tools +gcov extra_nonshared_cflags use_default_link sysheaders @@ -731,6 +732,7 @@ infodir docdir oldincludedir includedir +runstatedir localstatedir sharedstatedir sysconfdir @@ -765,6 +767,7 @@ with_default_link with_nonshared_cflags enable_sanity_checks enable_shared +enable_gcov enable_profile enable_static_pie enable_timezone_tools @@ -842,6 +845,7 @@ datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' +runstatedir='${localstatedir}/run' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' @@ -1094,6 +1098,15 @@ do | -silent | --silent | --silen | --sile | --sil) silent=yes ;; + -runstatedir | --runstatedir | --runstatedi | --runstated \ + | --runstate | --runstat | --runsta | --runst | --runs \ + | --run | --ru | --r) + ac_prev=runstatedir ;; + -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ + | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ + | --run=* | --ru=* | --r=*) + runstatedir=$ac_optarg ;; + -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ @@ -1231,7 +1244,7 @@ fi for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ - libdir localedir mandir + libdir localedir mandir runstatedir do eval ac_val=\$$ac_var # Remove trailing slashes. @@ -1384,6 +1397,7 @@ Fine tuning of the installation directories: --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] @@ -1420,6 +1434,8 @@ Optional Features: --disable-sanity-checks really do not use threads (should not be used except in special situations) [default=yes] --enable-shared build shared library [default=yes if GNU ld] + --enable-gcov build with instrumentation for gcov code coverage + [default=no] --enable-profile build profiled library [default=no] --enable-static-pie enable static PIE support and use it in the testsuite [default=no] @@ -3361,6 +3377,16 @@ else shared=yes fi + +# Check whether --enable-gcov was given. +if test "${enable_gcov+set}" = set; then : + enableval=$enable_gcov; gcov=$enableval +else + gcov=no +fi + + + # Check whether --enable-profile was given. if test "${enable_profile+set}" = set; then : enableval=$enable_profile; profile=$enableval diff --git a/configure.ac b/configure.ac index 93e68fb696..d5b27a4909 100644 --- a/configure.ac +++ b/configure.ac @@ -174,6 +174,14 @@ AC_ARG_ENABLE([shared], [build shared library @<:@default=yes if GNU ld@:>@]), [shared=$enableval], [shared=yes]) + +AC_ARG_ENABLE([gcov], + AC_HELP_STRING([--enable-gcov], + [build with instrumentation for gcov code coverage library @<:@default=no@:>@]), + [gcov=$enableval], + [gcov=no]) +AC_SUBST(gcov) + AC_ARG_ENABLE([profile], AC_HELP_STRING([--enable-profile], [build profiled library @<:@default=no@:>@]), diff --git a/manual/install.texi b/manual/install.texi index 2e164476d5..b990118ec6 100644 --- a/manual/install.texi +++ b/manual/install.texi @@ -141,6 +141,21 @@ Don't build shared libraries even if it is possible. Not all systems support shared libraries; you need ELF support and (currently) the GNU linker. +@item --enable-gcov +Enable building glibc with instrumentation for code coverage. For +individual files @option{--coverage} can be used, but this fails +when it is used as an option with @code{configure} command to build glibc. +To successfully build glibc with coverage, you must first build and install glibc +with shared libraries enabled. This will allow some files such as +@file{libc-modules.h} to be generated which are needed for code coverage +to work. +The command @samp{../configure --disable-shared --enable-gcov +--without-selinux --disable-nscd --prefix=/path/to/install} +will build glibc with code coverage. Note that not including a prefix, +or setting the prefix to usr/lib can affect the system glibc and can +render the system unusable. The command to make is 'make CXX=', without +which you will get a error 'cannot find -lgcc_s'. + @item --enable-static-pie Enable static position independent executable (static PIE) support. Static PIE is similar to static executable, but can be loaded at any -- 2.25.1