Re: ldd runs linux programs
--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--
討論串 (同標題文章)
完整討論串 (本文為第 15 之 15 篇):