This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/11434] How to config gcc under AIX 4.2.1
- From: "lq2001ca at yahoo dot ca" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 10 Jul 2003 19:04:00 -0000
- Subject: [Bug c++/11434] How to config gcc under AIX 4.2.1
- References: <20030704145733.11434.lq2001ca@yahoo.ca>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11434
------- Additional Comments From lq2001ca at yahoo dot ca 2003-07-10 19:03 -------
I figureed out the reason why do we fail to build gcc 3.3 under aix 4.2.1. the
reason is the Makefile is not correct for the target_srcdir =
${glibcpp_srcdir}/config. because there is no the file ctype_base.h under the
directory ${glibcpp_srcdir}/config. so target_srcdir should be set to
${glibcpp_srcdir}/config/os/generic. I don't know why we run ./configure it
doesnot generate correct Makefile. for temperary solution I just mannully
modify Makefile like what I mentioned about. Now I successfully finished
building gcc 3.3 under aix 4.2.1.
$ gcc -v
Reading specs from /p/benjamin/usr/gcc-3.3/lib/gcc-lib/powerpc-ibm-aix4.2.1.0/3.
3/specs
Configured with: ../gcc-3.3/configure --prefix=/p/benjamin/usr/gcc-3.3 --enable-
languages=c,c++ --enable-threads=aix --disable-shared
Thread model: aix
gcc version 3.3
But when I tested my multithreading program with new gcc 3.3 I got the same
problem(segmentation fault-core dump)problem with gcc 3.1.1.
following is my source code(test.cpp)
/* Demonstrate socket server: single process multiple threads */
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <string.h>
#include <pthread.h>
#include <string>
#include <iostream>
#include <fstream>
const short SERVERPORT = 8001;
const char* SERVERNAME = "aix42";
using namespace std;
namespace
{
class PTHREAD_ATTRIBUTE
{
public:
pthread_attr_t Attr;
PTHREAD_ATTRIBUTE(void)
{
pthread_attr_init(&Attr);
}
~PTHREAD_ATTRIBUTE(void)
{
pthread_attr_destroy(&Attr);
}
};
};
void *Service(void *);
int main()
{
char LineBuf[1024];
fstream fin("test.txt", ios::in);
if (fin.is_open())
while(!fin.eof() && fin.good())
{
fin.getline(LineBuf, 1024);
cout << LineBuf << endl;
}
const int ServerSocket = socket(PF_INET, SOCK_STREAM, 0);
if (ServerSocket < 0)
{
cout << "Failed to get server socket." << endl;
exit(1);
}
const hostent *hp = ::gethostbyname(SERVERNAME); // network byte order
if (hp == 0)
{
cout << "Failed to get host entry." << endl;
exit(1);
}
long ip;
memcpy((void *)&ip, hp->h_addr, hp->h_length);
sockaddr_in Address;
memset((void *)&Address, 0, sizeof(Address));
Address.sin_family = AF_INET;
Address.sin_port = htons(SERVERPORT);
memcpy((void*)&Address.sin_addr, (void*)&ip, sizeof(Address.sin_addr));
if (bind(ServerSocket, (sockaddr *)&Address, sizeof(Address)) < 0)
{
cout << "Failed to bind socket." << endl;
exit(1);
}
if (listen(ServerSocket, 5) < 0)
{
cout << "Failed to listen to port " << SERVERPORT << endl;
exit(1);
}
cout << "Server is listening to port " << SERVERPORT << "." << endl;
while (true)
{
// Wait for a new connection
const int ConnSocket = accept(ServerSocket, NULL, NULL);
if (ConnSocket < 0)
{
cout << "Failed to accept a new connection." << endl;
continue;
}
// Having accepted a connection.
cout << "Having accepted new connection " << ConnSocket << endl;
// create a child thread to receive/send data for this connection
PTHREAD_ATTRIBUTE ThreadAttr;
pthread_attr_setdetachstate(&ThreadAttr.Attr, PTHREAD_CREATE_DETACHED);
pthread_t thread;
if (pthread_create(&thread, &ThreadAttr.Attr, Service, (void*)
ConnSocket) < 0)
{
cout << "Failed to create a child thread." << endl;
close(ConnSocket);
}
cout <<"The main thread continues waiting for new connections." << endl;
}
cout << "Finished testing." << endl;
}
void * Service(void *arg)
{
cout << "1. Succeed lock" << endl;
const int ConnSocket = (int)arg;
char Buffer[1025];
while (true)
{
const int len = recv(ConnSocket, (void*)Buffer, 1024, 0);
if (len <= 0 )
break;
Buffer[len] = '\0';
cout << " Thread " << pthread_self() << " Socket " << ConnSocket
<< " received: " << Buffer << endl;
for (int i = 0; i < len; i++)
{
Buffer[i] = toupper(Buffer[i]);
}
cout << " Thread " << pthread_self() << " Socket " << ConnSocket
<< " sent: " << Buffer << endl;
send(ConnSocket, (void*)Buffer, len, 0);
//sleep(10);
}
cout << " Thread " << pthread_self() << " Socket " << ConnSocket << "
disconnected!" << endl;
close(ConnSocket);
pthread_exit(0); // quit after the client closed the connection
}
How to duplicate:
1. To compile it:
g++ -o test -g -O2 -pthread -D_THREAD_SAFE -fstack-check -fexceptions -
lpthreads -L/usr/lib/threads test.cpp
2. run it:
./test
Memory fault(coredump)
3. backtrace by gdb5.3
GNU gdb 5.3
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you ar
welcome to change it and/or distribute copies of it under certain condition
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "powerpc-ibm-aix4.2.1.0"...
(gdb) r
Starting program: /techsupport/benjamin/tmp/sc/test
Program received signal SIGSEGV, Segmentation fault.
0xd05bd888 in fetch_and_add () from /usr/lib/libc_r.a(shr.o)
(gdb) bt
#0 0xd05bd888 in fetch_and_add () from /usr/lib/libc_r.a(shr.o)
#1 0x100258b4 in std::locale::operator=(std::locale const&) (
this=<incomplete type>, __other=<incomplete type>) at _start_ :360
#2 0x10031b1c in std::ios_base::_M_init() (this=<incomplete type>)
at _start_ :299
#3 0x10031a14 in std::basic_ios<char, std::char_traits<char> >::init(std::basic
_streambuf<char, std::char_traits<char> >*) (this=<incomplete type>,
__sb=<incomplete type>) at _start_ :150
#4 0x100003f4 in main ()
at /p/benjamin/usr/gcc-3.3/include/c++/3.3/istream:106
#5 0x100001b4 in __start ()
(gdb)