fix hipe_bifs_alloc_data_2 to avoid "Yikes!" warning

Mikael Pettersson mikpe@REDACTED
Wed Aug 11 19:31:43 CEST 2010


It's been reported that HiPE-enabled Erlang VMs running on BSD
systems sometimes generate messages like

Yikes! erts_alloc() returned misaligned address 0x8016a512c

These originate from hipe_bif0.c:hipe_bifs_alloc_data_2().

A native code module has an associated data area of some
size and alignment.  In the case where the size is zero,
the alignment is irrelevant, but the allocation BIF checks
it anyway.  The warning then triggers on systems where
malloc(0) returns blocks with less alignment than we
(erroneously) expected.

The fix is to simply skip the allocation in this case and
return NULL.  The loader won't actually use the address in
this case so that's safe.  This is also an optimization since
it avoids allocating memory that cannot be used, and it avoids
fragmenting the system heap with useless tiny blocks.

A second problem is that the warning message failed to
identify its origin.  Fixed by prefixing the message by
the BIF's name rather than the silly Yikes! string.

Tested and confirmed to solve the original reporter's problem.

/Mikael

--- otp_src_R14A/erts/emulator/hipe/hipe_bif0.c.~1~	2010-02-19 19:04:06.000000000 +0100
+++ otp_src_R14A/erts/emulator/hipe/hipe_bif0.c	2010-08-05 09:57:48.000000000 +0200
@@ -440,9 +440,12 @@ BIF_RETTYPE hipe_bifs_alloc_data_2(BIF_A
 	 align != sizeof(long) && align != sizeof(double)))
 	BIF_ERROR(BIF_P, BADARG);
     nrbytes = unsigned_val(BIF_ARG_2);
+    if (nrbytes == 0)
+	BIF_RET(make_small(0));
     block = erts_alloc(ERTS_ALC_T_HIPE, nrbytes);
     if ((unsigned long)block & (align-1))
-	fprintf(stderr, "Yikes! erts_alloc() returned misaligned address %p\r\n", block);
+	fprintf(stderr, "%s: erts_alloc(%lu) returned %p which is not %lu-byte aligned\r\n",
+		__FUNCTION__, (unsigned long)nrbytes, block, (unsigned long)align);
     BIF_RET(address_to_term(block, BIF_P));
 }
 


More information about the erlang-patches mailing list