[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


Hi,

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 
`svn://tug.org/texlive/trunk/Build/source@58686`.

Best,
Naveen


[0]: https://www.msys2.org
[1]: https://github.com/msys2/MINGW-packages/pull/8271
[2]: 
https://github.com/TeX-Live/texlive-source/blob/9bad8358d2f98a8bed86ecfa238db24c4965b9da/texk/texlive/w64_mingw_wrapper/runscript_dll.c
[3]: https://www.lua.org/pil/1.html
[4]: 
https://github.com/TeX-Live/texlive-source/blob/9bad8358d2f98a8bed86ecfa238db24c4965b9da/texk/texlive/w64_mingw_wrapper/runscript.tlu
[5]: 
https://github.com/TeX-Live/texlive-source/blob/9bad8358d2f98a8bed86ecfa238db24c4965b9da/texk/texlive/w64_mingw_wrapper/runscript.tlu#L419-L455
[6]: 
https://github.com/msys2/MINGW-packages/blob/3e2204b3fa18cd967b7aa616dfef9e2d89efb1ca/mingw-w64-texlive-bin/0002-fix-lauchers-mingw32.patch


More information about the dev-luatex mailing list