History log of /freebsd-current/usr.bin/ldd/ldd.c
Revision Date Author Comments
# 5e3934b1 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

usr.bin: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by: Netflix


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# e17dd921 09-Jul-2023 Jessica Clarke <jrtc27@FreeBSD.org>

ldd: Use __PATH_RTLD("32") over _COMPAT32_PATH_RTLD

This will allow the latter to be removed, reducing the boilerplate
needed for a new libcompat.

Reviewed by: kib, brooks, jhb
Differential Revision: https://reviews.freebsd.org/D40934


# e9f8723c 21-Mar-2023 Ed Maste <emaste@FreeBSD.org>

ldd: clarify format options

-f may be specified zero, one, or two times. Make this clear in the
usage.

Reviewed by: markj, kib
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D34733


# f48114b6 06-Oct-2022 Simon J. Gerraty <sjg@FreeBSD.org>

ldd: ignore unverified files

When mac_veriexec is enforcing, we won't run unverified binaries,
don't let ldd examine them either.

Reviewed by: stevek emaste
MFC after: 1 week
Sponsored by: Juniper Networks, Inc.
Differential Revision: https://reviews.freebsd.org/D36897


# 9cabef3d 21-Sep-2022 Konstantin Belousov <kib@FreeBSD.org>

ldd: use direct exec mode unconditionally

Trying to exec malformed or unusual binary, for instance, a non-FreeBSD
ABI, or using a non-standard interpreter, might give unexpected outcome.

Reported by: The UK's National Cyber Security Centre (NCSC)
Reviewed by: emaste, markj, philip
Discussed with: jhb
Sponsored by: The FreeBSD Foundation
admbug: 991
PR: 127276, 175339, 231926
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D36650


# 7d20a080 15-Nov-2021 Konstantin Belousov <kib@FreeBSD.org>

ldd: also use exec mode for -a

The -a option also requires passing specific environment variables to
instance of rtld doing tracing.

PR: 259069
Sponsored by: The FreeBSD Foundation
MFC after: 1 week


# 2c7a6dad 11-Oct-2021 Konstantin Belousov <kib@FreeBSD.org>

ldd: do not use dlopen(RTLD_TRACE) for dso when format is specified

Problem is that rtld cannot reliably access updated environment.
This was made more obvious by bfd4c875a10560aaa2. The application
environment can be in arbitrary state and place, system components
can observe it only during execve(2), or in case of rtld, right after
execve, when environment is still at know location and format.

Instead spawn ld-elf.so.1 in direct exec mode which can correctly read
all inherited updates to the environment.

PR: 259069
Reviewed by: arichardson, jhb
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D32464


# ca8c576d 12-Oct-2021 Konstantin Belousov <kib@FreeBSD.org>

ldd: style

Reviewed by: arichardson, jhb
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D32464


# 17fc43bc 28-Aug-2021 Konstantin Belousov <kib@FreeBSD.org>

ldd: Remove non-functional -v option

It seems -v only worked for a.out. Remove it, not even keeping the current
nop for compat. Also remove more mentions of a.out format from the man
page.

Reviewed by: dim, emaste
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D31708


# 9d4104b2 29-Jan-2021 John Baldwin <jhb@FreeBSD.org>

Fix ldd to work with more ELF files.

- Use libelf to parse ELF data structures and remove code duplication
for ELF32.

- Don't require the OSABI field to be set to the FreeBSD OSABI for
shared libraries. Both AArch64 and RISC-V leave it set to "none"
and instead depend on the ABI tag note. For ldd, this means falling
back to walking the notes in PT_NOTE segments to find the ABI tag
note to determine if an ELF shared library without OSABI set in the
header file is a FreeBSD shared library.

Reviewed by: kib
MFC after: 5 days
Sponsored by: DARPA
Differential Revision: https://reviews.freebsd.org/D28342


# c8eee7c0 09-Jan-2021 Ed Maste <emaste@FreeBSD.org>

