From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2116.outbound.protection.outlook.com [40.107.237.116]) by sourceware.org (Postfix) with ESMTPS id AA7E93855035 for ; Thu, 17 Jun 2021 02:00:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AA7E93855035 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=i2bneaVUiOPO/huWdQI4REvFoY/9Jk5coj/JAopi0xwlZ94sJm31vI6wY1wiFZkdoQrlg1mPkMAjvXj3gwc19vyiMl3KBLxFkr3jwFslIlxfttxI+YQiIKKwwz+O+gI6Elil/SioK5YbQpN7zTfRyfJu1MQb26kO2uQNli6SYCZVinc0EGXLLxPB2KPEfgYGwc2/Xy5NPw2G7xQIsASQYm62NGMKLohtzSBuMKkBnccns5vdTEM74NNmoFrWx5gE5qHV3QDSAIi8uDcbgAsLZlJchFNFNy7htBMJ1q5TiPlmjHr5vY2gydzPOlyE+S/AFwWj5aj3ar18oMlpR2MJHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NB2nMirxvAOCD+hlDv7mdzMkajysztFkIiDRo72AfWU=; b=Gw0xg0A1qxf6aQpK1zH4oxkeEqecs6QEn2k1I7U41iYFfp3EgM8lQ1swygUumXkE7HRt1DrG2fNPzHmWGJp1gYJIeROD+FlZhaAXyzyiAIj8uOTZ5R4tTGGzQT9RKrTANuP2X75WaqRmwTbCKbvheNWWTrmPRSzY7GeEF9w5Jlc7rZTGZSpDTNyhI5qO9Va7VFf+1yB8vzeTTsWXvKV8Q1JFaAT4Un9qtefOeG6PNRg60Lyvf4ZcNpl6Bt2TabaRn9lgvkI/v3w37yw71JiG018a64Q68XoWZ2O7V43kQY4CUECmijIpqf0ULYVQeiA3nNRypmQW131ihk8/osDJFA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none Received: from MWHPR21MB0798.namprd21.prod.outlook.com (2603:10b6:300:128::18) by MWHPR21MB0831.namprd21.prod.outlook.com (2603:10b6:300:76::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.3; Thu, 17 Jun 2021 01:59:58 +0000 Received: from MWHPR21MB0798.namprd21.prod.outlook.com ([fe80::1d02:9a92:e9:c946]) by MWHPR21MB0798.namprd21.prod.outlook.com ([fe80::1d02:9a92:e9:c946%14]) with mapi id 15.20.4264.003; Thu, 17 Jun 2021 01:59:57 +0000 From: Eugene Rozenfeld To: =?iso-8859-2?Q?Martin_Li=B9ka?= , "gcc-patches@gcc.gnu.org" Subject: RE: [EXTERNAL] [PATCH] gcov: Use system IO buffering Thread-Topic: [EXTERNAL] [PATCH] gcov: Use system IO buffering Thread-Index: AQHXNoNFX4pDtFzbAkCvJKesOOcWkasXyj5A Date: Thu, 17 Jun 2021 01:59:57 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_ActionId=f3ca2aeb-da63-4efc-8740-c371d440f07b; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_ContentBits=0; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Enabled=true; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Method=Standard; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Name=Internal; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SetDate=2021-06-17T01:53:57Z; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SiteId=72f988bf-86f1-41af-91ab-2d7cd011db47; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 7a038f54-630a-4ef8-0381-08d931339bf5 x-ms-traffictypediagnostic: MWHPR21MB0831: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: LLwIvhK/4p7+9VxZjw9x1LaDeQWwR452IOEsn7jTmzTpJorp43ck4aLr0zjvE+rt6e5ycHNa81JQGf/1Nz3q1fav/OntCnaVqy0Q6C/i+JhbVGo6KPLWCeNVp5Op8aOhJA//XCidGddZD+PtGt+P3cSHqkzvbD+aIX9Ev6ZnqVvTsc3jv5ebIUJwbVhhEVvFWak+mSSGUc5f0bgAUTO6R96NLhq4TyR0ff+GAOEjv+OR7IIFpy1qge9E64eZRbA30y6RfmEvRYGeD+ajXWa0pQf0JecoELHRBz/SLJMY64B3mJk687JI05l0JCorBIeuwr1k5mgExgevOuOg4sWEKVri1Lz7bOUKEsZFa6AZYlo4j4Uxy96N5zeB5CDp280Hb8gUjqC5PoqPH8MjztNs1xhW8ZVD/6DZj/F5BxirFfK3X5cNmY4Ms3s+DTD9fVg1tRbX2eyGT1IT2EiFK53von8okfmT0EYcfrKF2bMGQHhDTCe9Wx8KSMhMEvo0g/ZtQZmFqxD1a1g3VVBPVUPVnlFmSj0Voax5kFnx5Jn0KLzfAQHPYouosP6jvjS0swXqK1AfKUPSfrR0Mx8ScqhqAUi/o7Map45x+BWYACSkEsokOs5xo2vr2FtIcBceEl/vPJaR+RZsUI9XLxNcpN3pAXjHjeApi3VG4pQwp6RIGD1stmO3CHEHskEtD11uduVTuET2B8yG1oFnCV9zCidwhl8uU0oa65iaA405ezeQzDQltE7oXqD6ZOiB+TULXqibeGG/nvomEvIKCPXyS33FTQ== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MWHPR21MB0798.namprd21.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(8676002)(6506007)(53546011)(8936002)(38100700002)(82960400001)(122000001)(82950400001)(83380400001)(33656002)(2906002)(66446008)(64756008)(66556008)(8990500004)(66574015)(10290500003)(30864003)(71200400001)(55016002)(316002)(86362001)(186003)(110136005)(478600001)(66476007)(66946007)(5660300002)(52536014)(76116006)(7696005)(9686003); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-2?Q?L+7bcnlBnDZJjuPLGlAX1CCAbFTK+//qViIh3HsiXSenB/yybQgIl5Rx7T?= =?iso-8859-2?Q?eqMuFUFr99GoWpNyD1fYrBUnLT0a8ERXhxtJ6XHEkELHb1rWCgYksN5P4W?= =?iso-8859-2?Q?fG05ArImb/CAeJ9upV71oNi/0oPTIHKt10e0sYJMT3eW+f4IUcCMT01qhT?= =?iso-8859-2?Q?ORBxmEIRZukqyWejLEa6gDFN7XXW3RU/1UEhfR3glAs4Ejk/mMhF45kaY+?= =?iso-8859-2?Q?5KOwHZQg9Asj+gPyb7Z67UVKtV4soLFlbR4gfb3B60B8CIiS8tFBivPuUA?= =?iso-8859-2?Q?YesZm88qqBw6LCnMHIyWWn0tUsmVEkrStg3ceJV7P8M470MBc5JvDC1FvM?= =?iso-8859-2?Q?t8BUgBY+uEFb6B89U7suXwuSu9uk0Aq9BKapkDnoGTozAasYkBQ9J3HwlI?= =?iso-8859-2?Q?OJHbpRUNYILuoUgPTJKgPTSIJP8rt1CVvDWYXWs3tKESeKUupvQjPP8DVb?= =?iso-8859-2?Q?HfglrjViD6R63JsUja1EmzvGxUk4lJtnBHgny5Zz4nSUxECFwURjCA9Va4?= =?iso-8859-2?Q?YfJYIAuDrHqtheeO6Q8b+xuaue9vXsCns++ks0OxKUTV8ByHyPw3PW5668?= =?iso-8859-2?Q?b1nh50zJmEIGfHtBh49vtPwoed5Z5OJ2CesSnLttxxGq9Jj+Bkvzk1lnlt?= =?iso-8859-2?Q?ODlJtRnyG6LO95VFcxzzHf5V5wTwJT/0O4JQ+2zA3/ufvp2FaNe6DFJHI8?= =?iso-8859-2?Q?KFMXy1pIVbHMRClm7dvc5CdSa3aORdCqq4dTWjFf88KWwqtZmcZ8MlIpfd?= =?iso-8859-2?Q?xIpKAAwxCM9QdY7q4gWcP5+rmRYmJnANNLHTezxDPF03Ff5QOql1YL55DJ?= =?iso-8859-2?Q?oMBZDs+7cKiSjdS4z6r/mZjoXJvOX8qQphxpAMCWVjVtCb67wIYlniGKPU?= =?iso-8859-2?Q?TVD4E9HADGGQ4TJ2tItOG+A+WgOb19r3v++ed8+fi2+6xtcROihkwUqYef?= =?iso-8859-2?Q?gCTp3RfvOm9jK2kDrtigpUBpc6sL6adYL3nMUUijCFoXhlHKZKuN2VIsbB?= =?iso-8859-2?Q?qNP761/5FtlMv1+DL5wXW0AwRmPXRJxzgihZwNS9VbqQod5Q/cJJ5WbDF0?= =?iso-8859-2?Q?eicqwQkQfrUSn7ZUbrAQ+YAhIputde+heAINPtmMQqO4wuqmezNS8YC0hy?= =?iso-8859-2?Q?m3fRibrlCjEgegY3NJIp1Rzgj16xEffF4VdBBnyFMwrbBGzayDRTwm1+vm?= =?iso-8859-2?Q?K8BThCdRG8h66xjnGdoTIA1aDzcsSHtE2uzWbjKNpofd38wcwOVj47QJfd?= =?iso-8859-2?Q?Ydg+QO4dS8/AI8n+PeWHya6M/KffWmPwSYPi+5oKdn6bhplkE2GqETdrvz?= =?iso-8859-2?Q?BRCgnk9aJz4rp5x3sA4YuAqYoTlu3GRWb254ci23sDn0HmPCdGkSqemxwH?= =?iso-8859-2?Q?PtsH0jOjgxx5ll55bYWqzIvvqAdhN26zR6uh9PGgvxQ1dNYnEkzqI=3D?= x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MWHPR21MB0798.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7a038f54-630a-4ef8-0381-08d931339bf5 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Jun 2021 01:59:57.7965 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Wz3ktLwaJL1bu8Y5DFaIk+9Q7W7l/t8faZdy+UUO0RuTpGXDHAiTJmLkpuEDTzPHQanWe00Hjc2h0jq3VgcUHw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR21MB0831 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, 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-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Jun 2021 02:00:03 -0000 The commit from this patch (https://gcc.gnu.org/git/?p=3Dgcc.git;a=3Dcommit= ;h=3D23eb66d1d46a34cb28c4acbdf8a1deb80a7c5a05) changed the semantics of gco= v_read_string and gcov_write_string. Before this change the string storage = was as described in gcov-io.h: "Strings are padded with 1 to 4 NUL bytes, to bring the length up to a multiple of 4. The number of 4 bytes is stored, followed by the padded string." After this change the number before the string indicates the number of byte= s (not words) and there is no padding. Was this file format change intentional? It breaks AutoFDO because create_g= cov produces strings in the format specified in gcov-io.h. Thanks, Eugene -----Original Message----- From: Gcc-patches On Behalf Of Martin Li= =B9ka Sent: Wednesday, April 21, 2021 12:52 AM To: gcc-patches@gcc.gnu.org Subject: [EXTERNAL] [PATCH] gcov: Use system IO buffering Hey. I/O buffering in gcov seems duplicite to what modern C library can provide. The patch is a simplification and can provide easier interface for system t= hat don't have a filesystem and would like using GCOV. I'm going to install the patch after 11.1 if there are no objections. Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Thanks, Martin gcc/ChangeLog: * gcov-io.c (gcov_write_block): Remove. (gcov_write_words): Likewise. (gcov_read_words): Re-implement using gcov_read_bytes. (gcov_allocate): Remove. (GCOV_BLOCK_SIZE): Likewise. (struct gcov_var): Remove most of the fields. (gcov_position): Implement with ftell. (gcov_rewrite): Remove setting of start and offset fields. (from_file): Re-format. (gcov_open): Remove setbuf call. It should not be needed. (gcov_close): Remove internal buffer handling. (gcov_magic): Use __builtin_bswap32. (gcov_write_counter): Use directly gcov_write_unsigned. (gcov_write_string): Use direct fwrite and do not round to 4 bytes. (gcov_seek): Use directly fseek. (gcov_write_tag): Use gcov_write_unsigned directly. (gcov_write_length): Likewise. (gcov_write_tag_length): Likewise. (gcov_read_bytes): Use directly fread. (gcov_read_unsigned): Use gcov_read_words. (gcov_read_counter): Likewise. (gcov_read_string): Use gcov_read_bytes. * gcov-io.h (GCOV_WORD_SIZE): Adjust to reflect that size is not in bytes, but words (4B). (GCOV_TAG_FUNCTION_LENGTH): Likewise. (GCOV_TAG_ARCS_LENGTH): Likewise. (GCOV_TAG_ARCS_NUM): Likewise. (GCOV_TAG_COUNTER_LENGTH): Likewise. (GCOV_TAG_COUNTER_NUM): Likewise. (GCOV_TAG_SUMMARY_LENGTH): Likewise. libgcc/ChangeLog: * libgcov-driver.c: Fix GNU coding style. --- gcc/gcov-io.c | 282 +++++++++------------------------------- gcc/gcov-io.h | 17 ++- libgcc/libgcov-driver.c | 6 +- 3 files changed, 76 insertions(+), 229 deletions(-) diff --git a/gcc/gcov-io.c b/gcc/gcov-io.c index 80c9082a649..bd2316dedab 1= 00644 --- a/gcc/gcov-io.c +++ b/gcc/gcov-io.c @@ -27,40 +27,14 @@ see the files COPYING3 and COPYING.RUNTIME respectively= . If not, see /* Routines declared in gcov-io.h. This file should be #included by another source file, after having #included gcov-io.h. */ =20 -#if !IN_GCOV -static void gcov_write_block (unsigned); -static gcov_unsigned_t *gcov_wri= te_words (unsigned); -#endif -static const gcov_unsigned_t *gcov_read_words= (unsigned); -#if !IN_LIBGCOV -static void gcov_allocate (unsigned); -#endi= f - -/* Optimum number of gcov_unsigned_t's read from or written to disk. */ -= #define GCOV_BLOCK_SIZE (1 << 10) +static gcov_unsigned_t *gcov_read_words (void *buffer, unsigned); =20 struct gcov_var { FILE *file; - gcov_position_t start; /* Position of first byte of block */ - unsigned offset; /* Read/write position within the block. */ - unsigned length; /* Read limit in the block. */ - unsigned overread; /* Number of words overread. */ int error; /* < 0 overflow, > 0 disk error. */ - int mode; /* < 0 writing, > 0 reading */ + int mode; /* < 0 writing, > 0 reading. */ int endian; /* Swap endianness. */ -#if IN_LIBGCOV - /* Holds one block plus 4 bytes, thus all coverage reads & writes - fit within this buffer and we always can transfer GCOV_BLOCK_SIZE - to and from the disk. libgcov never backtracks and only writes 4 - or 8 byte objects. */ - gcov_unsigned_t buffer[GCOV_BLOCK_SIZE + 1]; -#else - /* Holds a variable length block, as the compiler can write - strings and needs to backtrack. */ - size_t alloc; - gcov_unsigned_t *buffer; -#endif } gcov_var; =20 /* Save the current position in the gcov file. */ @@ -71,8 +45,7 @@ stati= c inline gcov_position_t gcov_position (void) { - gcov_nonruntime_assert (gcov_var.mode > 0); - return gcov_var.start + gcov_var.offset; + return ftell (gcov_var.file); } =20 /* Return nonzero if the error flag is set. */ @@ -92,20 +65,16 @@ GCOV_L= INKAGE inline void gcov_rewrite (void) { gcov_var.mode =3D -1; - gcov_var.start =3D 0; - gcov_var.offset =3D 0; fseek (gcov_var.file, 0L, SEEK_SET); } #endif =20 -static inline gcov_unsigned_t from_file (gcov_unsigned_t value) +static inline gcov_unsigned_t +from_file (gcov_unsigned_t value) { #if !IN_LIBGCOV || defined (IN_GCOV_TOOL) if (gcov_var.endian) - { - value =3D (value >> 16) | (value << 16); - value =3D ((value & 0xff00ff) << 8) | ((value >> 8) & 0xff00ff); - } + return __builtin_bswap32 (value); #endif return value; } @@ -140,9 +109,6 @@ gcov_open (const char *name, int mode) #endif =20 gcov_nonruntime_assert (!gcov_var.file); - gcov_var.start =3D 0; - gcov_var.offset =3D gcov_var.length =3D 0; - gcov_var.overread =3D -1u; gcov_var.error =3D 0; #if !IN_LIBGCOV || defined (IN_GCOV_TOOL) gcov_var.endian =3D 0; @@ -192,8 +158,6 @@ gcov_open (const char *name, int mode) =20 gcov_var.mode =3D mode ? mode : 1; =20 - setbuf (gcov_var.file, (char *)0); - return 1; } =20 @@ -205,19 +169,9 @@ gcov_close (void) { if (gcov_var.file) { -#if !IN_GCOV - if (gcov_var.offset && gcov_var.mode < 0) - gcov_write_block (gcov_var.offset); -#endif fclose (gcov_var.file); gcov_var.file =3D 0; - gcov_var.length =3D 0; } -#if !IN_LIBGCOV - free (gcov_var.buffer); - gcov_var.alloc =3D 0; - gcov_var.buffer =3D 0; -#endif gcov_var.mode =3D 0; return gcov_var.error; } @@ -232,9 +186,8 @@ gcov_magic (gcov_unsigned_t magic, gcov_unsigned_t expe= cted) { if (magic =3D=3D expected) return 1; - magic =3D (magic >> 16) | (magic << 16); - magic =3D ((magic & 0xff00ff) << 8) | ((magic >> 8) & 0xff00ff); - if (magic =3D=3D expected) + + if (__builtin_bswap32 (magic) =3D=3D expected) { gcov_var.endian =3D 1; return -1; @@ -243,71 +196,15 @@ gcov_magic (gcov_unsigned_t magic, gcov_unsigned_t ex= pected) } #endif =20 -#if !IN_LIBGCOV -static void -gcov_allocate (unsigned length) -{ - size_t new_size =3D gcov_var.alloc; - - if (!new_size) - new_size =3D GCOV_BLOCK_SIZE; - new_size +=3D length; - new_size *=3D 2; - - gcov_var.alloc =3D new_size; - gcov_var.buffer =3D XRESIZEVAR (gcov_unsigned_t, gcov_var.buffer, new_si= ze << 2); -} -#endif - #if !IN_GCOV -/* Write out the current block, if needs be. */ - -static void -gcov_write_block (unsigned size) -{ - if (fwrite (gcov_var.buffer, size << 2, 1, gcov_var.file) !=3D 1) - gcov_var.error =3D 1; - gcov_var.start +=3D size; - gcov_var.offset -=3D size; -} - -/* Allocate space to write BYTES bytes to the gcov file. Return a - pointer to those bytes, or NULL on failure. */ - -static gcov_unsigned_t * -gcov_write_words (unsigned words) -{ - gcov_unsigned_t *result; - - gcov_nonruntime_assert (gcov_var.mode < 0); -#if IN_LIBGCOV - if (gcov_var.offset >=3D GCOV_BLOCK_SIZE) - { - gcov_write_block (GCOV_BLOCK_SIZE); - if (gcov_var.offset) - { - memcpy (gcov_var.buffer, gcov_var.buffer + GCOV_BLOCK_SIZE, 4); - } - } -#else - if (gcov_var.offset + words > gcov_var.alloc) - gcov_allocate (gcov_var.offset + words); -#endif - result =3D &gcov_var.buffer[gcov_var.offset]; - gcov_var.offset +=3D words; - - return result; -} - -/* Write unsigned VALUE to coverage file. Sets error flag - appropriately. */ +/* Write unsigned VALUE to coverage file. */ =20 GCOV_LINKAGE void gcov_write_unsigned (gcov_unsigned_t value) { - gcov_unsigned_t *buffer =3D gcov_write_words (1); - - buffer[0] =3D value; + gcov_unsigned_t r =3D fwrite (&value, sizeof (value), 1,=20 + gcov_var.file); if (r !=3D 1) + gcov_var.error =3D 1; } =20 /* Write counter VALUE to coverage file. Sets error flag @@ -317,13 +214,= 11 @@ gcov_write_unsigned (gcov_unsigned_t value) GCOV_LINKAGE void gcov_= write_counter (gcov_type value) { - gcov_unsigned_t *buffer =3D gcov_write_words (2); - - buffer[0] =3D (gcov_unsigned_t) value; + gcov_write_unsigned ((gcov_unsigned_t) value); if (sizeof (value) > sizeof (gcov_unsigned_t)) - buffer[1] =3D (gcov_unsigned_t) (value >> 32); + gcov_write_unsigned ((gcov_unsigned_t) (value >> 32)); else - buffer[1] =3D 0; + gcov_write_unsigned (0); } #endif /* IN_LIBGCOV */ =20 @@ -335,23 +230,16 @@ GCOV_LINKAGE void gcov_write_string (const char *string) { unsigned length =3D 0; - unsigned alloc =3D 0; - gcov_unsigned_t *buffer; =20 if (string) - { - length =3D strlen (string); - alloc =3D (length + 4) >> 2; - } - - buffer =3D gcov_write_words (1 + alloc); + length =3D strlen (string) + 1; =20 - buffer[0] =3D alloc; - - if (alloc > 0) + gcov_write_unsigned (length); + if (length > 0) { - buffer[alloc] =3D 0; /* place nul terminators. */ - memcpy (&buffer[1], string, length); + gcov_unsigned_t r =3D fwrite (string, length, 1, gcov_var.file); + if (r !=3D 1) + gcov_var.error =3D 1; } } #endif @@ -388,6 +276,14 @@ gcov_write_filename (const char *filename) } #endif =20 +/* Move to a given position in a gcov file. */ + +GCOV_LINKAGE void +gcov_seek (gcov_position_t base) +{ + fseek (gcov_var.file, base, SEEK_SET); } + #if !IN_LIBGCOV /* Write a tag TAG and reserve space for the record length. Return a value to be used for gcov_write_length. */ @@ -395,11 +291,9 @@ gcov_w= rite_filename (const char *filename) GCOV_LINKAGE gcov_position_t gcov_wr= ite_tag (gcov_unsigned_t tag) { - gcov_position_t result =3D gcov_var.start + gcov_var.offset; - gcov_unsigned_t *buffer =3D gcov_write_words (2); - - buffer[0] =3D tag; - buffer[1] =3D 0; + gcov_position_t result =3D gcov_position (); gcov_write_unsigned=20 + (tag); gcov_write_unsigned (0); =20 return result; } @@ -412,19 +306,13 @@ gcov_write_tag (gcov_unsigned_t tag) GCOV_LINKAGE vo= id gcov_write_length (gcov_position_t position) { - unsigned offset; - gcov_unsigned_t length; - gcov_unsigned_t *buffer; - + gcov_position_t current_position =3D gcov_position (); gcov_nonruntime_assert (gcov_var.mode < 0); - gcov_nonruntime_assert (position + 2 <=3D gcov_var.start + gcov_var.offs= et); - gcov_nonruntime_assert (position >=3D gcov_var.start); - offset =3D position - gcov_var.start; - length =3D gcov_var.offset - offset - 2; - buffer =3D (gcov_unsigned_t *) &gcov_var.buffer[offset]; - buffer[1] =3D length; - if (gcov_var.offset >=3D GCOV_BLOCK_SIZE) - gcov_write_block (gcov_var.offset); + gcov_nonruntime_assert (current_position >=3D position + 2 *=20 + GCOV_WORD_SIZE); + + gcov_seek (position + GCOV_WORD_SIZE); gcov_write_unsigned=20 + (current_position - position - 2 * GCOV_WORD_SIZE); gcov_seek=20 + (current_position); } =20 #else /* IN_LIBGCOV */ @@ -434,10 +322,8 @@ gcov_write_length (gcov_position_t position) GCOV_LIN= KAGE void gcov_write_tag_length (gcov_unsigned_t tag, gcov_unsigned_t leng= th) { - gcov_unsigned_t *buffer =3D gcov_write_words (2); - - buffer[0] =3D tag; - buffer[1] =3D length; + gcov_write_unsigned (tag); + gcov_write_unsigned (length); } =20 /* Write a summary structure to the gcov file. Return nonzero on @@ -455,= 52 +341,28 @@ gcov_write_summary (gcov_unsigned_t tag, const struct gcov_su= mmary *summary) =20 #endif /*!IN_GCOV */ =20 -/* Return a pointer to read BYTES bytes from the gcov file. Returns +/* Return a pointer to read COUNT bytes from the gcov file. Returns NULL on failure (read past EOF). */ =20 -static const gcov_unsigned_t * -gcov_read_words (unsigned words) +static void * +gcov_read_bytes (void *buffer, unsigned count) { - const gcov_unsigned_t *result; - unsigned excess =3D gcov_var.length - gcov_var.offset; - if (gcov_var.mode <=3D 0) return NULL; =20 - if (excess < words) - { - gcov_var.start +=3D gcov_var.offset; - if (excess) - { -#if IN_LIBGCOV - memcpy (gcov_var.buffer, gcov_var.buffer + gcov_var.offset, 4); -#else - memmove (gcov_var.buffer, gcov_var.buffer + gcov_var.offset, - excess * 4); -#endif - } - gcov_var.offset =3D 0; - gcov_var.length =3D excess; -#if IN_LIBGCOV - excess =3D GCOV_BLOCK_SIZE; -#else - if (gcov_var.length + words > gcov_var.alloc) - gcov_allocate (gcov_var.length + words); - excess =3D gcov_var.alloc - gcov_var.length; -#endif - excess =3D fread (gcov_var.buffer + gcov_var.length, - 1, excess << 2, gcov_var.file) >> 2; - gcov_var.length +=3D excess; - if (gcov_var.length < words) - { - gcov_var.overread +=3D words - gcov_var.length; - gcov_var.length =3D 0; - return 0; - } - } - result =3D &gcov_var.buffer[gcov_var.offset]; - gcov_var.offset +=3D words; - return result; + unsigned read =3D fread (buffer, count, 1, gcov_var.file); if (read != =3D=20 + 1) + return NULL; + + return buffer; +} + +/* Read WORDS gcov_unsigned_t values from gcov file. */ + +static gcov_unsigned_t * +gcov_read_words (void *buffer, unsigned words) { + return (gcov_unsigned_t *)gcov_read_bytes (buffer, GCOV_WORD_SIZE *=20 +words); } =20 /* Read unsigned value from a coverage file. Sets error flag on file @@ -5= 10,10 +372,12 @@ GCOV_LINKAGE gcov_unsigned_t gcov_read_unsigned (void) { gcov_unsigned_t value; - const gcov_unsigned_t *buffer =3D gcov_read_words (1); + gcov_unsigned_t allocated_buffer[1]; + gcov_unsigned_t *buffer =3D gcov_read_words (&allocated_buffer, 1); =20 if (!buffer) return 0; + value =3D from_file (buffer[0]); return value; } @@ -525,7 +389,8 @@ GCOV_LINKAGE gcov_type gcov_read_counter (void) { gcov_type value; - const gcov_unsigned_t *buffer =3D gcov_read_words (2); + gcov_unsigned_t allocated_buffer[2]; + gcov_unsigned_t *buffer =3D gcov_read_words (&allocated_buffer, 2); =20 if (!buffer) return 0; @@ -602,7 +467,8 @@ gcov_read_string (void) if (!length) return 0; =20 - return (const char *) gcov_read_words (length); + void *buffer =3D XNEWVEC (char *, length); return (const char *)=20 + gcov_read_bytes (buffer, length); } #endif =20 @@ -624,27 +490,7 @@ gcov_sync (gcov_position_t base, gcov_unsigned_t lengt= h) { gcov_nonruntime_assert (gcov_var.mode > 0); base +=3D length; - if (base - gcov_var.start <=3D gcov_var.length) - gcov_var.offset =3D base - gcov_var.start; - else - { - gcov_var.offset =3D gcov_var.length =3D 0; - fseek (gcov_var.file, base << 2, SEEK_SET); - gcov_var.start =3D ftell (gcov_var.file) >> 2; - } -} -#endif - -#if IN_LIBGCOV -/* Move to a given position in a gcov file. */ - -GCOV_LINKAGE void -gcov_seek (gcov_position_t base) -{ - if (gcov_var.offset) - gcov_write_block (gcov_var.offset); - fseek (gcov_var.file, base << 2, SEEK_SET); - gcov_var.start =3D ftell (gcov_var.file) >> 2; + fseek (gcov_var.file, base, SEEK_SET); } #endif =20 diff --git a/gcc/gcov-io.h b/gcc/gcov-io.h index 75f16a274c7..c1a0eae4712 1= 00644 --- a/gcc/gcov-io.h +++ b/gcc/gcov-io.h @@ -241,22 +241,25 @@ typedef uint64_t gcov_type_unsigned; /* The record tags. Values [1..3f] are for tags which may be in either file. Values [41..9f] for those in the note file and [a1..ff] for the data file. The tag value zero is used as an explicit end of - file marker -- it is not required to be present. */ + file marker -- it is not required to be present. + All length values are in bytes. */ + +#define GCOV_WORD_SIZE 4 =20 #define GCOV_TAG_FUNCTION ((gcov_unsigned_t)0x01000000) -#define GCOV_TAG_FUNCTION_LENGTH (3) +#define GCOV_TAG_FUNCTION_LENGTH (3 * GCOV_WORD_SIZE) #define GCOV_TAG_BLOCKS ((gcov_unsigned_t)0x01410000) #define GCOV_TAG_BLOCKS_LENGTH(NUM) (NUM) #define GCOV_TAG_ARCS ((gcov_unsigned_t)0x01430000) -#define GCOV_TAG_ARCS_LENGTH(NUM) (1 + (NUM) * 2) -#define GCOV_TAG_ARCS_= NUM(LENGTH) (((LENGTH) - 1) / 2) +#define GCOV_TAG_ARCS_LENGTH(NUM) (1 + (NUM) * 2 * GCOV_WORD_SIZE)=20 +#define GCOV_TAG_ARCS_NUM(LENGTH) (((LENGTH / GCOV_WORD_SIZE) - 1) /=20 +2) #define GCOV_TAG_LINES ((gcov_unsigned_t)0x01450000) #define GCOV_TAG_COUNTER_BASE ((gcov_unsigned_t)0x01a10000) -#define GCOV_TAG_COUNTER_LENGTH(NUM) ((NUM) * 2) -#define GCOV_TAG_COUNTER= _NUM(LENGTH) ((LENGTH) / 2) +#define GCOV_TAG_COUNTER_LENGTH(NUM) ((NUM) * 2 * GCOV_WORD_SIZE)=20 +#define GCOV_TAG_COUNTER_NUM(LENGTH) ((LENGTH / GCOV_WORD_SIZE) / 2) #define GCOV_TAG_OBJECT_SUMMARY ((gcov_unsigned_t)0xa1000000) #define GC= OV_TAG_PROGRAM_SUMMARY ((gcov_unsigned_t)0xa3000000) /* Obsolete */ -#defin= e GCOV_TAG_SUMMARY_LENGTH (2) +#define GCOV_TAG_SUMMARY_LENGTH (2 * GCOV_WORD_SIZE) #define GCOV_TAG_AFDO_FILE_NAMES ((gcov_unsigned_t)0xaa000000) #define GC= OV_TAG_AFDO_FUNCTION ((gcov_unsigned_t)0xac000000) #define GCOV_TAG_AFDO_W= ORKING_SET ((gcov_unsigned_t)0xaf000000) diff --git a/libgcc/libgcov-driver= .c b/libgcc/libgcov-driver.c index a1338b6e525..02ae265aaa8 100644 --- a/libgcc/libgcov-driver.c +++ b/libgcc/libgcov-driver.c @@ -553,10 +553,8 @@ read_fatal:; fn_buffer =3D free_fn_data (gi_ptr, fn_buffer, GCOV_COUNTERS); =20 if ((error =3D gcov_close ())) - gcov_error (error < 0 ? - GCOV_PROF_PREFIX "Overflow writing\n" : - GCOV_PROF_PREFIX "Error writing\n", - gf->filename); + gcov_error ((error < 0 ? GCOV_PROF_PREFIX "Overflow writing\n" + : GCOV_PROF_PREFIX "Error writing\n"), gf->filename); } =20 =20 -- 2.31.1