[uClibc-cvs] uClibc/ldso/util Makefile,1.31,1.32 ldd.c,1.29,1.30 readelf.c,1.7,1.8

Erik Andersen andersen at codepoet.org
Fri Mar 7 12:23:14 UTC 2003


Update of /var/cvs/uClibc/ldso/util
In directory winder:/tmp/cvs-serv11416

Modified Files:
	Makefile ldd.c readelf.c 
Log Message:
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


Index: Makefile
===================================================================
RCS file: /var/cvs/uClibc/ldso/util/Makefile,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- Makefile	1 Mar 2003 11:02:43 -0000	1.31
+++ Makefile	7 Mar 2003 12:23:11 -0000	1.32
@@ -45,7 +45,7 @@
 	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

Index: ldd.c
===================================================================
RCS file: /var/cvs/uClibc/ldso/util/ldd.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- ldd.c	6 Mar 2003 22:00:12 -0000	1.29
+++ ldd.c	7 Mar 2003 12:23:11 -0000	1.30
@@ -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 *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 @@
 	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 @@
 	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 @@
 	*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 @@
 	}
 }
 
-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 @@
 	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 @@
 
 	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 @@
 		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 @@
 			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 @@
 	}
 #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);

Index: readelf.c
===================================================================
RCS file: /var/cvs/uClibc/ldso/util/readelf.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- readelf.c	8 Aug 2002 14:28:47 -0000	1.7
+++ readelf.c	7 Mar 2003 12:23:11 -0000	1.8
@@ -56,7 +56,7 @@
 	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 @@
 	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 @@
 	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 @@
 	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 @@
 		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 */




More information about the uClibc-cvs mailing list