Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LuaJIT miscompilation #92

Open
digitcrusher opened this issue Aug 30, 2024 · 1 comment
Open

LuaJIT miscompilation #92

digitcrusher opened this issue Aug 30, 2024 · 1 comment

Comments

@digitcrusher
Copy link

The code below freezes with Ziglua's LuaJIT. The C++ translation of my example works correctly. I reckon this may be a problem with how LuaJIT is compiled by Ziglua? The culprit seems to be a JIT-compiled version of the JLOOP opcode.

main.lua:

-- Interestingly enough, this is the minimal number of X's that causes the hang-up.
local xs = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
for i = 1, #xs do end

main.zig:

pub fn main() !void {
  var gpa = @import("std").heap.GeneralPurposeAllocator(.{}){};
  defer _ = gpa.deinit();

  var vm = try @import("ziglua").Lua.init(&gpa.allocator());
  defer vm.deinit();
  vm.openLibs();

  try vm.doFile("main.lua");
}

build.zig:

const std = @import("std");

pub fn build(b: *std.Build) void {
  const target = b.standardTargetOptions(.{});
  const optimize = b.standardOptimizeOption(.{});
  const exe = b.addExecutable(.{
    .name = "ziglua-bug",
    .root_source_file = b.path("main.zig"),
    .target = target,
    .optimize = optimize,
  });
  exe.root_module.addImport("ziglua", b.dependency("ziglua", .{
    .lang = .luajit,
    .target = target,
    .optimize = optimize,
  }).module("ziglua"));
  b.installArtifact(exe);
}

build.zig.zon:

.{
  .name = "ziglua-bug",
  .version = "0.0.0",
  .dependencies = .{
    .ziglua = .{
      .url = "https://github.com/natecraddock/ziglua/archive/7479680.tar.gz",
      .hash = "122094a86e7171946ec9dc47ea22c4782511c26ae555a7e79e315ae857ccce15cfa5",
    },
  },
  .paths = .{
    "build.zig",
    "build.zig.zon",
    "main.zig",
  },
}
@natecraddock
Copy link
Owner

Hey there! LuaJIT support is still WIP because the build process is very complex and I haven't had time to dedicate to that. Sorry about that.

I am open to contributions though!

See #19 for tracking luajit support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants