From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp37.i.mail.ru (smtp37.i.mail.ru [94.100.177.97]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 2328C469711 for ; Thu, 28 May 2020 02:32:38 +0300 (MSK) From: Vladislav Shpilevoy Date: Thu, 28 May 2020 01:32:24 +0200 Message-Id: <365b6e4fc1a9619044187c5c8476874829dc60eb.1590622225.git.v.shpilevoy@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH v2 05/10] sql: make BtCursor's memory aligned List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org, alyapunov@tarantool.org, korablev@tarantool.org, tsafin@tarantool.org Vdbe at runtime allocates VdbeCursor structure using allocateCursor() function. Inside there is a pointer at BtCursor structure. To make the allocation faster and improve cache locality, both cursors are allocated in one memory block + some extra memory for uint32_t array, where BtCursor followed VdbeCursor and the array without any padding: VdbeCursor + uint32_t * N + BtCursor The problem is that BtCursor needs 8 byte alignment. When it followed VdbeCursor (aligned by 8) + some uint32_t values, its actual alignment could become 4 bytes. That led to a crash when alignment sanitizer is enabled in clang. The patch makes BtCursor offset aligned by 8 bytes. Part of #4609 --- src/box/sql/vdbe.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c index 724bc188b..7a42602a2 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -234,10 +234,9 @@ allocateCursor( */ Mem *pMem = iCur>0 ? &p->aMem[p->nMem-iCur] : p->aMem; - int nByte; VdbeCursor *pCx = 0; - nByte = - ROUND8(sizeof(VdbeCursor)) + sizeof(u32)*nField + + int bt_offset = ROUND8(sizeof(VdbeCursor) + sizeof(uint32_t) * nField); + int nByte = bt_offset + (eCurType==CURTYPE_TARANTOOL ? ROUND8(sizeof(BtCursor)) : 0); assert(iCur>=0 && iCurnCursor); @@ -251,8 +250,7 @@ allocateCursor( pCx->eCurType = eCurType; pCx->nField = nField; if (eCurType==CURTYPE_TARANTOOL) { - pCx->uc.pCursor = (BtCursor*) - &pMem->z[ROUND8(sizeof(VdbeCursor))+sizeof(u32)*nField]; + pCx->uc.pCursor = (BtCursor*)&pMem->z[bt_offset]; sqlCursorZero(pCx->uc.pCursor); } } -- 2.21.1 (Apple Git-122.3)