summaryrefslogtreecommitdiffstats
path: root/configure
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-09-12 20:38:43 -0700
committerKaz Kylheku <kaz@kylheku.com>2019-09-12 20:38:43 -0700
commit350cd2e935aafb949892384db1451accf2d398c1 (patch)
tree8b2b97064c74d808e4a6ac0a2f6db6f46fba3892 /configure
parent71d01ae185d95888e3908cce5dba99890e970931 (diff)
downloadtxr-350cd2e935aafb949892384db1451accf2d398c1.tar.gz
txr-350cd2e935aafb949892384db1451accf2d398c1.tar.bz2
txr-350cd2e935aafb949892384db1451accf2d398c1.zip
gc: align objects more strictly.
In this commit, we ensure that objects in the heap are aligned to at east eight byte boundaries (the minimum alignment from most malloc implementations on 32 and 64 bit systems). If possible, we align objects to a multiple of their size, sizeof (obj_t), which is 16 bytes on 32 bit platforms and 32 bytes on 64 bit platforms. We do this by making the object array the first field of the heap structure, and by allocating it with an aligned allocator function, if possible. * configure: detect memory alignment function: either memalign (preferred) or else posix_memalign (ugly duckling). We conditionally add either HAVE_MEMALIGN or HAVE_POSIX_MEMALIGN into config.h. * gc.c (OBJ_ALIGN): New macro. (struct heap, heap_t): Put the block member first, so objects are aligned with the containing heap. (in_heap): If the pointer is not aligned to a multiple of OBJ_ALIGN, it can't be a heap object; return zero. If allocations of the heap are aligned, then we don't need the additional alignment check in the loop body; if the pointer lands in the array, then the earlier OBJ_ALIGN check assures us it must be aligned. If we have only malloc alignment, we must do the check; the pointer could be to an address divisible by 8 which is in the middle of an obj_t. * lib.c: If HAVE_MEMALIGN is true, then include <malloc.h> so we have it declared. (memalign): If HAVE_POSIX_MEMALIGN is true, this static function is defined; it's compatible with the Glibc memalign. If HAVE_MEMALIGN and HAVE_POSIX_MEMALIGN are false, then memalign is defined as a malloc wrapper which doesn't align. (chk_malloc_gc_more): Use memalign instead of malloc. If aligned allocation is available, this will cause the heap to be aligned to a multiple of the object size.
Diffstat (limited to 'configure')
-rwxr-xr-xconfigure38
1 files changed, 38 insertions, 0 deletions
diff --git a/configure b/configure
index ef489af5..34be9b59 100755
--- a/configure
+++ b/configure
@@ -2675,6 +2675,44 @@ if [ -z "$have_alloca" ] ; then
exit 1
fi
+printf "Checking for malloc-with-alignment function ... "
+
+while true ; do
+ cat > conftest.c <<!
+#include <malloc.h>
+
+int main(void)
+{
+ void *bytes = memalign(16, 42);
+ return 0;
+}
+!
+
+ if ! conftest ; then
+ printf "memalign\n"
+ printf "#define HAVE_MEMALIGN 1\n" $try_header >> config.h
+ break;
+ fi
+
+ cat > conftest.c <<!
+#include <stdlib.h>
+
+int main(void)
+{
+ void *bytes;
+ int res = posix_memalign(&bytes, 16, 42);
+ return 0;
+}
+!
+ if conftest ; then
+ printf "posix_memalign\n"
+ printf "#define HAVE_POSIX_MEMALIGN 1\n" $try_header >> config.h
+ break;
+ fi
+
+ printf "none\n"
+done
+
printf "Checking for termios ... "
cat > conftest.c <<!