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 -------------------------------------------------- */ /* -- 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. */ /* Collect external relocations. */
static int collect_reloc(BuildCtx *ctx, uint8_t *addr, int idx, int type) 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"); fprintf(stderr, "Error: too many relocations, increase BUILD_MAX_RELOC.\n");
exit(1); 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].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->reloc[ctx->nreloc].type = type;
ctx->nreloc++; ctx->nreloc++;
return 0; /* Encode symbol offset of 0. */ return 0; /* Encode symbol offset of 0. */
} }
/* Naive insertion sort. Performance doesn't matter here. */ /* 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) { while (i > 0) {
int a = perm[i-1]; if (ctx->sym[i-1].ofs <= ofs)
int b = perm[i]; break;
if (ofs[a] <= ofs[b]) break; ctx->sym[i] = ctx->sym[i-1];
perm[i] = a;
perm[i-1] = b;
i--; i--;
} }
ctx->sym[i].ofs = ofs;
ctx->sym[i].name = sym_decorate(ctx, prefix, suffix);
} }
/* Build the machine code. */ /* Build the machine code. */
static int build_code(BuildCtx *ctx) static int build_code(BuildCtx *ctx)
{ {
int status; int status;
int i, j; int i;
/* Initialize DynASM structures. */ /* Initialize DynASM structures. */
ctx->nglob = GLOB__MAX; ctx->nglob = GLOB__MAX;
@ -141,8 +174,10 @@ static int build_code(BuildCtx *ctx)
memset(ctx->glob, 0, ctx->nglob*sizeof(void *)); memset(ctx->glob, 0, ctx->nglob*sizeof(void *));
ctx->nreloc = 0; ctx->nreloc = 0;
ctx->extnames = extnames;
ctx->globnames = globnames; 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_ident = DASM_IDENT;
ctx->dasm_arch = DASM_ARCH; ctx->dasm_arch = DASM_ARCH;
@ -160,37 +195,41 @@ static int build_code(BuildCtx *ctx)
ctx->code = (uint8_t *)malloc(ctx->codesz); ctx->code = (uint8_t *)malloc(ctx->codesz);
if ((status = dasm_encode(Dst, (void *)ctx->code))) return status; if ((status = dasm_encode(Dst, (void *)ctx->code))) return status;
/* Allocate the symbol offset and permutation tables. */ /* Allocate symbol table and bytecode offsets. */
ctx->nsym = ctx->npc + ctx->nglob; ctx->beginsym = sym_decorate(ctx, "", LABEL_PREFIX "vm_asm_begin");
ctx->perm = (int *)malloc((ctx->nsym+1)*sizeof(int *)); ctx->sym = (BuildSym *)malloc((ctx->npc+ctx->nglob+1)*sizeof(BuildSym));
ctx->sym_ofs = (int32_t *)malloc((ctx->nsym+1)*sizeof(int32_t)); ctx->nsym = 0;
ctx->bc_ofs = (int32_t *)malloc(ctx->npc*sizeof(int32_t));
/* Collect the opcodes (PC labels). */ /* Collect the opcodes (PC labels). */
for (i = 0; i < ctx->npc; i++) { for (i = 0; i < ctx->npc; i++) {
int32_t n = dasm_getpclabel(Dst, i); int32_t ofs = dasm_getpclabel(Dst, i);
if (n < 0) return 0x22000000|i; if (ofs < 0) return 0x22000000|i;
ctx->sym_ofs[i] = n; ctx->bc_ofs[i] = ofs;
perm_insert(ctx->perm, ctx->sym_ofs, i); #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). */ /* Collect the globals (named labels). */
for (j = 0; j < ctx->nglob; j++, i++) { for (i = 0; i < ctx->nglob; i++) {
const char *gl = globnames[j]; const char *gl = globnames[i];
int len = (int)strlen(gl); int len = (int)strlen(gl);
if (!ctx->glob[j]) { if (!ctx->glob[i]) {
fprintf(stderr, "Error: undefined global %s\n", gl); fprintf(stderr, "Error: undefined global %s\n", gl);
exit(2); exit(2);
} }
if (len >= 2 && gl[len-2] == '_' && gl[len-1] == 'Z') /* Skip the _Z symbols. */
ctx->sym_ofs[i] = -1; /* Skip the _Z symbols. */ if (!(len >= 2 && gl[len-2] == '_' && gl[len-1] == 'Z'))
else sym_insert(ctx, (int32_t)((uint8_t *)(ctx->glob[i]) - ctx->code),
ctx->sym_ofs[i] = (int32_t)((uint8_t *)(ctx->glob[j]) - ctx->code); LABEL_PREFIX, globnames[i]);
perm_insert(ctx->perm, ctx->sym_ofs, i);
} }
/* Close the address range. */ /* Close the address range. */
ctx->sym_ofs[i] = (int32_t)ctx->codesz; sym_insert(ctx, (int32_t)ctx->codesz, "", "");
perm_insert(ctx->perm, ctx->sym_ofs, i); ctx->nsym--;
dasm_free(Dst); dasm_free(Dst);
@ -260,7 +299,7 @@ static void emit_bcdef(BuildCtx *ctx)
for (i = 0; i < ctx->npc; i++) { for (i = 0; i < ctx->npc; i++) {
if (i != 0) if (i != 0)
fprintf(ctx->fp, ",\n"); 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_LIBCF LABEL_PREFIX "lib_cf_"
#define LABEL_PREFIX_LIBINIT LABEL_PREFIX "lib_init_" #define LABEL_PREFIX_LIBINIT LABEL_PREFIX "lib_init_"
/* Extra labels. */
#define LABEL_ASM_BEGIN LABEL_PREFIX "vm_asm_begin"
/* Forward declaration. */ /* Forward declaration. */
struct dasm_State; struct dasm_State;
@ -66,6 +63,11 @@ typedef struct BuildReloc {
int type; int type;
} BuildReloc; } BuildReloc;
typedef struct BuildSym {
const char *name;
int32_t ofs;
} BuildSym;
/* Build context structure. */ /* Build context structure. */
typedef struct BuildCtx { typedef struct BuildCtx {
/* DynASM state pointer. Should be first member. */ /* DynASM state pointer. Should be first member. */
@ -78,12 +80,13 @@ typedef struct BuildCtx {
/* Code and symbols generated by DynASM. */ /* Code and symbols generated by DynASM. */
uint8_t *code; uint8_t *code;
size_t codesz; size_t codesz;
int npc, nglob, nsym, nreloc; int npc, nglob, nsym, nreloc, nrelocsym;
void **glob; void **glob;
int *perm; BuildSym *sym;
int32_t *sym_ofs; const char **relocsym;
int32_t *bc_ofs;
const char *beginsym;
/* Strings generated by DynASM. */ /* Strings generated by DynASM. */
const char *const *extnames;
const char *const *globnames; const char *const *globnames;
const char *dasm_ident; const char *dasm_ident;
const char *dasm_arch; const char *dasm_arch;

View File

@ -123,74 +123,33 @@ static void emit_asm_align(BuildCtx *ctx, int bits)
/* Emit assembler source code. */ /* Emit assembler source code. */
void emit_asm(BuildCtx *ctx) void emit_asm(BuildCtx *ctx)
{ {
char name[80]; int i, rel;
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
fprintf(ctx->fp, "\t.file \"buildvm_%s.dasc\"\n", ctx->dasm_arch); fprintf(ctx->fp, "\t.file \"buildvm_%s.dasc\"\n", ctx->dasm_arch);
fprintf(ctx->fp, "\t.text\n"); fprintf(ctx->fp, "\t.text\n");
emit_asm_align(ctx, 4); emit_asm_align(ctx, 4);
sprintf(name, "%s" LABEL_ASM_BEGIN, symprefix); emit_asm_label(ctx, ctx->beginsym, 0, 0);
emit_asm_label(ctx, name, 0, 0);
if (ctx->mode != BUILD_machasm) if (ctx->mode != BUILD_machasm)
fprintf(ctx->fp, ".Lbegin:\n"); fprintf(ctx->fp, ".Lbegin:\n");
i = 0; for (i = rel = 0; i < ctx->nsym; i++) {
do { int32_t ofs = ctx->sym[i].ofs;
pi = ctx->perm[i++]; int32_t next = ctx->sym[i+1].ofs;
prev = ctx->sym_ofs[pi]; emit_asm_label(ctx, ctx->sym[i].name, next - ofs, 1);
} while (prev < 0); /* Skip the _Z symbols. */ while (rel < ctx->nreloc && ctx->reloc[rel].ofs < next) {
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) {
BuildReloc *r = &ctx->reloc[rel]; BuildReloc *r = &ctx->reloc[rel];
int n = r->ofs - prev; int n = r->ofs - ofs;
char *p;
sprintf(name, "%s%s", symprefix, ctx->extnames[r->sym]);
p = strchr(name, '@');
if (p) { if (keepfc) name[0] = '@'; else *p = '\0'; }
if (ctx->mode == BUILD_machasm && r->type != 0) { 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 { } else {
emit_asm_bytes(ctx, ctx->code+prev, n); emit_asm_bytes(ctx, ctx->code+ofs, n);
emit_asm_reloc(ctx, r->type, name); emit_asm_reloc(ctx, r->type, ctx->relocsym[r->sym]);
} }
prev += n+4; ofs += n+4;
rel++; rel++;
} }
emit_asm_bytes(ctx, ctx->code+prev, stop-prev); emit_asm_bytes(ctx, ctx->code+ofs, next-ofs);
prev = next;
pi = ni;
} }
fprintf(ctx->fp, "\n"); fprintf(ctx->fp, "\n");

View File

@ -84,14 +84,11 @@ typedef struct PEsymaux {
#define PEOBJ_ARCH_TARGET 0x014c #define PEOBJ_ARCH_TARGET 0x014c
#define PEOBJ_RELOC_REL32 0x14 /* MS: REL32, GNU: DISP32. */ #define PEOBJ_RELOC_REL32 0x14 /* MS: REL32, GNU: DISP32. */
#define PEOBJ_RELOC_DIR32 0x06 #define PEOBJ_RELOC_DIR32 0x06
#define PEOBJ_SYM_PREFIX "_"
#define PEOBJ_SYMF_PREFIX "@"
#elif LJ_TARGET_X64 #elif LJ_TARGET_X64
#define PEOBJ_ARCH_TARGET 0x8664 #define PEOBJ_ARCH_TARGET 0x8664
#define PEOBJ_RELOC_REL32 0x04 /* MS: REL32, GNU: DISP32. */ #define PEOBJ_RELOC_REL32 0x04 /* MS: REL32, GNU: DISP32. */
#define PEOBJ_RELOC_DIR32 0x02 #define PEOBJ_RELOC_DIR32 0x02
#define PEOBJ_RELOC_ADDR32NB 0x03 #define PEOBJ_RELOC_ADDR32NB 0x03
#define PEOBJ_SYM_PREFIX ""
#endif #endif
/* Section numbers (0-based). */ /* 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); 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. */ /* Emit Windows PE object file. */
void emit_peobj(BuildCtx *ctx) void emit_peobj(BuildCtx *ctx)
{ {
PEheader pehdr; PEheader pehdr;
PEsection pesect[PEOBJ_NSECTIONS]; PEsection pesect[PEOBJ_NSECTIONS];
int nzsym, relocsyms;
uint32_t sofs; uint32_t sofs;
int i; int i, nrsym;
union { uint8_t b; uint32_t u; } host_endian; union { uint8_t b; uint32_t u; } host_endian;
host_endian.u = 1; host_endian.u = 1;
@ -230,16 +222,11 @@ void emit_peobj(BuildCtx *ctx)
/* Compute the size of the symbol table: /* Compute the size of the symbol table:
** @feat.00 + nsections*2 ** @feat.00 + nsections*2
** + asm_start + (nsyms-nzsym) ** + asm_start + nsym
** + relocsyms ** + nrsym
*/ */
/* Skip _Z syms. */ nrsym = ctx->nrelocsym;
for (nzsym = 0; ctx->sym_ofs[ctx->perm[nzsym]] < 0; nzsym++) ; pehdr.nsyms = 1+PEOBJ_NSECTIONS*2 + 1+ctx->nsym + nrsym;
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
#if LJ_TARGET_X64 #if LJ_TARGET_X64
pehdr.nsyms += 1; /* Symbol for lj_err_unwind_win64. */ pehdr.nsyms += 1; /* Symbol for lj_err_unwind_win64. */
#endif #endif
@ -264,13 +251,13 @@ void emit_peobj(BuildCtx *ctx)
PEreloc reloc; PEreloc reloc;
pdata[0] = 0; pdata[1] = (uint32_t)ctx->codesz; pdata[2] = 0; pdata[0] = 0; pdata[1] = (uint32_t)ctx->codesz; pdata[2] = 0;
owrite(ctx, &pdata, sizeof(pdata)); 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; reloc.type = PEOBJ_RELOC_ADDR32NB;
owrite(ctx, &reloc, PEOBJ_RELOC_SIZE); 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; reloc.type = PEOBJ_RELOC_ADDR32NB;
owrite(ctx, &reloc, PEOBJ_RELOC_SIZE); 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; reloc.type = PEOBJ_RELOC_ADDR32NB;
owrite(ctx, &reloc, PEOBJ_RELOC_SIZE); owrite(ctx, &reloc, PEOBJ_RELOC_SIZE);
} }
@ -287,7 +274,7 @@ void emit_peobj(BuildCtx *ctx)
xdata[7] = 0; /* Alignment. */ xdata[7] = 0; /* Alignment. */
xdata[8] = xdata[9] = 0; /* Relocated address of exception handler. */ xdata[8] = xdata[9] = 0; /* Relocated address of exception handler. */
owrite(ctx, &xdata, sizeof(xdata)); 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; reloc.type = PEOBJ_RELOC_ADDR32NB;
owrite(ctx, &reloc, PEOBJ_RELOC_SIZE); owrite(ctx, &reloc, PEOBJ_RELOC_SIZE);
} }
@ -299,69 +286,28 @@ void emit_peobj(BuildCtx *ctx)
/* Write symbol table. */ /* Write symbol table. */
strtab = NULL; /* 1st pass: collect string sizes. */ strtab = NULL; /* 1st pass: collect string sizes. */
for (;;) { for (;;) {
char name[80];
strtabofs = 4; strtabofs = 4;
/* Mark as SafeSEH compliant. */ /* Mark as SafeSEH compliant. */
emit_peobj_sym(ctx, "@feat.00", 1, emit_peobj_sym(ctx, "@feat.00", 1,
PEOBJ_SECT_ABS, PEOBJ_TYPE_NULL, PEOBJ_SCL_STATIC); PEOBJ_SECT_ABS, PEOBJ_TYPE_NULL, PEOBJ_SCL_STATIC);
emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_TEXT); emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_TEXT);
for (i = 0; ctx->extnames[i]; i++) { for (i = 0; i < nrsym; i++)
const char *sym = ctx->extnames[i]; emit_peobj_sym(ctx, ctx->relocsym[i], 0,
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,
PEOBJ_SECT_UNDEF, PEOBJ_TYPE_FUNC, PEOBJ_SCL_EXTERN); PEOBJ_SECT_UNDEF, PEOBJ_TYPE_FUNC, PEOBJ_SCL_EXTERN);
}
#if LJ_TARGET_X64 #if LJ_TARGET_X64
emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_PDATA); emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_PDATA);
emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_XDATA); 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); PEOBJ_SECT_UNDEF, PEOBJ_TYPE_FUNC, PEOBJ_SCL_EXTERN);
#endif #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); PEOBJ_SECT_TEXT, PEOBJ_TYPE_NULL, PEOBJ_SCL_EXTERN);
for (i = nzsym; i < ctx->nsym; i++) { for (i = 0; i < ctx->nsym; i++)
int pi = ctx->perm[i]; emit_peobj_sym(ctx, ctx->sym[i].name, (uint32_t)ctx->sym[i].ofs,
if (pi >= ctx->npc) { PEOBJ_SECT_TEXT, PEOBJ_TYPE_FUNC, PEOBJ_SCL_EXTERN);
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]);
}
}
emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_RDATA_Z); emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_RDATA_Z);

