diff options
author | Mike Pall <mike> | 2010-04-14 17:13:13 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2010-04-14 17:13:13 +0200 |
commit | ff82df797a5ddf6ed2610ff1808b1fdc53686ea1 (patch) | |
tree | b5d2f448f34ed2c9dd010503f8fd6410819ef95a /src | |
parent | fbe092c22d5df462d84749bada5a1e6bff4bf464 (diff) | |
download | luajit-ff82df797a5ddf6ed2610ff1808b1fdc53686ea1.tar.gz luajit-ff82df797a5ddf6ed2610ff1808b1fdc53686ea1.tar.bz2 luajit-ff82df797a5ddf6ed2610ff1808b1fdc53686ea1.zip |
Refactor buildvm symbol generation.
Fixes Windows and OSX builds with LUAJIT_DISABLE_JIT.
Diffstat (limited to 'src')
-rw-r--r-- | src/buildvm.c | 97 | ||||
-rw-r--r-- | src/buildvm.h | 17 | ||||
-rw-r--r-- | src/buildvm_asm.c | 67 | ||||
-rw-r--r-- | src/buildvm_peobj.c | 86 | ||||
-rw-r--r-- | src/buildvm_x64.h | 65 | ||||
-rw-r--r-- | src/buildvm_x64win.h | 65 | ||||
-rw-r--r-- | src/buildvm_x86.dasc | 65 | ||||
-rw-r--r-- | src/buildvm_x86.h | 65 |
8 files changed, 203 insertions, 324 deletions
diff --git a/src/buildvm.c b/src/buildvm.c index dd0cbcc6..1b4d6928 100644 --- a/src/buildvm.c +++ b/src/buildvm.c | |||
@@ -101,6 +101,33 @@ static void emit_raw(BuildCtx *ctx) | |||
101 | 101 | ||
102 | /* -- Build machine code -------------------------------------------------- */ | 102 | /* -- Build machine code -------------------------------------------------- */ |
103 | 103 | ||
104 | static const char *sym_decorate(BuildCtx *ctx, | ||
105 | const char *prefix, const char *suffix) | ||
106 | { | ||
107 | char name[256]; | ||
108 | char *p; | ||
109 | #if LJ_64 | ||
110 | const char *symprefix = ctx->mode == BUILD_machasm ? "_" : ""; | ||
111 | #else | ||
112 | const char *symprefix = ctx->mode != BUILD_elfasm ? "_" : ""; | ||
113 | #endif | ||
114 | sprintf(name, "%s%s%s", symprefix, prefix, suffix); | ||
115 | p = strchr(name, '@'); | ||
116 | if (p) { | ||
117 | if (!LJ_64 && (ctx->mode == BUILD_coffasm || ctx->mode == BUILD_peobj)) | ||
118 | name[0] = '@'; | ||
119 | else | ||
120 | *p = '\0'; | ||
121 | } | ||
122 | p = (char *)malloc(strlen(name)+1); /* MSVC doesn't like strdup. */ | ||
123 | strcpy(p, name); | ||
124 | return p; | ||
125 | } | ||
126 | |||
127 | #define NRELOCSYM (sizeof(extnames)/sizeof(extnames[0])-1) | ||
128 | |||
129 | static int relocmap[NRELOCSYM]; | ||
130 | |||
104 | /* Collect external relocations. */ | 131 | /* Collect external relocations. */ |
105 | static int collect_reloc(BuildCtx *ctx, uint8_t *addr, int idx, int type) | 132 | static int collect_reloc(BuildCtx *ctx, uint8_t *addr, int idx, int type) |
106 | { | 133 | { |
@@ -108,32 +135,38 @@ static int collect_reloc(BuildCtx *ctx, uint8_t *addr, int idx, int type) | |||
108 | fprintf(stderr, "Error: too many relocations, increase BUILD_MAX_RELOC.\n"); | 135 | fprintf(stderr, "Error: too many relocations, increase BUILD_MAX_RELOC.\n"); |
109 | exit(1); | 136 | exit(1); |
110 | } | 137 | } |
138 | if (relocmap[idx] < 0) { | ||
139 | relocmap[idx] = ctx->nrelocsym; | ||
140 | ctx->relocsym[ctx->nrelocsym] = sym_decorate(ctx, "", extnames[idx]); | ||
141 | ctx->nrelocsym++; | ||
142 | } | ||
111 | ctx->reloc[ctx->nreloc].ofs = (int32_t)(addr - ctx->code); | 143 | ctx->reloc[ctx->nreloc].ofs = (int32_t)(addr - ctx->code); |
112 | ctx->reloc[ctx->nreloc].sym = idx; | 144 | ctx->reloc[ctx->nreloc].sym = relocmap[idx]; |
113 | ctx->reloc[ctx->nreloc].type = type; | 145 | ctx->reloc[ctx->nreloc].type = type; |
114 | ctx->nreloc++; | 146 | ctx->nreloc++; |
115 | return 0; /* Encode symbol offset of 0. */ | 147 | return 0; /* Encode symbol offset of 0. */ |
116 | } | 148 | } |
117 | 149 | ||
118 | /* Naive insertion sort. Performance doesn't matter here. */ | 150 | /* Naive insertion sort. Performance doesn't matter here. */ |
119 | static void perm_insert(int *perm, int32_t *ofs, int i) | 151 | static void sym_insert(BuildCtx *ctx, int32_t ofs, |
152 | const char *prefix, const char *suffix) | ||
120 | { | 153 | { |
121 | perm[i] = i; | 154 | ptrdiff_t i = ctx->nsym++; |
122 | while (i > 0) { | 155 | while (i > 0) { |
123 | int a = perm[i-1]; | 156 | if (ctx->sym[i-1].ofs <= ofs) |
124 | int b = perm[i]; | 157 | break; |
125 | if (ofs[a] <= ofs[b]) break; | 158 | ctx->sym[i] = ctx->sym[i-1]; |
126 | perm[i] = a; | ||
127 | perm[i-1] = b; | ||
128 | i--; | 159 | i--; |
129 | } | 160 | } |
161 | ctx->sym[i].ofs = ofs; | ||
162 | ctx->sym[i].name = sym_decorate(ctx, prefix, suffix); | ||
130 | } | 163 | } |
131 | 164 | ||
132 | /* Build the machine code. */ | 165 | /* Build the machine code. */ |
133 | static int build_code(BuildCtx *ctx) | 166 | static int build_code(BuildCtx *ctx) |
134 | { | 167 | { |
135 | int status; | 168 | int status; |
136 | int i, j; | 169 | int i; |
137 | 170 | ||
138 | /* Initialize DynASM structures. */ | 171 | /* Initialize DynASM structures. */ |
139 | ctx->nglob = GLOB__MAX; | 172 | ctx->nglob = GLOB__MAX; |
@@ -141,8 +174,10 @@ static int build_code(BuildCtx *ctx) | |||
141 | memset(ctx->glob, 0, ctx->nglob*sizeof(void *)); | 174 | memset(ctx->glob, 0, ctx->nglob*sizeof(void *)); |
142 | ctx->nreloc = 0; | 175 | ctx->nreloc = 0; |
143 | 176 | ||
144 | ctx->extnames = extnames; | ||
145 | ctx->globnames = globnames; | 177 | ctx->globnames = globnames; |
178 | ctx->relocsym = (const char **)malloc(NRELOCSYM*sizeof(const char *)); | ||
179 | ctx->nrelocsym = 0; | ||
180 | for (i = 0; i < (int)NRELOCSYM; i++) relocmap[i] = -1; | ||
146 | 181 | ||
147 | ctx->dasm_ident = DASM_IDENT; | 182 | ctx->dasm_ident = DASM_IDENT; |
148 | ctx->dasm_arch = DASM_ARCH; | 183 | ctx->dasm_arch = DASM_ARCH; |
@@ -160,37 +195,41 @@ static int build_code(BuildCtx *ctx) | |||
160 | ctx->code = (uint8_t *)malloc(ctx->codesz); | 195 | ctx->code = (uint8_t *)malloc(ctx->codesz); |
161 | if ((status = dasm_encode(Dst, (void *)ctx->code))) return status; | 196 | if ((status = dasm_encode(Dst, (void *)ctx->code))) return status; |
162 | 197 | ||
163 | /* Allocate the symbol offset and permutation tables. */ | 198 | /* Allocate symbol table and bytecode offsets. */ |
164 | ctx->nsym = ctx->npc + ctx->nglob; | 199 | ctx->beginsym = sym_decorate(ctx, "", LABEL_PREFIX "vm_asm_begin"); |
165 | ctx->perm = (int *)malloc((ctx->nsym+1)*sizeof(int *)); | 200 | ctx->sym = (BuildSym *)malloc((ctx->npc+ctx->nglob+1)*sizeof(BuildSym)); |
166 | ctx->sym_ofs = (int32_t *)malloc((ctx->nsym+1)*sizeof(int32_t)); | 201 | ctx->nsym = 0; |
202 | ctx->bc_ofs = (int32_t *)malloc(ctx->npc*sizeof(int32_t)); | ||
167 | 203 | ||
168 | /* Collect the opcodes (PC labels). */ | 204 | /* Collect the opcodes (PC labels). */ |
169 | for (i = 0; i < ctx->npc; i++) { | 205 | for (i = 0; i < ctx->npc; i++) { |
170 | int32_t n = dasm_getpclabel(Dst, i); | 206 | int32_t ofs = dasm_getpclabel(Dst, i); |
171 | if (n < 0) return 0x22000000|i; | 207 | if (ofs < 0) return 0x22000000|i; |
172 | ctx->sym_ofs[i] = n; | 208 | ctx->bc_ofs[i] = ofs; |
173 | perm_insert(ctx->perm, ctx->sym_ofs, i); | 209 | #if !LJ_HASJIT |
210 | if (!(i == BC_JFORI || i == BC_JFORL || i == BC_JITERL || i == BC_JLOOP || | ||
211 | i == BC_IFORL || i == BC_IITERL || i == BC_ILOOP)) | ||
212 | #endif | ||
213 | sym_insert(ctx, ofs, LABEL_PREFIX_BC, bc_names[i]); | ||
174 | } | 214 | } |
175 | 215 | ||
176 | /* Collect the globals (named labels). */ | 216 | /* Collect the globals (named labels). */ |
177 | for (j = 0; j < ctx->nglob; j++, i++) { | 217 | for (i = 0; i < ctx->nglob; i++) { |
178 | const char *gl = globnames[j]; | 218 | const char *gl = globnames[i]; |
179 | int len = (int)strlen(gl); | 219 | int len = (int)strlen(gl); |
180 | if (!ctx->glob[j]) { | 220 | if (!ctx->glob[i]) { |
181 | fprintf(stderr, "Error: undefined global %s\n", gl); | 221 | fprintf(stderr, "Error: undefined global %s\n", gl); |
182 | exit(2); | 222 | exit(2); |
183 | } | 223 | } |
184 | if (len >= 2 && gl[len-2] == '_' && gl[len-1] == 'Z') | 224 | /* Skip the _Z symbols. */ |
185 | ctx->sym_ofs[i] = -1; /* Skip the _Z symbols. */ | 225 | if (!(len >= 2 && gl[len-2] == '_' && gl[len-1] == 'Z')) |
186 | else | 226 | sym_insert(ctx, (int32_t)((uint8_t *)(ctx->glob[i]) - ctx->code), |
187 | ctx->sym_ofs[i] = (int32_t)((uint8_t *)(ctx->glob[j]) - ctx->code); | 227 | LABEL_PREFIX, globnames[i]); |
188 | perm_insert(ctx->perm, ctx->sym_ofs, i); | ||
189 | } | 228 | } |
190 | 229 | ||
191 | /* Close the address range. */ | 230 | /* Close the address range. */ |
192 | ctx->sym_ofs[i] = (int32_t)ctx->codesz; | 231 | sym_insert(ctx, (int32_t)ctx->codesz, "", ""); |
193 | perm_insert(ctx->perm, ctx->sym_ofs, i); | 232 | ctx->nsym--; |
194 | 233 | ||
195 | dasm_free(Dst); | 234 | dasm_free(Dst); |
196 | 235 | ||
@@ -260,7 +299,7 @@ static void emit_bcdef(BuildCtx *ctx) | |||
260 | for (i = 0; i < ctx->npc; i++) { | 299 | for (i = 0; i < ctx->npc; i++) { |
261 | if (i != 0) | 300 | if (i != 0) |
262 | fprintf(ctx->fp, ",\n"); | 301 | fprintf(ctx->fp, ",\n"); |
263 | fprintf(ctx->fp, "%d", ctx->sym_ofs[i]); | 302 | fprintf(ctx->fp, "%d", ctx->bc_ofs[i]); |
264 | } | 303 | } |
265 | } | 304 | } |
266 | 305 | ||
diff --git a/src/buildvm.h b/src/buildvm.h index 6d242207..41038dd6 100644 --- a/src/buildvm.h +++ b/src/buildvm.h | |||
@@ -34,9 +34,6 @@ | |||
34 | #define LABEL_PREFIX_LIBCF LABEL_PREFIX "lib_cf_" | 34 | #define LABEL_PREFIX_LIBCF LABEL_PREFIX "lib_cf_" |
35 | #define LABEL_PREFIX_LIBINIT LABEL_PREFIX "lib_init_" | 35 | #define LABEL_PREFIX_LIBINIT LABEL_PREFIX "lib_init_" |
36 | 36 | ||
37 | /* Extra labels. */ | ||
38 | #define LABEL_ASM_BEGIN LABEL_PREFIX "vm_asm_begin" | ||
39 | |||
40 | /* Forward declaration. */ | 37 | /* Forward declaration. */ |
41 | struct dasm_State; | 38 | struct dasm_State; |
42 | 39 | ||
@@ -66,6 +63,11 @@ typedef struct BuildReloc { | |||
66 | int type; | 63 | int type; |
67 | } BuildReloc; | 64 | } BuildReloc; |
68 | 65 | ||
66 | typedef struct BuildSym { | ||
67 | const char *name; | ||
68 | int32_t ofs; | ||
69 | } BuildSym; | ||
70 | |||
69 | /* Build context structure. */ | 71 | /* Build context structure. */ |
70 | typedef struct BuildCtx { | 72 | typedef struct BuildCtx { |
71 | /* DynASM state pointer. Should be first member. */ | 73 | /* DynASM state pointer. Should be first member. */ |
@@ -78,12 +80,13 @@ typedef struct BuildCtx { | |||
78 | /* Code and symbols generated by DynASM. */ | 80 | /* Code and symbols generated by DynASM. */ |
79 | uint8_t *code; | 81 | uint8_t *code; |
80 | size_t codesz; | 82 | size_t codesz; |
81 | int npc, nglob, nsym, nreloc; | 83 | int npc, nglob, nsym, nreloc, nrelocsym; |
82 | void **glob; | 84 | void **glob; |
83 | int *perm; | 85 | BuildSym *sym; |
84 | int32_t *sym_ofs; | 86 | const char **relocsym; |
87 | int32_t *bc_ofs; | ||
88 | const char *beginsym; | ||
85 | /* Strings generated by DynASM. */ | 89 | /* Strings generated by DynASM. */ |
86 | const char *const *extnames; | ||
87 | const char *const *globnames; | 90 | const char *const *globnames; |
88 | const char *dasm_ident; | 91 | const char *dasm_ident; |
89 | const char *dasm_arch; | 92 | const char *dasm_arch; |
diff --git a/src/buildvm_asm.c b/src/buildvm_asm.c index b135b864..1898f0d5 100644 --- a/src/buildvm_asm.c +++ b/src/buildvm_asm.c | |||
@@ -123,74 +123,33 @@ static void emit_asm_align(BuildCtx *ctx, int bits) | |||
123 | /* Emit assembler source code. */ | 123 | /* Emit assembler source code. */ |
124 | void emit_asm(BuildCtx *ctx) | 124 | void emit_asm(BuildCtx *ctx) |
125 | { | 125 | { |
126 | char name[80]; | 126 | int i, rel; |
127 | int32_t prev; | ||
128 | int i, pi, rel; | ||
129 | #if LJ_64 | ||
130 | const char *symprefix = ctx->mode == BUILD_machasm ? "_" : ""; | ||
131 | int keepfc = 0; | ||
132 | #else | ||
133 | const char *symprefix = ctx->mode != BUILD_elfasm ? "_" : ""; | ||
134 | /* Keep fastcall suffix for COFF on WIN32. */ | ||
135 | int keepfc = (ctx->mode == BUILD_coffasm); | ||
136 | #endif | ||
137 | 127 | ||
138 | fprintf(ctx->fp, "\t.file \"buildvm_%s.dasc\"\n", ctx->dasm_arch); | 128 | fprintf(ctx->fp, "\t.file \"buildvm_%s.dasc\"\n", ctx->dasm_arch); |
139 | fprintf(ctx->fp, "\t.text\n"); | 129 | fprintf(ctx->fp, "\t.text\n"); |
140 | emit_asm_align(ctx, 4); | 130 | emit_asm_align(ctx, 4); |
141 | 131 | ||
142 | sprintf(name, "%s" LABEL_ASM_BEGIN, symprefix); | 132 | emit_asm_label(ctx, ctx->beginsym, 0, 0); |
143 | emit_asm_label(ctx, name, 0, 0); | ||
144 | if (ctx->mode != BUILD_machasm) | 133 | if (ctx->mode != BUILD_machasm) |
145 | fprintf(ctx->fp, ".Lbegin:\n"); | 134 | fprintf(ctx->fp, ".Lbegin:\n"); |
146 | 135 | ||
147 | i = 0; | 136 | for (i = rel = 0; i < ctx->nsym; i++) { |
148 | do { | 137 | int32_t ofs = ctx->sym[i].ofs; |
149 | pi = ctx->perm[i++]; | 138 | int32_t next = ctx->sym[i+1].ofs; |
150 | prev = ctx->sym_ofs[pi]; | 139 | emit_asm_label(ctx, ctx->sym[i].name, next - ofs, 1); |
151 | } while (prev < 0); /* Skip the _Z symbols. */ | 140 | while (rel < ctx->nreloc && ctx->reloc[rel].ofs < next) { |
152 | |||
153 | for (rel = 0; i <= ctx->nsym; i++) { | ||
154 | int ni = ctx->perm[i]; | ||
155 | int32_t next = ctx->sym_ofs[ni]; | ||
156 | int size = (int)(next - prev); | ||
157 | int32_t stop = next; | ||
158 | if (pi >= ctx->npc) { | ||
159 | char *p; | ||
160 | sprintf(name, "%s" LABEL_PREFIX "%s", symprefix, | ||
161 | ctx->globnames[pi-ctx->npc]); | ||
162 | p = strchr(name, '@'); | ||
163 | if (p) { if (keepfc) name[0] = '@'; else *p = '\0'; } | ||
164 | emit_asm_label(ctx, name, size, 1); | ||
165 | #if LJ_HASJIT | ||
166 | } else { | ||
167 | #else | ||
168 | } else if (!(pi == BC_JFORI || pi == BC_JFORL || pi == BC_JITERL || | ||
169 | pi == BC_JLOOP || pi == BC_IFORL || pi == BC_IITERL || | ||
170 | pi == BC_ILOOP)) { | ||
171 | #endif | ||
172 | sprintf(name, "%s" LABEL_PREFIX_BC "%s", symprefix, bc_names[pi]); | ||
173 | emit_asm_label(ctx, name, size, 1); | ||
174 | } | ||
175 | while (rel < ctx->nreloc && ctx->reloc[rel].ofs < stop) { | ||
176 | BuildReloc *r = &ctx->reloc[rel]; | 141 | BuildReloc *r = &ctx->reloc[rel]; |
177 | int n = r->ofs - prev; | 142 | int n = r->ofs - ofs; |
178 | char *p; | ||
179 | sprintf(name, "%s%s", symprefix, ctx->extnames[r->sym]); | ||
180 | p = strchr(name, '@'); | ||
181 | if (p) { if (keepfc) name[0] = '@'; else *p = '\0'; } | ||
182 | if (ctx->mode == BUILD_machasm && r->type != 0) { | 143 | if (ctx->mode == BUILD_machasm && r->type != 0) { |
183 | emit_asm_reloc_mach(ctx, ctx->code+prev, n, name); | 144 | emit_asm_reloc_mach(ctx, ctx->code+ofs, n, ctx->relocsym[r->sym]); |
184 | } else { | 145 | } else { |
185 | emit_asm_bytes(ctx, ctx->code+prev, n); | 146 | emit_asm_bytes(ctx, ctx->code+ofs, n); |
186 | emit_asm_reloc(ctx, r->type, name); | 147 | emit_asm_reloc(ctx, r->type, ctx->relocsym[r->sym]); |
187 | } | 148 | } |
188 | prev += n+4; | 149 | ofs += n+4; |
189 | rel++; | 150 | rel++; |
190 | } | 151 | } |
191 | emit_asm_bytes(ctx, ctx->code+prev, stop-prev); | 152 | emit_asm_bytes(ctx, ctx->code+ofs, next-ofs); |
192 | prev = next; | ||
193 | pi = ni; | ||
194 | } | 153 | } |
195 | 154 | ||
196 | fprintf(ctx->fp, "\n"); | 155 | fprintf(ctx->fp, "\n"); |
diff --git a/src/buildvm_peobj.c b/src/buildvm_peobj.c index 2ff274f9..4cde6e00 100644 --- a/src/buildvm_peobj.c +++ b/src/buildvm_peobj.c | |||
@@ -84,14 +84,11 @@ typedef struct PEsymaux { | |||
84 | #define PEOBJ_ARCH_TARGET 0x014c | 84 | #define PEOBJ_ARCH_TARGET 0x014c |
85 | #define PEOBJ_RELOC_REL32 0x14 /* MS: REL32, GNU: DISP32. */ | 85 | #define PEOBJ_RELOC_REL32 0x14 /* MS: REL32, GNU: DISP32. */ |
86 | #define PEOBJ_RELOC_DIR32 0x06 | 86 | #define PEOBJ_RELOC_DIR32 0x06 |
87 | #define PEOBJ_SYM_PREFIX "_" | ||
88 | #define PEOBJ_SYMF_PREFIX "@" | ||
89 | #elif LJ_TARGET_X64 | 87 | #elif LJ_TARGET_X64 |
90 | #define PEOBJ_ARCH_TARGET 0x8664 | 88 | #define PEOBJ_ARCH_TARGET 0x8664 |
91 | #define PEOBJ_RELOC_REL32 0x04 /* MS: REL32, GNU: DISP32. */ | 89 | #define PEOBJ_RELOC_REL32 0x04 /* MS: REL32, GNU: DISP32. */ |
92 | #define PEOBJ_RELOC_DIR32 0x02 | 90 | #define PEOBJ_RELOC_DIR32 0x02 |
93 | #define PEOBJ_RELOC_ADDR32NB 0x03 | 91 | #define PEOBJ_RELOC_ADDR32NB 0x03 |
94 | #define PEOBJ_SYM_PREFIX "" | ||
95 | #endif | 92 | #endif |
96 | 93 | ||
97 | /* Section numbers (0-based). */ | 94 | /* Section numbers (0-based). */ |
@@ -164,18 +161,13 @@ static void emit_peobj_sym_sect(BuildCtx *ctx, PEsection *pesect, int sect) | |||
164 | owrite(ctx, &aux, PEOBJ_SYM_SIZE); | 161 | owrite(ctx, &aux, PEOBJ_SYM_SIZE); |
165 | } | 162 | } |
166 | 163 | ||
167 | #define emit_peobj_sym_func(ctx, name, ofs) \ | ||
168 | emit_peobj_sym(ctx, name, (uint32_t)(ofs), \ | ||
169 | PEOBJ_SECT_TEXT, PEOBJ_TYPE_FUNC, PEOBJ_SCL_EXTERN) | ||
170 | |||
171 | /* Emit Windows PE object file. */ | 164 | /* Emit Windows PE object file. */ |
172 | void emit_peobj(BuildCtx *ctx) | 165 | void emit_peobj(BuildCtx *ctx) |
173 | { | 166 | { |
174 | PEheader pehdr; | 167 | PEheader pehdr; |
175 | PEsection pesect[PEOBJ_NSECTIONS]; | 168 | PEsection pesect[PEOBJ_NSECTIONS]; |
176 | int nzsym, relocsyms; | ||
177 | uint32_t sofs; | 169 | uint32_t sofs; |
178 | int i; | 170 | int i, nrsym; |
179 | union { uint8_t b; uint32_t u; } host_endian; | 171 | union { uint8_t b; uint32_t u; } host_endian; |
180 | 172 | ||
181 | host_endian.u = 1; | 173 | host_endian.u = 1; |
@@ -230,16 +222,11 @@ void emit_peobj(BuildCtx *ctx) | |||
230 | 222 | ||
231 | /* Compute the size of the symbol table: | 223 | /* Compute the size of the symbol table: |
232 | ** @feat.00 + nsections*2 | 224 | ** @feat.00 + nsections*2 |
233 | ** + asm_start + (nsyms-nzsym) | 225 | ** + asm_start + nsym |
234 | ** + relocsyms | 226 | ** + nrsym |
235 | */ | 227 | */ |
236 | /* Skip _Z syms. */ | 228 | nrsym = ctx->nrelocsym; |
237 | for (nzsym = 0; ctx->sym_ofs[ctx->perm[nzsym]] < 0; nzsym++) ; | 229 | pehdr.nsyms = 1+PEOBJ_NSECTIONS*2 + 1+ctx->nsym + nrsym; |
238 | for (relocsyms = 0; ctx->extnames[relocsyms]; relocsyms++) ; | ||
239 | pehdr.nsyms = 1+PEOBJ_NSECTIONS*2 + 1+(ctx->nsym-nzsym) + relocsyms; | ||
240 | #if !LJ_HASJIT | ||
241 | pehdr.nsyms -= 11; /* See below, removes [IJ]* opcode symbols. */ | ||
242 | #endif | ||
243 | #if LJ_TARGET_X64 | 230 | #if LJ_TARGET_X64 |
244 | pehdr.nsyms += 1; /* Symbol for lj_err_unwind_win64. */ | 231 | pehdr.nsyms += 1; /* Symbol for lj_err_unwind_win64. */ |
245 | #endif | 232 | #endif |
@@ -264,13 +251,13 @@ void emit_peobj(BuildCtx *ctx) | |||
264 | PEreloc reloc; | 251 | PEreloc reloc; |
265 | pdata[0] = 0; pdata[1] = (uint32_t)ctx->codesz; pdata[2] = 0; | 252 | pdata[0] = 0; pdata[1] = (uint32_t)ctx->codesz; pdata[2] = 0; |
266 | owrite(ctx, &pdata, sizeof(pdata)); | 253 | owrite(ctx, &pdata, sizeof(pdata)); |
267 | reloc.vaddr = 0; reloc.symidx = 1+2+relocsyms+2+2+1; | 254 | reloc.vaddr = 0; reloc.symidx = 1+2+nrsym+2+2+1; |
268 | reloc.type = PEOBJ_RELOC_ADDR32NB; | 255 | reloc.type = PEOBJ_RELOC_ADDR32NB; |
269 | owrite(ctx, &reloc, PEOBJ_RELOC_SIZE); | 256 | owrite(ctx, &reloc, PEOBJ_RELOC_SIZE); |
270 | reloc.vaddr = 4; reloc.symidx = 1+2+relocsyms+2+2+1; | 257 | reloc.vaddr = 4; reloc.symidx = 1+2+nrsym+2+2+1; |
271 | reloc.type = PEOBJ_RELOC_ADDR32NB; | 258 | reloc.type = PEOBJ_RELOC_ADDR32NB; |
272 | owrite(ctx, &reloc, PEOBJ_RELOC_SIZE); | 259 | owrite(ctx, &reloc, PEOBJ_RELOC_SIZE); |
273 | reloc.vaddr = 8; reloc.symidx = 1+2+relocsyms+2; | 260 | reloc.vaddr = 8; reloc.symidx = 1+2+nrsym+2; |
274 | reloc.type = PEOBJ_RELOC_ADDR32NB; | 261 | reloc.type = PEOBJ_RELOC_ADDR32NB; |
275 | owrite(ctx, &reloc, PEOBJ_RELOC_SIZE); | 262 | owrite(ctx, &reloc, PEOBJ_RELOC_SIZE); |
276 | } | 263 | } |
@@ -287,7 +274,7 @@ void emit_peobj(BuildCtx *ctx) | |||
287 | xdata[7] = 0; /* Alignment. */ | 274 | xdata[7] = 0; /* Alignment. */ |
288 | xdata[8] = xdata[9] = 0; /* Relocated address of exception handler. */ | 275 | xdata[8] = xdata[9] = 0; /* Relocated address of exception handler. */ |
289 | owrite(ctx, &xdata, sizeof(xdata)); | 276 | owrite(ctx, &xdata, sizeof(xdata)); |
290 | reloc.vaddr = sizeof(xdata)-4; reloc.symidx = 1+2+relocsyms+2+2; | 277 | reloc.vaddr = sizeof(xdata)-4; reloc.symidx = 1+2+nrsym+2+2; |
291 | reloc.type = PEOBJ_RELOC_ADDR32NB; | 278 | reloc.type = PEOBJ_RELOC_ADDR32NB; |
292 | owrite(ctx, &reloc, PEOBJ_RELOC_SIZE); | 279 | owrite(ctx, &reloc, PEOBJ_RELOC_SIZE); |
293 | } | 280 | } |
@@ -299,69 +286,28 @@ void emit_peobj(BuildCtx *ctx) | |||
299 | /* Write symbol table. */ | 286 | /* Write symbol table. */ |
300 | strtab = NULL; /* 1st pass: collect string sizes. */ | 287 | strtab = NULL; /* 1st pass: collect string sizes. */ |
301 | for (;;) { | 288 | for (;;) { |
302 | char name[80]; | ||
303 | |||
304 | strtabofs = 4; | 289 | strtabofs = 4; |
305 | /* Mark as SafeSEH compliant. */ | 290 | /* Mark as SafeSEH compliant. */ |
306 | emit_peobj_sym(ctx, "@feat.00", 1, | 291 | emit_peobj_sym(ctx, "@feat.00", 1, |
307 | PEOBJ_SECT_ABS, PEOBJ_TYPE_NULL, PEOBJ_SCL_STATIC); | 292 | PEOBJ_SECT_ABS, PEOBJ_TYPE_NULL, PEOBJ_SCL_STATIC); |
308 | 293 | ||
309 | emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_TEXT); | 294 | emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_TEXT); |
310 | for (i = 0; ctx->extnames[i]; i++) { | 295 | for (i = 0; i < nrsym; i++) |
311 | const char *sym = ctx->extnames[i]; | 296 | emit_peobj_sym(ctx, ctx->relocsym[i], 0, |
312 | const char *p = strchr(sym, '@'); | ||
313 | if (p) { | ||
314 | #ifdef PEOBJ_SYMF_PREFIX | ||
315 | sprintf(name, PEOBJ_SYMF_PREFIX "%s", sym); | ||
316 | #else | ||
317 | strncpy(name, sym, p-sym); | ||
318 | name[p-sym] = '\0'; | ||
319 | #endif | ||
320 | } else { | ||
321 | sprintf(name, PEOBJ_SYM_PREFIX "%s", sym); | ||
322 | } | ||
323 | emit_peobj_sym(ctx, name, 0, | ||
324 | PEOBJ_SECT_UNDEF, PEOBJ_TYPE_FUNC, PEOBJ_SCL_EXTERN); | 297 | PEOBJ_SECT_UNDEF, PEOBJ_TYPE_FUNC, PEOBJ_SCL_EXTERN); |
325 | } | ||
326 | 298 | ||
327 | #if LJ_TARGET_X64 | 299 | #if LJ_TARGET_X64 |
328 | emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_PDATA); | 300 | emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_PDATA); |
329 | emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_XDATA); | 301 | emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_XDATA); |
330 | emit_peobj_sym(ctx, PEOBJ_SYM_PREFIX "lj_err_unwind_win64", 0, | 302 | emit_peobj_sym(ctx, "lj_err_unwind_win64", 0, |
331 | PEOBJ_SECT_UNDEF, PEOBJ_TYPE_FUNC, PEOBJ_SCL_EXTERN); | 303 | PEOBJ_SECT_UNDEF, PEOBJ_TYPE_FUNC, PEOBJ_SCL_EXTERN); |
332 | #endif | 304 | #endif |
333 | 305 | ||
334 | emit_peobj_sym(ctx, PEOBJ_SYM_PREFIX LABEL_ASM_BEGIN, 0, | 306 | emit_peobj_sym(ctx, ctx->beginsym, 0, |
335 | PEOBJ_SECT_TEXT, PEOBJ_TYPE_NULL, PEOBJ_SCL_EXTERN); | 307 | PEOBJ_SECT_TEXT, PEOBJ_TYPE_NULL, PEOBJ_SCL_EXTERN); |
336 | for (i = nzsym; i < ctx->nsym; i++) { | 308 | for (i = 0; i < ctx->nsym; i++) |
337 | int pi = ctx->perm[i]; | 309 | emit_peobj_sym(ctx, ctx->sym[i].name, (uint32_t)ctx->sym[i].ofs, |
338 | if (pi >= ctx->npc) { | 310 | PEOBJ_SECT_TEXT, PEOBJ_TYPE_FUNC, PEOBJ_SCL_EXTERN); |
339 | const char *sym = ctx->globnames[pi-ctx->npc]; | ||
340 | const char *p = strchr(sym, '@'); | ||
341 | if (p) { | ||
342 | #ifdef PEOBJ_SYMF_PREFIX | ||
343 | sprintf(name, PEOBJ_SYMF_PREFIX LABEL_PREFIX "%s", sym); | ||
344 | #else | ||
345 | sprintf(name, LABEL_PREFIX "%s", sym); | ||
346 | name[(p-sym)+sizeof(LABEL_PREFIX)-1] = '\0'; | ||
347 | #endif | ||
348 | } else { | ||
349 | sprintf(name, PEOBJ_SYM_PREFIX LABEL_PREFIX "%s", sym); | ||
350 | } | ||
351 | emit_peobj_sym_func(ctx, name, ctx->sym_ofs[pi]); | ||
352 | #if LJ_HASJIT | ||
353 | } else { | ||
354 | #else | ||
355 | } else if (!(pi == BC_JFORI || pi == BC_JFORL || pi == BC_JITERL || | ||
356 | pi == BC_JLOOP || pi == BC_JFUNCF || pi == BC_JFUNCV || | ||
357 | pi == BC_IFORL || pi == BC_IITERL || pi == BC_ILOOP || | ||
358 | pi == BC_IFUNCF || pi == BC_IFUNCV)) { | ||
359 | #endif | ||
360 | sprintf(name, PEOBJ_SYM_PREFIX LABEL_PREFIX_BC "%s", | ||
361 | bc_names[pi]); | ||
362 | emit_peobj_sym_func(ctx, name, ctx->sym_ofs[pi]); | ||
363 | } | ||
364 | } | ||
365 | 311 | ||
366 | emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_RDATA_Z); | 312 | emit_peobj_sym_sect(ctx, pesect, PEOBJ_SECT_RDATA_Z); |
367 | 313 | ||
diff --git a/src/buildvm_x64.h b/src/buildvm_x64.h index b8d8f60a..747253fd 100644 --- a/src/buildvm_x64.h +++ b/src/buildvm_x64.h | |||
@@ -2403,50 +2403,33 @@ static void emit_asm_debug(BuildCtx *ctx) | |||
2403 | "\t.align " BSZPTR "\n" | 2403 | "\t.align " BSZPTR "\n" |
2404 | "LECIEX:\n\n"); | 2404 | "LECIEX:\n\n"); |
2405 | for (i = 0; i < ctx->nsym; i++) { | 2405 | for (i = 0; i < ctx->nsym; i++) { |
2406 | int pi = ctx->perm[i]; | 2406 | const char *name = ctx->sym[i].name; |
2407 | int ni = ctx->perm[i+1]; | 2407 | int32_t size = ctx->sym[i+1].ofs - ctx->sym[i].ofs; |
2408 | int size = ctx->sym_ofs[ni] - ctx->sym_ofs[pi]; | 2408 | fprintf(ctx->fp, |
2409 | if (ctx->sym_ofs[pi] >= 0 && size > 0) { | 2409 | "%s.eh:\n" |
2410 | char name[80]; | 2410 | "LSFDE%d:\n" |
2411 | if (pi >= ctx->npc) { | 2411 | "\t.set L$set$%d,LEFDE%d-LASFDE%d\n" |
2412 | char *p; | 2412 | "\t.long L$set$%d\n" |
2413 | sprintf(name, "_" LABEL_PREFIX "%s", ctx->globnames[pi - ctx->npc]); | 2413 | "LASFDE%d:\n" |
2414 | p = strchr(name, '@'); if (p) *p = '\0'; | 2414 | "\t.long LASFDE%d-EH_frame1\n" |
2415 | #if LJ_HASJIT | 2415 | "\t.long %s-.\n" |
2416 | } else { | 2416 | "\t.long %d\n" |
2417 | #else | 2417 | "\t.byte 0\n" /* augmentation length */ |
2418 | } else if (!(pi == BC_JFORI || pi == BC_JFORL || pi == BC_JITERL || | 2418 | "\t.byte 0xe\n\t.byte %d\n" /* def_cfa_offset */ |
2419 | pi == BC_JLOOP || pi == BC_IFORL || pi == BC_IITERL || | ||
2420 | pi == BC_ILOOP)) { | ||
2421 | #endif | ||
2422 | sprintf(name, "_" LABEL_PREFIX_BC "%s", bc_names[pi]); | ||
2423 | } | ||
2424 | fprintf(ctx->fp, | ||
2425 | "%s.eh:\n" | ||
2426 | "LSFDE%d:\n" | ||
2427 | "\t.set L$set$%d,LEFDE%d-LASFDE%d\n" | ||
2428 | "\t.long L$set$%d\n" | ||
2429 | "LASFDE%d:\n" | ||
2430 | "\t.long LASFDE%d-EH_frame1\n" | ||
2431 | "\t.long %s-.\n" | ||
2432 | "\t.long %d\n" | ||
2433 | "\t.byte 0\n" /* augmentation length */ | ||
2434 | "\t.byte 0xe\n\t.byte %d\n" /* def_cfa_offset */ | ||
2435 | #if LJ_64 | 2419 | #if LJ_64 |
2436 | "\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */ | 2420 | "\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */ |
2437 | "\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */ | 2421 | "\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */ |
2438 | "\t.byte 0x8f\n\t.byte 0x4\n" /* offset r15 */ | 2422 | "\t.byte 0x8f\n\t.byte 0x4\n" /* offset r15 */ |
2439 | "\t.byte 0x8e\n\t.byte 0x5\n" /* offset r14 */ | 2423 | "\t.byte 0x8e\n\t.byte 0x5\n" /* offset r14 */ |
2440 | #else | 2424 | #else |
2441 | "\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/ | 2425 | "\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/ |
2442 | "\t.byte 0x87\n\t.byte 0x3\n" /* offset edi */ | 2426 | "\t.byte 0x87\n\t.byte 0x3\n" /* offset edi */ |
2443 | "\t.byte 0x86\n\t.byte 0x4\n" /* offset esi */ | 2427 | "\t.byte 0x86\n\t.byte 0x4\n" /* offset esi */ |
2444 | "\t.byte 0x83\n\t.byte 0x5\n" /* offset ebx */ | 2428 | "\t.byte 0x83\n\t.byte 0x5\n" /* offset ebx */ |
2445 | #endif | 2429 | #endif |
2446 | "\t.align " BSZPTR "\n" | 2430 | "\t.align " BSZPTR "\n" |
2447 | "LEFDE%d:\n\n", | 2431 | "LEFDE%d:\n\n", |
2448 | name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i); | 2432 | name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i); |
2449 | } | ||
2450 | } | 2433 | } |
2451 | #if LJ_64 | 2434 | #if LJ_64 |
2452 | fprintf(ctx->fp, "\t.subsections_via_symbols\n"); | 2435 | fprintf(ctx->fp, "\t.subsections_via_symbols\n"); |
diff --git a/src/buildvm_x64win.h b/src/buildvm_x64win.h index 7876c9b3..b5cc4679 100644 --- a/src/buildvm_x64win.h +++ b/src/buildvm_x64win.h | |||
@@ -2404,50 +2404,33 @@ static void emit_asm_debug(BuildCtx *ctx) | |||
2404 | "\t.align " BSZPTR "\n" | 2404 | "\t.align " BSZPTR "\n" |
2405 | "LECIEX:\n\n"); | 2405 | "LECIEX:\n\n"); |
2406 | for (i = 0; i < ctx->nsym; i++) { | 2406 | for (i = 0; i < ctx->nsym; i++) { |
2407 | int pi = ctx->perm[i]; | 2407 | const char *name = ctx->sym[i].name; |
2408 | int ni = ctx->perm[i+1]; | 2408 | int32_t size = ctx->sym[i+1].ofs - ctx->sym[i].ofs; |
2409 | int size = ctx->sym_ofs[ni] - ctx->sym_ofs[pi]; | 2409 | fprintf(ctx->fp, |
2410 | if (ctx->sym_ofs[pi] >= 0 && size > 0) { | 2410 | "%s.eh:\n" |
2411 | char name[80]; | 2411 | "LSFDE%d:\n" |
2412 | if (pi >= ctx->npc) { | 2412 | "\t.set L$set$%d,LEFDE%d-LASFDE%d\n" |
2413 | char *p; | 2413 | "\t.long L$set$%d\n" |
2414 | sprintf(name, "_" LABEL_PREFIX "%s", ctx->globnames[pi - ctx->npc]); | 2414 | "LASFDE%d:\n" |
2415 | p = strchr(name, '@'); if (p) *p = '\0'; | 2415 | "\t.long LASFDE%d-EH_frame1\n" |
2416 | #if LJ_HASJIT | 2416 | "\t.long %s-.\n" |
2417 | } else { | 2417 | "\t.long %d\n" |
2418 | #else | 2418 | "\t.byte 0\n" /* augmentation length */ |
2419 | } else if (!(pi == BC_JFORI || pi == BC_JFORL || pi == BC_JITERL || | 2419 | "\t.byte 0xe\n\t.byte %d\n" /* def_cfa_offset */ |
2420 | pi == BC_JLOOP || pi == BC_IFORL || pi == BC_IITERL || | ||
2421 | pi == BC_ILOOP)) { | ||
2422 | #endif | ||
2423 | sprintf(name, "_" LABEL_PREFIX_BC "%s", bc_names[pi]); | ||
2424 | } | ||
2425 | fprintf(ctx->fp, | ||
2426 | "%s.eh:\n" | ||
2427 | "LSFDE%d:\n" | ||
2428 | "\t.set L$set$%d,LEFDE%d-LASFDE%d\n" | ||
2429 | "\t.long L$set$%d\n" | ||
2430 | "LASFDE%d:\n" | ||
2431 | "\t.long LASFDE%d-EH_frame1\n" | ||
2432 | "\t.long %s-.\n" | ||
2433 | "\t.long %d\n" | ||
2434 | "\t.byte 0\n" /* augmentation length */ | ||
2435 | "\t.byte 0xe\n\t.byte %d\n" /* def_cfa_offset */ | ||
2436 | #if LJ_64 | 2420 | #if LJ_64 |
2437 | "\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */ | 2421 | "\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */ |
2438 | "\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */ | 2422 | "\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */ |
2439 | "\t.byte 0x8f\n\t.byte 0x4\n" /* offset r15 */ | 2423 | "\t.byte 0x8f\n\t.byte 0x4\n" /* offset r15 */ |
2440 | "\t.byte 0x8e\n\t.byte 0x5\n" /* offset r14 */ | 2424 | "\t.byte 0x8e\n\t.byte 0x5\n" /* offset r14 */ |
2441 | #else | 2425 | #else |
2442 | "\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/ | 2426 | "\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/ |
2443 | "\t.byte 0x87\n\t.byte 0x3\n" /* offset edi */ | 2427 | "\t.byte 0x87\n\t.byte 0x3\n" /* offset edi */ |
2444 | "\t.byte 0x86\n\t.byte 0x4\n" /* offset esi */ | 2428 | "\t.byte 0x86\n\t.byte 0x4\n" /* offset esi */ |
2445 | "\t.byte 0x83\n\t.byte 0x5\n" /* offset ebx */ | 2429 | "\t.byte 0x83\n\t.byte 0x5\n" /* offset ebx */ |
2446 | #endif | 2430 | #endif |
2447 | "\t.align " BSZPTR "\n" | 2431 | "\t.align " BSZPTR "\n" |
2448 | "LEFDE%d:\n\n", | 2432 | "LEFDE%d:\n\n", |
2449 | name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i); | 2433 | name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i); |
2450 | } | ||
2451 | } | 2434 | } |
2452 | #if LJ_64 | 2435 | #if LJ_64 |
2453 | fprintf(ctx->fp, "\t.subsections_via_symbols\n"); | 2436 | fprintf(ctx->fp, "\t.subsections_via_symbols\n"); |
diff --git a/src/buildvm_x86.dasc b/src/buildvm_x86.dasc index e0a70daa..579e39da 100644 --- a/src/buildvm_x86.dasc +++ b/src/buildvm_x86.dasc | |||
@@ -5133,50 +5133,33 @@ static void emit_asm_debug(BuildCtx *ctx) | |||
5133 | "\t.align " BSZPTR "\n" | 5133 | "\t.align " BSZPTR "\n" |
5134 | "LECIEX:\n\n"); | 5134 | "LECIEX:\n\n"); |
5135 | for (i = 0; i < ctx->nsym; i++) { | 5135 | for (i = 0; i < ctx->nsym; i++) { |
5136 | int pi = ctx->perm[i]; | 5136 | const char *name = ctx->sym[i].name; |
5137 | int ni = ctx->perm[i+1]; | 5137 | int32_t size = ctx->sym[i+1].ofs - ctx->sym[i].ofs; |
5138 | int size = ctx->sym_ofs[ni] - ctx->sym_ofs[pi]; | 5138 | fprintf(ctx->fp, |
5139 | if (ctx->sym_ofs[pi] >= 0 && size > 0) { | 5139 | "%s.eh:\n" |
5140 | char name[80]; | 5140 | "LSFDE%d:\n" |
5141 | if (pi >= ctx->npc) { | 5141 | "\t.set L$set$%d,LEFDE%d-LASFDE%d\n" |
5142 | char *p; | 5142 | "\t.long L$set$%d\n" |
5143 | sprintf(name, "_" LABEL_PREFIX "%s", ctx->globnames[pi - ctx->npc]); | 5143 | "LASFDE%d:\n" |
5144 | p = strchr(name, '@'); if (p) *p = '\0'; | 5144 | "\t.long LASFDE%d-EH_frame1\n" |
5145 | #if LJ_HASJIT | 5145 | "\t.long %s-.\n" |
5146 | } else { | 5146 | "\t.long %d\n" |
5147 | #else | 5147 | "\t.byte 0\n" /* augmentation length */ |
5148 | } else if (!(pi == BC_JFORI || pi == BC_JFORL || pi == BC_JITERL || | 5148 | "\t.byte 0xe\n\t.byte %d\n" /* def_cfa_offset */ |
5149 | pi == BC_JLOOP || pi == BC_IFORL || pi == BC_IITERL || | ||
5150 | pi == BC_ILOOP)) { | ||
5151 | #endif | ||
5152 | sprintf(name, "_" LABEL_PREFIX_BC "%s", bc_names[pi]); | ||
5153 | } | ||
5154 | fprintf(ctx->fp, | ||
5155 | "%s.eh:\n" | ||
5156 | "LSFDE%d:\n" | ||
5157 | "\t.set L$set$%d,LEFDE%d-LASFDE%d\n" | ||
5158 | "\t.long L$set$%d\n" | ||
5159 | "LASFDE%d:\n" | ||
5160 | "\t.long LASFDE%d-EH_frame1\n" | ||
5161 | "\t.long %s-.\n" | ||
5162 | "\t.long %d\n" | ||
5163 | "\t.byte 0\n" /* augmentation length */ | ||
5164 | "\t.byte 0xe\n\t.byte %d\n" /* def_cfa_offset */ | ||
5165 | #if LJ_64 | 5149 | #if LJ_64 |
5166 | "\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */ | 5150 | "\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */ |
5167 | "\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */ | 5151 | "\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */ |
5168 | "\t.byte 0x8f\n\t.byte 0x4\n" /* offset r15 */ | 5152 | "\t.byte 0x8f\n\t.byte 0x4\n" /* offset r15 */ |
5169 | "\t.byte 0x8e\n\t.byte 0x5\n" /* offset r14 */ | 5153 | "\t.byte 0x8e\n\t.byte 0x5\n" /* offset r14 */ |
5170 | #else | 5154 | #else |
5171 | "\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/ | 5155 | "\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/ |
5172 | "\t.byte 0x87\n\t.byte 0x3\n" /* offset edi */ | 5156 | "\t.byte 0x87\n\t.byte 0x3\n" /* offset edi */ |
5173 | "\t.byte 0x86\n\t.byte 0x4\n" /* offset esi */ | 5157 | "\t.byte 0x86\n\t.byte 0x4\n" /* offset esi */ |
5174 | "\t.byte 0x83\n\t.byte 0x5\n" /* offset ebx */ | 5158 | "\t.byte 0x83\n\t.byte 0x5\n" /* offset ebx */ |
5175 | #endif | 5159 | #endif |
5176 | "\t.align " BSZPTR "\n" | 5160 | "\t.align " BSZPTR "\n" |
5177 | "LEFDE%d:\n\n", | 5161 | "LEFDE%d:\n\n", |
5178 | name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i); | 5162 | name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i); |
5179 | } | ||
5180 | } | 5163 | } |
5181 | #if LJ_64 | 5164 | #if LJ_64 |
5182 | fprintf(ctx->fp, "\t.subsections_via_symbols\n"); | 5165 | fprintf(ctx->fp, "\t.subsections_via_symbols\n"); |
diff --git a/src/buildvm_x86.h b/src/buildvm_x86.h index fec4d3f9..c36e2aa5 100644 --- a/src/buildvm_x86.h +++ b/src/buildvm_x86.h | |||
@@ -2529,50 +2529,33 @@ static void emit_asm_debug(BuildCtx *ctx) | |||
2529 | "\t.align " BSZPTR "\n" | 2529 | "\t.align " BSZPTR "\n" |
2530 | "LECIEX:\n\n"); | 2530 | "LECIEX:\n\n"); |
2531 | for (i = 0; i < ctx->nsym; i++) { | 2531 | for (i = 0; i < ctx->nsym; i++) { |
2532 | int pi = ctx->perm[i]; | 2532 | const char *name = ctx->sym[i].name; |
2533 | int ni = ctx->perm[i+1]; | 2533 | int32_t size = ctx->sym[i+1].ofs - ctx->sym[i].ofs; |
2534 | int size = ctx->sym_ofs[ni] - ctx->sym_ofs[pi]; | 2534 | fprintf(ctx->fp, |
2535 | if (ctx->sym_ofs[pi] >= 0 && size > 0) { | 2535 | "%s.eh:\n" |
2536 | char name[80]; | 2536 | "LSFDE%d:\n" |
2537 | if (pi >= ctx->npc) { | 2537 | "\t.set L$set$%d,LEFDE%d-LASFDE%d\n" |
2538 | char *p; | 2538 | "\t.long L$set$%d\n" |
2539 | sprintf(name, "_" LABEL_PREFIX "%s", ctx->globnames[pi - ctx->npc]); | 2539 | "LASFDE%d:\n" |
2540 | p = strchr(name, '@'); if (p) *p = '\0'; | 2540 | "\t.long LASFDE%d-EH_frame1\n" |
2541 | #if LJ_HASJIT | 2541 | "\t.long %s-.\n" |
2542 | } else { | 2542 | "\t.long %d\n" |
2543 | #else | 2543 | "\t.byte 0\n" /* augmentation length */ |
2544 | } else if (!(pi == BC_JFORI || pi == BC_JFORL || pi == BC_JITERL || | 2544 | "\t.byte 0xe\n\t.byte %d\n" /* def_cfa_offset */ |
2545 | pi == BC_JLOOP || pi == BC_IFORL || pi == BC_IITERL || | ||
2546 | pi == BC_ILOOP)) { | ||
2547 | #endif | ||
2548 | sprintf(name, "_" LABEL_PREFIX_BC "%s", bc_names[pi]); | ||
2549 | } | ||
2550 | fprintf(ctx->fp, | ||
2551 | "%s.eh:\n" | ||
2552 | "LSFDE%d:\n" | ||
2553 | "\t.set L$set$%d,LEFDE%d-LASFDE%d\n" | ||
2554 | "\t.long L$set$%d\n" | ||
2555 | "LASFDE%d:\n" | ||
2556 | "\t.long LASFDE%d-EH_frame1\n" | ||
2557 | "\t.long %s-.\n" | ||
2558 | "\t.long %d\n" | ||
2559 | "\t.byte 0\n" /* augmentation length */ | ||
2560 | "\t.byte 0xe\n\t.byte %d\n" /* def_cfa_offset */ | ||
2561 | #if LJ_64 | 2545 | #if LJ_64 |
2562 | "\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */ | 2546 | "\t.byte 0x86\n\t.byte 0x2\n" /* offset rbp */ |
2563 | "\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */ | 2547 | "\t.byte 0x83\n\t.byte 0x3\n" /* offset rbx */ |
2564 | "\t.byte 0x8f\n\t.byte 0x4\n" /* offset r15 */ | 2548 | "\t.byte 0x8f\n\t.byte 0x4\n" /* offset r15 */ |
2565 | "\t.byte 0x8e\n\t.byte 0x5\n" /* offset r14 */ | 2549 | "\t.byte 0x8e\n\t.byte 0x5\n" /* offset r14 */ |
2566 | #else | 2550 | #else |
2567 | "\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/ | 2551 | "\t.byte 0x84\n\t.byte 0x2\n" /* offset ebp (4 for MACH-O)*/ |
2568 | "\t.byte 0x87\n\t.byte 0x3\n" /* offset edi */ | 2552 | "\t.byte 0x87\n\t.byte 0x3\n" /* offset edi */ |
2569 | "\t.byte 0x86\n\t.byte 0x4\n" /* offset esi */ | 2553 | "\t.byte 0x86\n\t.byte 0x4\n" /* offset esi */ |
2570 | "\t.byte 0x83\n\t.byte 0x5\n" /* offset ebx */ | 2554 | "\t.byte 0x83\n\t.byte 0x5\n" /* offset ebx */ |
2571 | #endif | 2555 | #endif |
2572 | "\t.align " BSZPTR "\n" | 2556 | "\t.align " BSZPTR "\n" |
2573 | "LEFDE%d:\n\n", | 2557 | "LEFDE%d:\n\n", |
2574 | name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i); | 2558 | name, i, i, i, i, i, i, i, name, size, CFRAME_SIZE, i); |
2575 | } | ||
2576 | } | 2559 | } |
2577 | #if LJ_64 | 2560 | #if LJ_64 |
2578 | fprintf(ctx->fp, "\t.subsections_via_symbols\n"); | 2561 | fprintf(ctx->fp, "\t.subsections_via_symbols\n"); |