@@ -4724,5 +4724,135 @@ static int build_backend(BuildCtx *ctx)
47244724/* Emit pseudo frame-info for all assembler functions. */
47254725static void emit_asm_debug(BuildCtx *ctx)
47264726{
4727-
4727+ int fcofs = (int)((uint8_t *)ctx->glob[GLOB_vm_ffi_call] - ctx->code);
4728+ int i;
4729+ switch (ctx->mode) {
4730+ case BUILD_elfasm:
4731+ fprintf(ctx->fp, "\t.section .debug_frame,\"\",@progbits\n");
4732+ fprintf(ctx->fp,
4733+ ".Lframe0:\n"
4734+ "\t.4byte .LECIE0-.LSCIE0\n"
4735+ ".LSCIE0:\n"
4736+ "\t.4byte 0xffffffff\n"
4737+ "\t.byte 0x1\n"
4738+ "\t.string \"\"\n"
4739+ "\t.uleb128 0x1\n"
4740+ "\t.sleb128 -4\n"
4741+ "\t.byte 1\n" /* Return address is in ra. */
4742+ "\t.byte 0xc\n\t.uleb128 2\n\t.uleb128 0\n" /* def_cfa sp 0 */
4743+ "\t.align 3\n"
4744+ ".LECIE0:\n\n");
4745+ fprintf(ctx->fp,
4746+ ".LSFDE0:\n"
4747+ "\t.4byte .LEFDE0-.LASFDE0\n"
4748+ ".LASFDE0:\n"
4749+ "\t.4byte .Lframe0\n"
4750+ "\t.8byte .Lbegin\n"
4751+ "\t.8byte %d\n"
4752+ "\t.byte 0xe\n\t.uleb128 %d\n"
4753+ "\t.byte 0x81\n\t.uleb128 2*6\n" /* offset ra */,
4754+ fcofs, CFRAME_SIZE);
4755+ for (i = 27; i >= 18; i--) /* offset x27-x18 (s11-s2) */
4756+ fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+i, 2*(27-i+7));
4757+ fprintf(ctx->fp,
4758+ "\t.byte 0x89\n\t.uleb128 2*17\n" /* offset x9 (s1) */
4759+ "\t.byte 0x88\n\t.uleb128 2*18\n" /* offset x8 (s0/fp) */);
4760+ for (i = 27; i >= 18; i--) /* offset f31-f18 */
4761+ fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+32+i, 2*(27-i+19));
4762+ fprintf(ctx->fp,
4763+ "\t.byte 0x89+32\n\t.uleb128 2*29\n" /* offset f9 (fs1) */
4764+ "\t.byte 0x88+32\n\t.uleb128 2*30\n" /* offset f8 (fs0) */
4765+ "\t.align 3\n"
4766+ ".LEFDE0:\n\n");
4767+ #if LJ_HASFFI
4768+ fprintf(ctx->fp,
4769+ ".LSFDE1:\n"
4770+ "\t.4byte .LEFDE1-.LASFDE1\n"
4771+ ".LASFDE1:\n"
4772+ "\t.4byte .Lframe0\n"
4773+ "\t.4byte lj_vm_ffi_call\n"
4774+ "\t.4byte %d\n"
4775+ "\t.byte 0x81\n\t.uleb128 2*1\n" /* offset ra */
4776+ "\t.byte 0x92\n\t.uleb128 2*2\n" /* offset x18 */
4777+ "\t.byte 0xd\n\t.uleb128 0x12\n"
4778+ "\t.align 3\n"
4779+ ".LEFDE1:\n\n", (int)ctx->codesz - fcofs);
4780+ #endif
4781+ #if !LJ_NO_UNWIND
4782+ fprintf(ctx->fp, "\t.section .eh_frame,\"a\",@progbits\n");
4783+ fprintf(ctx->fp,
4784+ ".Lframe1:\n"
4785+ "\t.4byte .LECIE1-.LSCIE1\n"
4786+ ".LSCIE1:\n"
4787+ "\t.4byte 0\n"
4788+ "\t.byte 0x1\n"
4789+ "\t.string \"zPR\"\n"
4790+ "\t.uleb128 0x1\n"
4791+ "\t.sleb128 -4\n"
4792+ "\t.byte 1\n" /* Return address is in ra. */
4793+ "\t.uleb128 6\n" /* augmentation length */
4794+ "\t.byte 0x1b\n"
4795+ "\t.4byte lj_err_unwind_dwarf-.\n"
4796+ "\t.byte 0x1b\n"
4797+ "\t.byte 0xc\n\t.uleb128 2\n\t.uleb128 0\n" /* def_cfa sp 0 */
4798+ "\t.align 2\n"
4799+ ".LECIE1:\n\n");
4800+ fprintf(ctx->fp,
4801+ ".LSFDE2:\n"
4802+ "\t.4byte .LEFDE2-.LASFDE2\n"
4803+ ".LASFDE2:\n"
4804+ "\t.4byte .LASFDE2-.Lframe1\n"
4805+ "\t.4byte .Lbegin-.\n"
4806+ "\t.4byte %d\n"
4807+ "\t.uleb128 0\n" /* augmentation length */
4808+ "\t.byte 0xe\n\t.uleb128 %d\n"
4809+ "\t.byte 0x81\n\t.uleb128 2*6\n", /* offset ra */
4810+ fcofs, CFRAME_SIZE);
4811+ for (i = 27; i >= 18; i--) /* offset x27-x18 (s11-s2) */
4812+ fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+i, 2*(27-i+7));
4813+ fprintf(ctx->fp,
4814+ "\t.byte 0x89\n\t.uleb128 2*17\n" /* offset x9 (s1) */
4815+ "\t.byte 0x88\n\t.uleb128 2*18\n" /* offset x8 (s0/fp) */);
4816+ for (i = 27; i >= 18; i--) /* offset f31-f18 */
4817+ fprintf(ctx->fp, "\t.byte %d\n\t.uleb128 %d\n", 0x80+32+i, 2*(27-i+19));
4818+ fprintf(ctx->fp,
4819+ "\t.byte 0x89+32\n\t.uleb128 2*29\n" /* offset f9 (fs1) */
4820+ "\t.byte 0x88+32\n\t.uleb128 2*30\n" /* offset f8 (fs0) */
4821+ "\t.align 2\n"
4822+ ".LEFDE2:\n\n");
4823+ #if LJ_HASFFI
4824+ fprintf(ctx->fp,
4825+ ".Lframe2:\n"
4826+ "\t.4byte .LECIE2-.LSCIE2\n"
4827+ ".LSCIE2:\n"
4828+ "\t.4byte 0\n"
4829+ "\t.byte 0x1\n"
4830+ "\t.string \"zR\"\n"
4831+ "\t.uleb128 0x1\n"
4832+ "\t.sleb128 -4\n"
4833+ "\t.byte 1\n" /* Return address is in ra. */
4834+ "\t.uleb128 1\n" /* augmentation length */
4835+ "\t.byte 0x1b\n"
4836+ "\t.byte 0xc\n\t.uleb128 2\n\t.uleb128 0\n" /* def_cfa sp 0 */
4837+ "\t.align 2\n"
4838+ ".LECIE2:\n\n");
4839+ fprintf(ctx->fp,
4840+ ".LSFDE3:\n"
4841+ "\t.4byte .LEFDE3-.LASFDE3\n"
4842+ ".LASFDE3:\n"
4843+ "\t.4byte .LASFDE3- .Lframe2\n"
4844+ "\t.4byte lj_vm_ffi_call-.\n"
4845+ "\t.4byte %d\n"
4846+ "\t.uleb128 0\n" /* augmentation length */
4847+ "\t.byte 0x81\n\t.uleb128 2*1\n" /* offset ra */
4848+ "\t.byte 0x92\n\t.uleb128 2*2\n" /* offset x18 */
4849+ "\t.byte 0xd\n\t.uleb128 0x12\n"
4850+ "\t.align 2\n"
4851+ ".LEFDE3:\n\n", (int)ctx->codesz - fcofs);
4852+ #endif
4853+ #endif
4854+ break;
4855+ default:
4856+ break;
4857+ }
47284858}
0 commit comments