From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id A34D21C5A43; Thu, 24 Nov 2022 16:13:53 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A34D21C5A43 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1669295633; bh=KYb+oWrsQ+mBcdQc+2kWn2nXNQAQu3GkeX2w6d+5ly0=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=YxoSVhk9PSsfAVvIel+zwDn4pMjOgMYYb5mm8eC4dkx17GIv+7BQrEVWU1ngA8X7Y XiZ1tU7BTZ0giWm2WrhLLB8pm+RvAdDry5UdlPfdSR97BDtmRW09v3JPVE9uD+UCAn rDJf1QLUk04uUqPIccwvYnnmLddFFYmfxwaCiaZ0= Received: from smtp52.i.mail.ru (smtp52.i.mail.ru [94.100.177.112]) (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 B38FB7B11C for ; Thu, 24 Nov 2022 16:13:52 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org B38FB7B11C Received: by smtp52.i.mail.ru with esmtpa (envelope-from ) id 1oyC35-0002KA-LX; Thu, 24 Nov 2022 16:13:52 +0300 Date: Thu, 24 Nov 2022 16:10:42 +0300 To: Maksim Kokryashkin Message-ID: References: <20221028092638.11506-1-max.kokryashkin@gmail.com> <20221028092638.11506-9-max.kokryashkin@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221028092638.11506-9-max.kokryashkin@gmail.com> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9D4445358DD2C13E245ACF5921543DE6350F15BCE242B1851182A05F5380850407C27FE9DA412E76052AB08BA9BB6C7BDF099469A83001CEE72B8F792585EBEC5 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE72791110C931D1596EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637EFACF7FB96444C4B8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8C34BF7C55D6F8A458FDB56D1647623FB117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC8C7ADC89C2F0B2A5A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735200AC5B80A05675ACDF04B652EEC242312D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE042285CD7A5C321F2AE38A8E97BAFFB1D8FC6C240DEA7642DBF02ECDB25306B2B78CF848AE20165D0A6AB1C7CE11FEE34B6F6234D9065C97BA3038C0950A5D36B5C8C57E37DE458B330BD67F2E7D9AF16D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE7BEE702378D8A34C7731C566533BA786AA5CC5B56E945C8DA X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3419891600CCEF4607F328A24E7F4BCB1CA037CEB21BE104DF2063E071A1CDCDCC495C2965BFE99A501D7E09C32AA3244C94CD81417C8A24AFAA27D44656E3873D30452B15D76AEC14927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojZo+qSBrEvGRawae/tt9Slg== X-Mailru-Sender: F6248FDC0389C51188CF133EE5DC084F5EE64858BAEFEE5AC2E14019D0D7A83BB7CBEF92542CD7C88B0A2698F12F5C9EC77752E0C033A69E86920BD37369036789A8C6A0E60D2BB63A5DB60FBEB33A8A0DA7A0AF5A3A8387 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit v4 8/8] OSX/ARM64: Fix external unwinding. X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sergey Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Maksim! Thanks for the patch! LGTM, but I have a bunch of questions to clarify it. On 28.10.22, Maksim Kokryashkin wrote: > Contributed by Edmund Kapusniak. For more info, > see #698 and #757. > > (cherry picked from commit c38747b626b978555324504ec29a110f6b04902f) > > To allow compiler generate compact unwind info generation > for Mach-O, fp must point to the saved fp, and the frame > must be specified relative to fp+16. Is there any link to documentation or source code to inspect this behaviour? > ELF unwind info has > been updated to also use fp+16 rather than sp+CFRAME_SIZE. Also, I see that `.byte` notation is replaced with `.uleb128` or `.sleb128`. What is the reason? Same question for removing names of entries ("_lj_vm_ffi_call.eh:" for example). > > Offset to pointer to personality routine specified as @GOT-. rather > than @GOTPCREL. Does it mean that we use incorrect encoded offset (I see encoding for offset is still the same) for our personality routine? If so, maybe the other changes are just refactoring? > > Re-enabled LUAJIT_UNWIND_EXTERNAL by default on OSX. > > Maxim Kokryashkin: > * added the description for the issue and the test > > Resolves tarantool/tarantool#6096 > Part of tarantool/tarantool#7230 > --- > cmake/SetTargetFlags.cmake | 4 +- > src/Makefile.original | 5 +- > src/vm_arm64.dasc | 89 ++++++++----------- > ...-6096-external-unwinding-on-arm64.test.lua | 13 +++ > 4 files changed, 54 insertions(+), 57 deletions(-) > create mode 100644 test/tarantool-tests/gh-6096-external-unwinding-on-arm64.test.lua > > diff --git a/cmake/SetTargetFlags.cmake b/cmake/SetTargetFlags.cmake > index 8abb6288..7cf26be1 100644 > --- a/cmake/SetTargetFlags.cmake > +++ b/cmake/SetTargetFlags.cmake > diff --git a/src/Makefile.original b/src/Makefile.original > index 2d014e43..813d9c12 100644 > --- a/src/Makefile.original > +++ b/src/Makefile.original > diff --git a/src/vm_arm64.dasc b/src/vm_arm64.dasc > index ccfa72bd..f517a808 100644 > --- a/src/vm_arm64.dasc > +++ b/src/vm_arm64.dasc > @@ -504,8 +503,9 @@ static void build_subroutines(BuildCtx *ctx) > | ldr GL, L->glref // Setup pointer to global state. > | mov BASE, CARG2 > | str CARG1, SAVE_PC // Any value outside of bytecode is ok. > - | str RC, SAVE_CFRAME > - | str fp, L->cframe // Add our C frame to cframe chain. > + | add TMP0, sp, #0 > + | str RC, SAVE_CFRAME > + | str TMP0, L->cframe // Add our C frame to cframe chain. Why can't we just use the following? | str RC, SAVE_CFRAME | str sp, L->cframe // Add our C frame to cframe chain. > | > |3: // Entry point for vm_cpcall/vm_resume (BASE = base, PC = ftype). > | str L, GL->cur_L > @@ -540,8 +540,9 @@ static void build_subroutines(BuildCtx *ctx) > | sub RA, RA, RB // Compute -savestack(L, L->top). > | str RAw, SAVE_NRES // Neg. delta means cframe w/o frame. > | str wzr, SAVE_ERRF // No error function. > - | str RC, SAVE_CFRAME > - | str fp, L->cframe // Add our C frame to cframe chain. > + | add TMP0, sp, #0 > + | str RC, SAVE_CFRAME > + | str TMP0, L->cframe // Add our C frame to cframe chain. Ditto. > | str L, GL->cur_L > | blr CARG4 // (lua_State *L, lua_CFunction func, void *ud) > | mov BASE, CRET1 > @@ -2129,14 +2130,14 @@ static void build_subroutines(BuildCtx *ctx) > @@ -3879,7 +3880,7 @@ static void emit_asm_debug(BuildCtx *ctx) > "\t.uleb128 0x1\n" > "\t.sleb128 -8\n" > "\t.byte 30\n" /* Return address is in lr. */ > - "\t.byte 0xc\n\t.uleb128 31\n\t.uleb128 0\n" /* def_cfa sp */ > + "\t.byte 0xc\n\t.uleb128 29\n\t.uleb128 16\n" /* def_cfa fp 16 */ > "\t.align 3\n" > ".LECIE0:\n\n"); > fprintf(ctx->fp, > @@ -3889,10 +3890,9 @@ static void emit_asm_debug(BuildCtx *ctx) > "\t.long .Lframe0\n" > "\t.quad .Lbegin\n" > "\t.quad %d\n" > - "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */ > "\t.byte 0x9e\n\t.uleb128 1\n" /* offset lr */ > "\t.byte 0x9d\n\t.uleb128 2\n", /* offset fp */ > - fcofs, CFRAME_SIZE); > + fcofs); > for (i = 19; i <= 28; i++) /* offset x19-x28 */ > fprintf(ctx->fp, "\t.byte 0x%x\n\t.uleb128 %d\n", 0x80+i, i+(3-19)); > for (i = 8; i <= 15; i++) /* offset d8-d15 */ > @@ -3909,12 +3909,10 @@ static void emit_asm_debug(BuildCtx *ctx) > "\t.long .Lframe0\n" > "\t.quad lj_vm_ffi_call\n" > "\t.quad %d\n" > - "\t.byte 0xe\n\t.uleb128 32\n" /* def_cfa_offset */ > "\t.byte 0x9e\n\t.uleb128 1\n" /* offset lr */ > "\t.byte 0x9d\n\t.uleb128 2\n" /* offset fp */ > "\t.byte 0x93\n\t.uleb128 3\n" /* offset x19 */ > "\t.byte 0x94\n\t.uleb128 4\n" /* offset x20 */ > - "\t.byte 0xd\n\t.uleb128 0x1d\n" /* def_cfa_register fp */ > "\t.align 3\n" > ".LEFDE1:\n\n", (int)ctx->codesz - fcofs); > #endif > @@ -3933,7 +3931,7 @@ static void emit_asm_debug(BuildCtx *ctx) > "\t.byte 0x1b\n" /* pcrel|sdata4 */ > "\t.long lj_err_unwind_dwarf-.\n" > "\t.byte 0x1b\n" /* pcrel|sdata4 */ > - "\t.byte 0xc\n\t.uleb128 31\n\t.uleb128 0\n" /* def_cfa sp */ > + "\t.byte 0xc\n\t.uleb128 29\n\t.uleb128 16\n" /* def_cfa fp 16 */ > "\t.align 3\n" > ".LECIE1:\n\n"); > fprintf(ctx->fp, > @@ -3944,10 +3942,9 @@ static void emit_asm_debug(BuildCtx *ctx) > "\t.long .Lbegin-.\n" > "\t.long %d\n" > "\t.uleb128 0\n" /* augmentation length */ > - "\t.byte 0xe\n\t.uleb128 %d\n" /* def_cfa_offset */ > "\t.byte 0x9e\n\t.uleb128 1\n" /* offset lr */ > "\t.byte 0x9d\n\t.uleb128 2\n", /* offset fp */ > - fcofs, CFRAME_SIZE); > + fcofs); > for (i = 19; i <= 28; i++) /* offset x19-x28 */ > fprintf(ctx->fp, "\t.byte 0x%x\n\t.uleb128 %d\n", 0x80+i, i+(3-19)); > for (i = 8; i <= 15; i++) /* offset d8-d15 */ > @@ -3969,7 +3966,7 @@ static void emit_asm_debug(BuildCtx *ctx) > "\t.byte 30\n" /* Return address is in lr. */ > "\t.uleb128 1\n" /* augmentation length */ > "\t.byte 0x1b\n" /* pcrel|sdata4 */ > - "\t.byte 0xc\n\t.uleb128 31\n\t.uleb128 0\n" /* def_cfa sp */ > + "\t.byte 0xc\n\t.uleb128 29\n\t.uleb128 16\n" /* def_cfa fp 16 */ > "\t.align 3\n" > ".LECIE2:\n\n"); > fprintf(ctx->fp, > @@ -3980,18 +3977,15 @@ static void emit_asm_debug(BuildCtx *ctx) > "\t.long lj_vm_ffi_call-.\n" > "\t.long %d\n" > "\t.uleb128 0\n" /* augmentation length */ > - "\t.byte 0xe\n\t.uleb128 32\n" /* def_cfa_offset */ > "\t.byte 0x9e\n\t.uleb128 1\n" /* offset lr */ > "\t.byte 0x9d\n\t.uleb128 2\n" /* offset fp */ > "\t.byte 0x93\n\t.uleb128 3\n" /* offset x19 */ > "\t.byte 0x94\n\t.uleb128 4\n" /* offset x20 */ > - "\t.byte 0xd\n\t.uleb128 0x1d\n" /* def_cfa_register fp */ > "\t.align 3\n" > ".LEFDE3:\n\n", (int)ctx->codesz - fcofs); > #endif > break; > - /* Disabled until someone finds a fix. See #698. */ > -#if !LJ_NO_UNWIND && 0 > +#if !LJ_NO_UNWIND > case BUILD_machasm: { > #if LJ_HASFFI > int fcsize = 0; > @@ -4006,14 +4000,14 @@ static void emit_asm_debug(BuildCtx *ctx) > "\t.long 0\n" > "\t.byte 0x1\n" > "\t.ascii \"zPR\\0\"\n" > - "\t.byte 0x1\n" > - "\t.byte 128-8\n" > + "\t.uleb128 0x1\n" > + "\t.sleb128 -8\n" > "\t.byte 30\n" /* Return address is in lr. */ > - "\t.byte 6\n" /* augmentation length */ > + "\t.uleb128 6\n" /* augmentation length */ > "\t.byte 0x9b\n" /* indirect|pcrel|sdata4 */ > - "\t.long _lj_err_unwind_dwarf@GOTPCREL\n" > + "\t.long _lj_err_unwind_dwarf@GOT-.\n" > "\t.byte 0x1b\n" /* pcrel|sdata4 */ > - "\t.byte 0xc\n\t.byte 31\n\t.byte 0\n" /* def_cfa sp */ > + "\t.byte 0xc\n\t.uleb128 29\n\t.uleb128 16\n" /* def_cfa fp 16 */ > "\t.align 3\n" > "LECIEX:\n\n"); > for (j = 0; j < ctx->nsym; j++) { > @@ -4024,7 +4018,6 @@ static void emit_asm_debug(BuildCtx *ctx) > if (!strcmp(name, "_lj_vm_ffi_call")) { fcsize = size; continue; } > #endif > fprintf(ctx->fp, > - "%s.eh:\n" > "LSFDE%d:\n" > "\t.set L$set$%d,LEFDE%d-LASFDE%d\n" > "\t.long L$set$%d\n" > @@ -4032,15 +4025,14 @@ static void emit_asm_debug(BuildCtx *ctx) > "\t.long LASFDE%d-EH_frame1\n" > "\t.long %s-.\n" > "\t.long %d\n" > - "\t.byte 0\n" /* augmentation length */ > - "\t.byte 0xe\n\t.byte %d\n\t.byte 1\n" /* def_cfa_offset */ > - "\t.byte 0x9e\n\t.byte 1\n" /* offset lr */ > - "\t.byte 0x9d\n\t.byte 2\n", /* offset fp */ > - name, j, j, j, j, j, j, j, name, size, CFRAME_SIZE); > + "\t.uleb128 0\n" /* augmentation length */ > + "\t.byte 0x9e\n\t.uleb128 1\n" /* offset lr */ > + "\t.byte 0x9d\n\t.uleb128 2\n", /* offset fp */ > + j, j, j, j, j, j, j, name, size); > for (i = 19; i <= 28; i++) /* offset x19-x28 */ > - fprintf(ctx->fp, "\t.byte 0x%x\n\t.byte %d\n", 0x80+i, i+(3-19)); > + fprintf(ctx->fp, "\t.byte 0x%x\n\t.uleb128 %d\n", 0x80+i, i+(3-19)); > for (i = 8; i <= 15; i++) /* offset d8-d15 */ > - fprintf(ctx->fp, "\t.byte 5\n\t.byte 0x%x\n\t.byte %d\n", > + fprintf(ctx->fp, "\t.byte 5\n\t.uleb128 0x%x\n\t.uleb128 %d\n", > 64+i, i+(3+(28-19+1)-8)); > fprintf(ctx->fp, > "\t.align 3\n" > @@ -4056,16 +4048,15 @@ static void emit_asm_debug(BuildCtx *ctx) > "\t.long 0\n" > "\t.byte 0x1\n" > "\t.ascii \"zR\\0\"\n" > - "\t.byte 0x1\n" > - "\t.byte 128-8\n" > + "\t.uleb128 0x1\n" > + "\t.sleb128 -8\n" > "\t.byte 30\n" /* Return address is in lr. */ > - "\t.byte 1\n" /* augmentation length */ > + "\t.uleb128 1\n" /* augmentation length */ > "\t.byte 0x1b\n" /* pcrel|sdata4 */ > - "\t.byte 0xc\n\t.byte 31\n\t.byte 0\n" /* def_cfa sp */ > + "\t.byte 0xc\n\t.uleb128 29\n\t.uleb128 16\n" /* def_cfa fp 16 */ > "\t.align 3\n" > "LECIEY:\n\n"); > fprintf(ctx->fp, > - "_lj_vm_ffi_call.eh:\n" > "LSFDEY:\n" > "\t.set L$set$yy,LEFDEY-LASFDEY\n" > "\t.long L$set$yy\n" > @@ -4073,13 +4064,11 @@ static void emit_asm_debug(BuildCtx *ctx) > "\t.long LASFDEY-EH_frame2\n" > "\t.long _lj_vm_ffi_call-.\n" > "\t.long %d\n" > - "\t.byte 0\n" /* augmentation length */ > - "\t.byte 0xe\n\t.byte 32\n" /* def_cfa_offset */ > - "\t.byte 0x9e\n\t.byte 1\n" /* offset lr */ > - "\t.byte 0x9d\n\t.byte 2\n" /* offset fp */ > - "\t.byte 0x93\n\t.byte 3\n" /* offset x19 */ > - "\t.byte 0x94\n\t.byte 4\n" /* offset x20 */ > - "\t.byte 0xd\n\t.uleb128 0x1d\n" /* def_cfa_register fp */ > + "\t.uleb128 0\n" /* augmentation length */ > + "\t.byte 0x9e\n\t.uleb128 1\n" /* offset lr */ > + "\t.byte 0x9d\n\t.uleb128 2\n" /* offset fp */ > + "\t.byte 0x93\n\t.uleb128 3\n" /* offset x19 */ > + "\t.byte 0x94\n\t.uleb128 4\n" /* offset x20 */ > "\t.align 3\n" > "LEFDEY:\n\n", fcsize); > } > diff --git a/test/tarantool-tests/gh-6096-external-unwinding-on-arm64.test.lua b/test/tarantool-tests/gh-6096-external-unwinding-on-arm64.test.lua > new file mode 100644 > index 00000000..cdeea441 > --- /dev/null > +++ b/test/tarantool-tests/gh-6096-external-unwinding-on-arm64.test.lua > -- > 2.37.0 (Apple Git-136) > -- Best regards, Sergey Kaplun