Hello. I faced a problem I can't solve by myself so I will be grateful for any help. This code causes segfault:
#include <poll.h> #include <pthread.h>
static void * thread_func (void *arg) { int count = 0; struct pollfd pfds[1] = { 0 }; poll(pfds, count, 1000); }
int main () { pthread_t thread; if (pthread_create(&thread, NULL, thread_func, NULL)) return 1; if (pthread_cancel(thread)) return 2; if (pthread_join(thread, NULL)) return 3; return 0; }
This is how backtrace looks:
Thread 2 received signal SIG32.
Thread 2: #0 0xb76b24f6 in __poll_nocancel (fds=0xb76a0414, nfds=0, timeout=1000) at libc/sysdeps/linux/common/poll.c:27 #1 0xb76b2585 in __GI_poll (fds=0xb76a0414, nfds=0, timeout=1000) at libc/sysdeps/linux/common/poll.c:208 #2 0x080484c3 in thread_func () #3 0xb77954b0 in start_thread (arg=0xb76ebba0) at libpthread/nptl/pthread_create.c:285 #4 0xb76fcae7 in clone () at libc/sysdeps/linux/i386/clone.S:103
Thread 1: #0 0xb77996f1 in pthread_join (threadid=3077487520, thread_return=0x0) at libpthread/nptl/pthread_join.c:88 #1 0x08048522 in main ()
Architecture is i386. Interesting thing is that segmentation fault only happens when uClibc-ng built with debug enabled (DODEBUG=y).
Thank you.
Waldemar Brodkorb писал 2018-10-20 18:16:
Hi, Александр Усов wrote,
Hello. I faced a problem I can't solve by myself so I will be grateful for any help. This code causes segfault:
I can not reproduce the segfault in Qemu. Are you using any special compiler flags?
uClibc is built by Buildroot. This is a buildroot config:
BR2_x86_i686=y BR2_ENABLE_DEBUG=y BR2_DEBUG_3=y # BR2_STRIP_strip is not set BR2_OPTIMIZE_G=y BR2_REPRODUCIBLE=y BR2_KERNEL_HEADERS_4_9=y BR2_TOOLCHAIN_BUILDROOT_WCHAR=y BR2_TOOLCHAIN_BUILDROOT_CXX=y BR2_ROOTFS_MERGED_USR=y BR2_TARGET_GENERIC_ROOT_PASSWD="root" BR2_LINUX_KERNEL=y BR2_LINUX_KERNEL_CUSTOM_VERSION=y BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="4.9.93" BR2_LINUX_KERNEL_USE_ARCH_DEFAULT_CONFIG=y BR2_LINUX_KERNEL_INSTALL_TARGET=y BR2_PACKAGE_TESTS=y BR2_TARGET_ROOTFS_EXT2=y BR2_TARGET_GRUB2=y
I created a repo at https://github.com/aleksander/buildroot.git You can do 'make uclibc_segfault_test_defconfig; make all' to build an image and run 'test_uclibc_poll'.
best regards Waldemar