Re: ldd runs linux programs

From: Konstantin Belousov <kostikbel_at_gmail.com>
Date: Sun, 4 Aug 2013 09:51:14 +0300
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.
> 
> 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
> _at__at_ -49,12 +49,6 _at__at_ __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,
> _at__at_ -76,13 +70,23 _at__at_ 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);
> _at__at_ -121,7 +125,7 _at__at_ 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
> _at__at_ -210,15 +214,15 _at__at_ 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);
This looks fine to me.

Received on Sun Aug 04 2013 - 04:51:24 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:40 UTC