diff --git a/ChangeLog b/ChangeLog index a6a0578..b8fb3e5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,8 @@ -2016-22-28 Mark Hatle +2016-03-22 Mark Hatle + * src/gather.c, src/get.c: Fix LD_PRELOAD + * Merge with cross_prelink + +2016-03-22 Mark Hatle * Merge with cross_prelink 2016-03-18 Donn Seeley diff --git a/src/gather.c b/src/gather.c index 2eb7cbc..277f1b5 100644 --- a/src/gather.c +++ b/src/gather.c @@ -62,7 +62,7 @@ gather_deps (DSO *dso, struct prelink_entry *ent) int i, j, seen = 0; FILE *f = NULL; const char *argv[5]; - const char *envp[4]; + const char *envp[5]; char *line = NULL, *p, *q = NULL; const char **depends = NULL, **depends_temp; size_t ndepends = 0, ndepends_alloced = 0; @@ -162,10 +162,20 @@ gather_deps (DSO *dso, struct prelink_entry *ent) argv[i++] = ent_filename; argv[i] = NULL; - envp[0] = "LD_TRACE_LOADED_OBJECTS=1"; - envp[1] = "LD_TRACE_PRELINKING=1"; - envp[2] = "LD_WARN="; - envp[3] = NULL; + + j = 0; + if(etype == ET_EXEC && ld_preload) + { + p = alloca (sizeof "LD_PRELOAD=" + strlen (ld_preload) + 1); + strcpy (stpcpy (p, "LD_PRELOAD="), ld_preload); + envp[j++] = p; + } + + envp[j++] = "LD_TRACE_LOADED_OBJECTS=1"; + envp[j++] = "LD_TRACE_PRELINKING=1"; + envp[j++] = "LD_WARN="; + envp[j] = NULL; + f = execve_open (dl, (char * const *)argv, (char * const *)envp); if (f == NULL) goto error_out; diff --git a/src/get.c b/src/get.c index 6b4fed2..0659962 100644 --- a/src/get.c +++ b/src/get.c @@ -643,8 +643,8 @@ prelink_get_relocations (struct prelink_info *info) FILE *f; DSO *dso = info->dso; const char *argv[5]; - const char *envp[4]; - int i, ret, status; + const char *envp[5]; + int i, j, ret, status; char *p; const char *dl = dynamic_linker ?: dso->arch->dynamic_linker; const char *ent_filename; @@ -691,12 +691,20 @@ prelink_get_relocations (struct prelink_info *info) } argv[i++] = ent_filename; argv[i] = NULL; - envp[0] = "LD_TRACE_LOADED_OBJECTS=1"; - envp[1] = "LD_BIND_NOW=1"; + + j = 0; + if(etype == ET_EXEC && ld_preload) + { + p = alloca (sizeof "LD_PRELOAD=" + strlen (ld_preload)); + strcpy (stpcpy (p, "LD_PRELOAD="), ld_preload); + envp[j++] = p; + } + envp[j++] = "LD_TRACE_LOADED_OBJECTS=1"; + envp[j++] = "LD_BIND_NOW=1"; p = alloca (sizeof "LD_TRACE_PRELINKING=" + strlen (info->ent->filename)); strcpy (stpcpy (p, "LD_TRACE_PRELINKING="), info->ent->filename); - envp[2] = p; - envp[3] = NULL; + envp[j++] = p; + envp[j] = NULL; ret = 2; f = execve_open (dl, (char * const *)argv, (char * const *)envp);