Home > Articles > Operating Systems, Server > Solaris

This chapter is from the book

This chapter is from the book

4.5 Information about Applications

4.5.1 Reporting Library Linkage (ldd)

The ldd utility reports the shared libraries that are linked into an application. This is useful for acquiring information, but it should not have any effect on performance (unless the wrong version of a library is selected somehow).

The output in Example 4.50 shows the library the application is searching for on the left, and the library that has been located on the right.

Example 4.50. Output from ldd Showing the Linking of a Particular Application

$ ldd ap27
         libm.so.1 =>     /usr/lib/libm.so.1
         libc.so.1 =>     /usr/lib/libc.so.1
         /usr/platform/SUNW,Sun-Blade-2500/lib/libc_psr.so.1

Passing the -r option to ldd will cause it to check both the objects that are linked into the application and the particular function calls that are required. It will report whether the application is missing a library, and it will report the functions that are missing.

The output shown in Example 4.51 is from the -r option passed to ldd. There are two items of interest. First, ldd reports that it is unable to locate the libsunmath library, which is Sun's library of additional mathematical functions. Under this option, ldd reports the two function calls that it is unable to locate, and these function calls correspond to square root calls for single-precision floating-point, and for long integers.

Example 4.51. The -r Option for ldd

$ ldd -r someapp
         libdl.so.1 =>    /usr/lib/libdl.so.1
         libnsl.so.1 =>   /usr/lib/libnsl.so.1
         libgen.so.1 =>   /usr/lib/libgen.so.1
         libm.so.1 =>     /usr/lib/libm.so.1
         libc.so.1 =>     /usr/lib/libc.so.1
         libsocket.so.1 =>        /usr/lib/libsocket.so.1
         libsunmath.so.1 =>       (file not found)
         libelf.so.1 =>   /usr/lib/libelf.so.1
         libmp.so.2 =>    /usr/lib/libmp.so.2
         /usr/platform/SUNW,Sun-Blade-1000/lib/libc_psr.so.1
         symbol not found: sqrtf
(someapp)
         symbol not found: sqrtl
(someapp)

The paths where libraries are located are hard-coded into the application at link time. I will cover the procedure for doing this in more detail in Section 7.2.6 of Chapter 7. At runtime, it is possible to use the LD_LIBRARY_PATH environment variable to override where the application finds libraries, or to assist the application in locating a particular library. So, for the case in Example 4.51, if the LD_LIBRARY_PATH variable were set to point to a directory containing libsunmath.so, ldd would report that the application used that version of the library. Example 4.52 shows an example of setting the LD_LIBRARY_PATH environment variable under csh. Of course, you can use the same environment variable to change where the application loads all its libraries from, so be careful when setting it and do not rely on it as the default mechanism to enable an application locating its libraries at deployment.

Example 4.52. Example of Setting the LD_LIBRARY_PATH Variable

$ setenv LD_LIBRARY_PATH /export/home/my_libraries/

The LD_LIBRARY_PATH environment variable will override the search path for both 32-bit and 64-bit applications. To explicitly set search paths for these two application types you can use the environment variables LD_LIBRARY_PATH_32 and LD_LIBRARY_PATH_64.

It is also possible to set the LD_PRELOAD environment variable to specify a library that is to be loaded before the application. This enables the use of a different library in addition to the one shipped with the application. This can be a useful way to debug the application's interactions with libraries. I will cover this in more detail in Section 7.2.10 of Chapter 7.

The -u option will request that ldd report any libraries that are linked to the application but not used. In Example 4.53, both libm (the math library) and libsocket (the sockets library) are linked into the application but not actually used.

Example 4.53. Example of ldd -u to Check for Unused Libraries

$ ldd -u ./myapp
         libdl.so.1 =>    /usr/lib/libdl.so.1
         libnsl.so.1 =>   /usr/lib/libnsl.so.1
         libm.so.1 =>     /usr/lib/libm.so.1
         libc.so.1 =>     /usr/lib/libc.so.1
         libsocket.so.1 =>        /usr/lib/libsocket.so.1
         /usr/platform/SUNW,Sun-Blade-1000/lib/libc_psr.so.1

    unused object=/usr/lib/libm.so.1
    unused object=/usr/lib/libsocket.so.1

Another useful option for ldd is the -i flag. This requests that ldd report the order in which the libraries will be initialized. The output from ldd shown in Example 4.54 indicates that libc is initialized first, and libsocket is initialized last.

Example 4.54. Example of ldd -i Output

$ ldd -i ./thisapp
         libdl.so.1 =>    /usr/lib/libdl.so.1
         libnsl.so.1 =>   /usr/lib/libnsl.so.1
         libm.so.1 =>     /usr/lib/libm.so.1
         libc.so.1 =>     /usr/lib/libc.so.1
         libsocket.so.1 =>        /usr/lib/libsocket.so.1
         libmp.so.2 =>    /usr/lib/libmp.so.2
         /usr/platform/SUNW,Sun-Blade-1000/lib/libc_psr.so.1

    init object=/usr/lib/libc.so.1
    init object=/usr/lib/libmp.so.2
    init object=/usr/lib/libnsl.so.1
    init object=/usr/lib/libsocket.so.1