View File

@ -2403,24 +2403,8 @@ static void emit_asm_debug(BuildCtx *ctx)
"\t.align " BSZPTR "\n" "\t.align " BSZPTR "\n"
"LECIEX:\n\n"); "LECIEX:\n\n");
for (i = 0; i < ctx->nsym; i++) { for (i = 0; i < ctx->nsym; i++) {
int pi = ctx->perm[i]; const char *name = ctx->sym[i].name;
int ni = ctx->perm[i+1]; int32_t size = ctx->sym[i+1].ofs - ctx->sym[i].ofs;
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, fprintf(ctx->fp,
"%s.eh:\n" "%s.eh:\n"
"LSFDE%d:\n" "LSFDE%d:\n"
@ -2447,7 +2431,6 @@ static void emit_asm_debug(BuildCtx *ctx)
"LEFDE%d:\n\n", "LEFDE%d:\n\n",
name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i); name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i);
} }
}
#if LJ_64 #if LJ_64
fprintf(ctx->fp, "\t.subsections_via_symbols\n"); fprintf(ctx->fp, "\t.subsections_via_symbols\n");
#else #else

View File

@ -2404,24 +2404,8 @@ static void emit_asm_debug(BuildCtx *ctx)
"\t.align " BSZPTR "\n" "\t.align " BSZPTR "\n"
"LECIEX:\n\n"); "LECIEX:\n\n");
for (i = 0; i < ctx->nsym; i++) { for (i = 0; i < ctx->nsym; i++) {
int pi = ctx->perm[i]; const char *name = ctx->sym[i].name;
int ni = ctx->perm[i+1]; int32_t size = ctx->sym[i+1].ofs - ctx->sym[i].ofs;
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, fprintf(ctx->fp,
"%s.eh:\n" "%s.eh:\n"
"LSFDE%d:\n" "LSFDE%d:\n"
@ -2448,7 +2432,6 @@ static void emit_asm_debug(BuildCtx *ctx)
"LEFDE%d:\n\n", "LEFDE%d:\n\n",
name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i); name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i);
} }
}
#if LJ_64 #if LJ_64
fprintf(ctx->fp, "\t.subsections_via_symbols\n"); fprintf(ctx->fp, "\t.subsections_via_symbols\n");
#else #else

