bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

new module 'ldd'


From: Bruno Haible
Subject: new module 'ldd'
Date: Thu, 12 Jan 2006 13:56:07 +0100
User-agent: KMail/1.5

Hi,

gnulib is a portability library, and "ldd" is not portable. So I'm adding
the following module 'ldd'.

2006-01-12  Bruno Haible  <address@hidden>

        * modules/ldd: New file.
        * m4/ldd.m4: New file.
        * build-aux/ldd.sh.in: New file.
        * MODULES.html.sh (Support for building libraries and executables): Add
        ldd.

=============================== modules/ldd ===============================
Description:
Command to determine the dynamically linked dependencies of a program.

Files:
build-aux/ldd.sh.in
m4/ldd.m4

Depends-on:

configure.ac:
gl_LDD
AC_CONFIG_FILES([ldd.sh:build-aux/ldd.sh.in])

Makefile.am:

Include:

License:
GPLed build tool

Maintainer:
Bruno Haible

================================ m4/ldd.m4 ================================
# ldd.m4 serial 1
dnl Copyright (C) 2006 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.

# Sets LDDPROG to a command and LDDPOSTPROC to a filter command, such that
#   $LDDPROG program $LDDPOSTPROC
# outputs a whitespace-separated list of the dynamically linked dependencies
# of the program, as library names (no full pathnames), or nothing if the
# program is statically linked or if the service is not supported on the given
# system.

dnl From Bruno Haible.

AC_DEFUN([gl_LDD],
[
  AC_REQUIRE([AC_CANONICAL_HOST])
  AC_REQUIRE([AC_PROG_CC])
  dnl Default values.
  LDDPROG=':'
  LDDPOSTPROC=
  dnl First try objdump, since it works when cross-compiling.
  AC_CHECK_TOOL([OBJDUMP], [objdump], [:])
  if test "$OBJDUMP" != ":"; then
    LDDPROG="LC_ALL=C $OBJDUMP -p"
    dnl The output of "LC_ALL=C objdump -p program" of a program or library
    dnl looks like this:
    dnl
    dnl libnet.so:     file format elf32-i386
    dnl
    dnl Program Header:
    dnl     LOAD off    0x00000000 vaddr 0x00000000 paddr 0x00000000 align 2**12
    dnl          filesz 0x0001391d memsz 0x0001391d flags r-x
    dnl     LOAD off    0x00013920 vaddr 0x00014920 paddr 0x00014920 align 2**12
    dnl          filesz 0x00001874 memsz 0x0001b020 flags rw-
    dnl  DYNAMIC off    0x00015104 vaddr 0x00016104 paddr 0x00016104 align 2**2
    dnl          filesz 0x00000090 memsz 0x00000090 flags rw-
    dnl
    dnl Dynamic Section:
    dnl   NEEDED      libroot.so
    dnl   SONAME      libnet.so
    dnl   SYMBOLIC    0x0
    dnl   INIT        0x2aec
    dnl   FINI        0x12a2c
    dnl   HASH        0x94
    dnl   STRTAB      0x1684
    dnl   SYMTAB      0x774
    dnl   STRSZ       0xbd5
    dnl   SYMENT      0x10
    dnl   PLTGOT      0x15f20
    dnl   PLTRELSZ    0x320
    dnl   PLTREL      0x11
    dnl   JMPREL      0x27cc
    dnl   REL         0x225c
    dnl   RELSZ       0x570
    dnl   RELENT      0x8
    LDDPOSTPROC="2>/dev/null | sed -n -e 's,^  NEEDED *\\([^ ].*\\)\$,\\1,p'"
  else
    if test "$cross_compiling" = no; then
      dnl Not cross-compiling. Try system dependent vendor tools.
      case "$host_os" in
        aix*)
          LDDPROG="LC_ALL=C dump -H"
          dnl The output of "LC_ALL=C dump -H program" looks like this:
          dnl
          dnl program:
          dnl
          dnl                         ***Loader Section***
          dnl                       Loader Header Information
          dnl VERSION#         #SYMtableENT     #RELOCent        LENidSTR
          dnl 0x00000001       0x00000005       0x0000000d       0x0000001e     
  
          dnl 
          dnl #IMPfilID        OFFidSTR         LENstrTBL        OFFstrTBL
          dnl 0x00000002       0x00000134       0x0000000d       0x00000152     
  
          dnl 
          dnl 
          dnl                         ***Import File Strings***
          dnl INDEX  PATH                          BASE                MEMBER   
           
          dnl 0      /usr/lib:/lib                                              
           
          dnl 1                                    libc.a              shr.o    
           
          dnl
          LDDPOSTPROC="2>/dev/null | sed -e '/^[^0-9]/d' -e '/^0x/d' | sed -n 
-e 's,^[0-9]*         *\\([^      ]*\\).*\$,\\1,p' | sed -e 's,^.*/,,'"
          ;;
        darwin*)
          LDDPROG="otool -L"
          dnl The output of "otool -L program" looks like this:
          dnl program:
          dnl         /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, 
