Implemented the LD_LIBRARY_PATH environment variable
This commit is contained in:
parent
4f4a64c2bf
commit
e97614bc9d
24
tools/elf.c
24
tools/elf.c
|
@ -33,21 +33,23 @@
|
||||||
|
|
||||||
|
|
||||||
/* prototypes */
|
/* prototypes */
|
||||||
static int ELFFUNC(ldd)(char const * filename, FILE * fp, ELFTYPE(Ehdr) * ehdr);
|
static int ELFFUNC(ldd)(char const * filename, FILE * fp, ELFTYPE(Ehdr) * ehdr,
|
||||||
|
char const * ldpath);
|
||||||
|
|
||||||
|
|
||||||
/* functions */
|
/* functions */
|
||||||
/* ldd */
|
/* ldd */
|
||||||
static int ELFFUNC(ldd)(char const * filename, FILE * fp, ELFTYPE(Ehdr) * ehdr);
|
|
||||||
static int ELFFUNC(phdr)(char const * filename, FILE * fp, ELFTYPE(Ehdr) * ehdr,
|
static int ELFFUNC(phdr)(char const * filename, FILE * fp, ELFTYPE(Ehdr) * ehdr,
|
||||||
ELFTYPE(Phdr) * phdr);
|
ELFTYPE(Phdr) * phdr, char const * ldpath);
|
||||||
static int ELFFUNC(phdr_dyn)(char const * filename, FILE * fp,
|
static int ELFFUNC(phdr_dyn)(char const * filename, FILE * fp,
|
||||||
ELFTYPE(Ehdr) * ehdr, ELFTYPE(Phdr) * phdr, ELFTYPE(Dyn) * dyn);
|
ELFTYPE(Ehdr) * ehdr, ELFTYPE(Phdr) * phdr, ELFTYPE(Dyn) * dyn,
|
||||||
|
char const * ldpath);
|
||||||
static int ELFFUNC(phdr_dyn_print)(char const * filename, char const * rpath);
|
static int ELFFUNC(phdr_dyn_print)(char const * filename, char const * rpath);
|
||||||
static char * ELFFUNC(string)(char const * filename, FILE * fp,
|
static char * ELFFUNC(string)(char const * filename, FILE * fp,
|
||||||
ELFTYPE(Ehdr) * ehdr, ELFTYPE(Addr) addr, ELFTYPE(Addr) index);
|
ELFTYPE(Ehdr) * ehdr, ELFTYPE(Addr) addr, ELFTYPE(Addr) index);
|
||||||
|
|
||||||
static int ELFFUNC(ldd)(char const * filename, FILE * fp, ELFTYPE(Ehdr) * ehdr)
|
static int ELFFUNC(ldd)(char const * filename, FILE * fp, ELFTYPE(Ehdr) * ehdr,
|
||||||
|
char const * ldpath)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
ELFTYPE(Phdr) * phdr;
|
ELFTYPE(Phdr) * phdr;
|
||||||
|
@ -60,13 +62,13 @@ static int ELFFUNC(ldd)(char const * filename, FILE * fp, ELFTYPE(Ehdr) * ehdr)
|
||||||
return -_error(filename, strerror(errno), 1);
|
return -_error(filename, strerror(errno), 1);
|
||||||
if((phdr = malloc(sizeof(*phdr) * ehdr->e_phnum)) == NULL)
|
if((phdr = malloc(sizeof(*phdr) * ehdr->e_phnum)) == NULL)
|
||||||
return -_error(filename, strerror(errno), 1);
|
return -_error(filename, strerror(errno), 1);
|
||||||
ret = ELFFUNC(phdr)(filename, fp, ehdr, phdr);
|
ret = ELFFUNC(phdr)(filename, fp, ehdr, phdr, ldpath);
|
||||||
free(phdr);
|
free(phdr);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ELFFUNC(phdr)(char const * filename, FILE * fp, ELFTYPE(Ehdr) * ehdr,
|
static int ELFFUNC(phdr)(char const * filename, FILE * fp, ELFTYPE(Ehdr) * ehdr,
|
||||||
ELFTYPE(Phdr) * phdr)
|
ELFTYPE(Phdr) * phdr, char const * ldpath)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
@ -97,7 +99,7 @@ static int ELFFUNC(phdr)(char const * filename, FILE * fp, ELFTYPE(Ehdr) * ehdr,
|
||||||
}
|
}
|
||||||
if(fread(dyn, phdr[i].p_filesz, 1, fp) == 1)
|
if(fread(dyn, phdr[i].p_filesz, 1, fp) == 1)
|
||||||
ret = ELFFUNC(phdr_dyn)(filename, fp, ehdr, &phdr[i],
|
ret = ELFFUNC(phdr_dyn)(filename, fp, ehdr, &phdr[i],
|
||||||
dyn);
|
dyn, ldpath);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(ferror(fp) != 0)
|
if(ferror(fp) != 0)
|
||||||
|
@ -112,7 +114,8 @@ static int ELFFUNC(phdr)(char const * filename, FILE * fp, ELFTYPE(Ehdr) * ehdr,
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ELFFUNC(phdr_dyn)(char const * filename, FILE * fp,
|
static int ELFFUNC(phdr_dyn)(char const * filename, FILE * fp,
|
||||||
ELFTYPE(Ehdr) * ehdr, ELFTYPE(Phdr) * phdr, ELFTYPE(Dyn) * dyn)
|
ELFTYPE(Ehdr) * ehdr, ELFTYPE(Phdr) * phdr, ELFTYPE(Dyn) * dyn,
|
||||||
|
char const * ldpath)
|
||||||
{
|
{
|
||||||
ssize_t s = -1;
|
ssize_t s = -1;
|
||||||
ssize_t r = -1;
|
ssize_t r = -1;
|
||||||
|
@ -147,7 +150,8 @@ static int ELFFUNC(phdr_dyn)(char const * filename, FILE * fp,
|
||||||
if((p = ELFFUNC(string)(filename, fp, ehdr, dyn[s].d_un.d_ptr,
|
if((p = ELFFUNC(string)(filename, fp, ehdr, dyn[s].d_un.d_ptr,
|
||||||
dyn[i].d_un.d_val)) == NULL)
|
dyn[i].d_un.d_val)) == NULL)
|
||||||
continue;
|
continue;
|
||||||
if(ELFFUNC(phdr_dyn_print)(p, rpath) != 0
|
if(ELFFUNC(phdr_dyn_print)(p, ldpath) != 0
|
||||||
|
&& ELFFUNC(phdr_dyn_print)(p, rpath) != 0
|
||||||
&& ELFFUNC(phdr_dyn_print)(p,
|
&& ELFFUNC(phdr_dyn_print)(p,
|
||||||
"/usr/lib:/lib") != 0)
|
"/usr/lib:/lib") != 0)
|
||||||
printf("\t%s\n", p);
|
printf("\t%s\n", p);
|
||||||
|
|
14
tools/ldd.c
14
tools/ldd.c
|
@ -1,5 +1,5 @@
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
/* Copyright (c) 2010 Pierre Pronchery <khorben@defora.org> */
|
/* Copyright (c) 2011 Pierre Pronchery <khorben@defora.org> */
|
||||||
/* This file is part of DeforaOS System Loader */
|
/* This file is part of DeforaOS System Loader */
|
||||||
/* This program is free software: you can redistribute it and/or modify
|
/* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
/* private */
|
/* private */
|
||||||
/* prototypes */
|
/* prototypes */
|
||||||
static int _error(char const * error1, char const * error2, int ret);
|
static int _error(char const * error1, char const * error2, int ret);
|
||||||
static int _ldd(char const * filename);
|
static int _ldd(char const * filename, char const * ldpath);
|
||||||
#undef ELFSIZE
|
#undef ELFSIZE
|
||||||
#define ELFSIZE 32
|
#define ELFSIZE 32
|
||||||
#include "elf.c"
|
#include "elf.c"
|
||||||
|
@ -44,6 +44,7 @@ int main(int argc, char * argv[])
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int o;
|
int o;
|
||||||
int i;
|
int i;
|
||||||
|
char const * ldpath;
|
||||||
|
|
||||||
while((o = getopt(argc, argv, "")) != -1)
|
while((o = getopt(argc, argv, "")) != -1)
|
||||||
switch(o)
|
switch(o)
|
||||||
|
@ -53,8 +54,9 @@ int main(int argc, char * argv[])
|
||||||
}
|
}
|
||||||
if(optind == argc)
|
if(optind == argc)
|
||||||
return _usage();
|
return _usage();
|
||||||
|
ldpath = getenv("LD_LIBRARY_PATH");
|
||||||
for(i = optind; i < argc; i++)
|
for(i = optind; i < argc; i++)
|
||||||
ret |= _ldd(argv[i]);
|
ret |= _ldd(argv[i], ldpath);
|
||||||
return (ret == 0) ? 0 : 2;
|
return (ret == 0) ? 0 : 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +64,7 @@ int main(int argc, char * argv[])
|
||||||
/* private */
|
/* private */
|
||||||
/* functions */
|
/* functions */
|
||||||
/* ldd */
|
/* ldd */
|
||||||
static int _ldd(char const * filename)
|
static int _ldd(char const * filename, char const * ldpath)
|
||||||
{
|
{
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
FILE * fp;
|
FILE * fp;
|
||||||
|
@ -80,9 +82,9 @@ static int _ldd(char const * filename)
|
||||||
if(memcmp(elf.e_ident, ELFMAG, SELFMAG) != 0)
|
if(memcmp(elf.e_ident, ELFMAG, SELFMAG) != 0)
|
||||||
ret = -_error(filename, "Not an ELF file", 1);
|
ret = -_error(filename, "Not an ELF file", 1);
|
||||||
else if(elf.e_ident[EI_CLASS] == ELFCLASS32)
|
else if(elf.e_ident[EI_CLASS] == ELFCLASS32)
|
||||||
ret = _do_ldd32(filename, fp, &elf.ehdr32);
|
ret = _do_ldd32(filename, fp, &elf.ehdr32, ldpath);
|
||||||
else if(elf.e_ident[EI_CLASS] == ELFCLASS64)
|
else if(elf.e_ident[EI_CLASS] == ELFCLASS64)
|
||||||
ret = _do_ldd64(filename, fp, &elf.ehdr64);
|
ret = _do_ldd64(filename, fp, &elf.ehdr64, ldpath);
|
||||||
else
|
else
|
||||||
ret = -_error(filename, "Could not determine ELF class",
|
ret = -_error(filename, "Could not determine ELF class",
|
||||||
1);
|
1);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user