summaryrefslogtreecommitdiff
path: root/ldso
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2003-03-07 12:23:11 +0000
committerEric Andersen <andersen@codepoet.org>2003-03-07 12:23:11 +0000
commit443636be415c1920f071cfe4907fcc361b2999ce (patch)
tree49c863ca968b578a2af684f0b96c5f5217b0b816 /ldso
parenta2a493671ebbb9728d09eb99f0b8b3e0da5e88f8 (diff)
Patch from Stefan Allius
the ldd.c wasn't compilable for SuperH due to a missing ELFCLASSM define and the readelf executable was linked with a wrong dynamic linker path. To fix this I removed the --uclibc-use-build-dir. The patch also fixed all the compiler warnings (-Wall -W). Erik made a few additional changes to eliminate unused function arguments and fixup a static variable that was was doing the wrong thing
Diffstat (limited to 'ldso')
-rw-r--r--ldso/util/Makefile2
-rw-r--r--ldso/util/ldd.c34
-rw-r--r--ldso/util/readelf.c11
3 files changed, 24 insertions, 23 deletions
diff --git a/ldso/util/Makefile b/ldso/util/Makefile
index 7d49ee523..b7712f82a 100644
--- a/ldso/util/Makefile
+++ b/ldso/util/Makefile
@@ -45,7 +45,7 @@ readelf: readelf.c
strip -x -R .note -R .comment $@
readelf.target: readelf.c
- $(TARGET_CC) $(CFLAGS) --uclibc-use-build-dir -Wl,-s readelf.c -o $@
+ $(TARGET_CC) $(CFLAGS) -Wl,-s readelf.c -o $@
$(STRIPTOOL) -x -R .note -R .comment $@
readsoname.o: readsoname.c readsoname2.c
diff --git a/ldso/util/ldd.c b/ldso/util/ldd.c
index d4d7fcce9..defc91cfd 100644
--- a/ldso/util/ldd.c
+++ b/ldso/util/ldd.c
@@ -87,6 +87,7 @@
#if defined(__sh__)
#define MATCH_MACHINE(x) (x == EM_SH)
+#define ELFCLASSM ELFCLASS32
#endif
#if defined (__v850e__)
@@ -139,7 +140,7 @@ Elf32_Shdr * elf_find_section_type( int key, Elf32_Ehdr *ehdr)
Elf32_Shdr *shdr;
shdr = (Elf32_Shdr *)(ehdr->e_shoff + (char *)ehdr);
for (j = ehdr->e_shnum; --j>=0; ++shdr) {
- if (key==byteswap32_to_host(shdr->sh_type)) {
+ if (key==(int)byteswap32_to_host(shdr->sh_type)) {
return shdr;
}
}
@@ -151,7 +152,7 @@ Elf32_Phdr * elf_find_phdr_type( int type, Elf32_Ehdr *ehdr)
int j;
Elf32_Phdr *phdr = (Elf32_Phdr *)(ehdr->e_phoff + (char *)ehdr);
for (j = ehdr->e_phnum; --j>=0; ++phdr) {
- if (type==byteswap32_to_host(phdr->p_type)) {
+ if (type==(int)byteswap32_to_host(phdr->p_type)) {
return phdr;
}
}
@@ -165,7 +166,7 @@ void * elf_find_dynamic(int const key, Elf32_Dyn *dynp,
Elf32_Phdr *pt_text = elf_find_phdr_type(PT_LOAD, ehdr);
unsigned tx_reloc = byteswap32_to_host(pt_text->p_vaddr) - byteswap32_to_host(pt_text->p_offset);
for (; DT_NULL!=byteswap32_to_host(dynp->d_tag); ++dynp) {
- if (key == byteswap32_to_host(dynp->d_tag)) {
+ if (key == (int)byteswap32_to_host(dynp->d_tag)) {
if (return_val == 1)
return (void *)(intptr_t)byteswap32_to_host(dynp->d_un.d_val);
else
@@ -255,8 +256,7 @@ static void search_for_named_library(char *name, char *result, const char *path_
*result = '\0';
}
-void locate_library_file(Elf32_Ehdr* ehdr, Elf32_Dyn* dynamic, char *strtab,
- int is_suid, struct library *lib)
+void locate_library_file(Elf32_Ehdr* ehdr, Elf32_Dyn* dynamic, int is_suid, struct library *lib)
{
char *buf;
char *path;
@@ -336,7 +336,7 @@ void locate_library_file(Elf32_Ehdr* ehdr, Elf32_Dyn* dynamic, char *strtab,
}
}
-static int add_library(Elf32_Ehdr* ehdr, Elf32_Dyn* dynamic, char *strtab, int is_setuid, char *s)
+static int add_library(Elf32_Ehdr* ehdr, Elf32_Dyn* dynamic, int is_setuid, char *s)
{
char *tmp, *tmp1, *tmp2;
struct library *cur, *newlib=lib_list;
@@ -384,7 +384,7 @@ static int add_library(Elf32_Ehdr* ehdr, Elf32_Dyn* dynamic, char *strtab, int i
newlib->next = NULL;
/* Now try and locate where this library might be living... */
- locate_library_file(ehdr, dynamic, strtab, is_setuid, newlib);
+ locate_library_file(ehdr, dynamic, is_setuid, newlib);
//printf("add_library is adding '%s' to '%s'\n", newlib->name, newlib->path);
if (!lib_list) {
@@ -403,21 +403,20 @@ static void find_needed_libraries(Elf32_Ehdr* ehdr, Elf32_Dyn* dynamic, char *st
for (dyns=dynamic; byteswap32_to_host(dyns->d_tag)!=DT_NULL; ++dyns) {
if (DT_NEEDED == byteswap32_to_host(dyns->d_tag)) {
- add_library(ehdr, dynamic, strtab, is_setuid, (char*)strtab +
- byteswap32_to_host(dyns->d_un.d_val));
+ add_library(ehdr, dynamic, is_setuid,
+ (char*)strtab + byteswap32_to_host(dyns->d_un.d_val));
}
}
}
-static struct library *
-find_elf_interpreter(Elf32_Ehdr* ehdr, Elf32_Dyn* dynamic, char *strtab, int is_setuid)
+static int interpreter_already_found=0;
+static struct library * find_elf_interpreter(Elf32_Ehdr* ehdr)
{
- static int been_there_done_that=0;
Elf32_Phdr *phdr;
- if (been_there_done_that==1)
+ if (interpreter_already_found==1)
return NULL;
- been_there_done_that=1;
+ interpreter_already_found=1;
phdr = elf_find_phdr_type(PT_INTERP, ehdr);
if (phdr) {
struct library *cur, *newlib=NULL;
@@ -501,7 +500,7 @@ int find_dependancies(char* filename)
return -1;
}
- if (statbuf.st_size < sizeof(Elf32_Ehdr))
+ if ((size_t)statbuf.st_size < sizeof(Elf32_Ehdr))
goto foo;
/* mmap the file to make reading stuff from it effortless */
@@ -529,8 +528,8 @@ foo:
fprintf(stderr, "%s: is setuid\n", filename);
}
- dynsec = elf_find_section_type(SHT_DYNAMIC, ehdr);
- interp = find_elf_interpreter(ehdr, dynamic, dynstr, is_suid);
+ interpreter_already_found=0;
+ interp = find_elf_interpreter(ehdr);
#ifdef __LDSO_LDD_SUPPORT
if (interp && ehdr->e_ident[EI_CLASS] == ELFCLASSM && ehdr->e_ident[EI_DATA] == ELFDATAM
@@ -567,6 +566,7 @@ foo:
}
#endif
+ dynsec = elf_find_section_type(SHT_DYNAMIC, ehdr);
if (dynsec) {
dynamic = (Elf32_Dyn*)(byteswap32_to_host(dynsec->sh_offset) + (intptr_t)ehdr);
dynstr = (char *)elf_find_dynamic(DT_STRTAB, dynamic, ehdr, 0);
diff --git a/ldso/util/readelf.c b/ldso/util/readelf.c
index bb8aa26fd..a703b5da2 100644
--- a/ldso/util/readelf.c
+++ b/ldso/util/readelf.c
@@ -56,7 +56,7 @@ Elf32_Shdr * elf_find_section_type( int key, Elf32_Ehdr *ehdr)
int j;
Elf32_Shdr *shdr = (Elf32_Shdr *)(ehdr->e_shoff + (char *)ehdr);
for (j = ehdr->e_shnum; --j>=0; ++shdr) {
- if (key==byteswap32_to_host(shdr->sh_type)) {
+ if (key==(int)byteswap32_to_host(shdr->sh_type)) {
return shdr;
}
}
@@ -68,7 +68,7 @@ Elf32_Phdr * elf_find_phdr_type( int type, Elf32_Ehdr *ehdr)
int j;
Elf32_Phdr *phdr = (Elf32_Phdr *)(ehdr->e_phoff + (char *)ehdr);
for (j = ehdr->e_phnum; --j>=0; ++phdr) {
- if (type==byteswap32_to_host(phdr->p_type)) {
+ if (type==(int)byteswap32_to_host(phdr->p_type)) {
return phdr;
}
}
@@ -82,7 +82,7 @@ void * elf_find_dynamic(int const key, Elf32_Dyn *dynp,
Elf32_Phdr *pt_text = elf_find_phdr_type(PT_LOAD, ehdr);
unsigned tx_reloc = byteswap32_to_host(pt_text->p_vaddr) - byteswap32_to_host(pt_text->p_offset);
for (; DT_NULL!=byteswap32_to_host(dynp->d_tag); ++dynp) {
- if (key == byteswap32_to_host(dynp->d_tag)) {
+ if (key == (int)byteswap32_to_host(dynp->d_tag)) {
if (return_val == 1)
return (void *)(intptr_t)byteswap32_to_host(dynp->d_un.d_val);
else
@@ -307,8 +307,9 @@ int main( int argc, char** argv)
Elf32_Shdr *dynsec;
Elf32_Dyn *dynamic;
+ fprintf (stderr," argc:%d argv:'%s' '%s'\n",argc, argv[0], argv[1]);
- if (!thefilename) {
+ if (argc < 2 || !thefilename) {
fprintf(stderr, "No filename specified.\n");
exit(EXIT_FAILURE);
}
@@ -321,7 +322,7 @@ int main( int argc, char** argv)
exit(EXIT_FAILURE);
}
- if (statbuf.st_size < sizeof(Elf32_Ehdr))
+ if ((size_t)statbuf.st_size < sizeof(Elf32_Ehdr))
goto foo;
/* mmap the file to make reading stuff from it effortless */