4.5.2 Reporting the Type of Contents Held in a File (file)

The file tool reports on the type of a particular file. It can be useful for situations when it is necessary to check whether a particular application is a script wrapper for the actual real application, or the real application. Another way this tool can help is in determining on what type of processor a given application will run. Recall that the isalist tool from Section 4.2.5 reported the processor's architecture; the file tool will report the architecture an application requires. For a given application to run on a particular machine, the processor needs to support the application's architecture.

Example 4.55 shows file being run on an application. The binary is 32-bit and requires at least a v8plus architecture to run.

Example 4.55. Example of Running file on an Application

$ file a.out
a.out:          ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+ Required, dynamically linked, not stripped

The file command is often useful when examining files or libraries to determine why linking failed with an error reporting an attempt to link 32-bit and 64-bit objects.

4.5.3 Reporting Symbols in a File (nm)

The nm tool reports the symbols defined inside a library, object file, or executable. Typically, this tool will dump out a lot of information. The useful information is usually the names of routines defined in the file, and the names of routines the file requires. If the file has been stripped (using the strip utility), no information is reported. A snippet of example output from nm is shown in Example 4.56.

Example 4.56. Short Sample of Output from nm

$ nm a.out
a.out:
[Index]   Value      Size    Type  Bind  Other Shndx   Name
[45]    |    133144|       4|OBJT |WEAK |0    |15     |environ
[60]    |    132880|       0|FUNC |GLOB |0    |UNDEF  |exit
[37]    |     67164|      40|FUNC |LOCL |0    |8      |foo
[53]    |     67204|      48|FUNC |GLOB |0    |8      |main
[42]    |    132904|       0|FUNC |GLOB |0    |UNDEF  |printf
...

The output from nm shown in Example 4.56 indicates that a.out defines a couple of routines, such as main and foo, but depends on libraries to provide the routines exit and printf.

4.5.4 Reporting Library Version Information (pvs)

It is possible to define multiple versions of a library in a single library file. This is an important mechanism to allow older applications to run with newer versions of a library. The older library API is still available, and the older applications will link to these versions. The newer API is also present, and the newer applications will link to this.

The pvs utility prints out information about the functions and versions of those functions that a library exports, or the library versions that a library or executable requires. By default, pvs will report both the definitions in the library and the requirements of the library.

Example 4.57 shows pvs reporting the versions of the libraries that the ls executable requires.

Example 4.57. Libraries Required by the ls Command

% pvs /bin/ls
         libc.so.1 (SUNW_1.19, SUNWprivate_1.1);

The -r option, for displaying only the requirements of the file, can be used to show that libc.so.1 requires libdl.so.1, as demonstrated in Example 4.58.

Example 4.58. Requirements of libc.so.1

% pvs -r /usr/lib/libc.so.1
         libdl.so.1 (SUNW_1.4, SUNWprivate_1.1);

The -d option shows the versions defined in the library. Example 4.59 shows part of the output of the versions defined in libc.so.1.

Example 4.59. Versions Defined in libc.so.1

% pvs -d /usr/lib/libc.so.1
         libc.so.1;
         SUNW_1.21.2;
         SUNW_1.21.1;
         SUNW_1.21;
         SUNW_1.20.4;
....

It is also possible to list the symbols defined in a library using the -s flag. Part of the output of this for libdl.so.1 is shown in Example 4.60.

Example 4.60. Versions of Functions Exported by libdl.so.1

$ pvs -ds /usr/lib/libdl.so.1
        libdl.so.1:
                _DYNAMIC;
                _edata;
                _etext;
                _end;
                _PROCEDURE_LINKAGE_TABLE_;
        SUNW_1.4:
                dladdr1;
        SUNW_1.3:
        SUNW_1.2:
        SUNW_1.1:
                dlmopen;
                dldump;
                dlinfo;
...

4.5.5 Examining the Disassembly of an Application, Library, or Object (dis)

The dis utility will disassemble libraries, applications, and object files. An example of this is shown in Example 4.61.

Example 4.61. Example of Using dis

$ /usr/ccs/bin/dis a.out
                  ****    DISASSEMBLER  ****


disassembly for a.out

section .text
_start()
        10694:  bc 10 20 00        clr          %fp
        10698:  e0 03 a0 40        ld           [%sp + 0x40], %l0
        1069c:  13 00 00 83        sethi        %hi(0x20c00), %o1
        106a0:  e0 22 61 8c        st           %l0, [%o1 + 0x18c]
        106a4:  a2 03 a0 44        add          %sp, 0x44, %l1
...

4.5.6 Reporting the Size of the Various Segments in an Application, Library, or Object (size)

The size utility prints the size in bytes of the various segments in an application, library, or object file. When used without parameters the command reports the size of the text (executable code), data (initialized data), and bss (uninitialized data). The -f flag reports the name of each allocatable segment together with its size in bytes. The -n flag also reports the nonloadable segments (these segments contain metadata such as debug information). An example is shown in Example 4.62.

