Operating System - HP-UX
1748203 Members
3129 Online
108759 Solutions
New Discussion юеВ

Hp-ux ld linker option for shared library versioning

 
SOLVED
Go to solution
Roopa V
Occasional Advisor

Hp-ux ld linker option for shared library versioning

Hi,

The necessary symbols of a shared library can be exported to the application using linker option --version-script in Linux. The same can be done in Hp-ux using ld linker option +e. This can also be done by listing all the global symbols with +e in a file with linker option ld -c filename in hp-ux.

I use an export file listing all global symbols with "+e" in my shared library.
I have to add a new interface in my shared library without any compatibility issues. In Linux, there is an option to specify version nodes in the version-script file as:

VERS_1.1 {
global:
foo1;
old*;
};
VERS_1.2 {
foo2;
new*;
} VERS_1.1;


Is there any similar option in hp where I can add new interfaces using library versioning without any compatibility issues?

Any help in this regard is greatly appreciated.

Thanks,
Roopa
8 REPLIES 8
Dennis Handly
Acclaimed Contributor

Re: Hp-ux ld linker option for shared library versioning

>I use an export file listing all global symbols with "+e" in my shared library.

The use of +e hides ALL other symbols in the shlibs. It isn't supported to use +e for aC++.

>I have to add a new interface in my shared library without any compatibility issues.

If you are adding new functions, you just add them, no need to version at all.

If you are changing existing functions, this doesn't meet forward compatibility criteria.

To have multiple shlib versions, you create multiple shlibs:
ld -b -o libfoo.so.1 +h libfoo.so.1 ...
ld -b -o libfoo.so.2 +h libfoo.so.2 ...

Then you create a symlink to the latest:
ln -s libfoo.so.2 libfoo.so

That way when an application is linked to libfoo.so, it remembers it was linked with libfoo.so.2. Existing applications still use libfoo.so.1.

http://docs.hp.com/en/14640/OnlineHelp/creatingandusinglibraries.htm#S-LIBLEVEL-VERS
Roopa V
Occasional Advisor

Re: Hp-ux ld linker option for shared library versioning

Thanks Dennis for the quick reply. It was more helpful.

I'm only concerned about the scenario if a shared library is out of date and a required interface may be missing; when the application tries to use that interface, it may suddenly and unexpectedly fail.

Thanks,
Roopa
Dennis Handly
Acclaimed Contributor
Solution

Re: Hp-ux ld linker option for shared library versioning

>required interface may be missing; when the application tries to use that interface, it may suddenly and unexpectedly fail.

Putting this type of check in your application may be more trouble than it is worth. It would lead to multiple copies of the shlib.

If you link your application with "-Wl,-B,immediate" you will get an error at startup. But you will get a delay.

It may be better to have an installation checking script, so you pay the cost once.
Roopa V
Occasional Advisor

Re: Hp-ux ld linker option for shared library versioning

Thanks Dennis. This solves my problem.

Regards,
Roopa
ranganath ramachandra
Esteemed Contributor

Re: Hp-ux ld linker option for shared library versioning

from what i could gather, the linux linker version script is used for symbol versioning and not shared library versioning.

symbol versioning is also available through the hp c/c++ compilers:

$ cat 2.c
void foo () __attribute__((version_id(VERSION))) {}

$ cc -b 2.c -o lib1.so +DD64 -DVERSION=\"11.00\"
$ elfdump -t lib1.so | grep foo
5 FUNC GLOB 0 0x8 ... 28 foo{11.00}
24 FUNC GLOB 0 0x8 ... 28 foo{11.00}

the version information can be specified only through code, as shown above, through the compiler. it cannot be done post-compile, at the link phase.
 
--
ranga
[i work for hpe]

Accept or Kudo

ranganath ramachandra
Esteemed Contributor

Re: Hp-ux ld linker option for shared library versioning

further, the solution to your problem is through library-level versioning, which should be used whenever there are interface changes. dennis has already described it.
 
--
ranga
[i work for hpe]

Accept or Kudo

Dennis Handly
Acclaimed Contributor

Re: Hp-ux ld linker option for shared library versioning

>This solves my problem.

If you are happy with the answers you were given, please read the following about assigning points:
http://forums.itrc.hp.com/service/forums/helptips.do?#33
Roopa V
Occasional Advisor

Re: Hp-ux ld linker option for shared library versioning

Hi Ranganath,

You are right. I got confused between versioning of shared library and symbol version.

I already have versioning done for the shared library. Introducing a new interface will not have any compatibility issues. The installation check script in the application would solve my problem.

Thanks,
Roopa