From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D05A93858C41; Sat, 26 Aug 2023 20:21:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D05A93858C41 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1693081283; bh=zXrLpcEVGIXd/6la6W4Gx9Xo8ClsuCFjmwS2+b93ZVc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=AUtPRdcVnRcr099w1dpDMCxp6bbzeSFdDiRQTlVSzip2WyCSWlG4mdd8qNvSNa8pr nK6YQe3/NRNgFTtTiqdOWqOpqAW2Jv3XyCpeIhYGDVN6FNKBmtj7Rc25kbj7tPilyW PtlpBPgUfTI2FFI9Pf/t6YTAMbAjF302HL8DkyEY= From: "tg at mirbsd dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/111165] [13 regression] builtin strchr miscompiles on Debian/x32 with dietlibc Date: Sat, 26 Aug 2023 20:21:23 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 13.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: tg at mirbsd dot org X-Bugzilla-Status: WAITING 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: Message-ID: In-Reply-To: References: 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D111165 --- Comment #5 from Thorsten Glaser --- I managed to isolate one specific strchr call changing which causes the breakage to go away: asm volatile("nop"); //401 sp =3D cstrchr(sp, '\0') + 1; asm volatile("nop"); //403 where: #define cstrchr(s,c) ((const char *)strchr((s), (c))) const char *sp; I inserted NOPs around (see above) and set gdb breakpoints there, and before/after those breakpoints, the callee-saved registers differ (only sho= wing callee-saved registers for amd64/x32): (gdb) info r rbx 0x0 0 rbp 0xf7ff790c 4160715020 r12 0x2 2 r13 0xffffd1b4 4294955444 r14 0xf7ff510c 4160704780 r15 0x0 0 (gdb) c (gdb) info r rbx 0xf7ff790e 4160715022 rbp 0xf7ff790c 4160715020 r12 0xf7ff7912 4160715026 r13 0xffffd1b4 4294955444 r14 0xf7ff510c 4160704780 r15 0x0 0 Corresponding disassembly of generated code between the NOPs: =3D> 0x0040a635 <+1875>: nop 0x0040a636 <+1876>: mov 0x48(%rsp),%ebx 0x0040a63a <+1880>: mov %rbx,%rdi 0x0040a63d <+1883>: call 0x42cc6e 0x0040a642 <+1888>: mov 0x48(%rsp),%ecx 0x0040a646 <+1892>: lea 0x1(%rcx,%rax,1),%r12d 0x0040a64b <+1897>: nop or, in readable: =3D> 0x0040a635 <+1875>: nop 0x0040a636 <+1876>: mov ebx,DWORD PTR [rsp+0x48] 0x0040a63a <+1880>: mov rdi,rbx 0x0040a63d <+1883>: call 0x42cc6e 0x0040a642 <+1888>: mov ecx,DWORD PTR [rsp+0x48] 0x0040a646 <+1892>: lea r12d,[rcx+rax*1+0x1] 0x0040a64b <+1897>: nop OK, huh=E2=80=A6 no strchr involved here. For comparison, with -fno-builtin-strchr: =3D> 0x0040a632 <+1872>: nop 0x0040a633 <+1873>: mov ebx,DWORD PTR [rsp+0x48] 0x0040a637 <+1877>: xor esi,esi 0x0040a639 <+1879>: mov rdi,rbx 0x0040a63c <+1882>: call 0x42cba4 0x0040a641 <+1887>: mov r14d,eax 0x0040a644 <+1890>: inc eax 0x0040a646 <+1892>: mov DWORD PTR [rsp+0x3c],eax 0x0040a64a <+1896>: nop I=E2=80=99ll dig into strlen in dietlibc/x32 next.=