Index: libexec/rtld-elf/paths.h =================================================================== --- libexec/rtld-elf/paths.h +++ libexec/rtld-elf/paths.h @@ -31,12 +31,20 @@ #undef _PATH_ELF_HINTS +#if defined(__ILP32__) +#define LD_ "LD_32_" +#elif defined(__LP64__) +#define LD_ "LD_64_" +#else +#error "Unsupported pointer size" +#endif +#define LD_FALLBACK_ "LD_" + #ifdef COMPAT_32BIT #define _PATH_ELF_HINTS "/var/run/ld-elf32.so.hints" #define _PATH_LIBMAP_CONF "/etc/libmap32.conf" #define _BASENAME_RTLD "ld-elf32.so.1" #define STANDARD_LIBRARY_PATH "/lib32:/usr/lib32" -#define LD_ "LD_32_" #endif #ifndef _PATH_ELF_HINTS @@ -59,10 +67,6 @@ #define STANDARD_LIBRARY_PATH "/lib/casper:/lib:/usr/lib" #endif -#ifndef LD_ -#define LD_ "LD_" -#endif - #define _PATH_SOFT_ELF_HINTS "/var/run/ld-elf-soft.so.hints" #define _PATH_SOFT_LIBMAP_CONF "/etc/libmap-soft.conf" #define _PATH_SOFT_RTLD "/libexec/ld-elf.so.1" Index: libexec/rtld-elf/rtld.1 =================================================================== --- libexec/rtld-elf/rtld.1 +++ libexec/rtld-elf/rtld.1 @@ -127,10 +127,22 @@ recognizes a number of environment variables that can be used to modify its behaviour. On 64-bit architectures, the linker for 32-bit objects recognizes -all the environment variables listed below, but is being prefixed with -.Ev LD_32_ , +all the environment variables listed below but prefixed with +.Ev LD_32_ +instead of +.Ev LD_ , for example: .Ev LD_32_TRACE_LOADED_OBJECTS . +On 64-bit systems, +.Nm +also recognizes variables prefixed with +.Ev LD_64_ . +The variables prefixed with +.Ev LD_32_ +or +.Ev LD_64_ +have priority over the ones using +.Ev LD_ . .Bl -tag -width ".Ev LD_LIBMAP_DISABLE" .It Ev LD_DUMP_REL_POST If set, Index: libexec/rtld-elf/rtld.c =================================================================== --- libexec/rtld-elf/rtld.c +++ libexec/rtld-elf/rtld.c @@ -353,6 +353,20 @@ #define _LD(x) LD_ x #endif +/* Check LD_{32,64}_ and if that is not set fall back to LD_. */ +#define get_ld_env(var) _get_ld_env(_LD(var), LD_FALLBACK_ var) + +static char * +_get_ld_env(const char *preferred, const char *fallback) +{ + char *result; + + result = getenv(preferred); + if (result == NULL && fallback != NULL) + result = getenv(fallback); + return (result); +} + /* * Main entry point for dynamic linking. The first argument is the * stack pointer. The stack is expected to be laid out as described @@ -562,7 +576,7 @@ } } - ld_bind_now = getenv(_LD("BIND_NOW")); + ld_bind_now = get_ld_env("BIND_NOW"); /* * If the process is tainted, then we un-set the dangerous environment @@ -580,17 +594,17 @@ rtld_die(); } } - ld_debug = getenv(_LD("DEBUG")); + ld_debug = get_ld_env("DEBUG"); if (ld_bind_now == NULL) - ld_bind_not = getenv(_LD("BIND_NOT")) != NULL; - libmap_disable = getenv(_LD("LIBMAP_DISABLE")) != NULL; - libmap_override = getenv(_LD("LIBMAP")); - ld_library_path = getenv(_LD("LIBRARY_PATH")); - ld_library_dirs = getenv(_LD("LIBRARY_PATH_FDS")); - ld_preload = getenv(_LD("PRELOAD")); - ld_elf_hints_path = getenv(_LD("ELF_HINTS_PATH")); - ld_loadfltr = getenv(_LD("LOADFLTR")) != NULL; - library_path_rpath = getenv(_LD("LIBRARY_PATH_RPATH")); + ld_bind_not = get_ld_env("BIND_NOT") != NULL; + libmap_disable = get_ld_env("LIBMAP_DISABLE") != NULL; + libmap_override = get_ld_env("LIBMAP"); + ld_library_path = get_ld_env("LIBRARY_PATH"); + ld_library_dirs = get_ld_env("LIBRARY_PATH_FDS"); + ld_preload = get_ld_env("PRELOAD"); + ld_elf_hints_path = get_ld_env("ELF_HINTS_PATH"); + ld_loadfltr = get_ld_env("LOADFLTR") != NULL; + library_path_rpath = get_ld_env("LIBRARY_PATH_RPATH"); if (library_path_rpath != NULL) { if (library_path_rpath[0] == 'y' || library_path_rpath[0] == 'Y' || @@ -602,8 +616,8 @@ dangerous_ld_env = libmap_disable || (libmap_override != NULL) || (ld_library_path != NULL) || (ld_preload != NULL) || (ld_elf_hints_path != NULL) || ld_loadfltr; - ld_tracing = getenv(_LD("TRACE_LOADED_OBJECTS")); - ld_utrace = getenv(_LD("UTRACE")); + ld_tracing = get_ld_env("TRACE_LOADED_OBJECTS"); + ld_utrace = get_ld_env("UTRACE"); if ((ld_elf_hints_path == NULL) || strlen(ld_elf_hints_path) == 0) ld_elf_hints_path = ld_elf_hints_default; @@ -735,7 +749,7 @@ exit(0); } - if (getenv(_LD("DUMP_REL_PRE")) != NULL) { + if (get_ld_env("DUMP_REL_PRE") != NULL) { dump_relocations(obj_main); exit (0); } @@ -763,7 +777,7 @@ if (do_copy_relocations(obj_main) == -1) rtld_die(); - if (getenv(_LD("DUMP_REL_POST")) != NULL) { + if (get_ld_env("DUMP_REL_POST") != NULL) { dump_relocations(obj_main); exit (0); } @@ -4665,16 +4679,16 @@ const char *fmt1, *fmt2, *fmt, *main_local, *list_containers; int c; - if ((main_local = getenv(_LD("TRACE_LOADED_OBJECTS_PROGNAME"))) == NULL) + if ((main_local = get_ld_env("TRACE_LOADED_OBJECTS_PROGNAME")) == NULL) main_local = ""; - if ((fmt1 = getenv(_LD("TRACE_LOADED_OBJECTS_FMT1"))) == NULL) + if ((fmt1 = get_ld_env("TRACE_LOADED_OBJECTS_FMT1")) == NULL) fmt1 = "\t%o => %p (%x)\n"; - if ((fmt2 = getenv(_LD("TRACE_LOADED_OBJECTS_FMT2"))) == NULL) + if ((fmt2 = get_ld_env("TRACE_LOADED_OBJECTS_FMT2")) == NULL) fmt2 = "\t%o (%x)\n"; - list_containers = getenv(_LD("TRACE_LOADED_OBJECTS_ALL")); + list_containers = get_ld_env("TRACE_LOADED_OBJECTS_ALL"); for (; obj != NULL; obj = TAILQ_NEXT(obj, next)) { Needed_Entry *needed;