lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Okay, I've managed to isolate to a simple test case:

```
tostring(1.4999999999999999e-30)
```

This simple line crashes Lua 5.4 for me if it's not compiled with -D_FORTIFY_SOURCE=2 when using -O2.

```
lua5.4
Lua 5.4.0  Copyright (C) 1994-2020 Lua.org, PUC-Rio
> tostring(1.4999999999999999e-30)
Bus error (core dumped)
```

Em ter., 18 de ago. de 2020 às 15:04, Eduardo Bart <edub4rt@gmail.com> escreveu:
I have a large lua application that works fine with Lua 5.3 and Lua 5.4 that is shipped by my Linux package manager. However I've downloaded the Lua 5.4 sources and compiled myself and when using it I got a crash. I was intrigued because the sources of my system's Lua and the ones I downloaded were equal, just the compilation flags were different. So I decided to test each CFLAGS when compiling to see which one was effecting.

For instance my system compiles Lua 5.4 with the following flags:
gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -DLUA_USE_READLINE -march=native -O2 -pipe -fno-plt -fPIC -flto -g -D_FORTIFY_SOURCE=2

And I was manually compiling with the following flags:
gcc -DLUA_COMPAT_5_3 -DLUA_USE_LINUX -O2 -g

Changing the CFLAGS to the same CFLAGS used by my system my application didn't crash, then I ruled out each flag one by one, and I discovered the following:
Adding -D_FORTIFY_SOURCE=2 makes the crash go away with -O2.
Changing -O2 to -O1 (but not adding -D_FORTIFY_SOURCE=2) also makes the crash go away.

I've tried to use a different compiler, such as clang, and the crash still happens under the same conditions.
I've tried applying patches for all the known Lua 5.4 bugs, but the crash still happens under the same conditions.

And here is the full backtrace with symbols and source location:
https://pastebin.com/7ZAL1Edg
In that run -O2 -g flags were used, and I've used sources from the "v5.4.0-patch" branch for lua's github repository.

Unfortunately I don't have a small test case yet.

---
Eduardo Bart