Example 4.62. Using the size Command

% size a.out
3104 + 360 + 8 = 3472
% size -fn a.out
17(.interp) + 304(.hash) + 592(.dynsym) + 423(.dynstr) + 48(.SUNW_version) +
12(.rela.data) + 72(.rela.plt) + 1388(.text) + 16(.init) + 12(.fini) + 4(.rodata) +
4(.got) + 124(.plt) + 184(.dynamic) + 48(.data) + 8(.bss) + 1152(.symtab) +
525(.strtab) + 248(.debug_info) + 53(.debug_line) + 26(.debug_abbrev) + 650(.comment) +
184(.shstrtab) = 6094

4.5.7 Reporting Metadata Held in a File (dumpstabs, dwarfdump, elfdump, dump, and mcs)

It is possible to extract information about how an application was built using the dumpstabs utility, which is shipped with the compiler. This utility reports a lot of information, but the most useful is the command line that was passed to the compiler. Two other utilities serve a similar purpose: dwarfdump, which reports the data for applications built with the dwarf debug format, and elfdump which reports similar information for object files. All three utilities can take various flags to specify the level of detail, but by default, dumpstabs and elfdump print out all information, whereas dwarfdump does not report anything for versions earlier than Sun Studio 11 (in these cases, use the -a flag to print all the information). Applications built with the Sun Studio 10 compiler (and earlier) default to the stabs format, so dumpstabs is the appropriate command to use. In Sun Studio 11, the C compiler switched to using dwarf format. In Sun Studio 12, all the compilers default to using dwarf format.

Example 4.63 shows an example of building a file using Sun Studio 10, and then using dumpstabs and grep to extract the compile line used to build the file. In general, a lot of information is reported by dumpstabs, so passing the output through grep and searching for either the name of the file or the CMDLINE marker will reduce the output substantially.

Example 4.63. Example of Searching for the Command Line for a Compiler Using Sun Studio 10

$ cc -fast -o test test.c
$ dumpstabs test | grep test.c
 36:                   test.c  00000000  00000000  LOCAL    FILE  ABS
   0:  .stabs "test.c",N_UNDF,0x0,0x3,0xb8
   2:  .stabs "/export/home; /opt/SUNWspro/prod/bin/cc -fast -c test.c",N_CMDLINE,0x0,0x0,0x0

A similar set of actions for Sun Studio 11 and dwarfdump is shown in Example 4.64.

Example 4.64. Example of Searching for the Command Line for a Compiler Using Sun Studio 11

$ cc -fast -o test test.c
$ dwarfdump test | grep command_line
        DW_AT_SUN_command_line   /opt/SUNWspro/prod/bin/cc -fast -c  test.c
< 13>   DW_AT_SUN_command_line   DW_FORM_string

It is also possible to use the dump command with the -sv option to extract most of the information from an executable. This will dump all the sections in an executable, printing those that are text in text format and the other sections as hexadecimal. An example of the output from dump is shown in Example 4.65. The actual output from the command runs to a number of pages, and Example 4.65 shows only a small part of this output.

Example 4.65. Example of Output from dump

$ dump -sv a.out

a.out:

.interp:
        2f 75 73 72 2f 6c 69 62 2f 6c 64 2e 73 6f 2e 31 00

.hash:
        00 00 00 95 00 00 00 8e 00 00 00 00 00 00 00 00 00 00 00
....
     **** STRING TABLE INFORMATION ****
.strtab:
   <offset>     Name
   <0>
   <1>          a.out
   <7>          crti.s
   <14>         crt1.s
   <21>         __get_exit_frame_monitor_ptr
...
.stab.indexstr:
   <offset>     Name
   <115>        /tmp/;/opt/SUNWspro/prod/bin/f90 -g -qoption f90comp -
h.XAzwWCA01y4\$DCK. test.f90
...

The mcs tool, which is shipped with Solaris, manipulates the comments section in elf files. The -p option will print the comments. It is possible to delete the comments section using -d, or append more strings using -a. The comments section often holds details of the compiler version used and the header files included. An example of manipulating the comments section is shown in Example 4.66. The initial comments section shows the version information for the compiler, together with details of the header files included at compile time. Using the mcs flag -a, it is possible to append another comment to the file.

Example 4.66. Manipulating the Comments Section Using mcs

$ cc -O code.c
$ mcs -p a.out
a.out:

cg: Sun Compiler Common 11 2005/10/13
cg: Sun Compiler Common 11 2005/10/13
@(#)stdio.h     1.84    04/09/28 SMI
@(#)feature_tests.h     1.25    07/02/02 SMI
...
ld: Software Generation Utilities - Solaris Link Editors: 5.10-1.486
$ mcs -a "Hello" a.out
$ mcs -p a.out
a.out:

...
ld: Software Generation Utilities - Solaris Link Editors: 5.10-1.486
Hello

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020