Hi, With this change, ldd /lib/libc.so.12.220 fails under NetBSD/amd64 9.99.101.
/lib/libc.so.12.220: ldd: /lib/libc.so.12.220: invalid ELF class 2, expected 1 It seems that elf32_ldd() fails. Builds of some pkgsrc packages that use gobject introspection and meson fails because they uses ldd command during build. Thank you. -- Ryo ONODERA // r...@tetera.org PGP fingerprint = 82A2 DC91 76E0 A10A 8ABB FD1B F404 27FA C7D1 15F3 > On Oct 15, 2022, at 14:55, matthew green <m...@netbsd.org> wrote: > > Module Name: src > Committed By: mrg > Date: Sat Oct 15 05:55:46 UTC 2022 > > Modified Files: > src/usr.bin/ldd: ldd.1 ldd.c > > Log Message: > 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. > > > To generate a diff of this commit: > cvs rdiff -u -r1.20 -r1.21 src/usr.bin/ldd/ldd.1 > cvs rdiff -u -r1.25 -r1.26 src/usr.bin/ldd/ldd.c > > Please note that diffs are not public domain; they are subject to the > copyright notices on the relevant files. > > Modified files: Index: src/usr.bin/ldd/ldd.1 diff -u > src/usr.bin/ldd/ldd.1:1.20 src/usr.bin/ldd/ldd.1:1.21 --- > src/usr.bin/ldd/ldd.1:1.20 Mon Dec 25 05:08:49 2017 +++ src/usr.bin/ldd/ldd.1 > Sat Oct 15 05:55:45 2022 @@ -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 @@ > which makes .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 > @@ A 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. Index: src/usr.bin/ldd/ldd.c diff -u > src/usr.bin/ldd/ldd.c:1.25 src/usr.bin/ldd/ldd.c:1.26 --- > src/usr.bin/ldd/ldd.c:1.25 Fri Jul 23 04:20:05 2021 +++ src/usr.bin/ldd/ldd.c > Sat Oct 15 05:55:45 2022 @@ -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 #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 @@ -124,11 +124,12 @@ main(int > argc, char **argv) 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 @@ main(int > argc, char **argv) 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 @@ main(int argc, char **argv) > 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); }