View File

@ -5133,24 +5133,8 @@ static void emit_asm_debug(BuildCtx *ctx)
"\t.align " BSZPTR "\n" "\t.align " BSZPTR "\n"
"LECIEX:\n\n"); "LECIEX:\n\n");
for (i = 0; i < ctx->nsym; i++) { for (i = 0; i < ctx->nsym; i++) {
int pi = ctx->perm[i]; const char *name = ctx->sym[i].name;
int ni = ctx->perm[i+1]; int32_t size = ctx->sym[i+1].ofs - ctx->sym[i].ofs;
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, fprintf(ctx->fp,
"%s.eh:\n" "%s.eh:\n"
"LSFDE%d:\n" "LSFDE%d:\n"
@ -5177,7 +5161,6 @@ static void emit_asm_debug(BuildCtx *ctx)
"LEFDE%d:\n\n", "LEFDE%d:\n\n",
name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i); name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i);
} }
}
#if LJ_64 #if LJ_64
fprintf(ctx->fp, "\t.subsections_via_symbols\n"); fprintf(ctx->fp, "\t.subsections_via_symbols\n");
#else #else

View File

@ -2529,24 +2529,8 @@ static void emit_asm_debug(BuildCtx *ctx)
"\t.align " BSZPTR "\n" "\t.align " BSZPTR "\n"
"LECIEX:\n\n"); "LECIEX:\n\n");
for (i = 0; i < ctx->nsym; i++) { for (i = 0; i < ctx->nsym; i++) {
int pi = ctx->perm[i]; const char *name = ctx->sym[i].name;
int ni = ctx->perm[i+1]; int32_t size = ctx->sym[i+1].ofs - ctx->sym[i].ofs;
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, fprintf(ctx->fp,
"%s.eh:\n" "%s.eh:\n"
"LSFDE%d:\n" "LSFDE%d:\n"
@ -2573,7 +2557,6 @@ static void emit_asm_debug(BuildCtx *ctx)
"LEFDE%d:\n\n", "LEFDE%d:\n\n",
name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i); name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i);
} }
}
#if LJ_64 #if LJ_64
fprintf(ctx->fp, "\t.subsections_via_symbols\n"); fprintf(ctx->fp, "\t.subsections_via_symbols\n");
#else #else