Refactor buildvm symbol generation.

Fixes Windows and OSX builds with LUAJIT_DISABLE_JIT.
This commit is contained in:
Mike Pall 2010-04-14 17:13:13 +02:00
parent fbe092c22d
commit ff82df797a
8 changed files with 203 additions and 324 deletions

View File

@ -101,6 +101,33 @@ static void emit_raw(BuildCtx *ctx)
/* -- Build machine code -------------------------------------------------- */
static const char *sym_decorate(BuildCtx *ctx,
const char *prefix, const char *suffix)
{
char name[256];
char *p;
#if LJ_64
const char *symprefix = ctx->mode == BUILD_machasm ? "_" : "";
#else
const char *symprefix = ctx->mode != BUILD_elfasm ? "_" : "";
#endif
sprintf(name, "%s%s%s", symprefix, prefix, suffix);
p = strchr(name, '@');
if (p) {
if (!LJ_64 && (ctx->mode == BUILD_coffasm || ctx->mode == BUILD_peobj))
name[0] = '@';
else
*p = '\0';
}
p = (char *)malloc(strlen(name)+1); /* MSVC doesn't like strdup. */
strcpy(p, name);
return p;
}
#define NRELOCSYM (sizeof(extnames)/sizeof(extnames[0])-1)
static int relocmap[NRELOCSYM];
/* Collect external relocations. */
static int collect_reloc(BuildCtx *ctx, uint8_t *addr, int idx, int type)
{
@ -108,32 +135,38 @@ static int collect_reloc(BuildCtx *ctx, uint8_t *addr, int idx, int type)
fprintf(stderr, "Error: too many relocations, increase BUILD_MAX_RELOC.\n");
exit(1);
}
if (relocmap[idx] < 0) {
relocmap[idx] = ctx->nrelocsym;
ctx->relocsym[ctx->nrelocsym] = sym_decorate(ctx, "", extnames[idx]);
ctx->nrelocsym++;
}
ctx->reloc[ctx->nreloc].ofs = (int32_t)(addr - ctx->code);
ctx->reloc[ctx->nreloc].sym = idx;
ctx->reloc[ctx->nreloc].sym = relocmap[idx];
ctx->reloc[ctx->nreloc].type = type;
ctx->nreloc++;
return 0; /* Encode symbol offset of 0. */
}
/* Naive insertion sort. Performance doesn't matter here. */
static void perm_insert(int *perm, int32_t *ofs, int i)
static void sym_insert(BuildCtx *ctx, int32_t ofs,
const char *prefix, const char *suffix)
{
perm[i] = i;
ptrdiff_t i = ctx->nsym++;
while (i > 0) {
int a = perm[i-1];
int b = perm[i];
if (ofs[a] <= ofs[b]) break;
perm[i] = a;
perm[i-1] = b;
if (ctx->sym[i-1].ofs <= ofs)
break;
ctx->sym[i] = ctx->sym[i-1];
i--;
}
ctx->sym[i].ofs = ofs;
ctx->sym[i].name = sym_decorate(ctx, prefix, suffix);
}
/* Build the machine code. */
static int build_code(BuildCtx *ctx)
{
int status;
int i, j;
int i;
/* Initialize DynASM structures. */
ctx->nglob = GLOB__MAX;
@ -141,8 +174,10 @@ static int build_code(BuildCtx *ctx)
memset(ctx->glob, 0, ctx->nglob*sizeof(void *));
ctx->nreloc = 0;
ctx->extnames = extnames;
ctx->globnames = globnames;
ctx->relocsym = (const char **)malloc(NRELOCSYM*sizeof(const char *));
ctx->nrelocsym = 0;
for (i = 0; i < (int)NRELOCSYM; i++) relocmap[i] = -1;
ctx->dasm_ident = DASM_IDENT;
ctx->dasm_arch = DASM_ARCH;
@ -160,37 +195,41 @@ static int build_code(BuildCtx *ctx)
ctx->code = (uint8_t *)malloc(ctx->codesz);
if ((status = dasm_encode(Dst, (void *)ctx->code))) return status;
/* Allocate the symbol offset and permutation tables. */
ctx->nsym = ctx->npc + ctx->nglob;
ctx->perm = (int *)malloc((ctx->nsym+1)*sizeof(int *));
ctx->sym_ofs = (int32_t *)malloc((ctx->nsym+1)*sizeof(int32_t));
/* Allocate symbol table and bytecode offsets. */
ctx->beginsym = sym_decorate(ctx, "", LABEL_PREFIX "vm_asm_begin");
ctx->sym = (BuildSym *)malloc((ctx->npc+ctx->nglob+1)*sizeof(BuildSym));
ctx->nsym = 0;
ctx->bc_ofs = (int32_t *)malloc(ctx->npc*sizeof(int32_t));
/* Collect the opcodes (PC labels). */
for (i = 0; i < ctx->npc; i++) {
int32_t n = dasm_getpclabel(Dst, i);
if (n < 0) return 0x22000000|i;
ctx->sym_ofs[i] = n;
perm_insert(ctx->perm, ctx->sym_ofs, i);
int32_t ofs = dasm_getpclabel(Dst, i);
if (ofs < 0) return 0x22000000|i;
ctx->bc_ofs[i] = ofs;
#if !LJ_HASJIT
if (!(i == BC_JFORI || i == BC_JFORL || i == BC_JITERL || i == BC_JLOOP ||
i == BC_IFORL || i == BC_IITERL || i == BC_ILOOP))
#endif
sym_insert(ctx, ofs, LABEL_PREFIX_BC, bc_names[i]);
}
/* Collect the globals (named labels). */
for (j = 0; j < ctx->nglob; j++, i++) {
const char *gl = globnames[j];
for (i = 0; i < ctx->nglob; i++) {
const char *gl = globnames[i];
int len = (int)strlen(gl);
if (!ctx->glob[j]) {
if (!ctx->glob[i]) {
fprintf(stderr, "Error: undefined global %s\n", gl);
exit(2);
}
if (len >= 2 && gl[len-2] == '_' && gl[len-1] == 'Z')
ctx->sym_ofs[i] = -1; /* Skip the _Z symbols. */
else
ctx->sym_ofs[i] = (int32_t)((uint8_t *)(ctx->glob[j]) - ctx->code);
perm_insert(ctx->perm, ctx->sym_ofs, i);
/* Skip the _Z symbols. */
if (!(len >= 2 && gl[len-2] == '_' && gl[len-1] == 'Z'))
sym_insert(ctx, (int32_t)((uint8_t *)(ctx->glob[i]) - ctx->code),
LABEL_PREFIX, globnames[i]);
}
/* Close the address range. */
ctx->sym_ofs[i] = (int32_t)ctx->codesz;
perm_insert(ctx->perm, ctx->sym_ofs, i);
sym_insert(ctx, (int32_t)ctx->codesz, "", "");
ctx->nsym--;
dasm_free(Dst);
@ -260,7 +299,7 @@ static void emit_bcdef(BuildCtx *ctx)
for (i = 0; i < ctx->npc; i++) {
if (i != 0)
fprintf(ctx->fp, ",\n");
fprintf(ctx->fp, "%d", ctx->sym_ofs[i]);
fprintf(ctx->fp, "%d", ctx->bc_ofs[i]);
}
}

View File

@ -34,9 +34,6 @@
#define LABEL_PREFIX_LIBCF LABEL_PREFIX "lib_cf_"
#define LABEL_PREFIX_LIBINIT LABEL_PREFIX "lib_init_"
/* Extra labels. */
#define LABEL_ASM_BEGIN LABEL_PREFIX "vm_asm_begin"
/* Forward declaration. */
struct dasm_State;
@ -66,6 +63,11 @@ typedef struct BuildReloc {
int type;
} BuildReloc;
typedef struct BuildSym {
const char *name;
int32_t ofs;
} BuildSym;
/* Build context structure. */
typedef struct BuildCtx {
/* DynASM state pointer. Should be first member. */
@ -78,12 +80,13 @@ typedef struct BuildCtx {
/* Code and symbols generated by DynASM. */
uint8_t *code;
size_t codesz;
int npc, nglob, nsym, nreloc;
int npc, nglob, nsym, nreloc, nrelocsym;
void **glob;
int *perm;
int32_t *sym_ofs;
BuildSym *sym;
const char **relocsym;
int32_t *bc_ofs;
const char *beginsym;
/* Strings generated by DynASM. */
const char *const *extnames;
const char *const *globnames;
const char *dasm_ident;
const char *dasm_arch;

View File

@ -123,74 +123,33 @@ static void emit_asm_align(BuildCtx *ctx, int bits)
/* Emit assembler source code. */
void emit_asm(BuildCtx *ctx)
{
char name[80];
int32_t prev;
int i, pi, rel;
#if LJ_64
const char *symprefix = ctx->mode == BUILD_machasm ? "_" : "";
int keepfc = 0;
#else
const char *symprefix = ctx->mode != BUILD_elfasm ? "_" : "";
/* Keep fastcall suffix for COFF on WIN32. */
int keepfc = (ctx->mode == BUILD_coffasm);
#endif
int i, rel;
fprintf(ctx->fp, "\t.file \"buildvm_%s.dasc\"\n", ctx->dasm_arch);
fprintf(ctx->fp, "\t.text\n");
emit_asm_align(ctx, 4);
sprintf(name, "%s" LABEL_ASM_BEGIN, symprefix);
emit_asm_label(ctx, name, 0, 0);
emit_asm_label(ctx, ctx->beginsym, 0, 0);
if (ctx->mode != BUILD_machasm)
fprintf(ctx->fp, ".Lbegin:\n");
i = 0;
do {
pi = ctx->perm[i++];
prev = ctx->sym_ofs[pi];
} while (prev < 0); /* Skip the _Z symbols. */
for (rel = 0; i <= ctx->nsym; i++) {
int ni = ctx->perm[i];
int32_t next = ctx->sym_ofs[ni];
int size = (int)(next - prev);
int32_t stop = next;
if (pi >= ctx->npc) {
char *p;
sprintf(name, "%s" LABEL_PREFIX "%s", symprefix,
ctx->globnames[pi-ctx->npc]);
p = strchr(name, '@');
if (p) { if (keepfc) name[0] = '@'; else *p = '\0'; }
emit_asm_label(ctx, name, size, 1);
#if LJ_HASJIT
} else {
#else
} else if (!(pi == BC_JFORI || pi == BC_JFORL || pi == BC_JITERL ||
pi == BC_JLOOP || pi == BC_IFORL || pi == BC_IITERL ||
pi == BC_ILOOP)) {
#endif
sprintf(name, "%s" LABEL_PREFIX_BC "%s", symprefix, bc_names[pi]);
emit_asm_label(ctx, name, size, 1);
}
while (rel < ctx->nreloc && ctx->reloc[rel].ofs < stop) {
for (i = rel = 0; i < ctx->nsym; i++) {
int32_t ofs = ctx->sym[i].ofs;
int32_t next = ctx->sym[i+1].ofs;
emit_asm_label(ctx, ctx->sym[i].name, next - ofs, 1);
while (rel < ctx->nreloc && ctx->reloc[rel].ofs < next) {
BuildReloc *r = &ctx->reloc[rel];
int n = r->ofs - prev;
char *p;
sprintf(name, "%s%s", symprefix, ctx->extnames[r->sym]);
p = strchr(name, '@');
if (p) { if (keepfc) name[0] = '@'; else *p = '\0'; }
int n = r->ofs - ofs;
if (ctx->mode == BUILD_machasm && r->type != 0) {
emit_asm_reloc_mach(ctx, ctx->code+prev, n, name);
emit_asm_reloc_mach(ctx, ctx->code+ofs, n, ctx->relocsym[r->sym]);
} else {
emit_asm_bytes(ctx, ctx->code+prev, n);
emit_asm_reloc(ctx, r->type, name);
emit_asm_bytes(ctx, ctx->code+ofs, n);
emit_asm_reloc(ctx, r->type, ctx->relocsym[r->sym]);
}
prev += n+4;
ofs += n+4;
rel++;
}
emit_asm_bytes(ctx, ctx->code+prev, stop-prev);
prev = next;
pi = ni;
emit_asm_bytes(ctx, ctx->code+ofs, next-ofs);
}
fprintf(ctx->fp, "\n");

View File

@ -84,14 +84,11 @@ typedef struct PEsymaux {
#define PEOBJ_ARCH_TARGET 0x014c
#define PEOBJ_RELOC_REL32 0x14 /* MS: REL32, GNU: DISP32. */
#define PEOBJ_RELOC_DIR32 0x06
#define PEOBJ_SYM_PREFIX "_"
#define PEOBJ_SYMF_PREFIX "@"
#elif LJ_TARGET_X64
#define PEOBJ_ARCH_TARGET 0x8664
#define PEOBJ_RELOC_REL32 0x04 /* MS: REL32, GNU: DISP32. */
#define PEOBJ_RELOC_DIR32 0x02
#define PEOBJ_RELOC_ADDR32NB 0x03
#define PEOBJ_SYM_PREFIX ""
#endif
/* Section numbers (0-based). */
@ -164,18 +161,13 @@ static void emit_peobj_sym_sect(BuildCtx *ctx, PEsection *pesect, int sect)
owrite(ctx, &aux, PEOBJ_SYM_SIZE);
}
#define emit_peobj_sym_func(ctx, name, ofs) \
emit_peobj_sym(ctx, name, (uint32_t)(ofs), \
PEOBJ_SECT_TEXT, PEOBJ_TYPE_FUNC, PEOBJ_SCL_EXTERN)
/* Emit Windows PE object file. */
void emit_peobj(BuildCtx *ctx)
{
PEheader pehdr;
PEsection pesect[PEOBJ_NSECTIONS];
int nzsym, relocsyms;
uint32_t sofs;
int i;
int i, nrsym;
union { uint8_t b; uint32_t u; } host_endian;
host_endian.u = 1;
@ -230,16 +222,11 @@ void emit_peobj(BuildCtx *ctx)
/* Compute the size of the symbol table:
** @feat.00 + nsections*2
** + asm_start + (nsyms-nzsym)
** + relocsyms
** + asm_start + nsym
** + nrsym
*/
/* Skip _Z syms. */
for (nzsym = 0; ctx->sym_ofs[ctx->perm[nzsym]] < 0; nzsym++) ;
for (relocsyms = 0; ctx->extnames[relocsyms]; relocsyms++) ;
pehdr.nsyms = 1+PEOBJ_NSECTIONS*2 + 1+(ctx->nsym-nzsym) + relocsyms;
#if !LJ_HASJIT
pehdr.nsyms -= 11; /* See below, removes [IJ]* opcode symbols. */
#endif
nrsym = ctx->nrelocsym;
pehdr.nsyms = 1+PEOBJ_NSECTIONS*2 + 1+ctx->nsym + nrsym;
#if LJ_TARGET_X64
pehdr.nsyms += 1; /* Symbol for lj_err_unwind_win64. */
#endif
@ -264,13 +251,13 @@ void emit_peobj(BuildCtx *ctx)
PEreloc reloc;
pdata[0] = 0; pdata[1] = (uint32_t)ctx->codesz; pdata[2] = 0;
owrite(ctx, &pdata, sizeof(pdata));
reloc.vaddr = 0; reloc.symidx = 1+2+relocsyms+2+2+1;
reloc.vaddr = 0; reloc.symidx = 1+2+nrsym+2+2+1;
reloc.type = PEOBJ_RELOC_ADDR32NB;
owrite(ctx, &reloc, PEOBJ_RELOC_SIZE);
reloc.vaddr = 4; reloc.symidx = 1+2+relocsyms+2+2+1;
reloc.vaddr = 4; reloc.symidx = 1+2+nrsym+2+2+1;
reloc.type = PEOBJ_RELOC_ADDR32NB;
owrite(ctx, &reloc, PEOBJ_RELOC_SIZE);
reloc.vaddr = 8; reloc.symidx = 1+2+relocsyms+2;
reloc.vaddr = 8; reloc.symidx = 1+2+nrsym+2;
reloc.type = PEOBJ_RELOC_ADDR32NB;
owrite(ctx, &reloc, PEOBJ_RELOC_SIZE);
}
@ -287,7 +274,7 @@ void emit_peobj(BuildCtx *ctx)
xdata[7] = 0; /* Alignment. */
xdata[8] = xdata[9] = 0; /* Relocated address of exception handler. */
owrite(ctx, &xdata, sizeof(xdata));
reloc.vaddr = sizeof(xdata)-4; reloc.symidx = 1+2+relocsyms+2+2;
reloc.vaddr = sizeof(xdata)-4; reloc.symidx = 1+2+nrsym+2+2;
reloc.type = PEOBJ_RELOC_ADDR32NB;
owrite(ctx, &reloc, PEOBJ_RELOC_SIZE);
}
@ -299,69 +286,28 @@ void emit_peobj(BuildCtx *ctx)
/* Write symbol table. */
strtab = NULL; /* 1st pass: collect string sizes. */
for (;;) {
char name[80];
strtabofs = 4;
/* Mark as SafeSEH compliant. */
emit_peobj_sym(ctx, "@feat.00", 1,
PEOBJ_SECT_ABS, PEOBJ_TYPE_NULL, PEOBJ_SCL_STATIC);
emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_TEXT);
for (i = 0; ctx->extnames[i]; i++) {
const char *sym = ctx->extnames[i];
const char *p = strchr(sym, '@');
if (p) {
#ifdef PEOBJ_SYMF_PREFIX
sprintf(name, PEOBJ_SYMF_PREFIX "%s", sym);
#else
strncpy(name, sym, p-sym);
name[p-sym] = '\0';
#endif
} else {
sprintf(name, PEOBJ_SYM_PREFIX "%s", sym);
}
emit_peobj_sym(ctx, name, 0,
for (i = 0; i < nrsym; i++)
emit_peobj_sym(ctx, ctx->relocsym[i], 0,
PEOBJ_SECT_UNDEF, PEOBJ_TYPE_FUNC, PEOBJ_SCL_EXTERN);
}
#if LJ_TARGET_X64
emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_PDATA);
emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_XDATA);
emit_peobj_sym(ctx, PEOBJ_SYM_PREFIX "lj_err_unwind_win64", 0,
emit_peobj_sym(ctx, "lj_err_unwind_win64", 0,
PEOBJ_SECT_UNDEF, PEOBJ_TYPE_FUNC, PEOBJ_SCL_EXTERN);
#endif
emit_peobj_sym(ctx, PEOBJ_SYM_PREFIX LABEL_ASM_BEGIN, 0,
emit_peobj_sym(ctx, ctx->beginsym, 0,
PEOBJ_SECT_TEXT, PEOBJ_TYPE_NULL, PEOBJ_SCL_EXTERN);
for (i = nzsym; i < ctx->nsym; i++) {
int pi = ctx->perm[i];
if (pi >= ctx->npc) {
const char *sym = ctx->globnames[pi-ctx->npc];
const char *p = strchr(sym, '@');
if (p) {
#ifdef PEOBJ_SYMF_PREFIX
sprintf(name, PEOBJ_SYMF_PREFIX LABEL_PREFIX "%s", sym);
#else
sprintf(name, LABEL_PREFIX "%s", sym);
name[(p-sym)+sizeof(LABEL_PREFIX)-1] = '\0';
#endif
} else {
sprintf(name, PEOBJ_SYM_PREFIX LABEL_PREFIX "%s", sym);
}
emit_peobj_sym_func(ctx, name, ctx->sym_ofs[pi]);
#if LJ_HASJIT
} else {
#else
} else if (!(pi == BC_JFORI || pi == BC_JFORL || pi == BC_JITERL ||
pi == BC_JLOOP || pi == BC_JFUNCF || pi == BC_JFUNCV ||
pi == BC_IFORL || pi == BC_IITERL || pi == BC_ILOOP ||
pi == BC_IFUNCF || pi == BC_IFUNCV)) {
#endif
sprintf(name, PEOBJ_SYM_PREFIX LABEL_PREFIX_BC "%s",
bc_names[pi]);
emit_peobj_sym_func(ctx, name, ctx->sym_ofs[pi]);
}
}
for (i = 0; i < ctx->nsym; i++)
emit_peobj_sym(ctx, ctx->sym[i].name, (uint32_t)ctx->sym[i].ofs,
PEOBJ_SECT_TEXT, PEOBJ_TYPE_FUNC, PEOBJ_SCL_EXTERN);
emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_RDATA_Z);

View File

@ -2403,50 +2403,33 @@ static void emit_asm_debug(BuildCtx *ctx)
"\t.align " BSZPTR "\n"
"LECIEX:\n\n");
for (i = 0; i < ctx->nsym; i++) {
int pi = ctx->perm[i];
int ni = ctx->perm[i+1];
int size = ctx->sym_ofs[ni] - ctx->sym_ofs[pi];
if (ctx->sym_ofs[pi] >= 0 && size > 0) {
char name[80];
if (pi >= ctx->npc) {
char *p;
sprintf(name, "_" LABEL_PREFIX "%s", ctx->globnames[pi - ctx->npc]);
p = strchr(name, '@'); if (p) *p = '\0';
#if LJ_HASJIT
} else {
#else
} else if (!(pi == BC_JFORI || pi == BC_JFORL || pi == BC_JITERL ||
pi == BC_JLOOP || pi == BC_IFORL || pi == BC_IITERL ||
pi == BC_ILOOP)) {
#endif
sprintf(name, "_" LABEL_PREFIX_BC "%s", bc_names[pi]);
}
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"
"LASFDE%d:\n"
"\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" /* def_cfa_offset */
const char *name = ctx->sym[i].name;
int32_t size = ctx->sym[i+1].ofs - ctx->sym[i].ofs;
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"
"LASFDE%d:\n"
"\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" /* def_cfa_offset */
#if LJ_64
"\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */
"\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */
"\t.byte 0x8f\n\t.byte 0x4\n" /* offset r15 */
"\t.byte 0x8e\n\t.byte 0x5\n" /* offset r14 */
"\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */
"\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */
"\t.byte 0x8f\n\t.byte 0x4\n" /* offset r15 */
"\t.byte 0x8e\n\t.byte 0x5\n" /* offset r14 */
#else
"\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/
"\t.byte 0x87\n\t.byte 0x3\n" /* offset edi */
"\t.byte 0x86\n\t.byte 0x4\n" /* offset esi */
"\t.byte 0x83\n\t.byte 0x5\n" /* offset ebx */
"\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/
"\t.byte 0x87\n\t.byte 0x3\n" /* offset edi */
"\t.byte 0x86\n\t.byte 0x4\n" /* offset esi */
"\t.byte 0x83\n\t.byte 0x5\n" /* offset ebx */
#endif
"\t.align " BSZPTR "\n"
"LEFDE%d:\n\n",
name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i);
}
"\t.align " BSZPTR "\n"
"LEFDE%d:\n\n",
name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i);
}
#if LJ_64
fprintf(ctx->fp, "\t.subsections_via_symbols\n");

View File

@ -2404,50 +2404,33 @@ static void emit_asm_debug(BuildCtx *ctx)
"\t.align " BSZPTR "\n"
"LECIEX:\n\n");
for (i = 0; i < ctx->nsym; i++) {
int pi = ctx->perm[i];
int ni = ctx->perm[i+1];
int size = ctx->sym_ofs[ni] - ctx->sym_ofs[pi];
if (ctx->sym_ofs[pi] >= 0 && size > 0) {
char name[80];
if (pi >= ctx->npc) {
char *p;
sprintf(name, "_" LABEL_PREFIX "%s", ctx->globnames[pi - ctx->npc]);
p = strchr(name, '@'); if (p) *p = '\0';
#if LJ_HASJIT
} else {
#else
} else if (!(pi == BC_JFORI || pi == BC_JFORL || pi == BC_JITERL ||
pi == BC_JLOOP || pi == BC_IFORL || pi == BC_IITERL ||
pi == BC_ILOOP)) {
#endif
sprintf(name, "_" LABEL_PREFIX_BC "%s", bc_names[pi]);
}
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"
"LASFDE%d:\n"
"\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" /* def_cfa_offset */
const char *name = ctx->sym[i].name;
int32_t size = ctx->sym[i+1].ofs - ctx->sym[i].ofs;
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"
"LASFDE%d:\n"
"\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" /* def_cfa_offset */
#if LJ_64
"\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */
"\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */
"\t.byte 0x8f\n\t.byte 0x4\n" /* offset r15 */
"\t.byte 0x8e\n\t.byte 0x5\n" /* offset r14 */
"\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */
"\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */
"\t.byte 0x8f\n\t.byte 0x4\n" /* offset r15 */
"\t.byte 0x8e\n\t.byte 0x5\n" /* offset r14 */
#else
"\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/
"\t.byte 0x87\n\t.byte 0x3\n" /* offset edi */
"\t.byte 0x86\n\t.byte 0x4\n" /* offset esi */
"\t.byte 0x83\n\t.byte 0x5\n" /* offset ebx */
"\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/
"\t.byte 0x87\n\t.byte 0x3\n" /* offset edi */
"\t.byte 0x86\n\t.byte 0x4\n" /* offset esi */
"\t.byte 0x83\n\t.byte 0x5\n" /* offset ebx */
#endif
"\t.align " BSZPTR "\n"
"LEFDE%d:\n\n",
name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i);
}
"\t.align " BSZPTR "\n"
"LEFDE%d:\n\n",
name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i);
}
#if LJ_64
fprintf(ctx->fp, "\t.subsections_via_symbols\n");