ldd: renumber executable type constants

ldd had #defines for AOUT, ELF, and ELF32. The removal of AOUT left a
possibly confusing gap. These are not used anywhere but this file so
renumber to avoid the gap.

Reported by: allanjude


# 0713c7b8 07-Jan-2021 Ed Maste <emaste@FreeBSD.org>

ldd: Retire aout support

Userland aout support has not been required since FreeBSD 2.x.
If someone needs to use FreeBSD 2 shared libraries they will be best
served by using a FreeBSD 2 ldd, perhaps as part of a jail with a full
FreeBSD 2.x install.

Relnotes: Yes
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D27478


# 2b5d88fd 13-Jun-2020 Konstantin Belousov <kib@FreeBSD.org>

Fix ldd for PIE binaries after rtld stopped accepting binaries for dlopen.

ldd proclaims ET_DYN objects as shared libraries and tries to
dlopen(RTLD_TRACE) them to get dependencies. Since PIE binaries are
ET_DYN | DF_1_PIE, refusal to dlopen such binaries breaks ldd.

Fix it by reading and parsing dynamic segment looking for DF_FLAG_1
and taking DF_1_PIE into account when deciding between binary and
library.

Reported by: Dewayne Geraghty <dewayne@heuristicsystems.com.au>
Reviewed by: markj
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D25257


# 5a2c0ab1 17-Mar-2020 Ed Maste <emaste@FreeBSD.org>

ldd: add aout deprecation notice

Reported by: kib


# 1de7b4b8 27-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

various: general adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

No functional change intended.


# ca20f8ec 07-Aug-2017 Ruslan Bukin <br@FreeBSD.org>

o Replace __riscv__ with __riscv
o Replace __riscv64 with (__riscv && __riscv_xlen == 64)

This is required to support new GCC 7.1 compiler.
This is compatible with current GCC 6.1 compiler.

RISC-V is extensible ISA and the idea here is to have built-in define
per each extension, so together with __riscv we will have some subset
of these as well (depending on -march string passed to compiler):

__riscv_compressed
__riscv_atomic
__riscv_mul
__riscv_div
__riscv_muldiv
__riscv_fdiv
__riscv_fsqrt
__riscv_float_abi_soft
__riscv_float_abi_single
__riscv_float_abi_double
__riscv_cmodel_medlow
__riscv_cmodel_medany
__riscv_cmodel_pic
__riscv_xlen

Reviewed by: ngie
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D11901


# 4b426307 16-May-2016 Don Lewis <truckman@FreeBSD.org>

Increase size of argv[] array to avoid running off the end.

Reported by: Coverity
CID: 1193819
MFC after: 1 week


# 5a0bf0f5 24-Jan-2016 Ruslan Bukin <br@FreeBSD.org>

We don't support a.out executables on RISC-V.

Reviewed by: emaste
Sponsored by: DARPA, AFRL
Sponsored by: HEIF5
Differential Revision: https://reviews.freebsd.org/D5048


# a41dab8f 16-Oct-2015 Jung-uk Kim <jkim@FreeBSD.org>

Add support for ARM EABI.

MFC after: 1 week


# e1f65999 18-Mar-2015 Andrew Turner <andrew@FreeBSD.org>

Allowus to exclude a.out support from ldd and use it with arm64 as it won't
support the a.out format.

Reviewed by: emaste
Sponsored by: The FreeBSD Foundation


# a94a4b74 06-Aug-2013 Mark Johnston <markj@FreeBSD.org>

Pass variables prefixed with both LD_ and LD_32_ to the run-time linker.
This prevents unintentional execution of programs when running ldd(1) on
32-bit Linux binaries.

PR: 175339, 127276
Suggested by: kib, rstone
Reviewed by: kib
MFC after: 2 weeks


# 70557f4f 22-Nov-2010 Rebecca Cran <brucec@FreeBSD.org>

