public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/111165] New: [13 regression] builtin strchr miscompiles on Debian/x32 with dietlibc
@ 2023-08-26 18:17 tg at mirbsd dot org
  2023-08-26 18:20 ` [Bug target/111165] " pinskia at gcc dot gnu.org
                   ` (18 more replies)
  0 siblings, 19 replies; 20+ messages in thread
From: tg at mirbsd dot org @ 2023-08-26 18:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111165

            Bug ID: 111165
           Summary: [13 regression] builtin strchr miscompiles on
                    Debian/x32 with dietlibc
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tg at mirbsd dot org
  Target Milestone: ---

Debian bug reported as:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1050589

I’ve got no idea how to quickly reduce that down, but perhaps anyone has got an
idea.

In an x32 (amd64ilp32) environment, with dietlibc/x32 as packaged in Debian (no
shared libraries), building mksh and then running the command 'x=q; x=${ echo
a; typeset e=2; return 3; echo x$e;}; echo .$x.' with the resulting binary
results in the output “..” instead of “.a.”.

This does not occur when either
- giving -fno-builtin-strchr
- wrapping strchr as outlined below
  (which makes me think of register corruption occurring here)
- using amd64 instead of x32 (amd64ilp32)
- using glibc, klibc or musl (though klibc/x32 is in reality amd64 so it can be
discounted)
- using GCC 12.3.0

The codepath is a bit convoluted, setjmp/longjmp are involved.

Wrapping strchr by adding…

char *ucstrchr(char *, int);
const char *cstrchr(const char *, int);
#undef strchr
#define strchr          poisoned_strchr

… to a .h file that’s globally included, and adding the following…

#undef strchr
char *ucstrchr(char *s, int c)
{
        return (strchr(s, c));
}
const char *cstrchr(const char *s, int c)
{
        return (strchr(s, c));
}

… to one .c file *also* works around the bug, for some reason. (mksh is built
with -fno-lto because of other GCC issues I filed regarding this.)

IIRC the builtins are hidden within the LISPy machine definitions or something;
I’m afraid at this point this is beyond my own ability to reduce down, but do
ask me (ideally via eMail to both <1050589-submitter@bugs.debian.org> and
<1050589@bugs.debian.org> (to keep the bug in Cc), but
@mirabilos@toot.mirbsd.org on Fediverse is fine too) if you need any further
details.

(All testing has been done with GCC and dietlibc as packaged in Debian;
especially the latter has quite the deviation from upstream, but I have looked
at diffs and logs and don’t think those are relevant here.)

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2024-05-21  9:16 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-26 18:17 [Bug target/111165] New: [13 regression] builtin strchr miscompiles on Debian/x32 with dietlibc tg at mirbsd dot org
2023-08-26 18:20 ` [Bug target/111165] " pinskia at gcc dot gnu.org
2023-08-26 18:21 ` pinskia at gcc dot gnu.org
2023-08-26 19:36 ` tg at mirbsd dot org
2023-08-26 20:03 ` tg at mirbsd dot org
2023-08-26 20:21 ` tg at mirbsd dot org
2023-08-26 20:49 ` tg at mirbsd dot org
2023-08-26 21:18 ` tg at mirbsd dot org
2023-08-28  7:25 ` rguenth at gcc dot gnu.org
2023-08-28 14:22 ` tg at mirbsd dot org
2023-08-28 14:41 ` tg at mirbsd dot org
2023-08-28 14:46 ` tg at mirbsd dot org
2023-08-28 14:57 ` tg at mirbsd dot org
2023-08-28 15:02 ` tg at mirbsd dot org
2023-08-28 15:26 ` ubizjak at gmail dot com
2023-08-28 15:44 ` hjl.tools at gmail dot com
2023-08-28 16:08 ` tg at mirbsd dot org
2023-08-28 16:09 ` tg at mirbsd dot org
2023-08-28 16:38 ` tg at mirbsd dot org
2024-05-21  9:16 ` jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).