Subject: test-free segfaults with PGO

From: Andreas Stieger <[email-masked]>
Date: Mon, 7 Nov 2022 21:48:21 +0100

Hello,

well this is interesting. gnulib-tests/test-free.c is new in sed 4.9 and
it seems to break with PGO only. Specifically -fprofile-update=atomic
-fprofile-generate.

gcc12-12.2.1, glibc-2.36

[   32s] + ./configure --host=x86_64-suse-linux-gnu
--build=x86_64-suse-linux-gnu --program-prefix=
--disable-dependency-tracking --prefix=/usr --exec-prefix=/usr
--bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc
--datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64
--libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/var/lib
--mandir=/usr/share/man --infodir=/usr/share/info --without-included-regex

[  244s] + /usr/bin/make -O -j2 V=1 VERBOSE=1 'CFLAGS=-O2 -Wall
-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong
-funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection
-Werror=return-type -flto=auto -g -Wall -Wstrict-prototypes
-Wpointer-arith -Wformat-security -fPIE -fprofile-update=atomic
-fprofile-generate'

[  309s] + /usr/bin/make -O -j2 V=1 VERBOSE=1 'CFLAGS=-O2 -Wall
-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong
-funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection
-Werror=return-type -flto=auto -g -Wall -Wstrict-prototypes
-Wpointer-arith -Wformat-security -fPIE -fprofile-update=atomic
-fprofile-generate' check

[  611s] ../build-aux/test-driver: line 112:  8668 Segmentation
fault      (core dumped) "$@" >> "$log_file" 2>&1
[  611s] FAIL: test-free

[  726s] FAIL: test-free
[  726s] ===============
[  726s]
[  726s] FAIL test-free (exit status: 139)

./test-free
Segmentation fault (core dumped)

openat(AT_FDCWD, "/proc/sys/vm/max_map_count", O_RDONLY) = 3
mmap(NULL, 16777216, PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
0x7ff05a262000
openat(AT_FDCWD, "test-free", O_RDONLY) = 4
mmap(NULL, 16777216, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
-1, 0) = 0x7ff059262000
mmap(0x7ff059261000, 16785408, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7ff059261000
mmap(NULL, 4096, PROT_READ, MAP_PRIVATE, 4, 0) = 0x7ff05b482000

[...]

mmap(NULL, 4096, PROT_READ, MAP_PRIVATE, 4, 0) = 0x7ff049281000
mmap(NULL, 4096, PROT_READ, MAP_PRIVATE, 4, 0) = -1 ENOMEM (Cannot
allocate memory)
munmap(0x7ff059262000, 16777216)        = -1 ENOMEM (Cannot allocate memory)
getpid()                                = 12260
openat(AT_FDCWD,
"/home/abuild/rpmbuild/BUILD/sed-4.9/gnulib-tests/test-free.gcda",
O_RDWR|O_CREAT, 0666) = 5
fcntl(5, F_SETLKW, {l_type=F_WRLCK, l_whence=SEEK_SET, l_start=0,
l_len=0}) = 0
fcntl(5, F_GETFL)                       = 0x8002 (flags O_RDWR|O_LARGEFILE)
newfstatat(5, "", {st_mode=S_IFREG|0644, st_size=0, ...}, AT_EMPTY_PATH) = 0
read(5, "", 4096)                       = 0
lseek(5, 0, SEEK_SET)                   = 0
mmap(NULL, 16384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = -1 ENOMEM (Cannot allocate memory)
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR,
si_addr=0xffffffffffffffff} ---
+++ killed by SIGSEGV (core dumped) +++