Date: Sun, 4 Aug 2013 09:51:14 +0300 From: Konstantin Belousov <kostikbel@gmail.com> To: Mark Johnston <markj@freebsd.org> Cc: Gennady Proskurin <gprspb@mail.ru>, Mateusz Guzik <mjguzik@gmail.com>, freebsd-current@freebsd.org Subject: Re: ldd runs linux programs Message-ID: <20130804065114.GI4972@kib.kiev.ua> In-Reply-To: <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> <20130804041734.GB3259@raichu>
next in thread | previous in thread | raw e-mail | index | archive | help
--ShzNbizneSsKYyOp
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
On Sun, Aug 04, 2013 at 12:17:34AM -0400, Mark Johnston wrote:
> 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.
>=20
> 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$");
> =20
> #include "extern.h"
> =20
> -#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] d=
eclare
> * them. There is no official macro for determining whether they are de=
clared,
> @@ -76,13 +70,23 @@ static void usage(void);
> =20
> #define _PATH_LDD32 "/usr/bin/ldd32"
> =20
> +#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;
> =20
> - unsetenv(LD_ "TRACE_LOADED_OBJECTS");
> + LDD_UNSETENV("TRACE_LOADED_OBJECTS");
> rval =3D 0;
> i =3D 0;
> argv[i++] =3D strdup(_PATH_LDD32);
> @@ -121,7 +125,7 @@ execldd32(char *file, char *fmt1, char *fmt2, int afl=
ag, 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[])
> }
> =20
> /* ld.so magic */
> - setenv(LD_ "TRACE_LOADED_OBJECTS", "yes", 1);
> + LDD_SETENV("TRACE_LOADED_OBJECTS", "yes", 1);
> if (fmt1 !=3D NULL)
> - setenv(LD_ "TRACE_LOADED_OBJECTS_FMT1", fmt1, 1);
> + LDD_SETENV("TRACE_LOADED_OBJECTS_FMT1", fmt1, 1);
> if (fmt2 !=3D NULL)
> - setenv(LD_ "TRACE_LOADED_OBJECTS_FMT2", fmt2, 1);
> + LDD_SETENV("TRACE_LOADED_OBJECTS_FMT2", fmt2, 1);
> =20
> - 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 =3D=3D NULL && fmt2 =3D=3D NULL)
> /* Default formats */
> printf("%s:\n", *argv);
This looks fine to me.
--ShzNbizneSsKYyOp
Content-Type: application/pgp-signature
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.20 (FreeBSD)
iQIcBAEBAgAGBQJR/fniAAoJEJDCuSvBvK1B9swQAILL7cNpR7dw2xNneHCcTAso
jYZuzh9y/QE9SPQzWA4lLd/mzuahy5gFCYpkB1upHzW0VQc4+0/TqhjrFeeWsgT1
SweK6kjsyic2k96+ltSbOvulBVAK9sOdV+AyF5QncsrawXxyTriQCYyAOioI/1df
NUlGaaU3Mqn36TCm12skYeSf33JmI3KApTeD48tRIv2v1JTaaTPJU9Bxtkdm/ycZ
tvM88KRGiccI5end3OI4D3FkoYal3Lodm16utd9ZKE6o/YRLeH/RjW33Zdxx7SgW
yT4UNPjghi15tbGkILXGiB7cAmMEylBsabgsPsCYAtSjWLPoGJzs69QyhUr7c26Y
m5UU/B14WULaFkLUQoDuJxw+B66mTwbd6m/g3tSgiZk1SumeEOpSh/pf6EZ9hCdF
nyapcCiZD0UUFx09TmuEDmK6cMI9pVRluzyhmwtIkRkP9+E4N4WdeYPs1rokZlhx
kV1KhvDHs3Ye9UI0Zv2a6z6ruN0jrRz087qTD9SDgBzDFUpu6Eir/+5QXglcFoiY
ggQPv+q7+y3mOVyqWGsz6uJ6ZXm95T6LAziReH7v0l04azCe5W1KRoSk+M8SksDW
aw5490TF2IDGRcfEmuH1wDa7ZoTj2HSOQuYiXdgDBtLqUS/Dhk3j1ibAIaYzea+1
wsC+TqtdR5tj1ZLx/kNG
=FBmT
-----END PGP SIGNATURE-----
--ShzNbizneSsKYyOp--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130804065114.GI4972>
