From owner-freebsd-bugs@FreeBSD.ORG Thu Jan 13 10:50:10 2011 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 62A25106564A for ; Thu, 13 Jan 2011 10:50:10 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 37C798FC0A for ; Thu, 13 Jan 2011 10:50:10 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id p0DAo9Wa040479 for ; Thu, 13 Jan 2011 10:50:09 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id p0DAo94I040478; Thu, 13 Jan 2011 10:50:09 GMT (envelope-from gnats) Date: Thu, 13 Jan 2011 10:50:09 GMT Message-Id: <201101131050.p0DAo94I040478@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Dominic Fandrey Cc: Subject: Re: bin/127276: [patch] ldd(1) invokes linux yes X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Dominic Fandrey List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Jan 2011 10:50:10 -0000 The following reply was made to PR bin/127276; it has been noted by GNATS. From: Dominic Fandrey To: bug-followup@FreeBSD.org, kamikaze@bsdforen.de Cc: Subject: Re: bin/127276: [patch] ldd(1) invokes linux yes Date: Thu, 13 Jan 2011 11:44:06 +0100 I tested the patch, prior to the test: > ldd /compat/linux/usr/bin/yes y y y y y y ... After I applied the patch: > ldd /compat/linux/usr/bin/yes /compat/linux/usr/bin/yes: libc.so.6 => /lib/libc.so.6 (0x28075000) /lib/ld-linux.so.2 (0x2804f000) Apparently it returns libraries from the /compat/linux perspective. > ldd /compat/linux/lib/ld-linux.so.2 ldd: /compat/linux/lib/ld-linux.so.2: not a FreeBSD ELF shared object The behaviour caused by the patch is comprehensible and a vast improvement over the old behaviour in my opinion, so I'm all for it. At some point the manual page of ldd should be updated to describe the new behaviour. If the patch is committed, I volunteer to make the changes. Because the patch was mangled by Gnats, I resubmit it here. I did not make any changes apart from the header to trigger the usual patch detection magic. Regards diff -u ldd.c.old ldd.c --- ldd.c.old 2009-09-19 21:45:17.000000000 +0900 +++ ldd.c 2010-05-04 11:48:42.000000000 +0900 @@ -65,7 +65,7 @@ #endif static int is_executable(const char *fname, int fd, int *is_shlib, - int *type); + int *osabi, int *type); static void usage(void); #define TYPE_UNKNOWN 0 @@ -177,14 +177,14 @@ rval = 0; for (; argc > 0; argc--, argv++) { - int fd, status, is_shlib, rv, type; + int fd, status, is_shlib, rv, type, osabi; if ((fd = open(*argv, O_RDONLY, 0)) < 0) { warn("%s", *argv); rval |= 1; continue; } - rv = is_executable(*argv, fd, &is_shlib, &type); + rv = is_executable(*argv, fd, &is_shlib, &osabi, &type); close(fd); if (rv == 0) { rval |= 1; @@ -197,6 +197,8 @@ break; #if __ELF_WORD_SIZE > 32 && defined(ELF32_SUPPORTED) case TYPE_ELF32: + if (osabi != ELFOSABI_FREEBSD) + break; rval |= execldd32(*argv, fmt1, fmt2, aflag, vflag); continue; #endif @@ -267,7 +269,7 @@ } static int -is_executable(const char *fname, int fd, int *is_shlib, int *type) +is_executable(const char *fname, int fd, int *is_shlib, int *osabi, int *type) { union { struct exec aout; @@ -300,6 +302,8 @@ return (1); } + *osabi = hdr.elf.e_ident[EI_OSABI]; + #if __ELF_WORD_SIZE > 32 && defined(ELF32_SUPPORTED) if ((size_t)n >= sizeof(hdr.elf32) && IS_ELF(hdr.elf32) && hdr.elf32.e_ident[EI_CLASS] == ELFCLASS32) {