hdr.elf.e_ident[EI_OSABI] is not a bitmask so '==' should been used.

Reported by: Artem Belevich <fbsdlist at src.cx>


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 52122f31 01-Aug-2008 John Baldwin <jhb@FreeBSD.org>

A few style and whitespace fixes.

Submitted by: bde


# e68ed793 01-Aug-2008 John Baldwin <jhb@FreeBSD.org>

Tweak the support for using ldd on 32-bit objects a bit further.
Specifically, build a 32-bit /usr/bin/ldd32 on amd64 which handles 32-bit
objects. Since it is a 32-bit binary, it can fork a child process which
can dlopen() a 32-bit shared library. The current 32-bit support in ldd
can't do this because it does the dlopen() from a 64-bit process. In order
to preserve an intuitive interface for users, the ldd binary automatically
execs /usr/bin/ldd32 for 32-bit objects. The end result is that ldd on
amd64 now transparently handles 32-bit shared libraries in addition to
32-bit binaries.

Submitted by: ps (indirectly)


# bff71350 27-Jul-2008 Edwin Groothuis <edwin@FreeBSD.org>

Fix text in the comment why we check for ELF32_R_TYPE

Approved by: bde@
MFC after: 2 days2 days


# 8bd833ff 20-Jul-2008 Edwin Groothuis <edwin@FreeBSD.org>

After the commit of SVN rev 180236, wilko@ noticed that the approach
doesn't work on the Alpha platform: machine/elf.h doesn't include
sys/elf32.h there.

PR: related to bin/124906
Approved by: bde@
MFC after: 1 week


# fffd993d 03-Jul-2008 Edwin Groothuis <edwin@FreeBSD.org>

On 64 bit architectures, you can run 32 bit executables and the rtld can trace them, but ldd(1) doesn't know yet how to detect them:

[/] root@ed-exigent>ldd `which httpd`
ldd: /usr/local/sbin/httpd: can't read program header
ldd: /usr/local/sbin/httpd: not a dynamic executable

But...

[/] root@ed-exigent>LD_32_TRACE_LOADED_OBJECTS==1 `which httpd`
libm.so.4 => /lib32//libm.so.4 (0x280c8000)
libaprutil-1.so.2 => /usr/local/lib/libaprutil-1.so.2 (0x280de000)
libexpat.so.6 => /usr/local/lib/libexpat.so.6 (0x280f2000)
libiconv.so.3 => /usr/local/lib/libiconv.so.3 (0x28110000)
libapr-1.so.2 => /usr/local/lib/libapr-1.so.2 (0x281fd000)
libcrypt.so.3 => /lib32//libcrypt.so.3 (0x2821d000)
libpthread.so.2 => not found (0x0)
libc.so.6 => /lib32//libc.so.6 (0x28235000)
libpthread.so.2 => /usr/lib32/libpthread.so.2 (0x2830d000)

Added support in ldd(1) for the LD_32_xxx environment variables if
the architecture of the machine is >32 bits. If we ever go to 128
bit architectures this excercise will have to be repeated but thanks
to earlier commits today it will be relative simple.

PR: bin/124906
Submitted by: edwin
Approved by: bde (mentor)
MFC after: 1 week


# d3c1e14b 03-Jul-2008 Edwin Groothuis <edwin@FreeBSD.org>

Extract the determination of the kind of (dynamic) executable from
the main-loop into a seperate function.
Instead of using hardcoded environment variables, define them in a
lookup table.
For the rest, no functionality changes.

Approved by: bde (mentor)
MFC after: 1 week


# a0d476a9 03-Jul-2008 Edwin Groothuis <edwin@FreeBSD.org>

stylify ldd.c, no functional changes.

Approved by: bde (mentor)
MFC after: 1 week


# d1cf9ea2 19-Oct-2002 Maxim Sobolev <sobomax@FreeBSD.org>

