Browse Source

Patch from Stefan Allius and Edie C. Dost to let ldd and
readelf compile under solaris.

Eric Andersen 22 years ago
parent
commit
4c69b9f793
4 changed files with 74 additions and 10 deletions
  1. 4 1
      ldso/util/Makefile
  2. 56 0
      ldso/util/bswap.h
  3. 10 5
      ldso/util/ldd.c
  4. 4 4
      ldso/util/readelf.c

+ 4 - 1
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

+ 56 - 0
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

+ 10 - 5
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);
 	}

+ 4 - 4
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);
 	}