summaryrefslogtreecommitdiff
path: root/src/buildvm_asm.c
diff options
context:
space:
mode:
authorMike Pall <mike>2010-01-22 01:56:49 +0100
committerMike Pall <mike>2010-01-22 01:56:49 +0100
commit43f1e134709b06be7091ad8f6cfaaaa78adec886 (patch)
tree38d5819e5a6406c66cc2cf91bb5465d552d1c37b /src/buildvm_asm.c
parentc56811bb7acf40174ac9b63e69f58b42adf85bd7 (diff)
downloadluajit-43f1e134709b06be7091ad8f6cfaaaa78adec886.tar.gz
luajit-43f1e134709b06be7091ad8f6cfaaaa78adec886.tar.bz2
luajit-43f1e134709b06be7091ad8f6cfaaaa78adec886.zip
Integrate MinGW build with DWARF2 exception handling.
Only works with DWARF2-enabled GCC 4.x (not the default MinGW GCC). Fix fastcall symbol names for COFF assembler output. Add DWARF2 unwind info to COFF assembler output. Use COFF assembler mode for MinGW builds. Always enable the DWARF2 handler if compiled with GCC.
Diffstat (limited to 'src/buildvm_asm.c')
-rw-r--r--src/buildvm_asm.c60
1 files changed, 33 insertions, 27 deletions
diff --git a/src/buildvm_asm.c b/src/buildvm_asm.c
index bd835ebc..2d0ba3b5 100644
--- a/src/buildvm_asm.c
+++ b/src/buildvm_asm.c
@@ -33,14 +33,14 @@ static void emit_asm_reloc(BuildCtx *ctx, int type, const char *sym)
33 fprintf(ctx->fp, "\t.long %s\n", sym); 33 fprintf(ctx->fp, "\t.long %s\n", sym);
34 break; 34 break;
35 case BUILD_coffasm: 35 case BUILD_coffasm:
36 fprintf(ctx->fp, "\t.def _%s; .scl 3; .type 32; .endef\n", sym); 36 fprintf(ctx->fp, "\t.def %s; .scl 3; .type 32; .endef\n", sym);
37 if (type) 37 if (type)
38 fprintf(ctx->fp, "\t.long _%s-.-4\n", sym); 38 fprintf(ctx->fp, "\t.long %s-.-4\n", sym);
39 else 39 else
40 fprintf(ctx->fp, "\t.long _%s\n", sym); 40 fprintf(ctx->fp, "\t.long %s\n", sym);
41 break; 41 break;
42 default: /* BUILD_machasm for relative relocations handled below. */ 42 default: /* BUILD_machasm for relative relocations handled below. */
43 fprintf(ctx->fp, "\t.long _%s\n", sym); 43 fprintf(ctx->fp, "\t.long %s\n", sym);
44 break; 44 break;
45 } 45 }
46} 46}
@@ -70,7 +70,7 @@ err:
70 exit(1); 70 exit(1);
71 } 71 }
72 emit_asm_bytes(ctx, cp, n); 72 emit_asm_bytes(ctx, cp, n);
73 fprintf(ctx->fp, "\t%s _%s\n", opname, sym); 73 fprintf(ctx->fp, "\t%s %s\n", opname, sym);
74} 74}
75 75
76/* Emit an assembler label. */ 76/* Emit an assembler label. */
@@ -87,15 +87,15 @@ static void emit_asm_label(BuildCtx *ctx, const char *name, int size, int isfunc
87 name, name, name, isfunc ? "function" : "object", name, size, name); 87 name, name, name, isfunc ? "function" : "object", name, size, name);
88 break; 88 break;
89 case BUILD_coffasm: 89 case BUILD_coffasm:
90 fprintf(ctx->fp, "\n\t.globl _%s\n", name); 90 fprintf(ctx->fp, "\n\t.globl %s\n", name);
91 if (isfunc) 91 if (isfunc)
92 fprintf(ctx->fp, "\t.def _%s; .scl 3; .type 32; .endef\n", name); 92 fprintf(ctx->fp, "\t.def %s; .scl 3; .type 32; .endef\n", name);
93 fprintf(ctx->fp, "_%s:\n", name); 93 fprintf(ctx->fp, "%s:\n", name);
94 break; 94 break;
95 case BUILD_machasm: 95 case BUILD_machasm:
96 fprintf(ctx->fp, 96 fprintf(ctx->fp,
97 "\n\t.private_extern _%s\n" 97 "\n\t.private_extern %s\n"
98 "_%s:\n", name, name); 98 "%s:\n", name, name);
99 break; 99 break;
100 default: 100 default:
101 break; 101 break;
@@ -126,13 +126,22 @@ void emit_asm(BuildCtx *ctx)
126 char name[80]; 126 char name[80];
127 int32_t prev; 127 int32_t prev;
128 int i, pi, rel; 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
129 137
130 fprintf(ctx->fp, "\t.file \"buildvm_%s.dasc\"\n", ctx->dasm_arch); 138 fprintf(ctx->fp, "\t.file \"buildvm_%s.dasc\"\n", ctx->dasm_arch);
131 fprintf(ctx->fp, "\t.text\n"); 139 fprintf(ctx->fp, "\t.text\n");
132 emit_asm_align(ctx, 4); 140 emit_asm_align(ctx, 4);
133 141
134 emit_asm_label(ctx, LABEL_ASM_BEGIN, 0, 0); 142 sprintf(name, "%s" LABEL_ASM_BEGIN, symprefix);
135 if (ctx->mode == BUILD_elfasm) 143 emit_asm_label(ctx, name, 0, 0);
144 if (ctx->mode != BUILD_machasm)
136 fprintf(ctx->fp, ".Lbegin:\n"); 145 fprintf(ctx->fp, ".Lbegin:\n");
137 146
138 i = 0; 147 i = 0;
@@ -148,10 +157,10 @@ void emit_asm(BuildCtx *ctx)
148 int32_t stop = next; 157 int32_t stop = next;
149 if (pi >= ctx->npc) { 158 if (pi >= ctx->npc) {
150 char *p; 159 char *p;
151 sprintf(name, LABEL_PREFIX "%s", ctx->globnames[pi-ctx->npc]); 160 sprintf(name, "%s" LABEL_PREFIX "%s", symprefix,
152 /* Always strip fastcall suffix. Wrong for (unused) COFF on Win32. */ 161 ctx->globnames[pi-ctx->npc]);
153 p = strchr(name, '@'); 162 p = strchr(name, '@');
154 if (p) *p = '\0'; 163 if (p) { if (keepfc) name[0] = '@'; else *p = '\0'; }
155 emit_asm_label(ctx, name, size, 1); 164 emit_asm_label(ctx, name, size, 1);
156#if LJ_HASJIT 165#if LJ_HASJIT
157 } else { 166 } else {
@@ -160,25 +169,21 @@ void emit_asm(BuildCtx *ctx)
160 pi == BC_JLOOP || pi == BC_IFORL || pi == BC_IITERL || 169 pi == BC_JLOOP || pi == BC_IFORL || pi == BC_IITERL ||
161 pi == BC_ILOOP)) { 170 pi == BC_ILOOP)) {
162#endif 171#endif
163 sprintf(name, LABEL_PREFIX_BC "%s", bc_names[pi]); 172 sprintf(name, "%s" LABEL_PREFIX_BC "%s", symprefix, bc_names[pi]);
164 emit_asm_label(ctx, name, size, 1); 173 emit_asm_label(ctx, name, size, 1);
165 } 174 }
166 while (rel < ctx->nreloc && ctx->reloc[rel].ofs < stop) { 175 while (rel < ctx->nreloc && ctx->reloc[rel].ofs < stop) {
167 BuildReloc *r = &ctx->reloc[rel]; 176 BuildReloc *r = &ctx->reloc[rel];
168 int n = r->ofs - prev; 177 int n = r->ofs - prev;
169 const char *sym = ctx->extnames[r->sym]; 178 char *p;
170 const char *p = strchr(sym, '@'); 179 sprintf(name, "%s%s", symprefix, ctx->extnames[r->sym]);
171 if (p) { 180 p = strchr(name, '@');
172 /* Always strip fastcall suffix. Wrong for (unused) COFF on Win32. */ 181 if (p) { if (keepfc) name[0] = '@'; else *p = '\0'; }
173 strncpy(name, sym, p-sym);
174 name[p-sym] = '\0';
175 sym = name;
176 }
177 if (ctx->mode == BUILD_machasm && r->type != 0) { 182 if (ctx->mode == BUILD_machasm && r->type != 0) {
178 emit_asm_reloc_mach(ctx, ctx->code+prev, n, sym); 183 emit_asm_reloc_mach(ctx, ctx->code+prev, n, name);
179 } else { 184 } else {
180 emit_asm_bytes(ctx, ctx->code+prev, n); 185 emit_asm_bytes(ctx, ctx->code+prev, n);
181 emit_asm_reloc(ctx, r->type, sym); 186 emit_asm_reloc(ctx, r->type, name);
182 } 187 }
183 prev += n+4; 188 prev += n+4;
184 rel++; 189 rel++;
@@ -203,7 +208,8 @@ void emit_asm(BuildCtx *ctx)
203 } 208 }
204 emit_asm_align(ctx, 5); 209 emit_asm_align(ctx, 5);
205 210
206 emit_asm_label(ctx, LABEL_OP_OFS, 2*ctx->npc, 0); 211 sprintf(name, "%s" LABEL_OP_OFS, symprefix);
212 emit_asm_label(ctx, name, 2*ctx->npc, 0);
207 for (i = 0; i < ctx->npc; i++) 213 for (i = 0; i < ctx->npc; i++)
208 fprintf(ctx->fp, "\t.short %d\n", ctx->sym_ofs[i]); 214 fprintf(ctx->fp, "\t.short %d\n", ctx->sym_ofs[i]);
209 215