Fix a problem with RTLD_TRACE flag to dlopen(3), which sometimes can return
even if there was no error occured (when trying to dlopen(3) object that
already linked into executable which does dlopen(3) call). This is more
proper fix for `ldd /usr/lib/libc.so' problem, because the new behaviour
conforms to documentation.

Remove workaround from ldd.c (rev.1.32).

PR: 35099
Submitted by: Nathan Hawkins <utsl@quic.net>
MFC after: 1 week


# 005ba515 17-May-2002 Akinori MUSHA <knu@FreeBSD.org>

Fix a tiny bug in shlib support of ldd(1); if dlopen(lib, RTLD_TRACE)
returns, exit gracefully with 0.

This fixes the behavior you see when you specify libc.so. It occurs
because ldd(1) itself is linked with libc.so.

$ ldd /usr/lib/libc.so
/usr/lib/libc.so:
ldd: /usr/lib/libc.so: (null)
/usr/lib/libc.so: exit status 1

Reviewed by: silence of audit@


# a53809fd 27-Apr-2002 Mark Murray <markm@FreeBSD.org>

Warns; ANSIfy, constify and move declarations into a common header.


# a2cfdda8 20-Apr-2002 Mike Barcroft <mike@FreeBSD.org>

Include <arpa/inet.h> for prototype of ntohl() used in the N_BADMAG()
macro.


# f1bb2cd2 21-Mar-2002 Warner Losh <imp@FreeBSD.org>

remove __P


# 20249943 17-Feb-2002 David E. O'Brien <obrien@FreeBSD.org>

Add support such that if LD_TRACE_LOADED_OBJECTS_ALL is defined to a
non-empty string in the environment; we indicate which objects caused
each object to be loaded.

PR: 30908
Submitted-by: Mike Meyer <mwm@mired.org>


# 97b79abc 07-Feb-2002 Maxim Sobolev <sobomax@FreeBSD.org>

Inspect ELF header and reject any non-FreeBSD shared objects.

MFC after: 2 weeks


# c6de4ce7 04-Feb-2002 Maxim Sobolev <sobomax@FreeBSD.org>

Allow ldd(1) be used on shared libraries in addition to executables.


# fc41545e 04-Feb-2002 Maxim Sobolev <sobomax@FreeBSD.org>

GC meaningless assignment.

MFC after: 3 days


# 7bc6d015 09-Jul-2001 Brian Somers <brian@FreeBSD.org>

Fix the type of the NULL arg to execl()

Idea from: Theo de Raadt <deraadt@openbsd.org>


# 5e6220d9 02-May-2001 David E. O'Brien <obrien@FreeBSD.org>

* include/elf.h has been repo copied to include/elf-hints.h, and it no
longer includes machine/elf.h.
* consumers of elf.h now use the minimalist elf header possible.

This change is motivated by Binutils 2.11.0 and too much clashing over
our base elf headers and the Binutils elf headers.


# e6f0df2b 15-Dec-2000 Andrey A. Chernov <ache@FreeBSD.org>

Fix lseek args order (PR 23549)
Catch and report lseek errors too
While reading header don't attempt to continue reading
if some IO operation fails

PR: 23549


# 3e762626 10-Dec-2000 Philippe Charnier <charnier@FreeBSD.org>

Add rcsid. Remove unused #include. Remove error() definition and replace
with warn().


# 62f882d6 04-Sep-2000 Warner Losh <imp@FreeBSD.org>

getopt and friends are declared in <unistd.h>
getopt returns -1 not EOF.


# c3aac50f 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# 97db68b6 16-Sep-1998 Doug Rabson <dfr@FreeBSD.org>

Make ldd work on alpha.


# e2daa140 30-Aug-1998 John Polstra <jdp@FreeBSD.org>

Fix a bug which caused ldd to execute scripts listed on its command
line, instead of skipping them.

Also make a few minor cleanups.

PR: bin/7783


# c474c6d3 01-May-1998 Doug Rabson <dfr@FreeBSD.org>

Add ELF support.


# 170fa4e8 02-Sep-1997 John Polstra <jdp@FreeBSD.org>

Touch up the code that implements "ldd -v".

Bring the style of sods.c into better conformance. Add code to
print the contents of each datum being relocated. Correct the logic
that distinguishes between programs, shared libraries, and object
files. Make the entire program "-Wall" clean.


# fce15c9a 22-Feb-1997 Peter Wemm <peter@FreeBSD.org>

Revert $FreeBSD$ to $Id$


# 1130b656 14-Jan-1997 Jordan K. Hubbard <jkh@FreeBSD.org>

Make the long-awaited change from $Id$ to $FreeBSD$

This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore. This update would have been
insane otherwise.


# 18c0f29e 11-Jan-1997 John Polstra <jdp@FreeBSD.org>

Set LD_TRACE_LOADED_OBJECTS to "1" instead of to "". The dynamic linker
now treats empty "LD_*" environment variables as if they were unset, per
the standard SVR4 conventions.


# 45f4c7f9 30-Nov-1996 Bruce Evans <bde@FreeBSD.org>

Made the synopsis in the man page conform to the style guide.

Made the usage message conform to the style guide.

Don't use the implementation variable `__progname'.


