Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/ldd ldd(1): add a -v option to display all errors no...



details:   https://anonhg.NetBSD.org/src/rev/b183d4cf2636
branches:  trunk
changeset: 371846:b183d4cf2636
user:      mrg <mrg%NetBSD.org@localhost>
date:      Sat Oct 15 05:55:45 2022 +0000

description:
ldd(1): add a -v option to display all errors not just the latest.

ldd on a go binary currently fails with an error that basically
says "not elf32 class".  this is a true statement, as it is an
elf64 class object, but it's not useful.  it happens because
ldd_elf64() is called, fails in _rtld_map_object(), and then
ldd_elf32() is called, and it fails because the class is wrong,
and only this error is returned.  (this problem remains.  the
call to map the object fails due to there being 3 instead of 2
elf segments in the file.  i guess we need similar code in
ld.elf_so/map_objects.c as the kernel gained some time ago.)

perhaps the first error, not the last error, should be used if
everything fails, but this allows all failures to be see and
would be useful even if the error string handling changed.

diffstat:

 usr.bin/ldd/ldd.1 |  16 +++++++---------
 usr.bin/ldd/ldd.c |  36 +++++++++++++++++++++++++++---------
 2 files changed, 34 insertions(+), 18 deletions(-)

diffs (128 lines):

diff -r 2472cf5b2740 -r b183d4cf2636 usr.bin/ldd/ldd.1
--- a/usr.bin/ldd/ldd.1 Sat Oct 15 04:47:37 2022 +0000
+++ b/usr.bin/ldd/ldd.1 Sat Oct 15 05:55:45 2022 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: ldd.1,v 1.20 2017/12/25 05:08:49 maya Exp $
+.\"    $NetBSD: ldd.1,v 1.21 2022/10/15 05:55:45 mrg Exp $
 .\"
 .\" Copyright (c) 1998 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd December 25, 2017
+.Dd October 15, 2022
 .Dt LDD 1
 .Os
 .Sh NAME
@@ -35,7 +35,7 @@
 .Nd list dynamic object dependencies
 .Sh SYNOPSIS
 .Nm
-.Op Fl o
+.Op Fl ov
 .Op Fl f Ar format
 .Ar program ...
 .Sh DESCRIPTION
@@ -105,6 +105,10 @@
 .Nm
 behave analogously to
 .Ic nm Fl o .
+.Pp
+The
+.Fl v
+option turns on verbose mode.
 .Sh EXIT STATUS
 .Ex -std
 .Sh SEE ALSO
@@ -118,9 +122,3 @@
 utility first appeared in SunOS 4.0, it appeared in its current form
 in
 .Nx 0.9a .
-.Sh BUGS
-The
-a.out
-.Nm
-actually runs the program it has been requested to analyze which in specially
-constructed environments can have security implications.
diff -r 2472cf5b2740 -r b183d4cf2636 usr.bin/ldd/ldd.c
--- a/usr.bin/ldd/ldd.c Sat Oct 15 04:47:37 2022 +0000
+++ b/usr.bin/ldd/ldd.c Sat Oct 15 05:55:45 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ldd.c,v 1.25 2021/07/23 04:20:05 martin Exp $  */
+/*     $NetBSD: ldd.c,v 1.26 2022/10/15 05:55:45 mrg Exp $     */
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: ldd.c,v 1.25 2021/07/23 04:20:05 martin Exp $");
+__RCSID("$NetBSD: ldd.c,v 1.26 2022/10/15 05:55:45 mrg Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -124,11 +124,12 @@
        const char *fmt1 = NULL, *fmt2 = NULL;
        int c, exit_status = EXIT_SUCCESS;
        char cwd[MAXPATHLEN], path[MAXPATHLEN];
+       bool verbose = false, failed = false;
 
 #ifdef DEBUG
        debug = 1;
 #endif
-       while ((c = getopt(argc, argv, "f:o")) != -1) {
+       while ((c = getopt(argc, argv, "f:ov")) != -1) {
                switch (c) {
                case 'f':
                        if (fmt1) {
@@ -143,6 +144,9 @@
                                errx(1, "Cannot use -o and -f together");
                        fmt1 = "%a:-l%o.%m => %p\n";
                        break;
+               case 'v':
+                       verbose = true;
+                       break;
                default:
                        usage();
                        /*NOTREACHED*/
@@ -174,17 +178,31 @@
                        warn("%s", *argv);
                        continue;
                }
-               if (elf_ldd(fd, *argv, path, fmt1, fmt2) == -1
-                   /* Alpha never had 32 bit support. */
+               if (elf_ldd(fd, *argv, path, fmt1, fmt2) == -1) {
+                       if (verbose)
+                               warnx("%s", error_message);
+                       failed = true;
+               }
+               /* Alpha never had 32 bit support. */
 #if (defined(_LP64) && !defined(ELF64_ONLY)) || defined(MIPS_N32)
-                   && elf32_ldd(fd, *argv, path, fmt1, fmt2) == -1
+               if (elf32_ldd(fd, *argv, path, fmt1, fmt2) == -1) {
+                       if (verbose)
+                               warnx("%s", error_message);
+                       failed = true;
+               }
 #if defined(__mips__) && 0 /* XXX this is still hosed for some reason */
-                   && elf32_ldd_compat(fd, *argv, path, fmt1, fmt2) == -1
+               if (elf32_ldd_compat(fd, *argv, path, fmt1, fmt2) == -1) {
+                       if (verbose)
+                               warnx("%s", error_message);
+                       failed = true;
+               }
 #endif
 #endif
-                   ) {
+
+               if (failed) {
                        exit_status = EXIT_FAILURE;
-                       warnx("%s", error_message);
+                       if (!verbose)
+                               warnx("%s", error_message);
                }
                close(fd);
        }



Home | Main Index | Thread Index | Old Index