aboutsummaryrefslogtreecommitdiff
path: root/src/host/buildvm_asm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/host/buildvm_asm.c')
-rw-r--r--src/host/buildvm_asm.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/host/buildvm_asm.c b/src/host/buildvm_asm.c
index 079e9a80..c91f5bcd 100644
--- a/src/host/buildvm_asm.c
+++ b/src/host/buildvm_asm.c
@@ -51,8 +51,8 @@ static const char *const jccnames[] = {
51 "js", "jns", "jpe", "jpo", "jl", "jge", "jle", "jg" 51 "js", "jns", "jpe", "jpo", "jl", "jge", "jle", "jg"
52}; 52};
53 53
54/* Emit relocation for the incredibly stupid OSX assembler. */ 54/* Emit x86/x64 text relocations. */
55static void emit_asm_reloc_mach(BuildCtx *ctx, uint8_t *cp, int n, 55static void emit_asm_reloc_text(BuildCtx *ctx, uint8_t *cp, int n,
56 const char *sym) 56 const char *sym)
57{ 57{
58 const char *opname = NULL; 58 const char *opname = NULL;
@@ -71,6 +71,20 @@ err:
71 exit(1); 71 exit(1);
72 } 72 }
73 emit_asm_bytes(ctx, cp, n); 73 emit_asm_bytes(ctx, cp, n);
74 if (strncmp(sym+(*sym == '_'), LABEL_PREFIX, sizeof(LABEL_PREFIX)-1)) {
75 /* Various fixups for external symbols outside of our binary. */
76 if (ctx->mode == BUILD_elfasm) {
77 if (LJ_32)
78 fprintf(ctx->fp, "#if __PIC__\n\t%s lj_wrap_%s\n#else\n", opname, sym);
79 fprintf(ctx->fp, "\t%s %s@PLT\n", opname, sym);
80 if (LJ_32)
81 fprintf(ctx->fp, "#endif\n");
82 return;
83 } else if (LJ_32 && ctx->mode == BUILD_machasm) {
84 fprintf(ctx->fp, "\t%s L%s$stub\n", opname, sym);
85 return;
86 }
87 }
74 fprintf(ctx->fp, "\t%s %s\n", opname, sym); 88 fprintf(ctx->fp, "\t%s %s\n", opname, sym);
75} 89}
76#else 90#else
@@ -254,8 +268,9 @@ void emit_asm(BuildCtx *ctx)
254 BuildReloc *r = &ctx->reloc[rel]; 268 BuildReloc *r = &ctx->reloc[rel];
255 int n = r->ofs - ofs; 269 int n = r->ofs - ofs;
256#if LJ_TARGET_X86ORX64 270#if LJ_TARGET_X86ORX64
257 if (ctx->mode == BUILD_machasm && r->type != 0) { 271 if (r->type != 0 &&
258 emit_asm_reloc_mach(ctx, ctx->code+ofs, n, ctx->relocsym[r->sym]); 272 (ctx->mode == BUILD_elfasm || ctx->mode == BUILD_machasm)) {
273 emit_asm_reloc_text(ctx, ctx->code+ofs, n, ctx->relocsym[r->sym]);
259 } else { 274 } else {
260 emit_asm_bytes(ctx, ctx->code+ofs, n); 275 emit_asm_bytes(ctx, ctx->code+ofs, n);
261 emit_asm_reloc(ctx, r->type, ctx->relocsym[r->sym]); 276 emit_asm_reloc(ctx, r->type, ctx->relocsym[r->sym]);