# b988beb8 22-Nov-1996 Peter Wemm <peter@FreeBSD.org>

make the Usage string match reality

Submitted by: faried nawaz <fn@uidaho.edu>, PR#2075


# fecaa127 29-Oct-1996 Peter Wemm <peter@FreeBSD.org>

oops, uninitialised variable.. -v mode depended on stack contents.

Submitted by: Masafumi NAKANE <max@wide.ad.jp>, PR#1920


# 9731d137 30-Sep-1996 Peter Wemm <peter@FreeBSD.org>

Incorporate John Polstra's sods.c display of the details about the
dynamic linking information in the executable. It's quite extensive.
It's connected to ldd's (new) -v option.


# d138df61 30-Sep-1996 Peter Wemm <peter@FreeBSD.org>

Support for specifying printf-like output specs to control the ldd output
as present in the new rtld version.

Obtained from: NetBSD
Reviewed by: nate, jdp


# 61f9ce8d 23-Dec-1994 Nate Williams <nate@FreeBSD.org>

Updated to recent version of Paul K.'s shlib code. This code has better
warning handling and allows for link-time warnings with a modified
version of gas.

Note: Not all of the newer bits were updated such as some of the non-x86
machine-dependant code is relevant to FreeBSD right now.

Obtained from: NetBSD


# 699e1b82 15-Jun-1994 Rich Murphey <rich@FreeBSD.org>

Changes from Paul Kranenburg which bring us into sync with his sources:

handling of errors through the standard err() and warn()
more fixes for Geoff Rehmet's NULL pointer bug.
fixes NULL pointer bugs when linking mono and nested X servers.
supports a `-nostdlib' option.
accept object files without a symbol table
don't attempt dynamic linking when `-A' is given

a few variable names have chaged (desc -> fd), and the formatting has
changed which should make it much easier to track his sources.

I tested 'make world' for /usr/src and X twice with these changes.


# 09e3d49d 13-Feb-1994 Jordan K. Hubbard <jkh@FreeBSD.org>

This is Paul K's latest set of ld changes. A commit was necessary at this
late stage due to the fact that link.h was copyright Sun Microsystems.

This version of ld sync's us up with NetBSD's ld and supports compatablily
with NetBSD's -[zZ] flags (which we had reversed). Compiling with this
new ld will give you RRS warnings for libraries which do not contain .type
infomation - these wsarnings are harmless and will go away as soon as you
recompile your libraries (cd /usr/src; make libraries).


# b9ae52e3 03-Nov-1993 Paul Richards <paul@FreeBSD.org>

Imported NetBSD's ld for shared libs.