[PATCH] use 8 byte alignment in _dl_malloc

Atsushi Nemoto anemo at mba.ocn.ne.jp
Sat Feb 17 17:10:26 UTC 2007


On Sat, 17 Feb 2007 17:49:01 +0100, "Joakim Tjernlund" <joakim.tjernlund at transmode.se> wrote:
> > Thank you, third trial.  I hope everybody feel good with this.
> 
> Almost, the ifndef part should go into a header file, like dl-defs.h
> I think. Add an comment too for clarity.

Well, I thought is seems bit unlear that dl-sysdep.h is always
included before dl-defs.h, and it would not be better to bloat a
header file for symbol only used in single C file.

Anyway, take 4.

-------------- next part --------------
diff -urp uClibc-20070214/ldso/include/dl-defs.h uClibc/ldso/include/dl-defs.h
--- uClibc-20070214/ldso/include/dl-defs.h	2007-02-14 17:10:10.000000000 +0900
+++ uClibc/ldso/include/dl-defs.h	2007-02-18 02:06:54.825243313 +0900
@@ -164,4 +164,9 @@ typedef struct {
   ((*SIGNATURE DL_ADDR_TO_FUNC_PTR ((ADDR), (LOADADDR)))(__VA_ARGS__))
 #endif
 
+/* An alignment value for a memory block returned by _dl_malloc. */
+#ifndef DL_MALLOC_ALIGN
+# define DL_MALLOC_ALIGN (__WORDSIZE / 8)
+#endif
+
 #endif	/* _LD_DEFS_H */
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 02:02:42.914588832 +0900
@@ -950,10 +950,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