return true;
 }
 
-/* initialized on the first pass of build_body() */
-static int out_offset = -1;
-static int emit_bpf_tail_call(struct jit_ctx *ctx)
+static int emit_bpf_tail_call(struct jit_ctx *ctx, int insn)
 {
-       int off;
+       int off, tc_ninsn = 0;
        u8 tcc = tail_call_reg(ctx);
        u8 a1 = LOONGARCH_GPR_A1;
        u8 a2 = LOONGARCH_GPR_A2;
        const int idx0 = ctx->idx;
 
 #define cur_offset (ctx->idx - idx0)
-#define jmp_offset (out_offset - (cur_offset))
+#define jmp_offset (tc_ninsn - (cur_offset))
 
        /*
         * a0: &ctx
         * if (index >= array->map.max_entries)
         *       goto out;
         */
+       tc_ninsn = insn ? ctx->offset[insn+1] - ctx->offset[insn] : ctx->offset[0];
        off = offsetof(struct bpf_array, map.max_entries);
        emit_insn(ctx, ldwu, t1, a1, off);
        /* bgeu $a2, $t1, jmp_offset */
        emit_insn(ctx, ldd, t3, t2, off);
        __build_epilogue(ctx, true);
 
-       /* out: */
-       if (out_offset == -1)
-               out_offset = cur_offset;
-       if (cur_offset != out_offset) {
-               pr_err_once("tail_call out_offset = %d, expected %d!\n",
-                           cur_offset, out_offset);
-               return -1;
-       }
-
        return 0;
 
 toofar:
        /* tail call */
        case BPF_JMP | BPF_TAIL_CALL:
                mark_tail_call(ctx);
-               if (emit_bpf_tail_call(ctx) < 0)
+               if (emit_bpf_tail_call(ctx, i) < 0)
                        return -EINVAL;
                break;
 
        if (tmp_blinded)
                bpf_jit_prog_release_other(prog, prog == orig_prog ? tmp : orig_prog);
 
-       out_offset = -1;
 
        return prog;