rename __simple_malloc.c to lite_malloc.c - yes this affects behavior!
authorRich Felker <dalias@aerifal.cx>
Wed, 30 Mar 2011 13:29:49 +0000 (09:29 -0400)
committerRich Felker <dalias@aerifal.cx>
Wed, 30 Mar 2011 13:29:49 +0000 (09:29 -0400)
why does this affect behavior? well, the linker seems to traverse
archive files starting from its current position when resolving
symbols. since calloc.c comes alphabetically (and thus in sequence in
the archive file) between __simple_malloc.c and malloc.c, attempts to
resolve the "malloc" symbol for use by calloc.c were pulling in the
full malloc.c implementation rather than the __simple_malloc.c
implementation.

as of now, lite_malloc.c and malloc.c are adjacent in the archive and
in the correct order, so malloc.c should never be used to resolve
"malloc" unless it's already needed to resolve another symbol ("free"
or "realloc").

src/malloc/__simple_malloc.c [deleted file]
src/malloc/lite_malloc.c [new file with mode: 0644]

diff --git a/src/malloc/__simple_malloc.c b/src/malloc/__simple_malloc.c
deleted file mode 100644 (file)
index c829390..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-#include <stdlib.h>
-#include <stdint.h>
-#include <limits.h>
-#include <errno.h>
-#include "libc.h"
-
-uintptr_t __brk(uintptr_t);
-
-#define ALIGN 16
-
-void *__simple_malloc(size_t n)
-{
-       static uintptr_t cur, brk;
-       uintptr_t base, new;
-       static int lock;
-       size_t align=1;
-
-       if (!n) n++;
-       if (n > SIZE_MAX/2) goto toobig;
-
-       while (align<n && align<ALIGN)
-               align += align;
-       n = n + align - 1 & -align;
-
-       LOCK(&lock);
-       if (!cur) cur = brk = __brk(0)+16;
-       base = cur + align-1 & -align;
-       if (n > SIZE_MAX - PAGE_SIZE - base) goto fail;
-       if (base+n > brk) {
-               new = base+n + PAGE_SIZE-1 & -PAGE_SIZE;
-               if (__brk(new) != new) goto fail;
-               brk = new;
-       }
-       cur = base+n;
-       UNLOCK(&lock);
-
-       return (void *)base;
-
-fail:
-       UNLOCK(&lock);
-toobig:
-       errno = ENOMEM;
-       return 0;
-}
-
-weak_alias(__simple_malloc, malloc);
diff --git a/src/malloc/lite_malloc.c b/src/malloc/lite_malloc.c
new file mode 100644 (file)
index 0000000..c829390
--- /dev/null
@@ -0,0 +1,46 @@
+#include <stdlib.h>
+#include <stdint.h>
+#include <limits.h>
+#include <errno.h>
+#include "libc.h"
+
+uintptr_t __brk(uintptr_t);
+
+#define ALIGN 16
+
+void *__simple_malloc(size_t n)
+{
+       static uintptr_t cur, brk;
+       uintptr_t base, new;
+       static int lock;
+       size_t align=1;
+
+       if (!n) n++;
+       if (n > SIZE_MAX/2) goto toobig;
+
+       while (align<n && align<ALIGN)
+               align += align;
+       n = n + align - 1 & -align;
+
+       LOCK(&lock);
+       if (!cur) cur = brk = __brk(0)+16;
+       base = cur + align-1 & -align;
+       if (n > SIZE_MAX - PAGE_SIZE - base) goto fail;
+       if (base+n > brk) {
+               new = base+n + PAGE_SIZE-1 & -PAGE_SIZE;
+               if (__brk(new) != new) goto fail;
+               brk = new;
+       }
+       cur = base+n;
+       UNLOCK(&lock);
+
+       return (void *)base;
+
+fail:
+       UNLOCK(&lock);
+toobig:
+       errno = ENOMEM;
+       return 0;
+}
+
+weak_alias(__simple_malloc, malloc);