From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C497C3858D33; Thu, 9 Mar 2023 06:56:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C497C3858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678344988; bh=9rhzv7Q+bU3RZW2TEcep+6OoGtXz1AnSpz0MHlppAS4=; h=From:To:Subject:Date:From; b=BAkKWjM1igbQP2SMs+XokUCpnWnas3MKdo0Z6JrSpiRJ4YaNpu+Febl0RNFnXkaGL IaskqAaaVyCkIWp6WDYyzkkKy7+p5thZVNy/CBWmWrRrdzp4mqTklgcyHhKSGO2zIf 7uHqzz2OwUUQNmQwMvei2rU/zfnmdflr/rYHN4Vw= From: "murugesandins at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/109074] New: SIGABRT signal without using -lpthread at Linux RHEL 7.3 Date: Thu, 09 Mar 2023 06:56:28 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 4.8.5 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: murugesandins at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109074 Bug ID: 109074 Summary: SIGABRT signal without using -lpthread at Linux RHEL 7.3 Product: gcc Version: 4.8.5 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: murugesandins at gmail dot com Target Milestone: --- Hi G++ bugzilla, $ /usr/bin/g++ --version g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11) Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ /usr/bin/cat /etc/redhat-release Red Hat Enterprise Linux Server release 7.3 (Maipo) I don't have root access and sudo access. I tried following sample thread.cpp program: [code] /* * Creating thread using "class thread" at C++ * Sample C++ program using the "class thread". * Once an object is created, it used to create a thread. * When creating object, we need to pass the name of the function as parame= ter to that object. * Once creating the object, that function used to be called by the thread. * I will write mutex comments later. * Example: * thread t1(ThreadMethod); * Here t1 is creating the new thread. * I have not tested following code at other operating systems(UNIX/AIX/SunOS/HP-UX/...) excluding Linux, CYGWIN_NT and MINGW */ #include #if defined(LINUX) #include // syscall(SYS_gettid) #ifdef SYS_gettid #define gettid() ((pid_t)syscall(SYS_gettid)) #endif #elif defined(CYGWIN_NT) || defined (MINGW) #define gettid() (unsigned long)pthread_self() #endif #include #include #include using namespace std; int TotalThreadCount =3D 0; pthread_mutex_t mutex =3D PTHREAD_MUTEX_INITIALIZER; void ThreadMethod() { while(true) { if( 2 <=3D TotalThreadCount ) { break; } pthread_mutex_lock(&mutex); string DispTID =3D ""; DispTID =3D string("TotalThreadCount :") + to_string(TotalThreadCount) + " TID: " + to_string(gettid()) + "\n"; cout << DispTID; cout.flush(); sleep(1); ++TotalThreadCount; pthread_mutex_unlock(&mutex); } } int main() { // class thread available from C++11 // initialize the object using related thread function. thread t1(ThreadMethod); thread t2(ThreadMethod); t1.join(); t2.join(); // cout << "mutex.__data: " << (unsigned long long)&mutex.__data << "\n"; return 0; } /* pthread_mutex_t is a union having one struct one char array[40] and one lo= ng. union pthread_mutex_t { pthread_mutex_t::__pthread_mutex_s =3D=3D double linked list { int __lock; =3D=3D 04 bytes unsigned int __count; =3D=3D 04 bytes int __owner; =3D=3D 04 bytes unsigned int __nusers; =3D=3D 04 bytes int __kind; =3D=3D 04 bytes int __spins; =3D=3D 04 bytes __pthread_list_t __list; =3D=3D 16 bytes { *prev; *next; } } __data; =3D=3D 40 bytes char __size[40]; =3D=3D 40 bytes long __align; =3D=3D 08 bytes } =3D=3D 40 bytes since this = is union taking maximum bytes. Hence size of this union is 40 bytes. */ [/code] $ /usr/bin/g++ -DLINUX -g -Wall thread.cpp -o ./a.out -std=3Dc++11 $ ./a.out terminate called after throwing an instance of 'std::system_error' what(): Enable multithreading to use std::thread: Operation not permitted Aborted (core dumped) $ gdb a.out core.27255 Reading symbols from ./a.out...done. [New LWP 27255] Core was generated by `./a.out'. Program terminated with signal 6, Aborted. #0 0x00007f1125cdd1d7 in raise () from /lib64/libc.so.6 Missing separate debuginfos, use: debuginfo-install glibc-2.17-157.el7.x86_= 64 libgcc-4.8.5-11.el7.x86_64 libstdc++-4.8.5-11.el7.x86_64 (gdb) #0 0x00007f1125cdd1d7 in raise () from /lib64/libc.so.6 #1 0x00007f1125cde8c8 in abort () from /lib64/libc.so.6 #2 0x00007f11265e1ab5 in __gnu_cxx::__verbose_terminate_handler() () from /lib64/libstdc++.so.6 #3 0x00007f11265dfa26 in ?? () from /lib64/libstdc++.so.6 #4 0x00007f11265dfa53 in std::terminate() () from /lib64/libstdc++.so.6 #5 0x00007f11265dfc73 in __cxa_throw () from /lib64/libstdc++.so.6 #6 0x00007f11266364b9 in std::thread::_M_start_thread(std::shared_ptr) () from /lib64/libstdc++.so.6 #7 0x00000000004020d2 in std::thread::thread (this=3D0x7ffebb3= 2ae60, __f=3D@0x4017cd: {void (void)} 0x4017cd ) at /usr/include/c++/4.8.2/thread:135 #8 0x0000000000401a89 in main () at thread.cpp:50 (gdb) quit If I add -lpthread, it is working fine. $ /usr/bin/g++ -lpthread -DLINUX -std=3Dc++11 -g -Wall thread.cpp -o ./a.out;./a.out TotalThreadCount :0 TID: 29678 TotalThreadCount :1 TID: 29678 TotalThreadCount :2 TID: 29679 $ /usr/bin/g++ -DLINUX -std=3Dc++11 -g -Wall thread.cpp -o ./a.out $ /usr/bin/ldd ./a.out linux-vdso.so.1 =3D> (0x00007fff597bb000) libstdc++.so.6 =3D> /lib64/libstdc++.so.6 (0x00007f36c0c49000) libm.so.6 =3D> /lib64/libm.so.6 (0x00007f36c0946000) libgcc_s.so.1 =3D> /lib64/libgcc_s.so.1 (0x00007f36c0730000) libc.so.6 =3D> /lib64/libc.so.6 (0x00007f36c036f000) /lib64/ld-linux-x86-64.so.2 (0x00007f36c0f6f000) $ /usr/bin/g++ -lpthread -DLINUX -std=3Dc++11 -g -Wall thread.cpp -o ./a.out $ /usr/bin/ldd ./a.out linux-vdso.so.1 =3D> (0x00007ffec3d29000) libpthread.so.0 =3D> /lib64/libpthread.so.0 (0x00007f70f00b9000) libstdc++.so.6 =3D> /lib64/libstdc++.so.6 (0x00007f70efdb0000) libm.so.6 =3D> /lib64/libm.so.6 (0x00007f70efaae000) libgcc_s.so.1 =3D> /lib64/libgcc_s.so.1 (0x00007f70ef898000) libc.so.6 =3D> /lib64/libc.so.6 (0x00007f70ef4d6000) /lib64/ld-linux-x86-64.so.2 (0x00007f70f02f3000) If dependency /lib64/libpthread.so.0 is missing how the compiler show SIGAB= RT signal inside "class thread" ? I cannot download and install g++ latest version at current host. Can I download g++ binary alone at my home directory like the way I am using openssl at my home directory ? cygwin usage: $ /usr/bin/g++ -DCYGWIN_NT -g -Wall thread.cpp -o ./a.out -std=3Dc++11 $ /usr/bin/ldd ./a.out | grep -v -i WINDOWS /usr/bin/cygwin1.dll (0x61000000) cygwin1.dll =3D> /usr/bin/cygwin1.dll (0x7ffb5d4b0000) cyggcc_s-seh-1.dll =3D> /usr/bin/cyggcc_s-seh-1.dll (0x3e90a0000) /usr/bin/cygstdc++-6.dll (0x6d310000) cygstdc++-6.dll =3D> /usr/bin/cygstdc++-6.dll (0x3d11d0000) $ ./a.out TotalThreadCount :0 TID: 42949749056 TotalThreadCount :1 TID: 42949749344 TotalThreadCount :2 TID: 42949749056 $ /usr/bin/g++ -lpthread -DCYGWIN_NT -g -Wall thread.cpp -o ./a.out -std=3D= c++11 $ /usr/bin/ldd ./a.out | grep -v -i WINDOWS /usr/bin/cygwin1.dll (0x61000000) cygwin1.dll =3D> /usr/bin/cygwin1.dll (0x7ffb5d4b0000) cyggcc_s-seh-1.dll =3D> /usr/bin/cyggcc_s-seh-1.dll (0x3e90a0000) /usr/bin/cygstdc++-6.dll (0x6d310000) cygstdc++-6.dll =3D> /usr/bin/cygstdc++-6.dll (0x3d11d0000) I need to know if this bug later resolved using upgraded versions of g++? if yes, I need that version number of that g++ at RHEL.=