From patchwork Tue Sep 2 22:18:42 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rong Xu X-Patchwork-Id: 385339 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40C3D140141 for ; Wed, 3 Sep 2014 08:18:58 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:cc:content-type; q=dns; s=default; b=cVOPO6b/PUhSOJCOT6axgAKEXv9dW23O9OEO5h68OE9 iLOdUjEyCKJ7l5tI3SSfIdeyIyR842q3cLV6rdZq7G4/TlUGYimTz3GZLGB2psbo EXw3hMmOjcB7Lq8ln2pGFh8/zZwfBANa03ZDmrYT06gnucsmfi7OSZMNy7rAdK4g = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:cc:content-type; s=default; bh=suiTJ4iUmM0wnfpZ7tAP7300lQc=; b=F8d0nqhlguKRnXLrF Lbb/n7W66KBjYYRygTllG7evLFxFsX0hUIKinBr9qcjWN4Z8+U3fOcT4eG0+xo1A KchkOo7tRNODOq7BgMbtWiKFhRZAmHXFUZaDTQ1e4PP5pzLpg1C+rDN5srxEB1Ll nBpgB7B/vyX3sTBPyFRTUN1kPE= Received: (qmail 14613 invoked by alias); 2 Sep 2014 22:18:50 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 14603 invoked by uid 89); 2 Sep 2014 22:18:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS, SUBJ_ALL_CAPS autolearn=unavailable version=3.3.2 X-HELO: mail-oa0-f46.google.com Received: from mail-oa0-f46.google.com (HELO mail-oa0-f46.google.com) (209.85.219.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 02 Sep 2014 22:18:44 +0000 Received: by mail-oa0-f46.google.com with SMTP id m19so5328539oag.33 for ; Tue, 02 Sep 2014 15:18:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to:cc :content-type; bh=+OoABTtAk6EgXwCMg6tcKrvY3Ifsu0pserYqrvmrORE=; b=H7eqA8re3+e6afH+0MqhOQn6KGHNDs6yGhU4QarDbs/dHeDTu1FkL68YaTEJP6MT1l pT8aif3LdnyZkGQUbRZc2nO99S99La8aPAoZSFAclidS8AjqCYwrPRkeh+fB7TUexeFU vIUDC1eaVvk259QK+abF5L+KMEVa0+FG/piVCyktiT8BotIxppt2QyGkj7Co99LkON+Y L27nZk5NfYeRbMX0hgPbBnHFpfzZSTvmZ+E/y1+yhZE2+YqY77OxoIVDovtizFOcTrjh Mwbe59f8LmmLzvLJKxTaZkkGL1+qGR/bB4PiZMlVUTYK9SZEEErfh+qMe0WqPcsC7ctL a0Mw== X-Gm-Message-State: ALoCoQm0IN15ABF0tFDDyqaDjG/JA5tNVNFAYFoikaCm/kkTzBmZ32ieGNlgRzLlni5MGImFNsLO MIME-Version: 1.0 X-Received: by 10.60.57.193 with SMTP id k1mr4741408oeq.66.1409696322351; Tue, 02 Sep 2014 15:18:42 -0700 (PDT) Received: by 10.182.109.100 with HTTP; Tue, 2 Sep 2014 15:18:42 -0700 (PDT) Date: Tue, 2 Sep 2014 15:18:42 -0700 Message-ID: Subject: [PATCH] PR61889 From: Rong Xu To: GCC Patches Cc: Jan Hubicka , ktietz@gcc.gnu.org, rguenth@gcc.gnu.org X-IsSubscribed: yes This patch makes the build of gcov-tool configurable. It checks if ftw.h is available. For mingw build, it provides ftw functionality by using FindFirstFile/FindNextFile/FindClose API. Tested with and without --disable-gcov-tool. Thanks, -Rong 2014-09-02 Rong Xu * gcc/Makefile.in: Make the build gcov-tool configurable. * gcc/configure.ac: Ditto. * gcc/configure: Ditto. * gcc/config.in: Ditto. * gcc/gcov-tool.c (unlink_gcda_file): Support win32 build. (unlink_profile_dir): Ditto. * libgcc/libgcov-util.c (read_gcda_file): Ditto. (read_file_handler): Ditto. (ftw_read_file): Ditto. (myftw): Ditto. (gcov_read_profile_dir): Ditto. (gcov_profile_normalize): Ditto. Index: gcc/Makefile.in =================================================================== --- gcc/Makefile.in (revision 214831) +++ gcc/Makefile.in (working copy) @@ -123,9 +123,13 @@ SUBDIRS =@subdirs@ build # Selection of languages to be made. CONFIG_LANGUAGES = @all_selected_languages@ -LANGUAGES = c gcov$(exeext) gcov-dump$(exeext) gcov-tool$(exeext) \ - $(CONFIG_LANGUAGES) +LANGUAGES = c gcov$(exeext) gcov-dump$(exeext) $(CONFIG_LANGUAGES) +disable_gcov_tool = @disable_gcov_tool@ +ifneq ($(disable_gcov_tool),yes) +LANGUAGES += gcov-tool$(exeext) +endif + # Default values for variables overridden in Makefile fragments. # CFLAGS is for the user to override to, e.g., do a cross build with -O2. # TCFLAGS is used for compilations with the GCC just built. Index: gcc/configure.ac =================================================================== --- gcc/configure.ac (revision 214831) +++ gcc/configure.ac (working copy) @@ -5650,6 +5650,26 @@ if test "${ENABLE_LIBQUADMATH_SUPPORT}" != "no" ; fi +# Check if gcov-tool can be built. +AC_ARG_ENABLE(gcov-tool, +[AS_HELP_STRING([--disable-gcov-tool], + [disable the build of gcov-tool])]) +if test x"$enable_gcov_tool" = x"no"; then + disable_gcov_tool=yes +else + AC_CHECK_HEADERS(ftw.h, [disable_gcov_tool=no], + [case $host_os in + win32 | cygwin* | mingw32*) + disable_gcov_tool=no + ;; + *) + disable_gcov_tool=yes + ;; + esac]) +fi +AC_SUBST(disable_gcov_tool) + + # Specify what hash style to use by default. AC_ARG_WITH([linker-hash-style], [AC_HELP_STRING([--with-linker-hash-style={sysv,gnu,both}], Index: gcc/configure =================================================================== --- gcc/configure (revision 214831) +++ gcc/configure (working copy) @@ -600,6 +600,7 @@ ac_includes_default="\ ac_subst_vars='LTLIBOBJS LIBOBJS +disable_gcov_tool PICFLAG enable_host_shared enable_plugin @@ -932,6 +933,7 @@ enable_version_specific_runtime_libs enable_plugin enable_host_shared enable_libquadmath_support +enable_gcov_tool with_linker_hash_style ' ac_precious_vars='build_alias @@ -1655,6 +1657,7 @@ Optional Features: --enable-host-shared build host code as shared libraries --disable-libquadmath-support disable libquadmath support for Fortran + --disable-gcov-tool disable the build of gcov-tool Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] @@ -8353,7 +8356,7 @@ fi for ac_header in limits.h stddef.h string.h strings.h stdlib.h time.h iconv.h \ fcntl.h unistd.h sys/file.h sys/time.h sys/mman.h \ sys/resource.h sys/param.h sys/times.h sys/stat.h \ - direct.h malloc.h langinfo.h ldfcn.h locale.h wchar.h + direct.h malloc.h langinfo.h ldfcn.h locale.h wchar.h ftw.h do : as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` ac_fn_c_check_header_preproc "$LINENO" "$ac_header" "$as_ac_Header" @@ -18033,7 +18036,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 18036 "configure" +#line 18039 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -18139,7 +18142,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 18142 "configure" +#line 18145 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -28116,6 +28119,33 @@ $as_echo "#define ENABLE_LIBQUADMATH_SUPPORT 1" >> fi +# Check if gcov-tool can be built. +# Check whether --enable-gcov-tool was given. +if test "${enable_gcov_tool+set}" = set; then : + enableval=$enable_gcov_tool; +fi + +if test x"$enable_gcov_tool" = x"no"; then + disable_gcov_tool=yes +else + ac_fn_c_check_header_preproc "$LINENO" "ftw.h" "ac_cv_header_ftw_h" +if test "x$ac_cv_header_ftw_h" = x""yes; then : + disable_gcov_tool=no +else + case $host_os in + win32 | cygwin* | mingw32*) + disable_gcov_tool=no + ;; + *) + disable_gcov_tool=yes + ;; + esac +fi + +fi + + + # Specify what hash style to use by default. # Check whether --with-linker-hash-style was given. Index: gcc/config.in =================================================================== --- gcc/config.in (revision 214831) +++ gcc/config.in (working copy) @@ -1046,6 +1046,12 @@ #endif +/* Define to 1 if you have the header file. */ +#ifndef USED_FOR_TARGET +#undef HAVE_FTW_H +#endif + + /* Define to 1 if you have the `fwrite_unlocked' function. */ #ifndef USED_FOR_TARGET #undef HAVE_FWRITE_UNLOCKED @@ -1699,16 +1705,19 @@ #undef HAVE_WORKING_VFORK #endif -/* Define if isl is in use. */ -#ifndef USED_FOR_TARGET -#undef HAVE_isl -#endif /* Define if cloog is in use. */ #ifndef USED_FOR_TARGET #undef HAVE_cloog #endif + +/* Define if isl is in use. */ +#ifndef USED_FOR_TARGET +#undef HAVE_isl +#endif + + /* Define if F_SETLKW supported by fcntl. */ #ifndef USED_FOR_TARGET #undef HOST_HAS_F_SETLKW Index: gcc/gcov-tool.c =================================================================== --- gcc/gcov-tool.c (revision 214831) +++ gcc/gcov-tool.c (working copy) @@ -35,7 +35,9 @@ see the files COPYING3 and COPYING.RUNTIME respect #include #include #include +#ifdef HAVE_FTW_H #include +#endif #include extern int gcov_profile_merge (struct gcov_info*, struct gcov_info*, int, int); @@ -50,6 +52,7 @@ static bool verbose; /* Remove file NAME if it has a gcda suffix. */ +#ifdef HAVE_FTW_H static int unlink_gcda_file (const char *name, const struct stat *status ATTRIBUTE_UNUSED, @@ -68,15 +71,21 @@ unlink_gcda_file (const char *name, return ret; } +#endif /* Remove the gcda files in PATH recursively. */ static int unlink_profile_dir (const char *path) { +#ifdef HAVE_FTW_H return nftw(path, unlink_gcda_file, 64, FTW_DEPTH | FTW_PHYS); +#else + return 0; +#endif } + /* Output GCOV_INFO lists PROFILE to directory OUT. Note that we will remove all the gcda files in OUT. */ Index: libgcc/libgcov-util.c =================================================================== --- libgcc/libgcov-util.c (revision 214831) +++ libgcc/libgcov-util.c (working copy) @@ -52,7 +52,13 @@ void gcov_set_verbose (void) #include "obstack.h" #include +#ifdef HAVE_FTW_H #include +#else +#if defined(_WIN32) +#include +#endif +#endif static void tag_function (unsigned, unsigned); static void tag_blocks (unsigned, unsigned); @@ -281,13 +287,8 @@ read_gcda_file (const char *filename) } /* Read version. */ - version = gcov_read_unsigned (); if (version != GCOV_VERSION) - { - fnotice (stderr, "%s:incorrect gcov version %d vs %d \n", filename, version, GCOV_VERSION); - gcov_close (); - return NULL; - } + warning (0, "%s:incorrect gcov version %d vs %d \n", filename, version, GCOV_VERSION); /* Instantiate a gcov_info object. */ curr_gcov_info = obj_info = (struct gcov_info *) xcalloc (sizeof (struct gcov_info) + @@ -380,22 +381,16 @@ read_gcda_file (const char *filename) return obj_info; } -/* This will be called by ftw(). It opens and read a gcda file FILENAME. - Return a non-zero value to stop the tree walk. */ +/* Handler to open and read a gcda file FILENAME. */ + static int -ftw_read_file (const char *filename, - const struct stat *status ATTRIBUTE_UNUSED, - int type) +read_file_handler (const char *filename) { int filename_len; int suffix_len; struct gcov_info *obj_info; - /* Only read regular files. */ - if (type != FTW_F) - return 0; - filename_len = strlen (filename); suffix_len = strlen (GCOV_DATA_SUFFIX); @@ -418,6 +413,71 @@ static int return 0; } +#ifdef HAVE_FTW_H +/* This will be called by ftw(). It opens and read a gcda file FILENAME. + Return a non-zero value to stop the tree walk. */ + +static int +ftw_read_file (const char *filename, + const struct stat *status ATTRIBUTE_UNUSED, + int type) +{ + /* Only read regular files. */ + if (type != FTW_F) + return 0; + return read_file_handler (filename); +} + +#else /* !HAVE_FTW_H */ + +#if defined(_WIN32) +/* Funtion to find all the gcda files recursively in DIR. */ +static void +myftw (char *dir, char* pattern, int (*handler)(const char *)) +{ + char buffer[MAX_PATH]; + WIN32_FIND_DATA filedata; + HANDLE ret; + + /* Process the subdirectories. */ + sprintf (buffer, "%s\\*", dir); + ret = FindFirstFile (buffer, &filedata); + if(ret != INVALID_HANDLE_VALUE) + { + do + { + if(filedata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + { + if (filedata.cFileName[0] == '.') + continue; + sprintf (buffer, "%s\\%s", dir, filedata.cFileName); + myftw (buffer, pattern, handler); + } + } while(FindNextFile (ret, &filedata)); + FindClose(ret); + } + + /* Find the matching files. */ + sprintf (buffer, "%s\\%s", dir, pattern); + ret = FindFirstFile (buffer, &filedata); + if(ret != INVALID_HANDLE_VALUE) + { + do + { + if(!(filedata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) + { + /* Apply action. */ + (*handler) (buffer); + } + } while(FindNextFile (ret, &filedata)); + FindClose (ret); + } +} +#endif /* _WIN32 */ + +#endif /* HAVE_FTW_H */ + + /* Initializer for reading a profile dir. */ static inline void @@ -451,7 +511,14 @@ gcov_read_profile_dir (const char* dir_name, int r fnotice (stderr, "%s is not a directory\n", dir_name); return NULL; } +#ifdef HAVE_FTW_H ftw (".", ftw_read_file, 50); +#else +#if defined(_WIN32) + myftw (".", "*.gcda", read_file_handler); +#endif +#endif + ret = chdir (pwd); free (pwd); @@ -852,8 +919,10 @@ gcov_profile_normalize (struct gcov_info *profile, } scale_factor = (float)max_val / curr_max_val; +#if !defined(_WIN32) if (verbose) fnotice (stdout, "max_val is %lld\n", (long long) curr_max_val); +#endif return gcov_profile_scale (profile, scale_factor, 0, 0); }