Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Unresolved mcount profiling solaris dynamic library (gcc 3.1)

Posted on 2002-07-22
Medium Priority
Last Modified: 2013-12-05
Hello all,

I have built executables and static libraries with the compiler and linker "-pg" option in order to get profile information. That's ok.

Now I am trying to build a dynamic library in the same way, but I am getting the following linker error:

Undefined                       first referenced
 symbol                             in file
_mcount                             obj/cstring.o
ld: warning: Symbol referencing errors

The whole linker command (once every file has been compiled) is the one showed here:

g++ -shared -dynamic -Wl,-z,now -Wl,-B,symbolic -pg -Wl,-h, obj/cstring.o obj/argument.o obj/getpassword.o obj/mapass.o obj/witherror.o -olib/

I have searched for help for some days in news groups and search engines and I have seen this question posted multiple times but never solved.

Some help would be appreciated.

Best regards,
Question by:davidjava
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

JasonTheGreat earned 1200 total points
ID: 7180255

Based on the other question you posted I'm going to assume you're still on a Solaris machine.

There is bad news and good news.  Let's start with the bad but don't despair, the good news will trump the bad.

Unfortunately, dynamic libraries don't support the -pg option.  The gprof(1) man page is pretty clear about that.  From the NOTES section of the gprof(1) man page under the 32-bit profiling section:

"...   In 32-bit profiling, shared
     objects cannot be profiled with gprof.  Thus,  when  a  pro-
     filed,  dynamically  linked  program  is  executed, only the
     "main" portion of the image is sampled. "

And further on:

"... If  desired,  the
     program  should  be  linked  to  the  profiled  version of a
     library (or to the standard archive version if no  profiling
     version  is  available), instead of the shared object to get
     profile information on the functions of a library.  "

This was a bugger for me because our software uses dynamic loading to load plug-ins all the time.  Our main application is just a shell that loads the first dynamic library.

We eventually went on to use Rational's Quantify, which does support shared libraries (it supports Forte; I don't know about g++).  Expensive, but definitely worth the money if you have it in your budget (as well as Purify and Clearcase -- and no, I do not and have never had ties with Atria or Rational :).

If you don't have to profile with shared objects and can get away with profiling static objects, that would be my first recommendation.  

If you must dynamic libraries (as my group does), there are two other options you can try (sorry, but I haven't tried either one):

#1) Compile as normal and put that library in the LD_PROFILE environment variable.  From the man page on Solaris 8:

           Defines a shared object that will be profiled  by  the
           runtime linker. When profiling is enabled, a profiling
           buffer file is created and mapped.  The  name  of  the
           buffer  file  is  the  name of the shared object being
           profiled with a .profile extension. By  default,  this
           buffer is placed under /var/tmp. The environment vari-
           able LD_PROFILE_OUTPUT may also be supplied  to  indi-
           cate  an  alternative  directory in which to place the
           profiling buffer.

           This buffer contains profil(2) and call count informa-
           tion  similar to the gmon.out information generated by
           programs that have been linked with the -xpg option of
           cc.  Any applications that use the named shared object
           and run while this environment variable  is  set  will
           accumulate  data  in  the  profile buffer. The profile
           buffer information may be examined using gprof(1).

           Notice that this profiling technique is an alternative
           to any that may be provided by the compilation system.
           The shared object being profiled does not have  to  be
           instrumented  in any way, and LD_PROFILE should not be
           combined with a profile-instrumented application."

  Note that last paragraph:  LD_PROFILE shouldn't be combined with a profile-instrumented application.  Bummer.  It's a start, though.

#2) Compile using 64-bit options.

Once again, from the gprof(1) man page:

"64-bit profiling
     64-bit profiling may be used freely with dynamically  linked
     executables,  and profiling information is collected for the
     shared objects if the objects are  compiled  for  profiling."

64-bit compilation brings on a whole other set of issues but if your code is pretty clean and you're using a recent version of g++ it should be possible.

In conclusion, your options are to buy Rational Quantify, use the LD_PROFILE environment variable, or compile using 64-bit options.

Hope this helps.


LVL 11

Expert Comment

ID: 7378395
Dear davidjava

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to accept


comment(s) as an answer.


Expert Comment

ID: 7420011
Force accepted

** Mindphaser - Community Support Moderator **

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question