diff options
| author | Mike Pall <mike> | 2014-12-08 01:58:05 +0100 |
|---|---|---|
| committer | Mike Pall <mike> | 2014-12-08 01:58:05 +0100 |
| commit | e03df1e3395bc719d43bd9196d0290757f992b2f (patch) | |
| tree | 98a2a827c4b83900e7b330d82c5d369caf642db4 /src/host | |
| parent | f49c61a2776ae9abeb2297dbc3b53ea2962ad750 (diff) | |
| download | luajit-e03df1e3395bc719d43bd9196d0290757f992b2f.tar.gz luajit-e03df1e3395bc719d43bd9196d0290757f992b2f.tar.bz2 luajit-e03df1e3395bc719d43bd9196d0290757f992b2f.zip | |
x86/x64: Call external symbols directly from interpreter code.
Except for ELF/x86 PIC, where it's easier to use wrappers.
Diffstat (limited to 'src/host')
| -rw-r--r-- | src/host/buildvm.c | 1 | ||||
| -rw-r--r-- | src/host/buildvm.h | 1 | ||||
| -rw-r--r-- | src/host/buildvm_asm.c | 23 |
3 files changed, 21 insertions, 4 deletions
diff --git a/src/host/buildvm.c b/src/host/buildvm.c index 37b20ae2..d56c65ca 100644 --- a/src/host/buildvm.c +++ b/src/host/buildvm.c | |||
| @@ -179,6 +179,7 @@ static int build_code(BuildCtx *ctx) | |||
| 179 | ctx->nreloc = 0; | 179 | ctx->nreloc = 0; |
| 180 | 180 | ||
| 181 | ctx->globnames = globnames; | 181 | ctx->globnames = globnames; |
| 182 | ctx->extnames = extnames; | ||
| 182 | ctx->relocsym = (const char **)malloc(NRELOCSYM*sizeof(const char *)); | 183 | ctx->relocsym = (const char **)malloc(NRELOCSYM*sizeof(const char *)); |
| 183 | ctx->nrelocsym = 0; | 184 | ctx->nrelocsym = 0; |
| 184 | for (i = 0; i < (int)NRELOCSYM; i++) relocmap[i] = -1; | 185 | for (i = 0; i < (int)NRELOCSYM; i++) relocmap[i] = -1; |
diff --git a/src/host/buildvm.h b/src/host/buildvm.h index f9dc8c4f..b321bbda 100644 --- a/src/host/buildvm.h +++ b/src/host/buildvm.h | |||
| @@ -82,6 +82,7 @@ typedef struct BuildCtx { | |||
| 82 | const char *beginsym; | 82 | const char *beginsym; |
| 83 | /* Strings generated by DynASM. */ | 83 | /* Strings generated by DynASM. */ |
| 84 | const char *const *globnames; | 84 | const char *const *globnames; |
| 85 | const char *const *extnames; | ||
| 85 | const char *dasm_ident; | 86 | const char *dasm_ident; |
| 86 | const char *dasm_arch; | 87 | const char *dasm_arch; |
| 87 | /* Relocations. */ | 88 | /* Relocations. */ |
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. */ |
| 55 | static void emit_asm_reloc_mach(BuildCtx *ctx, uint8_t *cp, int n, | 55 | static 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]); |
