Subject: How to get DT_SONAME?
To: None <current-users@NetBSD.ORG>
From: Johnny C. Lam <lamj@stat.cmu.edu>
List: current-users
Date: 05/23/1998 20:46:38
I'm running the 19980419 snapshot of NetBSD/alpha.

I'm confused about why the following doesn't work.  I'm trying to
write something to print out the name stored in DT_SONAME.  According
to the ld documentation, if a library is linked with -soname=NAME,
then NAME gets written into the DT_SONAME field of the resulting
object.  But I get as output:

% ./soname /usr/lib/libposix.so.0.1
Error: No error
No DT_SONAME found.

% ./soname /usr/lib/libposix.so.0.1 alpha-unknown-netbsd1.3
Error: No error
No DT_SONAME found.

Can someone explain what's going on, or how to do what I'm trying
(unsuccessfully) to do?

Thanks,
--
   Johnny C. Lam
   Department of Statistics             lamj@stat.cmu.edu
   Carnegie Mellon University           http://www.stat.cmu.edu/~lamj/

                            @>---`---,----


--------- soname.c ---------
#include <stdio.h>
#include <bfd/bfd.h>

int
main( int argc, char * argv[] )
{
  bfd *		abfd;
  const char *	soname;
  const char *	errmsg;
  char *	target = NULL;

  if ( argc > 2 )
    target = argv[2];

  abfd = bfd_openr( argv[1], target );
  errmsg = bfd_errmsg( bfd_get_error() );
  printf( "Error: %s\n", errmsg );

  soname = bfd_elf_get_dt_soname( abfd );
  if ( soname != NULL )
    printf( "%s\n", soname );
  else
    printf( "No DT_SONAME found\n" );
  bfd_close( abfd );

  return 0;
}