diff options
-rw-r--r-- | ldso/util/Makefile | 5 | ||||
-rw-r--r-- | ldso/util/bswap.h | 56 | ||||
-rw-r--r-- | ldso/util/ldd.c | 15 | ||||
-rw-r--r-- | ldso/util/readelf.c | 8 |
4 files changed, 74 insertions, 10 deletions
diff --git a/ldso/util/Makefile b/ldso/util/Makefile index 3e9393aac..dcd91dbaf 100644 --- a/ldso/util/Makefile +++ b/ldso/util/Makefile @@ -24,7 +24,10 @@ TOPDIR=../../ include $(TOPDIR)Rules.mak TARGET_CC = $(TOPDIR)extra/gcc-uClibc/$(TARGET_ARCH)-uclibc-gcc -TARGETS = elf_header ldd readelf +TARGETS = elf_header ldd +ifeq ($(OSTYPE),linux) +TARGETS += readelf +endif ifneq ($(strip $(LIBRARY_CACHE)),) TARGETS += ldconfig endif diff --git a/ldso/util/bswap.h b/ldso/util/bswap.h new file mode 100644 index 000000000..71867885e --- /dev/null +++ b/ldso/util/bswap.h @@ -0,0 +1,56 @@ +#ifndef _BSWAP_H +#define _BSWAP_H 1 + +#if !defined(__BYTE_ORDER) && defined(BYTE_ORDER) +# define __BYTE_ORDER = BYTE_ORDER +#endif + +#ifndef __BYTE_ORDER +#ifdef linux +#include <endian.h> +#else +#define __LITTLE_ENDIAN 1234 /* least-significant byte first (vax, pc) */ +#define __BIG_ENDIAN 4321 /* most-significant byte first (IBM, net) */ +#define __PDP_ENDIAN 3412 /* LSB first in word, MSW first in long (pdp) */ + +#if defined(sun386) || defined(i386) +#define __BYTE_ORDER __LITTLE_ENDIAN +#endif + +#if defined(sparc) +#define __BYTE_ORDER __BIG_ENDIAN +#endif + +#endif /* linux */ +#endif /* __BYTE_ORDER */ + + +#ifndef __BYTE_ORDER +# error "Undefined __BYTE_ORDER" +#endif + +#ifdef linux +#include <byteswap.h> +#else +#include <string.h> +static __inline__ uint32_t bswap_32(uint32_t x) + { + uint32_t res; + + swab((void*)&x, (void*)&res, sizeof(uint32_t)); + printf ("bswap_32: %x > %x\n",x,res); + + return res; + } + +static __inline__ uint16_t bswap_16(uint16_t x) + { + uint16_t res; + + swab((void*)&x, (void*)&res, sizeof(uint16_t)); + printf ("bswap_32: %x > %x\n",x,res); + return res; + } +#endif + +#endif diff --git a/ldso/util/ldd.c b/ldso/util/ldd.c index 6b9326b53..29c520c60 100644 --- a/ldso/util/ldd.c +++ b/ldso/util/ldd.c @@ -29,7 +29,6 @@ #define _GNU_SOURCE -#include <features.h> #include <stdlib.h> #include <stdio.h> #include <fcntl.h> @@ -38,9 +37,14 @@ #include <sys/mman.h> #include <sys/stat.h> #include <sys/types.h> -#include <endian.h> -#include <byteswap.h> + +#include "bswap.h" +#if defined (sun) +#include "link.h" +#else #include "elf.h" +#endif + #ifdef DMALLOC #include <dmalloc.h> #endif @@ -102,7 +106,7 @@ void * elf_find_dynamic(int const key, Elf32_Dyn *dynp, for (; DT_NULL!=byteswap32_to_host(dynp->d_tag); ++dynp) { if (key == byteswap32_to_host(dynp->d_tag)) { if (return_val == 1) - return (void *)byteswap32_to_host(dynp->d_un.d_val); + return (void *)(intptr_t)byteswap32_to_host(dynp->d_un.d_val); else return (void *)(byteswap32_to_host(dynp->d_un.d_val) - tx_reloc + (char *)ehdr ); } @@ -133,6 +137,7 @@ int check_elf_header(Elf32_Ehdr *const ehdr) #else #error Unknown host byte order! #endif + /* Be vary lazy, and only byteswap the stuff we use */ if (byteswap==1) { ehdr->e_type=bswap_16(ehdr->e_type); @@ -457,7 +462,7 @@ foo: dynsec = elf_find_section_type(SHT_DYNAMIC, ehdr); find_elf_interpreter(ehdr, dynamic, dynstr, is_suid); if (dynsec) { - dynamic = (Elf32_Dyn*)(byteswap32_to_host(dynsec->sh_offset) + (int)ehdr); + dynamic = (Elf32_Dyn*)(byteswap32_to_host(dynsec->sh_offset) + (intptr_t)ehdr); dynstr = (char *)elf_find_dynamic(DT_STRTAB, dynamic, ehdr, 0); find_needed_libraries(ehdr, dynamic, dynstr, is_suid); } diff --git a/ldso/util/readelf.c b/ldso/util/readelf.c index 98df3ffda..bb8aa26fd 100644 --- a/ldso/util/readelf.c +++ b/ldso/util/readelf.c @@ -36,8 +36,8 @@ #include <sys/mman.h> #include <sys/stat.h> #include <sys/types.h> -#include <endian.h> -#include <byteswap.h> + +#include "bswap.h" #include "elf.h" @@ -84,7 +84,7 @@ void * elf_find_dynamic(int const key, Elf32_Dyn *dynp, for (; DT_NULL!=byteswap32_to_host(dynp->d_tag); ++dynp) { if (key == byteswap32_to_host(dynp->d_tag)) { if (return_val == 1) - return (void *)byteswap32_to_host(dynp->d_un.d_val); + return (void *)(intptr_t)byteswap32_to_host(dynp->d_un.d_val); else return (void *)(byteswap32_to_host(dynp->d_un.d_val) - tx_reloc + (char *)ehdr ); } @@ -339,7 +339,7 @@ foo: dynsec = elf_find_section_type(SHT_DYNAMIC, ehdr); if (dynsec) { - dynamic = (Elf32_Dyn*)(byteswap32_to_host(dynsec->sh_offset) + (int)ehdr); + dynamic = (Elf32_Dyn*)(byteswap32_to_host(dynsec->sh_offset) + (intptr_t)ehdr); dynstr = (char *)elf_find_dynamic(DT_STRTAB, dynamic, ehdr, 0); list_needed_libraries(dynamic, dynstr); } |