From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 67E245A9F2A; Mon, 4 Sep 2023 12:31:24 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 67E245A9F2A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1693819884; bh=w6PKXLi6bvUOYh3cBA7dK5Yq5KcUI08kgud5XShVdBI=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=CMWPdQ1YL1KGOmdqUA3+9EkYAnYoImKAkkHXteI8Aiq4C6QuxBjXLsEpkADb41P9B RUC/aH67o5nvrP/eQksrq0oHcx80S7j4Rp3PqjsTxp2y5o5h1ICzybti2lJ24BXts2 gSnmgxmosXNnpRuJnpWrW3MCa9xZ25mfzB5J5UGk= Received: from smtp47.i.mail.ru (smtp47.i.mail.ru [95.163.41.85]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id EF6E75A9F2A for ; Mon, 4 Sep 2023 12:31:22 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org EF6E75A9F2A Received: by smtp47.i.mail.ru with esmtpa (envelope-from ) id 1qd5vV-00Bj7n-1V; Mon, 04 Sep 2023 12:31:21 +0300 Message-ID: <1011cc5a-a628-450d-8c29-25972489bf0e@tarantool.org> Date: Mon, 4 Sep 2023 12:31:21 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 To: Maxim Kokryashkin , Sergey Bronnikov Cc: max.kokryashkin@gmail.com, tarantool-patches@dev.tarantool.org References: Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD96E142CFC92DB15CD43B17B8DE4233CAE5689C6DEE55D6799182A05F53808504074834022ED2912F18E736C9275025713ACE1B347DDC15727CEA7E786B3071ADB X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7A179494B5629353BEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006378997215BCAA11D778638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8BFEB7A96E1F6C5CA23A4AE416ABD95D9117882F4460429724CE54428C33FAD305F5C1EE8F4F765FC6D77D8F98F67F34EA471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18BDFBBEFFF4125B51D2E47CDBA5A96583BA9C0B312567BB2376E601842F6C81A19E625A9149C048EE9647ADFADE5905B1BFC1D8BB4B114D1ED8FC6C240DEA76429C9F4D5AE37F343AA9539A8B242431040A6AB1C7CE11FEE34CB6874B0BCFF0B8302FCEF25BFAB345C4224003CC836476E2F48590F00D11D6E2021AF6380DFAD1A18204E546F3947CB11811A4A51E3B096D1867E19FE1407959CC434672EE6371089D37D7C0E48F6C8AA50765F7900637D5EBF5C1E6A9BE26EFF80C71ABB335746BA297DBC24807EABDAD6C7F3747799A X-C1DE0DAB: 0D63561A33F958A568919FD1900655DF02EFA3BC60E88949298C00A86472F1B0F87CCE6106E1FC07E67D4AC08A07B9B04D3DDB508812D900CB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF0C1E13AC1DBEDB9959C193D3DFD9A1615428D9B20A82924672EBFC05523D07C8136FDBFCF0F91439EA61C66FA002EE27ACA2DDEAA06A5D7FB87682345B84F942A74DFFEFA5DC0E7F02C26D483E81D6BE0DBAE6F56676BC7117BB6831D7356A2DEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojNmsqR+t6vc+OY8KeJYuNzw== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A769BD6225D76422B0658E736C9275025713EC9A243AB1C8B1BCEBA65886582A37BD66FEC6BF5C9C28D98A98C1125256619760D574B6FC815AB872D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit 1/2][v2] Fix embedded bytecode loader. X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sergey Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Maxim On 9/1/23 12:42, Maxim Kokryashkin via Tarantool-patches wrote: >> diff --git a/test/tarantool-tests/lj-549-bytecode-loader.test.lua b/test/tarantool-tests/lj-549-bytecode-loader.test.lua >> new file mode 100644 >> index 00000000..889be80a >> --- /dev/null >> +++ b/test/tarantool-tests/lj-549-bytecode-loader.test.lua >> @@ -0,0 +1,96 @@ >> +local tap = require('tap') >> +local ffi = require('ffi') >> +local utils = require('utils') >> +local test = tap.test('lj-549-bytecode-loader'):skipcond({ >> + -- ['Test requires GC64 mode enabled'] = not require('ffi').abi('gc64'), > Why this skipcond is commented out? it is not needed anymore, so I removed it. Iterative patch is below: --- a/test/tarantool-tests/lj-549-bytecode-loader.test.lua +++ b/test/tarantool-tests/lj-549-bytecode-loader.test.lua @@ -1,9 +1,7 @@  local tap = require('tap')  local ffi = require('ffi')  local utils = require('utils') -local test = tap.test('lj-549-bytecode-loader'):skipcond({ -    -- ['Test requires GC64 mode enabled'] = not require('ffi').abi('gc64'), -}) +local test = tap.test('lj-549-bytecode-loader')  test:plan(1) >> +}) >> + >> +test:plan(1) >> + >> +-- Test creates a shared library with LuaJIT bytecode, >> +-- loads shared library as a Lua module and checks, >> +-- that no crashes eliminated. >> +-- >> +-- $ 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 function file_exists(fname) >> + return io.open(fname, 'r') or true and false >> +end >> + >> +local function get_file_name(file) >> + return file:match("[^/]*$") >> +end >> + >> +local stdout_msg = 'Lango team' >> +local lua_code = ('print(%q)'):format(stdout_msg) >> +local fpath = os.tmpname() >> +local path_lua = ('%s.lua'):format(fpath) >> +local path_c = ('%s.c'):format(fpath) >> +local path_so = ('%s.so'):format(fpath) >> + >> +-- Create a file with a minimal Lua code. >> +local fh = assert(io.open(path_lua, 'w')) >> +fh:write(lua_code) >> +fh:close() >> + >> +local module_name = assert(get_file_name(fpath)) >> + >> +local basedir = function(path) >> + local sep = '/' >> + return path:match('(.*' .. sep .. ')') or './' >> +end >> + >> +-- Create a C file with LuaJIT bytecode. >> +-- We cannot use utils.makecmd, because command-line generated >> +-- by `makecmd` contains `-e` that is incompatible with option `-b`. >> +local function create_c_file(pathlua, pathc) >> + local lua_path = os.getenv('LUA_PATH') >> + local lua_bin = require('utils').exec.luacmd(arg):match('%S+') >> + local cmd_fmt = 'LUA_PATH="%s" %s -b %s %s' >> + local cmd = (cmd_fmt):format(lua_path, lua_bin, pathlua, pathc) >> + local ret = os.execute(cmd) >> + assert(ret == 0, 'create a C file with bytecode') >> +end >> + >> +create_c_file(path_lua, path_c) >> +assert(file_exists(path_c)) >> + >> +-- Compile C source code with LuaJIT bytecode to a shared library. >> +-- `-m64` is not available on ARM64, see >> +-- "3.18.1 AArch64 Options in the manual", >> +-- https://gcc.gnu.org/onlinedocs/gcc/AArch64-Options.html >> +local cflags_64 = jit.arch == 'arm64' and '-march=armv8-a' or '-m64' >> +local cflags = ffi.abi('32bit') and '-m32' or cflags_64 >> +local cc_cmd = ('cc %s -fPIC -shared %s -o %s'):format(cflags, path_c, path_so) >> +local ph = io.popen(cc_cmd) >> +ph:close() > I suggest using the os.execute and checking the exit code. > Popen is excessive here. replaced, iterative patch is below --- a/test/tarantool-tests/lj-549-bytecode-loader.test.lua +++ b/test/tarantool-tests/lj-549-bytecode-loader.test.lua @@ -68,8 +68,8 @@ assert(file_exists(path_c))  local cflags_64 = jit.arch == 'arm64' and '-march=armv8-a' or '-m64'  local cflags = ffi.abi('32bit') and '-m32' or cflags_64  local cc_cmd = ('cc %s -fPIC -shared %s -o %s'):format(cflags, path_c, path_so) -local ph = io.popen(cc_cmd) -ph:close() +local rc = os.execute(cc_cmd) +assert(rc == 0)  assert(file_exists(path_so))  -- Load shared library as a Lua module. > >> +assert(file_exists(path_so)) >> + >> +-- Load shared library as a Lua module. >> +local lua_cpath = ('"/tmp/?.so;"'):format(basedir(fpath)) >> +assert(file_exists(path_so)) >> +local cmd = utils.exec.makecmd(arg, { >> + script = ('-e "require([[%s]])"'):format(module_name), >> + env = { >> + LUA_CPATH = lua_cpath, >> + -- It is required to cleanup LUA_PATH, otherwise >> + -- LuaJIT loads Lua module, see tarantool-tests/utils/init.lua. >> + LUA_PATH = '', >> + }, >> +}) >> +local res = cmd() >> +test:ok(res == stdout_msg, 'bytecode loader works') >> + >> +os.remove(path_lua) >> +os.remove(path_c) >> +os.remove(path_so) >> + >> +os.exit(test:check() and 0 or 1) > `test:done` should be used instead. Fixed. @@ -91,4 +91,4 @@ os.remove(path_lua)  os.remove(path_c)  os.remove(path_so) -os.exit(test:check() and 0 or 1) +test:done(true) >> -- >> 2.34.1 >>