Page MenuHomePhabricator

Lua should give better error message when trying to use LuaStandalone on ARM
Open, Needs TriagePublic

Description

Right now we do not ship a lua binary for lua standalone on linux in ARM. If the user tries to use scribunto in this situation, they get the error: Syntax Error "(" unexpected. This is a terrible error message to mean architecture not supported. We should show a better error message

Event Timeline

... WTF? Is it trying to execute the ELF binary as a shell script or something, rather than doing something sane like giving a "binary format not recognized" error?

Note: I didn't encounter this myself. Report was from irc. There was also a second report at https://www.mediawiki.org/wiki/Topic:Sqeu40egi1wa49a9 . Given there were two separate reports, I assumed it wasn't the one guy doing something weird (That would be my initial assumption for such an odd error message) but the general error condition that happens when running on wrong architecture.

It looks like it probably really is. On my (x86_64) system, bash gives a sensible error when passed the binary as the "script" but dash gives something similar to what's reported here.

$ bash lua5_1_5_linux_32_generic/lua 
lua5_1_5_linux_32_generic/lua: lua5_1_5_linux_32_generic/lua: cannot execute binary file
$ dash lua5_1_5_linux_32_generic/lua 
lua5_1_5_linux_32_generic/lua: 1: lua5_1_5_linux_32_generic/lua: Syntax error: "(" unexpected

And POSIX specifically says that, when the shell tries to execute a file, "If the execl() function fails due to an error equivalent to the [ENOEXEC] error, the shell shall execute a command equivalent to having a shell invoked with the command name as its first operand, with any remaining arguments passed to the new shell." Detecting that the file isn't even a text file (to avoid being stupid like this) is optional. Sigh.

The tricky part is detecting this situation. Probably the only thing we could do would be to use php_uname( 'm' ) and avoid the built-in binaries if it's not "i386" or "x86_64", and hope that's not too restrictive (e.g. that it never returns "x86_32" or "i686" or whatever).

The examples at https://en.wikipedia.org/wiki/Uname suggest i686 is somewhat common

Realistically, matching on /i\[3-6]86|x86.*|amd64/ would almost certainly get 99.999999999% of everything.