Operating System - HP-UX
1847902 Members
4038 Online
104021 Solutions
New Discussion

Re: Optimization problems with aC++ 3.50/3.52 on 11.11 (PA-RISC)

 
SOLVED
Go to solution
Darren Middleman_1
New Member

Optimization problems with aC++ 3.50/3.52 on 11.11 (PA-RISC)

I'm running into some issues with optimizations using the aC++ compiler (A.03.50/A.03.52) on PA-RISC 11.11, running on an HP9000/785.

Our code compiles and executes without any problems when optimizations are turned off or only level 1 optimizations are used. When level 2 optimizations are enabled using either the -O or +O2 flags, some of our demo applications crash with a signal 10, Bus error.

The following are a couple of traces we get using gdb on the core file:

1)
Core was generated by `server'.
Program terminated with signal 10, Bus error.
(no debugging symbols found)...
warning: The shared libraries were not privately mapped; setting a
breakpoint in a shared library will not work until you rerun the
program.

#0 0xc0000000000beef8 in pthread_mutex_lock+0 ()
from /usr/lib/pa20_64/libpthread.1
Unable to find AP register.

2)
Core was generated by `eventserv'.
Program terminated with signal 10, Bus error.

#0 0xc0000000000beef8 in ?? ()
warning: Attempting to unwind past bad PC 0xc0000000000beef8
#1 0xc000000000076a6c in ?? ()

NOTE: the -mt flag was used to set the appropriate threading flags

Are there any known issues with the optimizer on this compiler? Has anyone come across any similar issues? HP-UX 11i was recently installed (last couple of months) on our system and I believe the most recent update CDs were used.

Thanks,
Darren
4 REPLIES 4
Mike Stroyan
Honored Contributor
Solution

Re: Optimization problems with aC++ 3.50/3.52 on 11.11 (PA-RISC)

It looks like you are overflowing the maximum stack size for a thread. The instruction at the pthread_mutex_lock+0 address would be storing a register to the top of the stack. That could get a bus error storing to a guard page.

Perhaps the +O2 code is using more stack space for storing registers and local variables than the non-optimized code. That could happen if the optimized code saved and restored many registers for something like loop unrolling in some functions.

Try increasing the stack size for your threads. You can do that with a call to pthread_attr_setstacksize before pthread_create or with the non-portable pthread_default_stacksize_np function.
Scot Bean
Honored Contributor

Re: Optimization problems with aC++ 3.50/3.52 on 11.11 (PA-RISC)

What is your patch level? C++ HPUX patches are released regularly, and many do fix optimization issues.

The current patch for 11.11 C++ is PHSS_29483.
Darren Middleman_1
New Member

Re: Optimization problems with aC++ 3.50/3.52 on 11.11 (PA-RISC)

Thanks for your help. It was an issue with the stack size for the threads. After I modified the code with the pthread_attr_setstacksize function, the bus errors went away.

As a follow up, is there a way to modify this value for the system (for example, on the command line) so that I don't have to call the pthread_attr_setstacksize function for every program that I write? I'm asking this because the code we are writing is designed to run on a variety of platforms and I don't want to fix something on other systems that isn't broken. I realize that I could just put a #if/#endif block checking for PA-RISC (which is what I have right now) but I was wondering if there was another way.

Thanks,
Darren
Mike Stroyan
Honored Contributor

Re: Optimization problems with aC++ 3.50/3.52 on 11.11 (PA-RISC)

There is no external mechanism to change the default stack size of thread. There is no such command line option or environment variable or chatr setting. You can call the non-portable pthread_default_stacksize_np() function to set the default in a process.

You could encapsulate that step by linking your programs against a shared library that set the default stack size in an initializer function. This simple library would set the thread stack size to either 128K or a value set in a THREAD_STACK_SIZE environment variable. It could be used with the LD_PRELOAD environment variable to affect an already compiled program. (LD_PRELOAD is described in "man dld.sl".)

thread_stack.c:
---------------------
#include
#include
void thread_stack()
{
size_t size = atol(getenv("THREAD_STACK_SIZE"));
if (size == 0) size = 128*1024;
pthread_default_stacksize_np(size, NULL);
}

Makefile:
---------------------
libthread_stack.sl: thread_stack.c
cc +z -c thread_stack.c
ld -b -o libthread_stack.sl thread_stack.o +init thread_stack
rm thread_stack.o