From owner-freebsd-current@FreeBSD.ORG Sun Aug 4 04:17:39 2013 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 74A08F15; Sun, 4 Aug 2013 04:17:39 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: from mail-qe0-x22a.google.com (mail-qe0-x22a.google.com [IPv6:2607:f8b0:400d:c02::22a]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 195F82AE2; Sun, 4 Aug 2013 04:17:39 +0000 (UTC) Received: by mail-qe0-f42.google.com with SMTP id s14so1138157qeb.1 for ; Sat, 03 Aug 2013 21:17:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=6aBHD11gnhYcvGCTTJpWe0i2EkeCn17FQTeGF/iUJ48=; b=iE3F1mTU5u1mbgKIBierrvLZNNlg/90PVlw1+s8qpVDavlfUHnamvZ4aVJFk1HtzWz WTPbduEhGia4njYcHZkSgd25CG0pCxgcw5BFKjeDxK37Tvl0tIoU/2ljRPT++Qk/UdH4 m7YgnlgNojbN1O45snLKS3/OSqotDphmuNJp0vfGn/r/eHbEBg5q90uDBYe9AkrrO7xZ eM8znBbLHHIqKg4rAOPEy7j8on6Y2EhPC6yISwRsA1TRxHnGTe1ydeTptiRmBybnIibg 0v+Ek38KQa6JhwJ03GIvRoKORo890iIhajCPO1dKhnb5GcsKb1QsMZfxNEvBLBsNyBD6 Na/Q== X-Received: by 10.224.45.138 with SMTP id e10mr21231074qaf.47.1375589857869; Sat, 03 Aug 2013 21:17:37 -0700 (PDT) Received: from raichu (24-212-218-13.cable.teksavvy.com. [24.212.218.13]) by mx.google.com with ESMTPSA id w2sm3968351qec.8.2013.08.03.21.17.36 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 03 Aug 2013 21:17:37 -0700 (PDT) Sender: Mark Johnston Date: Sun, 4 Aug 2013 00:17:34 -0400 From: Mark Johnston To: Konstantin Belousov Subject: Re: ldd runs linux programs Message-ID: <20130804041734.GB3259@raichu> References: <20130728193110.GB17514@gpr.nnz-home.ru> <20130728204958.GA32322@dft-labs.eu> <51F5D491.1080803@freebsd.org> <20130729081254.GB32322@dft-labs.eu> <20130729155625.GA2544@charmander> <20130729205449.GA6007@dft-labs.eu> <20130801021231.GA58998@raichu> <20130801133935.GT4972@kib.kiev.ua> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20130801133935.GT4972@kib.kiev.ua> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: Gennady Proskurin , Mateusz Guzik , freebsd-current@freebsd.org X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 04 Aug 2013 04:17:39 -0000 On Thu, Aug 01, 2013 at 04:39:35PM +0300, Konstantin Belousov wrote: > On Wed, Jul 31, 2013 at 10:12:31PM -0400, Mark Johnston wrote: > > On Mon, Jul 29, 2013 at 10:54:49PM +0200, Mateusz Guzik wrote: > > > On Mon, Jul 29, 2013 at 11:56:25AM -0400, Mark Johnston wrote: > > > > > 127276 suggests running the binary as is (which I don't like) and > > > > > achieves this with a hacky way. So if we really want to do this, the > > > > > patch should be reworked to detect Linux binaries properly. > > > > > > > > > > In general we should gain linux_ldd (like linux_kdump) and our ldd > > > > > should work only on FreeBSD binaries. The last part is achieved with my > > > > > patch. > > > > > > > > > > markj, are you working on this? > > > > > > > > Not really; my original fix for this problem was essentially the same as > > > > yours. That is, just change ldd(1) to bail if the OS ABI byte isn't > > > > equal to ELFOSABI_FREEBSD. That's the change I have committed in my > > > > local tree right now. > > > > > > > > Then I thought I'd try to get ldd to work properly with Linux binaries > > > > as well, but wasn't sure what the right approach should be. As the above > > > > PR suggests, the easy thing to do is to just pass > > > > LD_TRACE_LOADED_OBJECTS and not LD_32_TRACE_LOADED_OBJECTS for 32-bit > > > > ELF objects if the OS isn't FreeBSD. This feels somewhat hacky to me, > > > > but I didn't really see another approach. > > > > > > > > That said, I think your patch should be committed since it's clearly an > > > > improvement over the current behaviour. I'm willing to test and commit > > > > it, and clean up the open PRs. If you could expand on the right way to > > > > handle Linux binaries, I'd be willing to implement and commit that too. > > > > I don't quite understand your reference to linux_kdump though - I have > > > > no such program on my laptop running CURRENT, and ktrace+kdump seem to > > > > work fine with the Linux binaries under /compat/linux. > > > > > > > > > > Well, there was linux_kdump in ports but it apparently got obsolete as > > > necessary support for included in our regular kdump. > > > > > > So it may make sense to teach our ldd how to deal with Linux binaries > > > for consistency, but its unclear for me if this is better than providing > > > linux_ldd. Also there is the problem of (not) appending /compat/linux to > > > printed paths (for Linux binaries the kernel performs file lookups against > > > /compat/linux first). I'm not that interested in this problem though. :P > > > > What do you think of the patch below, which just sets both variables in > > the compat case? It's somewhat less intrusive than the patch in the PR. > > If that's no good then I'll just commit your original patch; I really > > just want to fix the fact that the example pipeline in the ldd(1) man > > page starts a GTK program (some Adobe Flash thingy to be specific) when > > run in /usr/local/bin on my desktop machine. :) > > > > [snip] > > I do not understand this COMPAT_32BIT business in ldd(1). Its only > application seems to preventing ldd 32bit binary from amd64 host to > work on i386 ? > > IMO, both LD_TRACE and LD_32_TRACE should be passed unconditionally > always. I do not see any harm of doing this. I spent some time trying to figure out if there was any reason for this and didn't come up with anything. Does the patch below look ok? It just adds a couple of macros to set both the native and 32-bit compat variable. It works properly for me for 32-bit, native, and (32-bit) Linux executables and shared libs on an amd64 machine. diff --git a/usr.bin/ldd/ldd.c b/usr.bin/ldd/ldd.c index 00c8797..39f38e8 100644 --- a/usr.bin/ldd/ldd.c +++ b/usr.bin/ldd/ldd.c @@ -49,12 +49,6 @@ __FBSDID("$FreeBSD$"); #include "extern.h" -#ifdef COMPAT_32BIT -#define LD_ "LD_32_" -#else -#define LD_ "LD_" -#endif - /* * 32-bit ELF data structures can only be used if the system header[s] declare * them. There is no official macro for determining whether they are declared, @@ -76,13 +70,23 @@ static void usage(void); #define _PATH_LDD32 "/usr/bin/ldd32" +#define LDD_SETENV(name, value, overwrite) do { \ + setenv("LD_" name, value, overwrite); \ + setenv("LD_32_" name, value, overwrite); \ +} while (0) + +#define LDD_UNSETENV(name) do { \ + unsetenv("LD_" name); \ + unsetenv("LD_32_" name); \ +} while (0) + static int execldd32(char *file, char *fmt1, char *fmt2, int aflag, int vflag) { char *argv[8]; int i, rval, status; - unsetenv(LD_ "TRACE_LOADED_OBJECTS"); + LDD_UNSETENV("TRACE_LOADED_OBJECTS"); rval = 0; i = 0; argv[i++] = strdup(_PATH_LDD32); @@ -121,7 +125,7 @@ execldd32(char *file, char *fmt1, char *fmt2, int aflag, int vflag) } while (i--) free(argv[i]); - setenv(LD_ "TRACE_LOADED_OBJECTS", "yes", 1); + LDD_SETENV("TRACE_LOADED_OBJECTS", "yes", 1); return (rval); } #endif @@ -210,15 +214,15 @@ main(int argc, char *argv[]) } /* ld.so magic */ - setenv(LD_ "TRACE_LOADED_OBJECTS", "yes", 1); + LDD_SETENV("TRACE_LOADED_OBJECTS", "yes", 1); if (fmt1 != NULL) - setenv(LD_ "TRACE_LOADED_OBJECTS_FMT1", fmt1, 1); + LDD_SETENV("TRACE_LOADED_OBJECTS_FMT1", fmt1, 1); if (fmt2 != NULL) - setenv(LD_ "TRACE_LOADED_OBJECTS_FMT2", fmt2, 1); + LDD_SETENV("TRACE_LOADED_OBJECTS_FMT2", fmt2, 1); - setenv(LD_ "TRACE_LOADED_OBJECTS_PROGNAME", *argv, 1); + LDD_SETENV("TRACE_LOADED_OBJECTS_PROGNAME", *argv, 1); if (aflag) - setenv(LD_ "TRACE_LOADED_OBJECTS_ALL", "1", 1); + LDD_SETENV("TRACE_LOADED_OBJECTS_ALL", "1", 1); else if (fmt1 == NULL && fmt2 == NULL) /* Default formats */ printf("%s:\n", *argv);