current version 71.1.4)
          LDDPOSTPROC="2>/dev/null | sed -n -e 's,^     \\([^   
]*\\).*\$,\\1,p' | sed -e 's,^.*/,,'"
          ;;
        hpux*)
          LDDPROG="LC_ALL=C chatr"
          dnl The output of "LC_ALL=C chatr program" looks like this:
          dnl program: 
          dnl          shared executable 
          dnl          shared library dynamic path search:
          dnl              SHLIB_PATH     disabled  second 
          dnl              embedded path  disabled  first  Not Defined
          dnl          shared library list:
          dnl              dynamic   /usr/lib/libc.2
          dnl          shared library binding:
          dnl              deferred 
          dnl          global hash table disabled
          dnl          plabel caching disabled
          dnl          global hash array size:1103
          dnl          global hash array nbuckets:3
          dnl          shared vtable support disabled
          dnl          static branch prediction disabled
          dnl          executable from stack: D (default)
          dnl          kernel assisted branch prediction enabled
          dnl          lazy swap allocation disabled
          dnl          text segment locking disabled
          dnl          data segment locking disabled
          dnl          third quadrant private data space disabled
          dnl          fourth quadrant private data space disabled
          dnl          third quadrant global data space disabled
          dnl          data page size: D (default)
          dnl          instruction page size: D (default)
          dnl          nulptr references disabled
          dnl          shared library private mapping disabled
          dnl          shared library text merging disabled
          dnl
          dnl or like this:
          dnl a.out:
          dnl          32-bit ELF executable
          dnl          shared library dynamic path search:
          dnl              LD_LIBRARY_PATH    enabled  first 
          dnl              SHLIB_PATH         enabled  second
          dnl              embedded path      enabled  third  
/usr/lib/hpux32:/opt/langtools/lib/hpux32
          dnl          shared library list:
          dnl              libc.so.1
          dnl          shared library binding:
          dnl              deferred
          dnl          global hash table disabled
          dnl          global hash table size 1103
          dnl          shared library mapped private disabled
          dnl          shared library segment merging disabled
          dnl          shared vtable support disabled
          dnl          explicit unloading disabled
          dnl          segments:
          dnl              index type     address      flags size
          dnl                  7 text     04000000     z---c-    D (default)
          dnl                  8 data     40000000     ---m--    D (default)
          dnl          executable from stack: D (default)
          dnl          kernel assisted branch prediction enabled 
          dnl          lazy swap allocation for dynamic segments disabled
          dnl          nulptr references disabled
          dnl          address space model: default
          dnl          caliper dynamic instrumentation disabled
          dnl
          LDDPOSTPROC="2>/dev/null | sed -e '1,/shared library list:/d' -e 
'/shared library binding:/,\$d' | sed -e 's,^.*[     ]\\([^  ][^     
]*\\)\$,\\1,' | sed -e 's,^.*/,,'"
          ;;
        irix*)
          LDDPROG="elfdump -Dl"
          dnl The output of "elfdump -Dl program" looks like this:
          dnl
          dnl program:
          dnl
          dnl                    **** MIPS LIBLIST INFORMATION ****
          dnl .liblist :
          dnl [INDEX] Timestamp               Checksum        Flags   Name      
      Version
          dnl [1]     Oct  2 05:19:12 1999    0x867bf7a8      -----   libc.so.1 
      sgi1.0
          dnl
          LDDPOSTPROC="2>/dev/null | sed -n -e 's,^[[][0-9]*[]].*       0x[^    
]*      [^      ][^     ]*      \\([^   ][^     ]*\\).*\$,\\1,p' | sed -e 
's,^.*/,,'"
          ;;
        linux* | gnu* | kfreebsd*-gnu | knetbsd*-gnu) # glibc-based systems
          LDDPROG="LC_ALL=C ldd"
          dnl The output of "ldd program" looks like this:
          dnl         libc.so.6 => /lib/libc.so.6 (0x4002d000)
          dnl         /lib/ld-linux.so.2 (0x40000000)
          LDDPOSTPROC="2>/dev/null | sed -n -e 's,^     \\([^   ][^     
]*\\).*\$,\\1,p' | sed -e 's,^.*/,,'"
          ;;
        osf*)
          LDDPROG="LC_ALL=C odump -Dl"
          dnl The output of "odump -Dl program" looks like this:
          dnl
          dnl                         ***LIBRARY LIST SECTION***
          dnl         Name             Time-Stamp        CheckSum   Flags 
Version
          dnl program:
          dnl         libc.so      Dec 30 00:09:30 1997 0x5e955f9b     0 osf.1
          dnl
          LDDPOSTPROC="2>/dev/null | sed -n -e 's,^     \\([^   ][^     
]*\\).*,\\1,p' | sed -e '/^Name\$/d' | sed -e 's,^.*/,,'"
          ;;
        solaris*)
          LDDPROG="LC_ALL=C ldd"
          dnl The output of "ldd program" looks like this:
          dnl         libc.so.1 =>     /usr/lib/libc.so.1
          dnl         libdl.so.1 =>    /usr/lib/libdl.so.1
          dnl         /usr/platform/SUNW,Ultra-5_10/lib/libc_psr.so.1
          dnl The first sed collects the indented lines.
          dnl The second sed extracts the left-hand part.
          dnl The third sed removes directory specifications.
          LDDPOSTPROC="2>/dev/null | sed -n -e 's,^     \\([^ ].*\\)\$,\\1,p' | 
sed -e 's, =>.*\$,,' | sed -e 's,^.*/,,'"
          ;;
      esac
    fi
  fi
  AC_SUBST([LDDPROG])
  AC_SUBST([LDDPOSTPROC])
])
=========================== build-aux/ldd.sh.in ===========================
#!/bin/sh
# Determine the dynamically linked dependencies of a program.

# Copyright (C) 2006 Free Software Foundation, Inc.
# Written by Bruno Haible <address@hidden>, 2006.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

# Usage: ldd.sh program

@LDDPROG@ "$1" @LDDPOSTPROC@
===========================================================================





reply via email to

[Prev in Thread] Current Thread [Next in Thread]