View File

@ -5133,50 +5133,33 @@ static void emit_asm_debug(BuildCtx *ctx)
"\t.align " BSZPTR "\n"
"LECIEX:\n\n");
for (i = 0; i < ctx->nsym; i++) {
int pi = ctx->perm[i];
int ni = ctx->perm[i+1];
int size = ctx->sym_ofs[ni] - ctx->sym_ofs[pi];
if (ctx->sym_ofs[pi] >= 0 && size > 0) {
char name[80];
if (pi >= ctx->npc) {
char *p;
sprintf(name, "_" LABEL_PREFIX "%s", ctx->globnames[pi - ctx->npc]);
p = strchr(name, '@'); if (p) *p = '\0';
#if LJ_HASJIT
} else {
#else
} else if (!(pi == BC_JFORI || pi == BC_JFORL || pi == BC_JITERL ||
pi == BC_JLOOP || pi == BC_IFORL || pi == BC_IITERL ||
pi == BC_ILOOP)) {
#endif
sprintf(name, "_" LABEL_PREFIX_BC "%s", bc_names[pi]);
}
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"
"LASFDE%d:\n"
"\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" /* def_cfa_offset */
const char *name = ctx->sym[i].name;
int32_t size = ctx->sym[i+1].ofs - ctx->sym[i].ofs;
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"
"LASFDE%d:\n"
"\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" /* def_cfa_offset */
#if LJ_64
"\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */
"\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */
"\t.byte 0x8f\n\t.byte 0x4\n" /* offset r15 */
"\t.byte 0x8e\n\t.byte 0x5\n" /* offset r14 */
"\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */
"\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */
"\t.byte 0x8f\n\t.byte 0x4\n" /* offset r15 */
"\t.byte 0x8e\n\t.byte 0x5\n" /* offset r14 */
#else
"\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/
"\t.byte 0x87\n\t.byte 0x3\n" /* offset edi */
"\t.byte 0x86\n\t.byte 0x4\n" /* offset esi */
"\t.byte 0x83\n\t.byte 0x5\n" /* offset ebx */
"\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/
"\t.byte 0x87\n\t.byte 0x3\n" /* offset edi */
"\t.byte 0x86\n\t.byte 0x4\n" /* offset esi */
"\t.byte 0x83\n\t.byte 0x5\n" /* offset ebx */
#endif
"\t.align " BSZPTR "\n"
"LEFDE%d:\n\n",
name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i);
}
"\t.align " BSZPTR "\n"
"LEFDE%d:\n\n",
name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i);
}
#if LJ_64
fprintf(ctx->fp, "\t.subsections_via_symbols\n");

