Operating System - HP-UX
1829705 Members
2437 Online
109992 Solutions
New Discussion

global variable of C++ on HP-UX 11i

 
tash S
Frequent Advisor

global variable of C++ on HP-UX 11i

Hi All,

If we use global variable of C++ on HP-UX, do we need to staticaly link due to limitations of the HP libs. Would Dynamic loading cause problems with globals being define more than once.

According to the below URL, do we need to compile using +tls=dynamic ?

http://docs.hp.com/en/5187-0701/ch07s09.html

So my question is that, can we need to run global variable of C++ on HP-UX 11i ?

3 REPLIES 3
Dennis Handly
Acclaimed Contributor

Re: global variable of C++ on HP-UX 11i

This should be under: languages and scripting

>HP-UX 11i

This isn't specific enough, what OS version?

What's the real issue? What doesn't work? You just use a global and you access it.

You can link with archive or shared libs. In the archive case, you only have one definition and lots of externs. If you link with shared libs, you can violate the ODR rule and have multiple definitions, one in each shlib. You shouldn't do this if you can help it.

If these are PODs, no problem, dld will make it look like there is only one copy. If there is runtime initialization, the same storage may be initialized N times. This can cause problems depending on the constructor destructor.

If you are doing dynamic loading, you could have problems (multiple disjoint copies) depending on binding modes. But basically, dld chooses the first in binding order.

>+tls=dynamic

This is probably unrelated. TLS is an orthogonal attribute.
tash S
Frequent Advisor

Re: global variable of C++ on HP-UX 11i


> This isn't specific enough, what OS version?

bash-2.04# uname -a
HP-UX rsasj-hp B.11.11 U 9000/785 2003522226 unlimited-user license


>What's the real issue? What doesn't work?

>You just use a global and you access it.

We use a global and dynamic link using C++.
This program was developed by Apache plugin.
The core is rarely occured when apache start.

Here is the trace of gdb for core


(gdb) bt
#0 0xc83a43b8 in ()
warning: Attempting to unwind past bad PC 0xc83a43b8
#1 0xc944fbe4 in __rw::__rb_tree< ... >::_C_get_link (this=0x79f26f1c)
...

--------------------
You can link with archive or shared libs. In the archive case, you only have one definition and lots of externs. If you link with shared libs, you can violate the ODR rule and have multiple definitions, one in each shlib. You shouldn't do this if you can help it.
--------------------

What does ODR stand for ?


What does PODs stand for ?

--------------------
If these are PODs, no problem, dld will make it look like there is only one copy. If there is runtime initialization, the same storage may be initialized N times. This can cause problems depending on the constructor destructor.

If you are doing dynamic loading, you could have problems (multiple disjoint copies) depending on binding modes. But basically, dld chooses the first in binding order.

>+tls=dynamic

This is probably unrelated. TLS is an orthogonal attribute.
--------------------

What is "orthogonal attribute" ?

Dennis Handly
Acclaimed Contributor

Re: global variable of C++ on HP-UX 11i

>We use a global and dynamic link using C++.
This program was developed by Apache plugin.

This is dynamic loading.

#0 0xc83a43b8 in
warning: Attempting to unwind past bad PC 0xc83a43b8
#1 0xc944fbe4 in __rw::__rb_tree< ... >::_C_get_link (this=0x79f26f1c)

It appears you have branched to a shlib you have unloaded?

_C_get_link seems to only call _C_add_new_buffer. If you had this function in multiple shlibs, and unloaded one of them, you could have this problem. So it could be related to duplicate functions not globals.

>What does ODR stand for?

One Definition Rule

>What does PODs stand for?

Plain Old Data

>What is "orthogonal attribute"?

Unrelated, as in 90 degrees from.