[PATCH] use 8 byte alignment in _dl_malloc

Atsushi Nemoto anemo at mba.ocn.ne.jp
Sat Feb 17 08:37:35 PST 2007


On Sat, 17 Feb 2007 17:10:27 +0100, "Joakim Tjernlund" <joakim.tjernlund at transmode.se> wrote:
> Add this in a common header
> #ifndef DL_MALLOC_ALIGN
>  #define DL_MALLOC_ALIGN 4
> #endif
> Then change
> _dl_malloc_addr = (unsigned char *) (((unsigned long) _dl_malloc_addr + DL_MALLOC_ALIGN - 1) & ~(DL_MALLOC_ALIGN - 1));
> Now you can change DL_MALLOC_ALIGN in your arch headers
> 
> or like your first patch.

Thank you, third trial.  I hope everybody feel good with this.

Every patch is OK for me :)

-------------- next part --------------
diff -urp uClibc-20070214/ldso/ldso/ldso.c uClibc/ldso/ldso/ldso.c
--- uClibc-20070214/ldso/ldso/ldso.c	2007-02-14 17:10:10.000000000 +0900
+++ uClibc/ldso/ldso/ldso.c	2007-02-18 01:27:11.782218143 +0900
@@ -926,6 +926,10 @@ static int _dl_suid_ok(void)
 	return 0;
 }
 
+#ifndef DL_MALLOC_ALIGN
+# define DL_MALLOC_ALIGN (__WORDSIZE / 8)
+#endif
+
 void *_dl_malloc(int size)
 {
 	void *retval;
@@ -950,10 +954,11 @@ void *_dl_malloc(int size)
 	_dl_malloc_addr += size;
 
 	/*
-	 * Align memory to 4 byte boundary.  Some platforms require this,
-	 * others simply get better performance.
+	 * Align memory to DL_MALLOC_ALIGN byte boundary.  Some
+	 * platforms require this, others simply get better
+	 * performance.
 	 */
-	_dl_malloc_addr = (unsigned char *) (((unsigned long) _dl_malloc_addr + 3) & ~(3));
+	_dl_malloc_addr = (unsigned char *) (((unsigned long) _dl_malloc_addr + DL_MALLOC_ALIGN - 1) & ~(DL_MALLOC_ALIGN - 1));
 	return retval;
 }
 
diff -urp uClibc-20070214/ldso/ldso/mips/dl-sysdep.h uClibc/ldso/ldso/mips/dl-sysdep.h
--- uClibc-20070214/ldso/ldso/mips/dl-sysdep.h	2007-02-14 17:10:10.000000000 +0900
+++ uClibc/ldso/ldso/mips/dl-sysdep.h	2007-02-18 01:29:54.131553840 +0900
@@ -214,3 +214,7 @@ elf_machine_relative (ElfW(Addr) load_of
 {
 	/* No RELATIVE relocs in MIPS? */
 }
+
+#ifdef __mips64
+#define DL_MALLOC_ALIGN 8	/* N64/N32 needs 8 byte alignment */
+#endif


More information about the uClibc mailing list