Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

troubleshooting bus errors compiling with gcc 3.4.3 on 11.11

 
SOLVED
Go to solution
Highlighted
Occasional Visitor

troubleshooting bus errors compiling with gcc 3.4.3 on 11.11

I am porting/compiling a working multithreaded app to HPUX 11.11 using gcc3.4.3 from the porting centre - binary install, as well as any dependent packages. I have the latest cumulative linker patch installed.

I link the objects using:

gcc -o foo f1.o f2.o f3.o -lpthread -lrt

Upon running the application, I get a bus error whenever passing the address of a stack variable into a function call, e.g. main() calls f2_func(&stack_var). Avoiding that by allocating the variable using malloc, I consistently get -1 returns from *all* system calls with errno still 0. These are obviously audited calls like mkdir("/tmp/foo",S_IRWXU) when foo does not exist

The constituent objects are built with no command line options to gcc except -g:

gcc -g -c -o f1.o f1.c (and so forth)

Clearly there is some memory alignment problem in the first case and an application linking/compat problem in the latter, but I know not how to resolve then and my initial doc readings did not turn anything up. Any help would be appreciated. Thanks!
5 REPLIES 5
Highlighted
Honored Contributor

Re: troubleshooting bus errors compiling with gcc 3.4.3 on 11.11

Please try compiling your files with -mt or -pthread flags.

-mt
-pthread

Add support for multithreading using the POSIX threads library. This option sets flags for both the preprocessor and linker. It does not affect the thread safety of object code produced by the compiler or that of libraries supplied with it. These are HP-UX specific flags.
Highlighted
Occasional Visitor

Re: troubleshooting bus errors compiling with gcc 3.4.3 on 11.11

Those are not valid options for gcc, at least not the build out of the porting centre

[root@chpux1]# make
gcc -mt -pthread -Wall -g -c -o find.o find.c
cc1: error: invalid option `t'
gmake: *** [find.o] Error 1
[root@chpux1]# gcc -mmt -Wall -g -c -o find.o find.c
cc1: error: invalid option `mt'
[root@chpux1]# gcc --version
gcc (GCC) 3.4.3
Copyright (C) 2004 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.

[root@chpux1]# uname -s -r -m
HP-UX B.11.11 9000/800
[root@chpux1]#


Highlighted
Occasional Visitor

Re: troubleshooting bus errors compiling with gcc 3.4.3 on 11.11

It seems that the -D_REENTRANT flag is required to flip on support for the non-stubbed versions. While this does not solve the bus error problem, it does cause the correct system call prototypes to be used, and later the enabled multithreaded system calls to be linked into the binary.
Highlighted
Honored Contributor
Solution

Re: troubleshooting bus errors compiling with gcc 3.4.3 on 11.11

This is from version 3.4.2 I got from http://www.hp.com/go/gcc.

$ gcc -pthread -v test.c
...
/opt/local/libexec/gcc/hppa2.0w-hp-hpux11.11/3.4.2/cc1 -quiet -v -iprefix /opt/local/bin/../lib/gcc/hppa2.0w-hp-hpux11.11/3.4.2/ -D_REENTRANT -D_THREAD_SAFE -D_POSIX_C_SOURCE=199506L test.c -quiet -dumpbase test.c -auxbase test -version -o /var/tmp//ccYG5pet.s
...
$ gcc -dumpspecs | grep pthread
%{mt|pthread:-D_REENTRANT -D_THREAD_SAFE -D_POSIX_C_SOURCE=199506L}

If you specify -pthread it will add -D_REENTRANT -D_THREAD_SAFE -D_POSIX_C_SOURCE=199506L preprocessor flags.

Highlighted
Occasional Visitor

Re: troubleshooting bus errors compiling with gcc 3.4.3 on 11.11

The flags give me correct compilation for my application - I am working through the bus error and will open another thread with any specific questions there, as they do not appear to be related to the compiling/linking problem per se. Thanks for the help!