View File

@ -2529,50 +2529,33 @@ static void emit_asm_debug(BuildCtx *ctx)
"\t.align " BSZPTR "\n"
"LECIEX:\n\n");
for (i = 0; i < ctx->nsym; i++) {
int pi = ctx->perm[i];
int ni = ctx->perm[i+1];
int size = ctx->sym_ofs[ni] - ctx->sym_ofs[pi];
if (ctx->sym_ofs[pi] >= 0 && size > 0) {
char name[80];
if (pi >= ctx->npc) {
char *p;
sprintf(name, "_" LABEL_PREFIX "%s", ctx->globnames[pi - ctx->npc]);
p = strchr(name, '@'); if (p) *p = '\0';
#if LJ_HASJIT
} else {
#else
} else if (!(pi == BC_JFORI || pi == BC_JFORL || pi == BC_JITERL ||
pi == BC_JLOOP || pi == BC_IFORL || pi == BC_IITERL ||
pi == BC_ILOOP)) {
#endif
sprintf(name, "_" LABEL_PREFIX_BC "%s", bc_names[pi]);
}
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"
"LASFDE%d:\n"
"\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" /* def_cfa_offset */
const char *name = ctx->sym[i].name;
int32_t size = ctx->sym[i+1].ofs - ctx->sym[i].ofs;
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"
"LASFDE%d:\n"
"\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" /* def_cfa_offset */
#if LJ_64
"\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */
"\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */
"\t.byte 0x8f\n\t.byte 0x4\n" /* offset r15 */
"\t.byte 0x8e\n\t.byte 0x5\n" /* offset r14 */
"\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */
"\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */
"\t.byte 0x8f\n\t.byte 0x4\n" /* offset r15 */
"\t.byte 0x8e\n\t.byte 0x5\n" /* offset r14 */
#else
"\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/
"\t.byte 0x87\n\t.byte 0x3\n" /* offset edi */
"\t.byte 0x86\n\t.byte 0x4\n" /* offset esi */
"\t.byte 0x83\n\t.byte 0x5\n" /* offset ebx */
"\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/
"\t.byte 0x87\n\t.byte 0x3\n" /* offset edi */
"\t.byte 0x86\n\t.byte 0x4\n" /* offset esi */
"\t.byte 0x83\n\t.byte 0x5\n" /* offset ebx */
#endif
"\t.align " BSZPTR "\n"
"LEFDE%d:\n\n",
name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i);
}
"\t.align " BSZPTR "\n"
"LEFDE%d:\n\n",
name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i);
}
#if LJ_64
fprintf(ctx->fp, "\t.subsections_via_symbols\n");