[uClibc-cvs] uClibc/ldso/include dl-string.h, 1.4, 1.5 dl-syscall.h, 1.5, 1.6

Erik Andersen,,, andersen at uclibc.org
Sat Jun 12 08:38:41 UTC 2004


Update of /var/cvs/uClibc/ldso/include
In directory nail:/tmp/cvs-serv3470/include

Modified Files:
	dl-string.h dl-syscall.h 
Log Message:
Jakub Bogusz from pld-linux dot org writes:

Hello,

I managed to get ldso (and thus shared linking to uClibc) to work on
sparc (actually sparc64 kernel with 32-bit userspace), at least on
simple "hello world" program (more complex ones not tested).

Some notes on attached patch (against 0.9.26, would require some work
to apply on current CVS - but I tested 0.9.26, not CVS):

- ELF magic cannot be examined by _dl_strncmp so early, probably because of
  string constant, like on ppc/mips/sh
  (note that early SEND_STDERR still crashes when trying to do _dl_strlen
   - I suppose that string constants require relocation; but adding
   load_addr didn't help, just ELF header was displayed instead of crash)
- mmap() is syscall6 like on ppc/mips/sh, not old i386 mmap()
- for generic sparc (i.e. not sparcv8/sparcv9) gcc produces .udiv/.urem
  calls for unsigned integer / and % operators - so these operations
  must be avoided. I copied do_rem definition from arm header.
  But / and % are used also in _dl_simple_ltoa() and
  _dl_simple_ltoahex(); in ltoahex gcc optimizes it to shifts (but
  I think it's safer to use shifts explicitly, not rely on
  optimization...).
  I changed % in ltoa to do_rem, but as there was no do_div definition,
  I changed all "%d" specifiers to "%x" to avoid crashes (this changes
  wouldn't be needed if _dl_simple_ltoa() were fixed to not use
  division on sparc).
- "#define SOLARIS_COMPATIBLE" in ld_sysdep.h broke ldso on Linux
  because of redefining _dl_linux_resolve only in some places (it was
  still referenced in INIT_GOT before redefinition). So
  _dl_linux_resolve redefinition should be moved before INIT_GOT
  definition or removed.
- sparc64 kernel requires mmap() addresses to be aligned to 8192, not
  4096, otherwise mmap() call failed
- reloc_entry must be shifted by 10, not 12 (I found similar operation
  in glibc sources)

Aside of sparc-specific fixes:
- I moved some _dl_dprintf()s inside if(_dl_debug_*) conditions (to avoid
  debugging messages when LD_DEBUG is not defined)
- it seems that there was possible off-by-one in ltoa and ltoahex?
  they are called with char[22] as 1st argument, and then '\0' is stored
  in local[22] (_before_ p decrementation)... or am I missing something?
  If not, fix is included in patch.



Index: dl-syscall.h
===================================================================
RCS file: /var/cvs/uClibc/ldso/include/dl-syscall.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- a/dl-syscall.h	19 Mar 2004 12:03:30 -0000	1.5
+++ b/dl-syscall.h	12 Jun 2004 08:38:38 -0000	1.6
@@ -104,7 +104,7 @@
 static inline _syscall3(int, _dl_readlink, const char *, path, char *, buf, size_t, bufsiz);
 
 #ifdef __NR_mmap
-#if defined(__powerpc__) || defined(__mips__) || defined(__sh__)
+#if defined(__powerpc__) || defined(__mips__) || defined(__sh__) || defined(__sparc__)
 /* PowerPC, MIPS and SuperH have a different calling convention for mmap(). */
 #define __NR__dl_mmap __NR_mmap
 static inline _syscall6(void *, _dl_mmap, void *, start, size_t, length,

Index: dl-string.h
===================================================================
RCS file: /var/cvs/uClibc/ldso/include/dl-string.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- a/dl-string.h	10 Feb 2004 09:26:46 -0000	1.4
+++ b/dl-string.h	12 Jun 2004 08:38:38 -0000	1.5
@@ -204,15 +204,18 @@
 }
 
 /* Early on, we can't call printf, so use this to print out
- * numbers using the SEND_STDERR() macro */
+ * numbers using the SEND_STDERR() macro.  Avoid using mod
+ * or using long division */
 static inline char *_dl_simple_ltoa(char * local, unsigned long i)
 {
 	/* 21 digits plus null terminator, good for 64-bit or smaller ints */
-	char *p = &local[22];
+	char *p = &local[21];
 	*p-- = '\0';
 	do {
-		*p-- = '0' + i % 10;
-		i /= 10;
+	    char temp;
+	    do_rem(temp, i, 10);
+	    *p-- = '0' + temp;
+	    i /= 10;
 	} while (i > 0);
 	return p + 1;
 }
@@ -220,15 +223,15 @@
 static inline char *_dl_simple_ltoahex(char * local, unsigned long i)
 {
 	/* 21 digits plus null terminator, good for 64-bit or smaller ints */
-	char *p = &local[22];
+	char *p = &local[21];
 	*p-- = '\0';
 	do {
-		char temp = i % 0x10;
+		char temp = i & 0xf;
 		if (temp <= 0x09)
 		    *p-- = '0' + temp;
 		else
 		    *p-- = 'a' - 0x0a + temp;
-		i /= 0x10;
+		i >>= 4;
 	} while (i > 0);
 	*p-- = 'x';
 	*p-- = '0';




More information about the uClibc-cvs mailing list