# HG changeset patch # Parent b8b22cbf20ed06a91a2cc02e201e957b6a3e813d diff -r b8b22cbf20ed -r dd68b09339ba libexec/rtld-elf/aarch64/rtld_machdep.h --- a/libexec/rtld-elf/aarch64/rtld_machdep.h +++ b/libexec/rtld-elf/aarch64/rtld_machdep.h @@ -80,4 +80,6 @@ extern void *__tls_get_addr(tls_index *t #define RTLD_DEFAULT_STACK_PF_EXEC PF_X #define RTLD_DEFAULT_STACK_EXEC PROT_EXEC +#define md_exe_hook(x) + #endif diff -r b8b22cbf20ed -r dd68b09339ba libexec/rtld-elf/amd64/rtld_machdep.h --- a/libexec/rtld-elf/amd64/rtld_machdep.h +++ b/libexec/rtld-elf/amd64/rtld_machdep.h @@ -79,4 +79,6 @@ void *__tls_get_addr(tls_index *ti) __ex #define RTLD_DEFAULT_STACK_PF_EXEC PF_X #define RTLD_DEFAULT_STACK_EXEC PROT_EXEC +#define md_exe_hook(x) + #endif diff -r b8b22cbf20ed -r dd68b09339ba libexec/rtld-elf/arm/reloc.c --- a/libexec/rtld-elf/arm/reloc.c +++ b/libexec/rtld-elf/arm/reloc.c @@ -16,6 +16,14 @@ #include "debug.h" #include "rtld.h" +extern char *ld_env_prefix; + +void +md_exe_hook(Elf_Auxinfo *aux) +{ + +} + void init_pltgot(Obj_Entry *obj) { diff -r b8b22cbf20ed -r dd68b09339ba libexec/rtld-elf/arm/rtld_machdep.h --- a/libexec/rtld-elf/arm/rtld_machdep.h +++ b/libexec/rtld-elf/arm/rtld_machdep.h @@ -75,4 +75,6 @@ extern void *__tls_get_addr(tls_index *t #define RTLD_DEFAULT_STACK_PF_EXEC PF_X #define RTLD_DEFAULT_STACK_EXEC PROT_EXEC +void md_exe_hook(Elf_Auxinfo *); + #endif diff -r b8b22cbf20ed -r dd68b09339ba libexec/rtld-elf/i386/rtld_machdep.h --- a/libexec/rtld-elf/i386/rtld_machdep.h +++ b/libexec/rtld-elf/i386/rtld_machdep.h @@ -80,4 +80,6 @@ void *__tls_get_addr(tls_index *ti) __ex #define RTLD_DEFAULT_STACK_PF_EXEC PF_X #define RTLD_DEFAULT_STACK_EXEC PROT_EXEC +#define md_exe_hook(x) + #endif diff -r b8b22cbf20ed -r dd68b09339ba libexec/rtld-elf/mips/rtld_machdep.h --- a/libexec/rtld-elf/mips/rtld_machdep.h +++ b/libexec/rtld-elf/mips/rtld_machdep.h @@ -75,4 +75,6 @@ extern void *__tls_get_addr(tls_index *t #define RTLD_DEFAULT_STACK_PF_EXEC PF_X #define RTLD_DEFAULT_STACK_EXEC PROT_EXEC +#define md_exe_hook(x) + #endif diff -r b8b22cbf20ed -r dd68b09339ba libexec/rtld-elf/powerpc/rtld_machdep.h --- a/libexec/rtld-elf/powerpc/rtld_machdep.h +++ b/libexec/rtld-elf/powerpc/rtld_machdep.h @@ -90,4 +90,6 @@ extern void *__tls_get_addr(tls_index* t #define RTLD_DEFAULT_STACK_PF_EXEC PF_X #define RTLD_DEFAULT_STACK_EXEC PROT_EXEC +#define md_exe_hook(x) + #endif diff -r b8b22cbf20ed -r dd68b09339ba libexec/rtld-elf/powerpc64/rtld_machdep.h --- a/libexec/rtld-elf/powerpc64/rtld_machdep.h +++ b/libexec/rtld-elf/powerpc64/rtld_machdep.h @@ -82,4 +82,6 @@ extern void *__tls_get_addr(tls_index* t #define RTLD_DEFAULT_STACK_PF_EXEC PF_X #define RTLD_DEFAULT_STACK_EXEC PROT_EXEC +#define md_exe_hook(x) + #endif diff -r b8b22cbf20ed -r dd68b09339ba libexec/rtld-elf/rtld.c --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -182,10 +182,8 @@ static char *ld_library_path; /* Environ static char *ld_library_dirs; /* Environment variable for library descriptors */ static char *ld_preload; /* Environment variable for libraries to load first */ -static char *ld_elf_hints_path; /* Environment variable for alternative hints path */ static char *ld_tracing; /* Called from ldd to print libs */ static char *ld_utrace; /* Use utrace() to log events. */ -static char *ld_standard_library_path; /* Default path to search libraries */ static Obj_Entry *obj_list; /* Head of linked list of shared objects */ static Obj_Entry **obj_tail; /* Link field of last object in list */ static Obj_Entry *obj_main; /* The main program shared object */ @@ -261,6 +259,14 @@ int tls_max_index = 1; /* Largest modul bool ld_library_path_rpath = false; /* + * Globals to control env prefix. Must be set by the time that + * md_exe_hook() returns to be effective. + */ +char *ld_env_prefix = _LD_; /* Prefix for environment variable names */ +char *ld_standard_library_path; /* Default path to search libraries */ +char *ld_elf_hints_path; /* Environment variable for alternative hints path */ + +/* * Fill in a DoneList with an allocation large enough to hold all of * the currently-loaded objects. Keep this as a macro since it calls * alloca and we want that to occur within the scope of the caller. @@ -321,6 +327,34 @@ ld_utrace_log(int event, void *handle, v } /* + * can't call str* functions, so inline. Should never overflow + * the buffer, since user never can set what's going on here, + * but better paranoid than wrong. + */ +static const char * +_LD(const char *var) +{ + static char buffer[80]; + char *walker, *ep; + const char *src; + + walker = buffer; + ep = buffer + sizeof(buffer) - 1; + src = ld_env_prefix; + while (*src && walker < ep) + *walker++ = *src++; + src = var; + while (*src && walker < ep) + *walker++ = *src++; + if (walker >= ep) { + _rtld_error("environemtn variable too long, aborting"); + rtld_die(); + } + *walker++ = '\0'; + rerturn buffer; +} + +/* * Main entry point for dynamic linking. The first argument is the * stack pointer. The stack is expected to be laid out as described * in the SVR4 ABI specification, Intel 386 Processor Supplement. @@ -414,7 +448,7 @@ func_ptr_type trust = !issetugid(); - md_somehow_examine_elf_hdr_and_do_magic(aux_info); + md_exe_hook(aux_info); ld_bind_now = getenv(LD_("BIND_NOW")); /* diff -r b8b22cbf20ed -r dd68b09339ba libexec/rtld-elf/rtld.h --- a/libexec/rtld-elf/rtld.h +++ b/libexec/rtld-elf/rtld.h @@ -47,14 +47,13 @@ #define _PATH_ELF_HINTS "/var/run/ld-elf32.so.hints" /* For running 32 bit binaries */ #define STANDARD_LIBRARY_PATH "/lib32:/usr/lib32" -#define LD_(x) "LD_32_" x +#define _LD_ "LD_32_" #endif #ifndef STANDARD_LIBRARY_PATH #define STANDARD_LIBRARY_PATH "/lib:/usr/lib" #endif -#ifndef LD_ -#define LD_(x) "LD_" x +#ifndef _LD_ "LD_" #endif #define NEW(type) ((type *) xmalloc(sizeof(type))) diff -r b8b22cbf20ed -r dd68b09339ba libexec/rtld-elf/sparc64/rtld_machdep.h --- a/libexec/rtld-elf/sparc64/rtld_machdep.h +++ b/libexec/rtld-elf/sparc64/rtld_machdep.h @@ -71,4 +71,6 @@ extern void *__tls_get_addr(tls_index *t #define RTLD_DEFAULT_STACK_PF_EXEC 0 #define RTLD_DEFAULT_STACK_EXEC 0 +#define md_exe_hook(x) + #endif