forked from LuaJIT/LuaJIT
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(cherry-picked from commit 8203399) The original problem is specific to x32 and is as follows: when a chunk with a bytecode library is loaded into memory, and the address is higher than 0x80000100, the `LexState->pe`, that contains an address of the end of the bytecode chunk in the memory, will wrap around and become smaller than the address in `LexState->p`, that contains an address of the beginning of bytecode chunk in the memory. In `bcread_fill()` called by `bcread_want()`, `memcpy()` is called with a very large size and causes the bus error on x86 and the segmentation fault on ARM Android. The problem cannot be reproduced on platforms supported by Tarantool (ARM64, x86_64), so test doesn't reproduce a problem without a patch and tests the patch partially. Sergey Bronnikov: * added the description and the test Part of tarantool/tarantool#8825
- Loading branch information
Showing
8 changed files
with
65 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
local tap = require('tap') | ||
local test = tap.test('lj-549-bytecode-loader') | ||
|
||
test:plan(2) | ||
|
||
-- Test creates a shared library with LuaJIT bytecode, | ||
-- loads shared library as a Lua module and checks, | ||
-- that no crashes eliminated. | ||
-- | ||
-- Manual steps for reproducing are the following: | ||
-- | ||
-- $ make HOST_CC='gcc -m32' TARGET_CFLAGS='-m32' \ | ||
-- TARGET_LDFLAGS='-m32' \ | ||
-- TARGET_SHLDFLAGS='-m32' \ | ||
-- -f Makefile.original | ||
-- $ echo 'print("test")' > a.lua | ||
-- $ LUA_PATH="src/?.lua;;" luajit -b a.lua a.c | ||
-- $ gcc -m32 -fPIC -shared a.c -o a.so | ||
-- $ luajit -e "require('a')" | ||
-- Program received signal SIGBUS, Bus error | ||
|
||
local module_name = 'script' | ||
local ok, module = pcall(require, module_name) | ||
test:is(ok, true, 'bytecode loader works') | ||
test:is(module.msg, 'Lango team', 'message is ok') | ||
|
||
test:done(true) |
20 changes: 20 additions & 0 deletions
20
test/tarantool-tests/lj-549-bytecode-loader/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
set(LIB_NAME "script") | ||
set(LUA_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LIB_NAME}.lua) | ||
set(C_FILE ${LIB_NAME}.c) | ||
|
||
make_lua_path(LUA_PATH | ||
PATHS | ||
${PROJECT_SOURCE_DIR}/src/?.lua | ||
${PROJECT_SOURCE_DIR}/src/jit/?.lua | ||
) | ||
|
||
add_custom_target(export_bc | ||
COMMAND ${CMAKE_COMMAND} -E env LUA_PATH=${LUA_PATH} ${LUAJIT_BINARY} -b ${LUA_FILE} ${C_FILE} | ||
DEPENDS luajit-main ${LUA_FILE} | ||
BYPRODUCTS ${C_FILE} | ||
COMMENT "Exporting bytecode to a C file" | ||
VERBATIM | ||
) | ||
|
||
BuildTestCLib(${LIB_NAME} ${C_FILE}) | ||
add_dependencies(${LIB_NAME} export_bc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
return { | ||
msg = 'Lango team', | ||
} |