From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 42813385BF81; Sat, 6 Jun 2020 01:22:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 42813385BF81 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1591406558; bh=FZjbmoGWQlsba/0nP9Dg23WE4jLJikHutJ5zP97m64w=; h=From:To:Subject:Date:From; b=tDmjrsYTWqbARRtol1MaQ1CtcJWbLGdq9kBl2EIoli8nrHCpTHR7uHyhKxYdP6EUm xA9aZ8TsE3aq9abaWZyLed8eb+RvaNxfGGoBRlsarVt8TzgwSvT64fnGwPRa6b+bRg +mRALTjohieYb4rts7uKgAX+o9794LKD3+2iPhBI= From: "pgsql@j-davis.com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/95556] New: Not replacing __builtin___memcpy_chk() as documented Date: Sat, 06 Jun 2020 01:22:38 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 7.5.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: pgsql@j-davis.com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 06 Jun 2020 01:22:38 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95556 Bug ID: 95556 Summary: Not replacing __builtin___memcpy_chk() as documented Product: gcc Version: 7.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: pgsql@j-davis.com Target Milestone: --- Created attachment 48686 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D48686&action=3Dedit Example 2 GCC's Object Size Checking doc says: "There are built-in functions added for many common string operation functions, e.g., for memcpy=20 __builtin___memcpy_chk built-in is provided. This built-in has an additional last argument, which is the number of bytes remaining in the object the dest argument points to or (size_t) -1 if the size is not known. The built-in functions are optimized into the normal string functions like memcpy if the last argument is (size_t) -1 or if it is known at compile time that the destination object will not be overflowed..." https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html In the attached example1.c, __builtin___memcpy_chk() is optimized into the normal memcpy(), as expected. But in a slightly different example2.c, it is not, despite an object size of -1. When the checked version is left in place (like example2.c), it causes a significant regression in my case. This is important because Ubuntu 18.04 uses _FORTIFY_SOURCE, which ends up using __builtin___memcpy_chk() for memcpy. If gcc is arbitrarily leaving it= in place when it should be (according to the docs) optimized away, that affect= s a lot of code. I'm seeing this on Ubuntu 18.04 with both: gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0 gcc-9 (Ubuntu 9.2.1-19ubuntu1~18.04.york0) 9.2.1 20191109 It happens with or without -fno-builtin-memcpy (which is not a surprise, si= nce I am directly calling the builtin version anyway). Compiled using: gcc-9 -O2 -c -S -o example1.S example1.c gcc-9 -O2 -c -S -o example2.S example2.c example1.S:50: call memcpy@PLT example2.S:75: rep movsq=