Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libast: Work around gcc optimiser bug for strdup() (rhbz#1221766)
Red Hat erratum: https://bugzilla.redhat.com/1221766 "Previously, the gcc utility optimized out a non-NULL test in the ksh implementation of the strdup() function. This caused an unexpected termination when ksh was executed in a clean chroot environment. With this update, ksh compilation parameters have been updated to prevent optimizing out a non-NULL test, and ksh no longer crashes in clean chroot environments." The optimizer bug occurs in that function's single-line body: return (s && (t = oldof(0, char, n = strlen(s) + 1, 0))) ? (char*)memcpy(t, s, n) : (char*)0; So it must be the test for non-NULL 's' that fails. And 's' is declared in the function definition, as follows: extern char* strdup(register const char* s) So that makes me wonder if we can work around the bug by simply removing the 'const' (and the 'register' while we're at it). However, I have no easy way to verify that at the moment. The Red Hat patch instead tells gcc to disable optimization for this function using a #pragma directive. I have no idea if that gcc optimiser bug has been fixed in the meantime, but experience from c258a04 has shown that we cannot trust that it has been fixed (that other optimizer bug is at least a decade old and still not fixed). So, in it goes, until someone shows evidence that we no longer need it. Original patch: https://src.fedoraproject.org/rpms/ksh/blob/642af4d6/f/ksh-20120801-badgcc.patch src/lib/libast/string/strdup.c: - Tell GCC to disable all optimisations for strdup().
- Loading branch information
7afb30e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The relevant Red Hat bug report for this patch is rhbz#1269088 (which does have a reproducer). I looked at the stack trace in the thread and noticed the
strdup
that triggers the crash callsttyname
:This leads me to believe the crash is the same as the one I fixed in #63, although that doesn't necessarily mean Red Hat's patch is useless. GCC still over-optimizes
strdup
, as made plain by the fact GCC produces a-Wnonnull-compare
warning when compilingstrdup.c
: