<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: help need with handling libraries loaded using shl_load in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/help-need-with-handling-libraries-loaded-using-shl-load/m-p/3925736#M762000</link>
    <description>hi, &lt;BR /&gt;the above problem can be solved by using &lt;BR /&gt;BIND_RESTRICTED and BIND_FIRST when loading the library using shl_load.&lt;BR /&gt;&lt;BR /&gt;but i still dont understand why this happends, when the man pages for shl_findsym tells that it will search for the symbol only in the specified library(handle that is.).... &lt;BR /&gt;&lt;BR /&gt;thankx</description>
    <pubDate>Mon, 15 Jan 2007 08:26:42 GMT</pubDate>
    <dc:creator>Premkumar P</dc:creator>
    <dc:date>2007-01-15T08:26:42Z</dc:date>
    <item>
      <title>help need with handling libraries loaded using shl_load</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-need-with-handling-libraries-loaded-using-shl-load/m-p/3925731#M761995</link>
      <description>hi, &lt;BR /&gt; i will start with what i am trying to do,&lt;BR /&gt;my program loads shared libraries using shl_load and then calls and exposed method called "Initilizer". &lt;BR /&gt;&lt;BR /&gt;The code:&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;DL.H&gt;&lt;BR /&gt;#include &lt;DLFCN.H&gt;&lt;BR /&gt;#include &lt;ERRNO.H&gt;&lt;BR /&gt;#include &lt;MEMORY.H&gt;&lt;BR /&gt;#include &lt;MALLOC.H&gt;&lt;BR /&gt;&lt;BR /&gt;typedef long (*Function_T)(char *,...);&lt;BR /&gt;&lt;BR /&gt;void* LoadandCall(char *libraryname)&lt;BR /&gt;{&lt;BR /&gt; shl_t dl_handle;&lt;BR /&gt; long bind_flags = BIND_DEFERRED;&lt;BR /&gt; struct shl_descriptor *desc;&lt;BR /&gt; int i, rc;&lt;BR /&gt; char imagename[20];&lt;BR /&gt; char buffer[512];&lt;BR /&gt; void *sym_adr = NULL;&lt;BR /&gt; void *entrypoint = NULL;&lt;BR /&gt;&lt;BR /&gt; //append .sl to the end&lt;BR /&gt; strcpy(imagename, libraryname);&lt;BR /&gt; strcat(imagename, ".sl");&lt;BR /&gt;&lt;BR /&gt; //load the library&lt;BR /&gt; dl_handle = shl_load( imagename, bind_flags, 0L );&lt;BR /&gt;&lt;BR /&gt; if(dl_handle == 0 )&lt;BR /&gt; {&lt;BR /&gt;  printf("unable to load %s %s\n", imagename, strerror(errno));&lt;BR /&gt;  return 1;&lt;BR /&gt; }&lt;BR /&gt; else&lt;BR /&gt; {&lt;BR /&gt;  printf("The address of the loaded function is %u \n", dl_handle);&lt;BR /&gt; }&lt;BR /&gt;   &lt;BR /&gt; //printf the filename loaded if the load is successfull&lt;BR /&gt; for ( i = 0; i &amp;lt; 512; i++ ) &lt;BR /&gt; {&lt;BR /&gt; rc = shl_get( i, &amp;amp;desc );&lt;BR /&gt; if ( rc == 0 ) {&lt;BR /&gt;  if ( dl_handle == desc-&amp;gt;handle ) {&lt;BR /&gt;   strcpy( buffer, desc-&amp;gt;filename );&lt;BR /&gt;   printf("The filename for the handle returned is: %s \n", buffer);&lt;BR /&gt;   }&lt;BR /&gt;  }&lt;BR /&gt; else&lt;BR /&gt;  break;&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt; sym_adr = 0;&lt;BR /&gt; entrypoint = 0;&lt;BR /&gt;&lt;BR /&gt; rc = shl_findsym( &amp;amp;dl_handle, "Initilizer", TYPE_PROCEDURE, &amp;amp;sym_adr );&lt;BR /&gt;&lt;BR /&gt; if(rc &amp;lt; 0) {&lt;BR /&gt;  printf(" Error when trying to get Initilizer %d\n", rc);&lt;BR /&gt;  return 1;&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt; entrypoint = (DspatchFN_T)sym_adr;&lt;BR /&gt; ((Function_T)entrypoint)(imagename,"Initialize");&lt;BR /&gt;&lt;BR /&gt; //unload the library&lt;BR /&gt; /* shl_unload(dl_handle); */&lt;BR /&gt; return 0;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;int main()&lt;BR /&gt;{&lt;BR /&gt; LoadandCall("A");&lt;BR /&gt; LoadandCall("B");&lt;BR /&gt; LoadandCall("C");&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;the problem:&lt;BR /&gt;the above program runs fine, but if i remove shl_unload, then the calls for B and C also end up calling the initilizer of A. The behaviour is strange&lt;BR /&gt;This is a test program, acutally i have to keep these libraries in memory at the same time. &lt;BR /&gt;&lt;BR /&gt;is this the way loading is meant to be done ?? &lt;BR /&gt;&lt;BR /&gt;about the libraries:&lt;BR /&gt;the libraraies i am trying to load are c++ shared libs, having an exposed method that initilizes a c++ class withing which inturn initilizes a c++ class(this is different between the libs).  the libraries might expose same symbols and stuff&lt;BR /&gt;&lt;BR /&gt;The way all the c++ libs are created is just the same&lt;BR /&gt;&lt;BR /&gt;advise please,&lt;BR /&gt;&lt;BR /&gt;regards&lt;/MALLOC.H&gt;&lt;/MEMORY.H&gt;&lt;/ERRNO.H&gt;&lt;/DLFCN.H&gt;&lt;/DL.H&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Fri, 12 Jan 2007 22:03:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-need-with-handling-libraries-loaded-using-shl-load/m-p/3925731#M761995</guid>
      <dc:creator>Premkumar P</dc:creator>
      <dc:date>2007-01-12T22:03:24Z</dc:date>
    </item>
    <item>
      <title>Re: help need with handling libraries loaded using shl_load</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-need-with-handling-libraries-loaded-using-shl-load/m-p/3925732#M761996</link>
      <description>I have no problems with and without the shl_load with simple C functions.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;the libraries might expose same symbols and stuff&lt;BR /&gt;&lt;BR /&gt;You can't do this except for your extern "C" function "Initilizer".&lt;BR /&gt;&lt;BR /&gt;If you are going to use C++ classes, you need to make sure they are different in each of the shared libs, 3.2 ODR rule.  With the way dld(5) works, each lib will call only the first symbols of that name, even if defined inside itself.  While there are linker options to control this, you may be asking for trouble.&lt;BR /&gt;&lt;BR /&gt;I would need more info on why you want to do this?</description>
      <pubDate>Fri, 12 Jan 2007 22:29:33 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-need-with-handling-libraries-loaded-using-shl-load/m-p/3925732#M761996</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-01-12T22:29:33Z</dc:date>
    </item>
    <item>
      <title>Re: help need with handling libraries loaded using shl_load</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-need-with-handling-libraries-loaded-using-shl-load/m-p/3925733#M761997</link>
      <description>sorry! i was wrong, the class exports only the 'initilizer' function and 2 more functions 'attach' and 'detach' namely.&lt;BR /&gt;&lt;BR /&gt;i will try my best to explain wht the libs are made of:&lt;BR /&gt;i have a base class lets call it as "SUPPOTCLASS", and then i have service classes lets call them "SERVICE", &lt;BR /&gt;we compile the SUPPORTCLASS class first, then we have differnt services which are linked to the SUPPORTCLASS class. and my program is calling the exposed initilizer which in turn creates and instance of the BASE class, which creates an instance of SERVICE class(which is differnt for differnt shared libraries)... &lt;BR /&gt;&lt;BR /&gt;all the functionality common for the services are implemented in the SUPPORTCLASS and the services have some specific implemention for the type of service they provide.. &lt;BR /&gt;&lt;BR /&gt;it is a server environment wheren when u put the shared libraries and a corresponding configuration then it will automatically be loaded by the server program...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 12 Jan 2007 22:48:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-need-with-handling-libraries-loaded-using-shl-load/m-p/3925733#M761997</guid>
      <dc:creator>Premkumar P</dc:creator>
      <dc:date>2007-01-12T22:48:14Z</dc:date>
    </item>
    <item>
      <title>Re: help need with handling libraries loaded using shl_load</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-need-with-handling-libraries-loaded-using-shl-load/m-p/3925734#M761998</link>
      <description>&amp;gt;the class exports only the 'initilizer' function and 2 more functions 'attach' and 'detach' namely.&lt;BR /&gt;&lt;BR /&gt;Did you mean "class" or the shlib exports?&lt;BR /&gt;&lt;BR /&gt;By default, HP-UX exports EVERY global symbol in a shared lib.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;I have a base class lets call it as "SUPPORTCLASS", and then i have service classes lets call them "SERVICE",&lt;BR /&gt;&lt;BR /&gt;If all 3 shlibs have the same class names, you are violating the ODR rule and this isn't supported.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;we compile the SUPPORTCLASS class first, then we have different services which are linked to the SUPPORTCLASS class. and my program is calling the exposed initilizer which in turn creates and instance of the BASE class, which creates an instance of SERVICE class (which is different for different shared libraries)...&lt;BR /&gt;&lt;BR /&gt;Different names or different functionality?&lt;BR /&gt;&lt;BR /&gt;This is something where you have to be an expert and can cause lots of problems if you don't know what you are doing.&lt;BR /&gt;&lt;BR /&gt;Other than me saying "don't do this", I would have to have a small test case (attach it) that fails so I can add the next set of kludges to move you on.</description>
      <pubDate>Sat, 13 Jan 2007 00:42:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-need-with-handling-libraries-loaded-using-shl-load/m-p/3925734#M761998</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-01-13T00:42:37Z</dc:date>
    </item>
    <item>
      <title>Re: help need with handling libraries loaded using shl_load</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-need-with-handling-libraries-loaded-using-shl-load/m-p/3925735#M761999</link>
      <description>hi dennis, &lt;BR /&gt;thank you, for your valuable time.&lt;BR /&gt;&lt;BR /&gt;as i cant share the code i am taking about(company stuff),&lt;BR /&gt;i wrote a similar one just that it dosent do anytime, but still the problem can be found.&lt;BR /&gt;&lt;BR /&gt;"i am upload the file as loader.tar"&lt;BR /&gt;content:&lt;BR /&gt;loader -- contains loader.c which loads and makes calls &lt;BR /&gt;support -- a archive library that is used by any service for base functionalities&lt;BR /&gt;&lt;BR /&gt;services/service* - differnt services, shared libraries that are loaded by the loader&lt;BR /&gt;&lt;BR /&gt;problem:&lt;BR /&gt;this is the output i got when is used shl_unload after making the necessary calls,&lt;BR /&gt;&lt;BR /&gt;The address of the loaded function is 2139010832 &lt;BR /&gt;the buffer content is service1.sl &lt;BR /&gt;got addre for proc and it is 2138878086 &lt;BR /&gt;Dispatch function called with name service1.sl&lt;BR /&gt;Support initilizing&lt;BR /&gt;Initilizing class service 1&lt;BR /&gt;Service called for service1&lt;BR /&gt;The address of the loaded function is 2139010832 &lt;BR /&gt;the buffer content is service2.sl &lt;BR /&gt;got addre for proc and it is 2138878070 &lt;BR /&gt;Dispatch function called with name service2.sl&lt;BR /&gt;Support initilizing&lt;BR /&gt;Initilizing class service 2&lt;BR /&gt;Service called for service 2&lt;BR /&gt;The address of the loaded function is 2139010832 &lt;BR /&gt;the buffer content is service3.sl &lt;BR /&gt;got addre for proc and it is 2138878086 &lt;BR /&gt;Dispatch function called with name service3.sl&lt;BR /&gt;Support initilizing&lt;BR /&gt;Initilizing class service 3&lt;BR /&gt;Service called for service 3&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;but if i remove shl_unload, i get this output:&lt;BR /&gt;The address of the loaded function is 2139010832 &lt;BR /&gt;the buffer content is service1.sl &lt;BR /&gt;got addre for proc and it is 2138878086 &lt;BR /&gt;Dispatch function called with name service1.sl&lt;BR /&gt;Support initilizing&lt;BR /&gt;Initilizing class service 1&lt;BR /&gt;Service called for service1&lt;BR /&gt;The address of the loaded function is 2139012144 &lt;BR /&gt;the buffer content is service2.sl &lt;BR /&gt;got addre for proc and it is 2139003802 &lt;BR /&gt;Dispatch function called with name service2.sl&lt;BR /&gt;Support initilizing&lt;BR /&gt;Initilizing class service 1&lt;BR /&gt;Service called for service1&lt;BR /&gt;The address of the loaded function is 2139012472 &lt;BR /&gt;the buffer content is service3.sl &lt;BR /&gt;got addre for proc and it is 2139004250 &lt;BR /&gt;Dispatch function called with name service3.sl&lt;BR /&gt;Support initilizing&lt;BR /&gt;Initilizing class service 1&lt;BR /&gt;Service called for service1&lt;BR /&gt;&lt;BR /&gt;note that the same service is being initlized though it says service 2 and service 3 ....&lt;BR /&gt;&lt;BR /&gt;please let me know what is wrong in the code, the code i have attached is at max 50 lines.&lt;BR /&gt;&lt;BR /&gt;thankx in advance...</description>
      <pubDate>Sat, 13 Jan 2007 17:07:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-need-with-handling-libraries-loaded-using-shl-load/m-p/3925735#M761999</guid>
      <dc:creator>Premkumar P</dc:creator>
      <dc:date>2007-01-13T17:07:22Z</dc:date>
    </item>
    <item>
      <title>Re: help need with handling libraries loaded using shl_load</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-need-with-handling-libraries-loaded-using-shl-load/m-p/3925736#M762000</link>
      <description>hi, &lt;BR /&gt;the above problem can be solved by using &lt;BR /&gt;BIND_RESTRICTED and BIND_FIRST when loading the library using shl_load.&lt;BR /&gt;&lt;BR /&gt;but i still dont understand why this happends, when the man pages for shl_findsym tells that it will search for the symbol only in the specified library(handle that is.).... &lt;BR /&gt;&lt;BR /&gt;thankx</description>
      <pubDate>Mon, 15 Jan 2007 08:26:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-need-with-handling-libraries-loaded-using-shl-load/m-p/3925736#M762000</guid>
      <dc:creator>Premkumar P</dc:creator>
      <dc:date>2007-01-15T08:26:42Z</dc:date>
    </item>
    <item>
      <title>Re: help need with handling libraries loaded using shl_load</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/help-need-with-handling-libraries-loaded-using-shl-load/m-p/3925737#M762001</link>
      <description>As I mentioned what you are doing is illegal.  You have 2 C++ functions that have exactly the same name in the 3 shlibs:&lt;BR /&gt;Invoke__7supportFv  interface__Fv&lt;BR /&gt;&lt;BR /&gt;As I mentioned dld.sl(5) binds to the first.&lt;BR /&gt;And by default, HP-UX exports EVERY global symbol in a shared lib.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;the above problem can be solved by using&lt;BR /&gt;BIND_RESTRICTED and BIND_FIRST when loading the library using shl_load.&lt;BR /&gt;&lt;BR /&gt;BIND_RESTRICTED is may be what you want.  This causes the symbols to be bound locally.&lt;BR /&gt;&lt;BR /&gt;You should never ever use BIND_FIRST since it not standard and no other vendor supports it.  BIND_FIRST would not work if you chose to call service1 twice.  BIND_FIRST will get you into trouble on IPF.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;shl_findsym tells that it will search for the symbol only in the specified library(handle that is.).... &lt;BR /&gt;&lt;BR /&gt;This part works fine.  The problem is that function HookFun calls Invoke__7supportFv which dld binds to the first shlib.  Similar problems with interface().&lt;BR /&gt;&lt;BR /&gt;Changes in your test case:&lt;BR /&gt;You need to link your a.out with -z.  It doesn't work on shlibs.  Also add -lcl.&lt;BR /&gt;&lt;BR /&gt;If you are printing out addresses, you must use %p.  Do not use decimal.&lt;BR /&gt;&lt;BR /&gt;Your link line for your services shlibs should be:&lt;BR /&gt;aCC -b -lstd_v2 -lCsup_v2 -lcl -Wl,-Bsymbolic&lt;BR /&gt;&lt;BR /&gt;You had the -AP lib -lCsup and were missing -lcl.  You also had the libs in the wrong order:&lt;BR /&gt;&lt;A href="http://www.docs.hp.com/en/7762/5991-4874/distributing.htm#linking" target="_blank"&gt;http://www.docs.hp.com/en/7762/5991-4874/distributing.htm#linking&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;(You'll need to link your a.out with -lcl, since you use -mt.)&lt;BR /&gt;&lt;BR /&gt;But your immediate issue was either you need to use BIND_* or you need to use -Wl,-Bsymbolic, which causes calls in a shlib to bind locally if present.&lt;BR /&gt;&lt;BR /&gt;If you call U_STACK_TRACE(), you would see what you were going:&lt;BR /&gt;&lt;BR /&gt;extern "C" void U_STACK_TRACE();&lt;BR /&gt;&lt;BR /&gt;Dispatch function called with name service3.sl&lt;BR /&gt;Support initilizing&lt;BR /&gt;Initilizing class service 1&lt;BR /&gt;( 0)  0xc033b8c0   __ct__8service1Fv_2 + 0x40  [service1.sl]&lt;BR /&gt;( 1)  0xc033b7b8   interface__Fv + 0x18  [service1.sl]&lt;BR /&gt;( 2)  0xc033bb14   Invoke__7supportFv + 0x1c  [service1.sl]&lt;BR /&gt;( 3)  0xc0463a3c   HookFun + 0x40  [service3.sl]&lt;BR /&gt;( 4)  0x00002ebc   LoadandCall + 0x25c  [./a.out]</description>
      <pubDate>Wed, 17 Jan 2007 04:52:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/help-need-with-handling-libraries-loaded-using-shl-load/m-p/3925737#M762001</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2007-01-17T04:52:09Z</dc:date>
    </item>
  </channel>
</rss>

