public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109074] New: SIGABRT signal without using -lpthread at Linux RHEL 7.3
@ 2023-03-09  6:56 murugesandins at gmail dot com
  2023-03-09 10:20 ` [Bug c++/109074] " rguenth at gcc dot gnu.org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: murugesandins at gmail dot com @ 2023-03-09  6:56 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109074

            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 parameter
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 <unistd.h>
#if defined(LINUX)
        #include <sys/syscall.h>        // 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 <iostream>
#include <thread>
#include <unistd.h>
using namespace std;
int TotalThreadCount = 0;
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
void ThreadMethod()
{
        while(true)
        {
                if( 2 <= TotalThreadCount )
                {
                        break;
                }
                pthread_mutex_lock(&mutex);
                string DispTID = "";
                DispTID = 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 long.
 union pthread_mutex_t
 {
        pthread_mutex_t::__pthread_mutex_s      == double linked list
        {
                int __lock;                     == 04 bytes
                unsigned int __count;           == 04 bytes
                int __owner;                    == 04 bytes
                unsigned int __nusers;          == 04 bytes
                int __kind;                     == 04 bytes
                int __spins;                    == 04 bytes
                __pthread_list_t __list;        == 16 bytes
                {
                        *prev;
                        *next;
                }
        } __data;                               == 40 bytes
        char __size[40];                        == 40 bytes
        long __align;                           == 08 bytes
 }                                              == 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=c++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<std::thread::_Impl_base>) ()
   from /lib64/libstdc++.so.6
#7  0x00000000004020d2 in std::thread::thread<void (&)()> (this=0x7ffebb32ae60,
    __f=@0x4017cd: {void (void)} 0x4017cd <ThreadMethod()>) 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=c++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=c++11 -g -Wall thread.cpp -o ./a.out
$ /usr/bin/ldd ./a.out
        linux-vdso.so.1 =>  (0x00007fff597bb000)
        libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f36c0c49000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f36c0946000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f36c0730000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f36c036f000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f36c0f6f000)

$ /usr/bin/g++ -lpthread -DLINUX -std=c++11 -g -Wall thread.cpp -o ./a.out
$ /usr/bin/ldd ./a.out
        linux-vdso.so.1 =>  (0x00007ffec3d29000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f70f00b9000)
        libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f70efdb0000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f70efaae000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f70ef898000)
        libc.so.6 => /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 SIGABRT
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=c++11
$ /usr/bin/ldd ./a.out | grep -v -i WINDOWS
/usr/bin/cygwin1.dll (0x61000000)
        cygwin1.dll => /usr/bin/cygwin1.dll (0x7ffb5d4b0000)
        cyggcc_s-seh-1.dll => /usr/bin/cyggcc_s-seh-1.dll (0x3e90a0000)
/usr/bin/cygstdc++-6.dll (0x6d310000)
        cygstdc++-6.dll => /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=c++11
$ /usr/bin/ldd ./a.out | grep -v -i WINDOWS
/usr/bin/cygwin1.dll (0x61000000)
        cygwin1.dll => /usr/bin/cygwin1.dll (0x7ffb5d4b0000)
        cyggcc_s-seh-1.dll => /usr/bin/cyggcc_s-seh-1.dll (0x3e90a0000)
/usr/bin/cygstdc++-6.dll (0x6d310000)
        cygstdc++-6.dll => /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.

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2023-03-13  3:30 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-09  6:56 [Bug c++/109074] New: SIGABRT signal without using -lpthread at Linux RHEL 7.3 murugesandins at gmail dot com
2023-03-09 10:20 ` [Bug c++/109074] " rguenth at gcc dot gnu.org
2023-03-09 11:28 ` pinskia at gcc dot gnu.org
2023-03-09 11:30 ` pinskia at gcc dot gnu.org
2023-03-10  4:34 ` [Bug libstdc++/109074] " murugesandins at gmail dot com
2023-03-10  4:53 ` murugesandins at gmail dot com
2023-03-10  5:01 ` pinskia at gcc dot gnu.org
2023-03-10  5:26 ` murugesandins at gmail dot com
2023-03-10 10:32 ` redi at gcc dot gnu.org
2023-03-10 21:30 ` murugesandins at gmail dot com
2023-03-10 23:20 ` murugesandins at gmail dot com
2023-03-10 23:30 ` pinskia at gcc dot gnu.org
2023-03-12 20:52 ` redi at gcc dot gnu.org
2023-03-13  3:30 ` murugesandins at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).