[Dev-luatex] i686-mingw: texlua.exe FFI module not working

Naveen M K naveen at syrusdark.website
Mon Apr 26 12:24:37 CEST 2021


I had been trying to compile TexLive on MINGW compilers on Windows 
provided by MSYS2[0] project. See this PR[1]. It was only for 
i686-mingw. x86-64-mingw worked without any problems.

I found that there was Segmentation Fault(or crash) when running the 
`runscript.exe` the launchers which TexLive provides on Windows and I 
could see it uses LuaTeX. You can find the source here[2]. What is 
essentially does is calls the `texlua.exe` with `runscript.tlu` passed 
it in. I initially thought it was a problem with compiled version of the 
launcher itself, but it wasn't it, it was a problem with `texlua.exe`.

`runscript.exe` just returns the code returned from `texlua.exe` and the 
return code was a crash and there is a popup which say the program isn't 
working correctly and crashed at `ntdll.dll`.

While just running `texlua.exe` on a normal hello world lua script[3] 
works without any crash or error. So, I thought something from the code 
in `runscript.tlu`[4] should be causing this issue. I don't know how to 
debug a lua script, so my plan was to randomly place print statements 
(you know that is the easiest and best way to debug something), and 
whether it printed or not. I first looked over the `runscript.tlu` to 
see if there are parts of code which could crash the interpreter and I 
found this block of code[5] which uses ffi module.

Now I placed print statements before and after

	local runscripthandle = ffi.C.GetModuleHandleA("runscript.dll")

and found that the one before was printed and `texlua.exe` crashed. So 
it is something related to ffi module. I tried the same with 
`texluajit.exe` and it seemed to work. What I did to make the launchers 
work was to patch this [6] and it worked without any problem.

But that isn't the actual fix the Crash in `texlua.exe` on using ffi 
module in `i686-mingw`. I hope anybody will help me fix this. For the 
version, I am building TexLive with this 
`ccb6338507149edf2772bfccb9933b72761f4cc4` commit on GitHub or 


[0]: https://www.msys2.org
[1]: https://github.com/msys2/MINGW-packages/pull/8271
[3]: https://www.lua.org/pil/1.html

More information about the dev-luatex mailing list