From 6b8733b2b7e240bbda505b10e6e443f9278451b8 Mon Sep 17 00:00:00 2001 From: Mikael Pettersson Date: Wed, 11 Aug 2010 19:31:43 +0200 Subject: fix hipe_bifs_alloc_data_2 to avoid "Yikes!" warning 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. --- erts/emulator/hipe/hipe_bif0.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'erts') diff --git a/erts/emulator/hipe/hipe_bif0.c b/erts/emulator/hipe/hipe_bif0.c index b0abfd2310..2a877d8ace 100644 --- a/erts/emulator/hipe/hipe_bif0.c +++ b/erts/emulator/hipe/hipe_bif0.c @@ -440,9 +440,12 @@ BIF_RETTYPE hipe_bifs_alloc_data_2(BIF_ALIST_2) 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)); } -- cgit v1.2.3