https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103961
Bug ID: 103961
Summary: gcc-12 apparently miscompiles libcap's cap_to_text()
function
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: manuel.lauss at googlemail dot com
Target Milestone: ---
Created attachment 52152
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52152&action=edit
preprocessed source file
gcc-12 apparently miscompiles the libcap-2.62 function "cap_to_text()".
I've seen it manifest with "ls" segfaulting in certain directories:
$ ls
*** buffer overflow detected ***: terminated
Aborted (core dumped)
#0 __pthread_kill_implementation (threadid=<optimized out>,
signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
44 return INTERNAL_SYSCALL_ERROR_P (ret) ? INTERNAL_SYSCALL_ERRNO
(ret) : 0;
(gdb) bt
#0 __pthread_kill_implementation (threadid=<optimized out>,
signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
#1 0x00007f34f856932f in __pthread_kill_internal (signo=6, threadid=<optimized
out>) at pthread_kill.c:78
#2 0x00007f34f8518e42 in __GI_raise (sig=sig@entry=6) at
../sysdeps/posix/raise.c:26
#3 0x00007f34f8503457 in __GI_abort () at abort.c:79
#4 0x00007f34f855d5a8 in __libc_message (action=action@entry=do_abort,
fmt=fmt@entry=0x7f34f8690291 "*** %s ***: terminated\n") at
../sysdeps/posix/libc_fatal.c:155
#5 0x00007f34f85fb042 in __GI___fortify_fail (msg=msg@entry=0x7f34f8690237
"buffer overflow detected") at fortify_fail.c:26
#6 0x00007f34f85f9b60 in __GI___chk_fail () at chk_fail.c:28
#7 0x00007f34f85f96d5 in ___sprintf_chk (s=s@entry=0x7fff9f08c6c2 ",",
flag=flag@entry=1, slen=slen@entry=0, format=format@entry=0x7f34f86dc085
"%c%s%s%s")
at sprintf_chk.c:37
#8 0x00007f34f86da882 in sprintf (__fmt=0x7f34f86dc085 "%c%s%s%s",
__s=<optimized out>) at /usr/include/bits/stdio2.h:38
#9 cap_to_text (caps=0x5643cf9b1a38, length_p=0x0) at cap_text.c:431
#10 0x00005643cf983285 in ?? ()
If I replace the cap_text.o file from the gcc-12 build with one from a gcc-11.3
build, the error disappears. It also disappears when ls is run under strace.
-fno-tree-vectorize does NOT help.
Find attached the preprocessed cap_text.i file from libcap-2.62, as well as
.S files of gcc-11.3 and 12.0
gcc version 12.0.0 20220110 (experimental) (Gentoo 12.0.0_pre9999 p2, commit
92e114d66e93d60dcef97c66cddbae38b657d768)