2 dnl Copyright (C) 2006, 2009-2020 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 # Sets LDDPROG to a command and LDDPOSTPROC to a filter command, such that
8 # $LDDPROG program $LDDPOSTPROC
9 # outputs a whitespace-separated list of the dynamically linked dependencies
10 # of the program, as library names (no full pathnames), or nothing if the
11 # program is statically linked or if the service is not supported on the given
14 dnl From Bruno Haible.
18 AC_REQUIRE([AC_CANONICAL_HOST])
19 AC_REQUIRE([AC_PROG_CC])
23 dnl First try objdump, since it works when cross-compiling.
24 AC_CHECK_TOOL([OBJDUMP], [objdump], [false])
26 if test "$OBJDUMP" != "false"; then
28 dnl The output of "LC_ALL=C objdump -p program" of a program or library
31 dnl libnet.so: file format elf32-i386
34 dnl LOAD off 0x00000000 vaddr 0x00000000 paddr 0x00000000 align 2**12
35 dnl filesz 0x0001391d memsz 0x0001391d flags r-x
36 dnl LOAD off 0x00013920 vaddr 0x00014920 paddr 0x00014920 align 2**12
37 dnl filesz 0x00001874 memsz 0x0001b020 flags rw-
38 dnl DYNAMIC off 0x00015104 vaddr 0x00016104 paddr 0x00016104 align 2**2
39 dnl filesz 0x00000090 memsz 0x00000090 flags rw-
59 LDDPOSTPROC="2>/dev/null | sed -n -e 's,^ NEEDED *\\([^ ].*\\)\$,\\1,p'"
61 if test "$cross_compiling" = no; then
62 dnl Not cross-compiling. Try system dependent vendor tools.
66 dnl The output of "LC_ALL=C dump -H program" looks like this:
70 dnl ***Loader Section***
71 dnl Loader Header Information
72 dnl VERSION# #SYMtableENT #RELOCent LENidSTR
73 dnl 0x00000001 0x00000005 0x0000000d 0x0000001e
75 dnl #IMPfilID OFFidSTR LENstrTBL OFFstrTBL
76 dnl 0x00000002 0x00000134 0x0000000d 0x00000152
79 dnl ***Import File Strings***
80 dnl INDEX PATH BASE MEMBER
84 LDDPOSTPROC="2>/dev/null | sed -e '/^[^0-9]/d' -e '/^0x/d' | sed -n -e 's,^[0-9]* *\\([^ ]*\\).*\$,\\1,p' | sed -e 's,^.*/,,'"
88 dnl The output of "otool -L program" looks like this:
90 dnl /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 71.1.4)
91 LDDPOSTPROC="2>/dev/null | sed -n -e 's,^ \\([^ ]*\\).*\$,\\1,p' | sed -e 's,^.*/,,'"
95 dnl The output of "LC_ALL=C chatr program" looks like this:
98 dnl shared library dynamic path search:
99 dnl SHLIB_PATH disabled second
100 dnl embedded path disabled first Not Defined
101 dnl shared library list:
102 dnl dynamic /usr/lib/libc.2
103 dnl shared library binding:
105 dnl global hash table disabled
106 dnl plabel caching disabled
107 dnl global hash array size:1103
108 dnl global hash array nbuckets:3
109 dnl shared vtable support disabled
110 dnl static branch prediction disabled
111 dnl executable from stack: D (default)
112 dnl kernel assisted branch prediction enabled
113 dnl lazy swap allocation disabled
114 dnl text segment locking disabled
115 dnl data segment locking disabled
116 dnl third quadrant private data space disabled
117 dnl fourth quadrant private data space disabled
118 dnl third quadrant global data space disabled
119 dnl data page size: D (default)
120 dnl instruction page size: D (default)
121 dnl nulptr references disabled
122 dnl shared library private mapping disabled
123 dnl shared library text merging disabled
127 dnl 32-bit ELF executable
128 dnl shared library dynamic path search:
129 dnl LD_LIBRARY_PATH enabled first
130 dnl SHLIB_PATH enabled second
131 dnl embedded path enabled third /usr/lib/hpux32:/opt/langtools/lib/hpux32
132 dnl shared library list:
134 dnl shared library binding:
136 dnl global hash table disabled
137 dnl global hash table size 1103
138 dnl shared library mapped private disabled
139 dnl shared library segment merging disabled
140 dnl shared vtable support disabled
141 dnl explicit unloading disabled
143 dnl index type address flags size
144 dnl 7 text 04000000 z---c- D (default)
145 dnl 8 data 40000000 ---m-- D (default)
146 dnl executable from stack: D (default)
147 dnl kernel assisted branch prediction enabled
148 dnl lazy swap allocation for dynamic segments disabled
149 dnl nulptr references disabled
150 dnl address space model: default
151 dnl caliper dynamic instrumentation disabled
153 LDDPOSTPROC="2>/dev/null | sed -e '1,/shared library list:/d' -e '/shared library binding:/,\$d' | sed -e 's,^.*[ ]\\([^ ][^ ]*\\)\$,\\1,' | sed -e 's,^.*/,,'"
156 LDDPROG="elfdump -Dl"
157 dnl The output of "elfdump -Dl program" looks like this:
161 dnl **** MIPS LIBLIST INFORMATION ****
163 dnl [INDEX] Timestamp Checksum Flags Name Version
164 dnl [1] Oct 2 05:19:12 1999 0x867bf7a8 ----- libc.so.1 sgi1.0
166 LDDPOSTPROC="2>/dev/null | sed -n -e 's,^[[][0-9]*[]].* 0x[^ ]* [^ ][^ ]* \\([^ ][^ ]*\\).*\$,\\1,p' | sed -e 's,^.*/,,'"
168 linux* | gnu* | kfreebsd*-gnu | knetbsd*-gnu) # glibc-based systems
170 dnl The output of "ldd program" looks like this:
171 dnl libc.so.6 => /lib/libc.so.6 (0x4002d000)
172 dnl /lib/ld-linux.so.2 (0x40000000)
173 LDDPOSTPROC="2>/dev/null | sed -n -e 's,^ \\([^ ][^ ]*\\).*\$,\\1,p' | sed -e 's,^.*/,,'"
177 dnl The output of "odump -Dl program" looks like this:
179 dnl ***LIBRARY LIST SECTION***
180 dnl Name Time-Stamp CheckSum Flags Version
182 dnl libc.so Dec 30 00:09:30 1997 0x5e955f9b 0 osf.1
184 LDDPOSTPROC="2>/dev/null | sed -n -e 's,^ \\([^ ][^ ]*\\).*,\\1,p' | sed -e '/^Name\$/d' | sed -e 's,^.*/,,'"
188 dnl The output of "ldd program" looks like this:
189 dnl libc.so.1 => /usr/lib/libc.so.1
190 dnl libdl.so.1 => /usr/lib/libdl.so.1
191 dnl /usr/platform/SUNW,Ultra-5_10/lib/libc_psr.so.1
192 dnl The first sed collects the indented lines.
193 dnl The second sed extracts the left-hand part.
194 dnl The third sed removes directory specifications.
195 LDDPOSTPROC="2>/dev/null | sed -n -e 's,^ \\([^ ].*\\)\$,\\1,p' | sed -e 's, =>.*\$,,' | sed -e 's,^.*/,,'"
200 dnl Avoid locale dependencies.
201 if test "$LDDPROG" != ":"; then
202 LDDPROG="LC_ALL=C $LDDPROG"
206 AC_SUBST([LDDPOSTPROC])