Giter Site home page Giter Site logo

openresty / luajit2 Goto Github PK

View Code? Open in Web Editor NEW
1.2K 82.0 189.0 8.93 MB

OpenResty's Branch of LuaJIT 2

Home Page: https://luajit.org/luajit.html

License: Other

Makefile 1.16% C 78.92% Lua 17.77% C++ 0.45% Batchfile 0.87% Roff 0.07% Shell 0.01% Perl 0.43% Terra 0.32%

luajit2's Introduction

Name

openresty/luajit2 - OpenResty's maintained branch of LuaJIT.

Table of Contents

Description

This is the official OpenResty branch of LuaJIT. It is not to be considered a fork, since we still regularly synchronize changes from the upstream LuaJIT project (https://github.com/LuaJIT/LuaJIT).

OpenResty extensions

Additionally to synchronizing upstream changes, we introduce our own changes which haven't been merged yet (or never will be). This document describes those changes that are specific to this branch.

New Lua APIs

table.isempty

syntax: res = isempty(tab)

Returns true when the given Lua table contains neither non-nil array elements nor non-nil key-value pairs, or false otherwise.

This API can be JIT compiled.

Usage:

local isempty = require "table.isempty"

print(isempty({}))  -- true
print(isempty({nil, dog = nil}))  -- true
print(isempty({"a", "b"}))  -- false
print(isempty({nil, 3}))  -- false
print(isempty({cat = 3}))  -- false

Back to TOC

table.isarray

syntax: res = isarray(tab)

Returns true when the given Lua table is a pure array-like Lua table, or false otherwise.

Empty Lua tables are treated as arrays.

This API can be JIT compiled.

Usage:

local isarray = require "table.isarray"

print(isarray{"a", true, 3.14})  -- true
print(isarray{dog = 3})  -- false
print(isarray{})  -- true

Back to TOC

table.nkeys

syntax: n = nkeys(tab)

Returns the total number of elements in a given Lua table (i.e. from both the array and hash parts combined).

This API can be JIT compiled.

Usage:

local nkeys = require "table.nkeys"

print(nkeys({}))  -- 0
print(nkeys({ "a", nil, "b" }))  -- 2
print(nkeys({ dog = 3, cat = 4, bird = nil }))  -- 2
print(nkeys({ "a", dog = 3, cat = 4 }))  -- 3

Back to TOC

table.clone

syntax: t = clone(tab)

Returns a shallow copy of the given Lua table.

This API can be JIT compiled.

Usage:

local clone = require "table.clone"

local x = {x=12, y={5, 6, 7}}
local y = clone(x)
... use y ...

Note: We observe 7% over-all speedup in the edgelang-fan compiler's compiling speed whose Lua is generated by the fanlang compiler.

Note bis: Deep cloning is planned to be supported by adding true as a second argument.

Back to TOC

jit.prngstate

syntax: state = jit.prngstate(state?)

Returns (and optionally sets) the current PRNG state (an array of 8 Lua numbers with 32-bit integer values) currently used by the JIT compiler.

When the state argument is non-nil, it is expected to be an array of up to 8 unsigned Lua numbers, each with value less than 2**32-1. This will set the current PRNG state and return the state that was overridden.

Note: For backward compatibility, state argument can also be an unsigned Lua number less than 2**32-1.

Note: When the state argument is an array and less than 8 numbers, or the state is a number, the remaining positions are filled with zeros.

Usage:

local state = jit.prngstate()
local oldstate = jit.prngstate{ a, b, c, ... }

jit.prngstate(32) -- {32, 0, 0, 0, 0, 0, 0, 0}
jit.prngstate{432, 23, 50} -- {432, 23, 50, 0, 0, 0, 0, 0}

Note: This API has no effect if LuaJIT is compiled with -DLUAJIT_DISABLE_JIT, and will return a table with all 0.

Back to TOC

thread.exdata

syntax: exdata = th_exdata(data?)

This API allows for embedding user data into a thread (lua_State).

The retrieved exdata value on the Lua land is represented as a cdata object of the ctype void*.

As of this version, retrieving the exdata (i.e. th_exdata() without any argument) can be JIT compiled.

Usage:

local th_exdata = require "thread.exdata"

th_exdata(0xdeadbeefLL)  -- set the exdata of the current Lua thread
local exdata = th_exdata()  -- fetch the exdata of the current Lua thread

Also available are the following public C API functions for manipulating exdata on the C land:

void lua_setexdata(lua_State *L, void *exdata);
void *lua_getexdata(lua_State *L);

The exdata pointer is initialized to NULL when the main thread is created. Any child Lua thread will inherit its parent's exdata, but still can override it.

Note: This API will not be available if LuaJIT is compiled with -DLUAJIT_DISABLE_FFI.

Note bis: This API is used internally by the OpenResty core, and it is strongly discouraged to use it yourself in the context of OpenResty.

Back to TOC

thread.exdata2

syntax: exdata = th_exdata2(data?)

Similar to thread.exdata but for a 2nd separate user data as a pointer value.

Back to TOC

New C API

lua_setexdata

void lua_setexdata(lua_State *L, void *exdata);

Sets extra user data as a pointer value to the current Lua state or thread.

Back to TOC

lua_getexdata

void *lua_getexdata(lua_State *L);

Gets extra user data as a pointer value to the current Lua state or thread.

Back to TOC

lua_setexdata2

void lua_setexdata2(lua_State *L, void *exdata2);

Similar to lua_setexdata but for a 2nd user data (pointer) value.

Back to TOC

lua_getexdata2

void *lua_getexdata2(lua_State *L);

Similar to lua_getexdata but for a 2nd user data (pointer) value.

Back to TOC

lua_resetthread

void lua_resetthread(lua_State *L, lua_State *th);

Resets the state of th to the initial state of a newly created Lua thread object as returned by lua_newthread(). This is mainly for Lua thread recycling. Lua threads in arbitrary states (like yielded or errored) can be reset properly.

The current implementation does not shrink the already allocated Lua stack though. It only clears it.

Back to TOC

New macros

The macros described in this section have been added to this branch.

Back to TOC

OPENRESTY_LUAJIT

In the luajit.h header file, a new macro OPENRESTY_LUAJIT was defined to help distinguishing this OpenResty-specific branch of LuaJIT.

HAVE_LUA_RESETTHREAD

This macro is set when the lua_resetthread C API is present.

Back to TOC

Optimizations

Updated JIT default parameters

We use more appressive default JIT compiler options to help large OpenResty Lua applications.

The following jit.opt options are used by default:

maxtrace=8000
maxrecord=16000
minstitch=3
maxmcode=40960  -- in KB

Back to TOC

String hashing

This optimization only applies to Intel CPUs supporting the SSE 4.2 instruction sets. For such CPUs, and when this branch is compiled with -msse4.2, the string hashing function used for strings interning will be based on an optimized crc32 implementation (see lj_str_new()).

This optimization still provides constant-time hashing complexity (O(n)), but makes hash collision attacks harder for strings up to 127 bytes of size.

Back to TOC

Updated bytecode options

New -bL option

The bytecode option L was added to display Lua sources line numbers.

For example, luajit -bL -e 'print(1)' now produces bytecode dumps like below:

-- BYTECODE -- "print(1)":0-1
0001     [1]    GGET     0   0      ; "print"
0002     [1]    KSHORT   1   1
0003     [1]    CALL     0   1   2
0004     [1]    RET0     0   1

The [N] column corresponds to the Lua source line number. For example, [1] means "the first source line".

Back to TOC

Updated -bl option

The bytecode option l was updated to display the constant tables of each Lua prototype.

For example, luajit -bl a.lua' now produces bytecode dumps like below:

-- BYTECODE -- a.lua:0-48
KGC    0    "print"
KGC    1    "hi"
KGC    2    table
KGC    3    a.lua:17
KN    1    1000000
KN    2    1.390671161567e-309
...

Back to TOC

Miscellaneous

  • Increased the maximum number of allowed upvalues from 60 to 120.
  • Various important bugfixes in the JIT compiler and Lua VM which have not been merged in upstream LuaJIT.
  • Removed the GCC 4 requirement for x86 on older systems such as Solaris i386.
  • In the Makefile file, make sure we always install the symlink for "luajit" even for alpha or beta versions.
  • Applied a patch to fix DragonFlyBSD compatibility. Note: this is not an officially supported target.
  • feature: jit.dump: output Lua source location after every BC.
  • feature: added internal memory-buffer-based trace entry/exit/start-recording event logging, mainly for debugging bugs in the JIT compiler. it requires -DLUA_USE_TRACE_LOGS when building LuaJIT.
  • feature: save g->jit_base to g->saved_jit_base before lj_err_throw clears g->jit_base which makes it impossible to get Lua backtrace in such states.

Back to TOC

Copyright & License

LuaJIT is a Just-In-Time (JIT) compiler for the Lua programming language.

Project Homepage: http://luajit.org/

LuaJIT is Copyright (C) 2005-2019 Mike Pall.

Additional patches for OpenResty are copyrighted by Yichun Zhang and OpenResty Inc.:

Copyright (C) 2017-2019 Yichun Zhang. All rights reserved.

Copyright (C) 2017-2019 OpenResty Inc. All rights reserved.

LuaJIT is free software, released under the MIT license. See full Copyright Notice in the COPYRIGHT file or in luajit.h.

Documentation for the official LuaJIT is available in HTML format. Please point your favorite browser to:

doc/luajit.html

Back to TOC

luajit2's People

Contributors

abhay1722 avatar agentzh avatar alekseinikiforovibm avatar alhad-deshpande avatar autobakterie avatar bisht13 avatar bubuabu avatar chipitsine avatar chronolaw avatar doujiang24 avatar iii-i avatar manirajdeivendran avatar msva avatar pgalizia-qdt avatar siddhesh avatar spacewander avatar sumitd2 avatar thibaultcha avatar velemas avatar xiaocang avatar xiongjiabin avatar xmiliah avatar xrxr avatar zhuizhuhaomeng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

luajit2's Issues

When a special input is constructed, the Lua engine fails to parse the input and crash.

When a special input is constructed, the Lua engine fails to parse the input and crashes.
For details about the special input, see poc1 to poc3 in the attachment.
When poc1 and poc3 are entered, a segment error occurs in the lj_str_original_hash function, resulting in crash.
When poc2 is entered, a segment error occurs after the lj_BC_JMP function is called, causing the system crash.

pls comfirm above, from Huawei & Tencent Enke Laboratory.

poc1.txt
poc2.txt
poc3.txt

Segmentation faults in Mike's test suite when running qemu-arm on x86_64

I'm always seeing the following 2 test failures due to crashes in qemu-arm when running Mike's test suite in the openresty/luajit2-test-suite github repo with a cross-compiled build of LuaJIT (both the official v2.1 branch and our v2.1-agentzh branch):

Failed test when running /home/agentzh/git/luajit2-test-suite/arm-luajit wbarrier_jit.lua 1: 139
...
Failed test when running /home/agentzh/git/luajit2-test-suite/arm-luajit parse_andor.lua 1: 139
...
2 tests failed.

Not sure if they are reproducible on real ARMv7hf hardware.

47-bit address restriction, lightuserdata and arm64

The mainline LuaJIT has a proposal to support enhancements to lightuserdata to handle the arm64 architecture which has 48-bit addresses. The lengthy discussion is at LuaJIT/LuaJIT#49 and there is a PR at LuaJIT/LuaJIT#230 which is labelled "wontfix".

Is the OpenResty LuaJIT community amenable to reopening this issue? If so, I'm happy to address this issue with downstream projects that are affected by it.

luajit Infinite loop and cpu 100%

Centos6.5, kernel 2.6.32-754.2.1.el6.x86_64, nginx 1.14.2
luajit2-2.1-20190221, lua-resty-core 0.1.16

behavior:
nginx cpu 100% and luajit Fall into the loop

gbd result:

#0  ctype_raw (L=0x416691f8, cd=0x40fef868) at lj_ctype.h:420
#1  lj_ccall_func (L=0x416691f8, cd=0x40fef868) at lj_ccall.c:1148
#2  0x00000000004d1076 in lj_cf_ffi_meta___call (L=0x416691f8) at lib_ffi.c:230
#3  0x00000000004d2fd7 in lj_BC_FUNCC ()
#4  0x000000000049bfc6 in ngx_http_lua_run_thread (L=0x41654378, r=0x1cc8290, ctx=0x1cc8eb8, nrets=0)
    at /tmp/luajit-bug-report/lua-nginx-module-0.10.14/src/ngx_http_lua_util.c:1084
#5  0x000000000049d968 in ngx_http_lua_content_by_chunk (L=0x41654378, r=0x1cc8290) at /tmp/luajit-bug-report/lua-nginx-module-0.10.14/src/ngx_http_lua_contentby.c:122
#6  0x000000000049da4e in ngx_http_lua_content_handler_inline (r=0x1cc8290) at /tmp/luajit-bug-report/lua-nginx-module-0.10.14/src/ngx_http_lua_contentby.c:312
#7  0x000000000049dd14 in ngx_http_lua_content_handler (r=0x1cc8290) at /tmp/luajit-bug-report/lua-nginx-module-0.10.14/src/ngx_http_lua_contentby.c:224
#8  0x0000000000442323 in ngx_http_core_content_phase (r=0x1cc8290, ph=0x1ce02a8) at src/http/ngx_http_core_module.c:1169
#9  0x000000000043ccd3 in ngx_http_core_run_phases (r=0x1cc8290) at src/http/ngx_http_core_module.c:858
#10 0x000000000043cde6 in ngx_http_handler (r=<value optimized out>) at src/http/ngx_http_core_module.c:841
#11 0x0000000000444cdf in ngx_http_process_request (r=0x1cc8290) at src/http/ngx_http_request.c:1952
#12 0x000000000044684c in ngx_http_process_request_headers (rev=<value optimized out>) at src/http/ngx_http_request.c:1379
#13 0x0000000000446cce in ngx_http_process_request_line (rev=0x1ce23a0) at src/http/ngx_http_request.c:1052
#14 0x0000000000446fb2 in ngx_http_keepalive_handler (rev=0x1ce23a0) at src/http/ngx_http_request.c:3238
#15 0x0000000000439cde in ngx_epoll_process_events (cycle=<value optimized out>, timer=<value optimized out>, flags=<value optimized out>)
    at src/event/modules/ngx_epoll_module.c:902
#16 0x00000000004319d7 in ngx_process_events_and_timers (cycle=0x1cc4070) at src/event/ngx_event.c:242
#17 0x000000000043824c in ngx_worker_process_cycle (cycle=0x1cc4070, data=<value optimized out>) at src/os/unix/ngx_process_cycle.c:750
#18 0x0000000000436a38 in ngx_spawn_process (cycle=0x1cc4070, proc=0x4381db <ngx_worker_process_cycle>, data=0x1, name=0x515be8 "worker process", respawn=-3)
    at src/os/unix/ngx_process.c:199
#19 0x00000000004376f8 in ngx_start_worker_processes (cycle=0x1cc4070, n=2, type=-3) at src/os/unix/ngx_process_cycle.c:359
#20 0x000000000043879d in ngx_master_process_cycle (cycle=0x1cc4070) at src/os/unix/ngx_process_cycle.c:131
#21 0x0000000000414c4a in main (argc=<value optimized out>, argv=<value optimized out>) at src/core/nginx.c:382
(gdb) f 0
#0  ctype_raw (L=0x416691f8, cd=0x40fef868) at lj_ctype.h:420
420   while (ctype_isattrib(ct->info)) ct = ctype_child(cts, ct);

LuaJIT:

    make install CCDEBUG=-g XCFLAGS='-msse4.2' PREFIX=/opt/luajit

nginx install:

    cd /tmp
    wget http://nginx.org/download/nginx-1.14.2.tar.gz;tar -zxvf nginx-1.14.2.tar.gz
    wget https://github.com/openresty/lua-nginx-module/archive/v0.10.14.tar.gz;tar -zxvf v0.10.14.tar.gz
    wget https://codeload.github.com/simplresty/ngx_devel_kit/tar.gz/v0.3.1rc1;tar -zxvf v0.3.1rc1
    cd /tmp/nginx-1.14.2/
    ./configure  --prefix=/usr/local/nginx --add-module=/tmp/ngx_devel_kit-0.3.1rc1 --add-module=/tmp/lua-nginx-module-0.10.14
    make install

Steps:

    git clone https://github.com/zx827882285/luajit-bug-report.git
    cp luajit-bug-report/nginx.conf /usr/local/nginx/conf
    cp luajit-bug-report/lua /usr/local/nginx -rf
    /usr/local/nginx/sbin/nginx
    curl  http://localhost/set;./wrk -t4 -c120 -d10  http://localhost/
    top

instructions:
Sorry, it is difficult to occur, if I delete some code or function, it may not occur.
a.lua and b.lua belong to company, I delete some function. until behavior can't be occur when i delete code

need ppc64le support

There is a PR to add ppc64le support but it has been sitting without review for a long time. Please review and merge this. Thanks!

#77

CLA for openresty/luajit2

Currently, this project doesn't appear to have a contributor licensing agreement—it isn't clear if by submitting code to this project we're giving you a license to use it, or (as is implied by the statement of copyright ownership on the github page) we're giving you the copyright, not even retaining rights to keep using it ourselves. Could you clarify that we're only giving you a license to use the code we submit, not that we're assigning the copyright to you?

Can not install on CentOS 5.11

Used https://github.com/openresty/luajit2/archive/v2.1-20190302.tar.gz

  • uname -a
Linux xxx 2.6.18-308.11.1.el5xen #1 SMP Tue Jul 10 09:29:47 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux
  • message
==== Building LuaJIT 2.1.0-beta3 ====
make -C src
make[1]: Entering directory `/home1/irteam/src/luajit2-2.1-20190302/src'
HOSTCC    host/minilua.o
HOSTLINK  host/minilua
DYNASM    host/buildvm_arch.h
HOSTCC    host/buildvm.o
HOSTCC    host/buildvm_asm.o
HOSTCC    host/buildvm_peobj.o
HOSTCC    host/buildvm_lib.o
HOSTCC    host/buildvm_fold.o
HOSTLINK  host/buildvm
BUILDVM   lj_vm.S
ASM       lj_vm.o
CC        lj_gc.o
BUILDVM   lj_ffdef.h
CC        lj_err.o
CC        lj_char.o
BUILDVM   lj_bcdef.h
CC        lj_bc.o
CC        lj_obj.o
CC        lj_buf.o
CC        lj_str.o
CC        lj_tab.o
CC        lj_func.o
CC        lj_udata.o
CC        lj_meta.o
CC        lj_debug.o
CC        lj_state.o
CC        lj_dispatch.o
CC        lj_vmevent.o
CC        lj_vmmath.o
lj_vmmath.c: In function ‘lj_vm_foldfpm’:
lj_vmmath.c:133: warning: implicit declaration of function ‘exp2’
lj_vmmath.c:133: warning: incompatible implicit declaration of built-in function ‘exp2’
lj_vmmath.c:135: warning: implicit declaration of function ‘log2’
lj_vmmath.c:135: warning: incompatible implicit declaration of built-in function ‘log2’
lj_vmmath.c: In function ‘lj_vm_foldfpm’:
lj_vmmath.c:133: warning: implicit declaration of function ‘exp2’
lj_vmmath.c:133: warning: incompatible implicit declaration of built-in function ‘exp2’
lj_vmmath.c:135: warning: implicit declaration of function ‘log2’
lj_vmmath.c:135: warning: incompatible implicit declaration of built-in function ‘log2’
CC        lj_strscan.o
CC        lj_strfmt.o
CC        lj_strfmt_num.o
CC        lj_api.o
CC        lj_profile.o
CC        lj_lex.o
CC        lj_parse.o
CC        lj_bcread.o
CC        lj_bcwrite.o
CC        lj_load.o
CC        lj_ir.o
lj_ir.c:64: error: ‘exp2’ undeclared here (not in a function)
lj_ir.c:64: error: ‘log2’ undeclared here (not in a function)
make[1]: *** [lj_ir.o] 오류 1
make[1]: Leaving directory `/home1/irteam/src/luajit2-2.1-20190302/src'
make: *** [default] 오류 2

Help me! Please.

Make luajit2 into a fully supported project with releases

Given that the official repository for LuaJIT is now abandoned for almost a year, most people I know who are interested in the LuaJIT ecosystem are interested in seeing luajit2 become a first class project instead of a branch of LuaJIT.

To make this possible, the following goals need to be met:

  1. Put the openresty extensions under an optional flag. I need to think about it more seriously and make suggestions/PRs in #63
  2. Start development on the master branch
  3. Start making release tarballs

Then there are secondary features that would be highly desirable for distributions:

  1. Release branches (v2.1, v2.2, etc.)
  2. Testsuite integrated into the main repository so that distributions can run make check in their %check targets for testing. I have PR #78 open for this.

Branches

To start development on the master branch, I propose the following:

  1. Make a v2.0 branch that tracks the current master branch. This is where v2.0 fixes go in as needed
  2. Keep the v2.1 branch as is and make a release tarball (2.1.0) for distributions to pick up
  3. Merge v2.1 into master and then start putting all new patches into master going forward, making release branches and/or tarballs at a regular cadence, say, every 3 months.

Documentation

I propose that we convert the luajit HTML documentation into markdown so that it is convenient to read in github. We should also move the features mentioned in README.md into the main documentation and make README.md more about installation and development documentation.

Needless to say, I'm happy to help with one or more of these tasks. My intention is to propose a new package luajit2 to deprecate luajit in Fedora. That way I can add tarballs instead of having to host hundreds of patches.

Core dump in openresty docker container

I've trouble with core dump recently:
Core was generated by nginx: worker process is shutting down '.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 gc_traverse_frames (g=0x7f9fdfbc13e0, th=0x7f9fd7aa2f00) at lj_gc.c:283
283 lj_gc.c: No such file or directory.
[Current thread is 1 (Thread 0x7f9fdfbe1740 (LWP 3301))]`

My version nginx version: openresty/1.15.8.1
Nginx service is still running at well, but it's generate too much core.* file
Can you please help me to resolve this trouble.
Thanks.

fail to build luajit2 at Centos 5.x

fail snice v2.1-20150120

cat /etc/issue

CentOS release 5.6 (Final)
Kernel \r on an \m

gcc -v

Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --disable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=i386-redhat-linux
Thread model: posix
gcc version 4.1.2 20080704 (Red Hat 4.1.2-51)

==== Building LuaJIT 2.1.0-alpha ====
make -C src
make[1]: Entering directory `/tmp/luajit2/src'
HOSTCC    host/minilua.o
HOSTLINK  host/minilua
DYNASM    host/buildvm_arch.h
HOSTCC    host/buildvm.o
HOSTCC    host/buildvm_asm.o
HOSTCC    host/buildvm_peobj.o
HOSTCC    host/buildvm_lib.o
HOSTCC    host/buildvm_fold.o
HOSTLINK  host/buildvm
BUILDVM   lj_vm.S
ASM       lj_vm.o
CC        lj_gc.o
BUILDVM   lj_ffdef.h
CC        lj_err.o
CC        lj_char.o
BUILDVM   lj_bcdef.h
CC        lj_bc.o
CC        lj_obj.o
CC        lj_buf.o
CC        lj_str.o
CC        lj_tab.o
CC        lj_func.o
CC        lj_udata.o
CC        lj_meta.o
CC        lj_debug.o
CC        lj_state.o
CC        lj_dispatch.o
CC        lj_vmevent.o
CC        lj_vmmath.o
lj_vmmath.c: In function ‘lj_vm_foldfpm’:
lj_vmmath.c:133: warning: implicit declaration of function ‘exp2’
lj_vmmath.c:133: warning: incompatible implicit declaration of built-in function ‘exp2’
lj_vmmath.c:135: warning: implicit declaration of function ‘log2’
lj_vmmath.c:135: warning: incompatible implicit declaration of built-in function ‘log2’
lj_vmmath.c: In function ‘lj_vm_foldfpm’:
lj_vmmath.c:133: warning: implicit declaration of function ‘exp2’
lj_vmmath.c:133: warning: incompatible implicit declaration of built-in function ‘exp2’
lj_vmmath.c:135: warning: implicit declaration of function ‘log2’
lj_vmmath.c:135: warning: incompatible implicit declaration of built-in function ‘log2’
CC        lj_strscan.o
CC        lj_strfmt.o
CC        lj_api.o
CC        lj_profile.o
CC        lj_lex.o
CC        lj_parse.o
CC        lj_bcread.o
CC        lj_bcwrite.o
CC        lj_load.o
CC        lj_ir.o
lj_ir.c:64: error: ‘exp2’ undeclared here (not in a function)
lj_ir.c:64: error: ‘log2’ undeclared here (not in a function)
make[1]: *** [lj_ir.o] Error 1
make[1]: Leaving directory `/tmp/luajit2/src'
make: *** [default] Error 2

I add next 2 lines into lj_arch.h will compile success.

#define LUAJIT_NO_LOG2 1
#define LUAJIT_NO_EXP2 1

dead loop in err_unwind() due to lj_mem_newgco() memory allocation failure

openresty version : openresty-1.13.6.1
perf:Stuck in err_unwind and nginx process CPU 100% higher
error.log:nginx: lua atpanic: Lua VM crashed, reason: not enough memory
STACK1:
Traceback (most recent call last):

File "luajit21.py", line 588, in invoke

bt = lj_debug_dumpstack(L, 0, 30, base, full)

File "luajit21.py", line 423, in lj_debug_dumpstack

frame, size = lj_debug_frame(L, base, level, bot)

File "luajit21.py", line 218, in lj_debug_frame

if frame_gc(frame) == obj2gco(L):

File "luajit21.py", line 177, in frame_gc

return gcref(frame['fr']['func'])

File "luajit21.py", line 170, in gcref

return r['gcptr32'].cast(typ("uintptr_t")).cast(typ("GCobj*"))

g
gdb.MemoryError: Cannot access memory at address 0xfffffffffffffff8
E
Error occurred in Python command: Cannot access memory at address 0xfffffffffffffff8

STACK2:
#0 err_unwind (L=L@entry=0x41e9f378, stopcf=0x7ffcddad1520, errcode=errcode@entry=0) at lj_err.c:109

#1 0x00007f988b3504a5 in lj_err_unwind_dwarf (version=, actions=1, uexclass=5500374307216568836, uex=0x7f988c51e760, ctx=0x7ffcddad1170) at lj_err.c:240

#2 0x00007f988a347c33 in _Unwind_RaiseException () from /lib64/libgcc_s.so.1

#3 0x00007f988b350329 in err_raise_ext (errcode=4) at lj_err.c:301

#4 lj_err_throw (L=L@entry=0x41e9f378, errcode=errcode@entry=4) at lj_err.c:515

#5 0x00007f988b350563 in lj_err_mem (L=L@entry=0x41e9f378) at lj_err.c:551

#6 0x00007f988b350000 in lj_mem_newgco (L=L@entry=0x41e9f378, size=20) at lj_gc.c:833

#7 0x00007f988b3530ec in func_newL (L=L@entry=0x41e9f378, pt=pt@entry=0x41ee8010, env=0x41ea09d8) at lj_func.c:122

#8 0x00007f988b353310 in lj_func_newL_gc (L=0x41e9f378, pt=, parent=0x415cde28) at lj_func.c:160

#9 0x00007f988b34bbe9 in lj_BC_FNEW () from /usr/local/NSP/luajit/lib/libluajit-5.1.so.2

#10 0x00007f988b35d0bd in lua_pcall (L=L@entry=0x41e9f378, nargs=nargs@entry=0, nresults=nresults@entry=1, errfunc=errfunc@entry=0) at lj_api.c:1129

#11 0x00000000004f9c75 in ngx_http_lua_cache_load_code (log=log@entry=0x2062db70, L=L@entry=0x41e9f378, key=key@entry=0x21327480 "nhlf_cdbb7e422b70672672ea5d04e77ae42c")

at ../ngx_lua-0.10.11/src/ngx_http_lua_cache.c:56

#12 0x00000000004f9f1c in ngx_http_lua_cache_loadfile (log=0x2062db70, L=L@entry=0x41e9f378, script=0x31727c38 "/usr/local/NSP/etc/router/router_ext.luac",

cache_key=0x21327480 "nhlf_cdbb7e422b70672672ea5d04e77ae42c") at ../ngx_lua-0.10.11/src/ngx_http_lua_cache.c:232

#13 0x00000000004fb9c7 in ngx_http_lua_access_handler_file (r=0x31726cf0) at ../ngx_lua-0.10.11/src/ngx_http_lua_accessby.c:219

#14 0x00000000004fb5d0 in ngx_http_lua_access_handler (r=0x31726cf0) at ../ngx_lua-0.10.11/src/ngx_http_lua_accessby.c:163

#15 0x0000000000459dbb in ngx_http_core_access_phase (r=, ph=0x17ab770) at src/http/ngx_http_core_module.c:1087

#16 0x000000000045562d in ngx_http_core_run_phases (r=r@entry=0x31726cf0) at src/http/ngx_http_core_module.c:862

#17 0x0000000000455722 in ngx_http_handler (r=r@entry=0x31726cf0) at src/http/ngx_http_core_module.c:845

#18 0x000000000046024e in ngx_http_process_request (r=0x31726cf0) at src/http/ngx_http_request.c:1986

#19 0x0000000000460ac7 in ngx_http_process_request_line (rev=0x7f981e7851c8) at src/http/ngx_http_request.c:1076

#20 0x000000000044a09c in ngx_epoll_process_events (cycle=, timer=, flags=) at src/event/modules/ngx_epoll_module.c:968

#21 0x00000000004413df in ngx_process_events_and_timers (cycle=cycle@entry=0x15ac050) at src/event/ngx_event.c:266

#22 0x0000000000447f21 in ngx_worker_process_cycle (cycle=cycle@entry=0x15ac050, data=data@entry=0x17) at src/os/unix/ngx_process_cycle.c:821

#23 0x00000000004468c6 in ngx_spawn_process (cycle=cycle@entry=0x15ac050, proc=proc@entry=0x447ea0 <ngx_worker_process_cycle>, data=data@entry=0x17,

name=name@entry=0x5a58e5 "worker process", respawn=respawn@entry=-4) at src/os/unix/ngx_process.c:198

#24 0x0000000000448240 in ngx_start_worker_processes (cycle=cycle@entry=0x15ac050, n=32, type=type@entry=-4) at src/os/unix/ngx_process_cycle.c:396

#25 0x0000000000448ef5 in ngx_master_process_cycle (cycle=0x15ac050, cycle@entry=0x15a6230) at src/os/unix/ngx_process_cycle.c:250

#26 0x0000000000421583 in main (argc=, argv=) at src/core/nginx.c:387

Incorrect result for a special lua script, if jit enabled

At begining, everything is OK, but after dozens of requests, I got wrong result。
If I disable the jit by jit.off(), it works well

Software Environment

os: centos6
gcc:  gcc-4.9.3
nginx: nginx-1.13.12
luajit:  luajit-2.1.0(v2.1-agentzh branch)
lua-nginx-module: v0.10.13
lua-resty-core: v0.1.13

nginx -V

# ./nginx -V
nginx version: nginx/1.13.12
built by gcc 4.9.3 (GCC) 
configure arguments: --prefix=/usr/local/nginx --with-debug --with-cc-opt='-g -O0' --with-ld-opt=-Wl,-rpath=/usr/local/lib --with-pcre=/root/Nginx/pcre-8.40 --with-zlib=/root/Nginx/zlib-1.2.11 --add-module=/root/Nginx/lua-nginx-module

nginx config file

daemon off;
master_process off;
error_log logs/error.log error;

events {
    use epoll;
}

http {
    lua_package_path "lib/?.lua;;";
    init_by_lua_block {
        g_test = {status = "", count = 0}
    }
    server {
        listen 127.0.0.1:80;
        location / {
            set $x_value "0";

            access_by_lua_block {
                --jit.off()
                require "resty.core.var"
                require "resty.core.response"

                local control = require "control"
                control.access_handler()
            }
            log_by_lua_block {
                g_test.count = g_test.count + 1
                ngx.log(ngx.ERR, "req_count: ", g_test.count, ", status: ", g_test.status, ", value: ", ngx.var.x_value)
            }
    
            content_by_lua_block {
                ngx.say("method: ", ngx.var.request_method)
                ngx.say("request_uri: ", ngx.var.request_uri)
                ngx.say("value: ", ngx.var.x_value)
            }
        }
    }
}

file control.lua(a lua module)

local function dummy(mconf) return nil end

local function handler()
    g_test.status = "init"
    local mconf = {
        { path = "/", value = 180 }, { path = "/api/", value = 60 }
    }

	local t = {}
    for _, v in ipairs(mconf) do
        local pos = #t + 1
        while pos > 1 do
            if v["path"] == "/" then break end
            pos = pos - 1
        end

        table.insert(t, pos, v)
    end

    local value = 0
    local url = ngx.var["uri"]
    for _, rule in ipairs(t) do
        if string.find(url, rule["path"], 1, true) then
            g_test.status = g_test.status .. " + matched"
            value = rule["value"]
            break
        end
    end

    if value <= 0 then
        g_test.status = g_test.status .. " + noValue"
        return
    end

    ngx.var["x_value"] = value
    ngx.header["X-header"] = value
    return
end

return {
    access_handler = handler
}

visit nginx in ternimal

$ while true; do curl 127.0.0.1/; done

Corrent result as bellow

$ curl 127.0.0.1
method: GET
request_uri: /
value: 180

Incorrect result after visit nginx 34 times

[root@SHTELVM-001 nginx]# curl 127.0.0.1
method: GET
request_uri: /
value: 0

nginx error log as bellow, after 34th request, rule matched but value not assgin a proper value in control.lua, line 25.

2018/05/09 15:44:43 [error] 14447#0: *1 [lua] log_by_lua(nginx.conf:30):3: req_count: 1, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:43 [error] 14447#0: *2 [lua] log_by_lua(nginx.conf:30):3: req_count: 2, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:43 [error] 14447#0: *3 [lua] log_by_lua(nginx.conf:30):3: req_count: 3, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:43 [error] 14447#0: *4 [lua] log_by_lua(nginx.conf:30):3: req_count: 4, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:43 [error] 14447#0: *5 [lua] log_by_lua(nginx.conf:30):3: req_count: 5, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:43 [error] 14447#0: *6 [lua] log_by_lua(nginx.conf:30):3: req_count: 6, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:43 [error] 14447#0: *7 [lua] log_by_lua(nginx.conf:30):3: req_count: 7, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:43 [error] 14447#0: *8 [lua] log_by_lua(nginx.conf:30):3: req_count: 8, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:44 [error] 14447#0: *9 [lua] log_by_lua(nginx.conf:30):3: req_count: 9, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:44 [error] 14447#0: *10 [lua] log_by_lua(nginx.conf:30):3: req_count: 10, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:44 [error] 14447#0: *11 [lua] log_by_lua(nginx.conf:30):3: req_count: 11, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:44 [error] 14447#0: *12 [lua] log_by_lua(nginx.conf:30):3: req_count: 12, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:44 [error] 14447#0: *13 [lua] log_by_lua(nginx.conf:30):3: req_count: 13, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:44 [error] 14447#0: *14 [lua] log_by_lua(nginx.conf:30):3: req_count: 14, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:44 [error] 14447#0: *15 [lua] log_by_lua(nginx.conf:30):3: req_count: 15, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:44 [error] 14447#0: *16 [lua] log_by_lua(nginx.conf:30):3: req_count: 16, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:44 [error] 14447#0: *17 [lua] log_by_lua(nginx.conf:30):3: req_count: 17, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:45 [error] 14447#0: *18 [lua] log_by_lua(nginx.conf:30):3: req_count: 18, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:45 [error] 14447#0: *19 [lua] log_by_lua(nginx.conf:30):3: req_count: 19, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:45 [error] 14447#0: *20 [lua] log_by_lua(nginx.conf:30):3: req_count: 20, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:45 [error] 14447#0: *21 [lua] log_by_lua(nginx.conf:30):3: req_count: 21, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:45 [error] 14447#0: *22 [lua] log_by_lua(nginx.conf:30):3: req_count: 22, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:45 [error] 14447#0: *23 [lua] log_by_lua(nginx.conf:30):3: req_count: 23, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:45 [error] 14447#0: *24 [lua] log_by_lua(nginx.conf:30):3: req_count: 24, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:45 [error] 14447#0: *25 [lua] log_by_lua(nginx.conf:30):3: req_count: 25, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:45 [error] 14447#0: *26 [lua] log_by_lua(nginx.conf:30):3: req_count: 26, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:45 [error] 14447#0: *27 [lua] log_by_lua(nginx.conf:30):3: req_count: 27, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:46 [error] 14447#0: *28 [lua] log_by_lua(nginx.conf:30):3: req_count: 28, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:46 [error] 14447#0: *29 [lua] log_by_lua(nginx.conf:30):3: req_count: 29, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:46 [error] 14447#0: *30 [lua] log_by_lua(nginx.conf:30):3: req_count: 30, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:46 [error] 14447#0: *31 [lua] log_by_lua(nginx.conf:30):3: req_count: 31, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:46 [error] 14447#0: *32 [lua] log_by_lua(nginx.conf:30):3: req_count: 32, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:46 [error] 14447#0: *33 [lua] log_by_lua(nginx.conf:30):3: req_count: 33, status: init + matched, value: 180 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:46 [error] 14447#0: *34 [lua] log_by_lua(nginx.conf:30):3: req_count: 34, status: init + matched + noValue, value: 0 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:46 [error] 14447#0: *35 [lua] log_by_lua(nginx.conf:30):3: req_count: 35, status: init + matched + noValue, value: 0 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:46 [error] 14447#0: *36 [lua] log_by_lua(nginx.conf:30):3: req_count: 36, status: init + matched + noValue, value: 0 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:47 [error] 14447#0: *37 [lua] log_by_lua(nginx.conf:30):3: req_count: 37, status: init + matched + noValue, value: 0 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:47 [error] 14447#0: *38 [lua] log_by_lua(nginx.conf:30):3: req_count: 38, status: init + matched + noValue, value: 0 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:47 [error] 14447#0: *39 [lua] log_by_lua(nginx.conf:30):3: req_count: 39, status: init + matched + noValue, value: 0 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"
2018/05/09 15:44:47 [error] 14447#0: *40 [lua] log_by_lua(nginx.conf:30):3: req_count: 40, status: init + matched + noValue, value: 0 while logging request, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1"

segmentation fault in lj_vm_growstack_f

Hello!

We occurred a segmentation fault in LuaJIT. The backtrace is:

(gdb) bt
#0  0x00007f0c1a6aade2 in lj_vm_growstack_f () from /usr/local/marco/luajit/lib/libluajit-5.1.so.2
#1  0x0000000000550c13 in ngx_http_lua_run_thread (L=0x41a00378, r=0x1767f80, ctx=0x13793f0, nrets=0)
    at /disk/ssd2/alex_workflow/marco/deps/lua-nginx-module-0.10.11h/src/ngx_http_lua_util.c:1013
#2  0x000000000057825c in ngx_http_lua_ssl_cert_by_chunk (L=0x41a00378, r=0x1767f80)
    at /disk/ssd2/alex_workflow/marco/deps/lua-nginx-module-0.10.11h/src/ngx_http_lua_ssl_certby.c:527
#3  0x0000000000577457 in ngx_http_lua_ssl_cert_handler_file (r=0x1767f80, lscf=0x12c2138, L=0x41a00378)
    at /disk/ssd2/alex_workflow/marco/deps/lua-nginx-module-0.10.11h/src/ngx_http_lua_ssl_certby.c:57
#4  0x0000000000577c2c in ngx_http_lua_ssl_cert_handler (ssl_conn=0x1765790, data=0x0)
    at /disk/ssd2/alex_workflow/marco/deps/lua-nginx-module-0.10.11h/src/ngx_http_lua_ssl_certby.c:315
#5  0x00007f0c1a1e544a in tls_post_process_client_hello (s=0x1765790, wst=WORK_MORE_B) at ssl/statem/statem_srvr.c:2179
#6  0x00007f0c1a1e2d2f in ossl_statem_server_post_process_message (s=0x1765790, wst=WORK_MORE_A) at ssl/statem/statem_srvr.c:1148
#7  0x00007f0c1a1cfe52 in read_state_machine (s=0x1765790) at ssl/statem/statem.c:660
#8  0x00007f0c1a1cf7a9 in state_machine (s=0x1765790, server=1) at ssl/statem/statem.c:428
#9  0x00007f0c1a1cf33b in ossl_statem_accept (s=0x1765790) at ssl/statem/statem.c:251
#10 0x00007f0c1a1b642d in ssl_do_handshake_intern (vargs=0x12c6730) at ssl/ssl_lib.c:3467
#11 0x00007f0c19d0770f in async_start_func () at crypto/async/async.c:154
#12 0x00007f0c199108f0 in __malloc_info (fp=0x7ffea8f29be0, options=<optimized out>) at malloc.c:5196
#13 0x0000000001f6b870 in ?? ()
#14 0x0000000000000000 in ?? ()
    0x7f0c1a6aadb3 <lj_vm_growstack_f>      lea    -0x8(%rdx,%rax,8),%eax                                                                                                           │
   │0x7f0c1a6aadb7 <lj_vm_growstack_f+4>    movzbl -0x3d(%rbx),%ecx                                                                                                                 │
   │0x7f0c1a6aadbb <lj_vm_growstack_f+8>    add    $0x4,%ebx                                                                                                                        │
   │0x7f0c1a6aadbe <lj_vm_growstack_f+11>   mov    %edx,0x10(%rbp)                                                                                                                  │
   │0x7f0c1a6aadc1 <lj_vm_growstack_f+14>   mov    %eax,0x18(%rbp)                                                                                                                  │
   │0x7f0c1a6aadc4 <lj_vm_growstack_f+17>   mov    %ebx,0x1c(%rsp)                                                                                                                  │
   │0x7f0c1a6aadc8 <lj_vm_growstack_f+21>   mov    %ecx,%esi                                                                                                                        │
   │0x7f0c1a6aadca <lj_vm_growstack_f+23>   mov    %ebp,%edi                                                                                                                        │
   │0x7f0c1a6aadcc <lj_vm_growstack_f+25>   callq  0x7f0c1a6b4470 <lj_state_growstack>                                                                                              │
   │0x7f0c1a6aadd1 <lj_vm_growstack_f+30>   mov    0x10(%rbp),%edx                                                                                                                  │
   │0x7f0c1a6aadd4 <lj_vm_growstack_f+33>   mov    0x18(%rbp),%eax                                                                                                                  │
   │0x7f0c1a6aadd7 <lj_vm_growstack_f+36>   mov    -0x8(%rdx),%ebp                                                                                                                  │
   │0x7f0c1a6aadda <lj_vm_growstack_f+39>   sub    %edx,%eax                                                                                                                        │
   │0x7f0c1a6aaddc <lj_vm_growstack_f+41>   shr    $0x3,%eax                                                                                                                        │
   │0x7f0c1a6aaddf <lj_vm_growstack_f+44>   add    $0x1,%eax                                                                                                                        │
  >| 0x7f0c1a6aade2 <lj_vm_growstack_f+47>   mov    0x10(%rbp),%ebx                                                                                                                 
   │0x7f0c1a6aade5 <lj_vm_growstack_f+50>   mov    (%rbx),%ecx                                                                                                                      │
   │0x7f0c1a6aade7 <lj_vm_growstack_f+52>   movzbl %cl,%ebp                                                                                                                         │
   │0x7f0c1a6aadea <lj_vm_growstack_f+55>   movzbl %ch,%ecx                                                                                                                         │
   │0x7f0c1a6aaded <lj_vm_growstack_f+58>   add    $0x4,%ebx                                                                                                                        │
   │0x7f0c1a6aadf0 <lj_vm_growstack_f+61>   jmpq   *(%r14,%rbp,8)

It seems that data inside %rbp was corrupted?

(gdb) p/x $rbp
$1 = 0x7009a593
(gdb) x 0x7009a593
0x7009a593:     Cannot access memory at address 0x7009a593

(gdb) info thread
  Id   Target Id         Frame
* 1    LWP 2883818       0x00007f0c1a6aade2 in lj_vm_growstack_f () from /usr/local/marco/luajit/lib/libluajit-5.1.so.2

We are using the asynchronous OpenSSL mode (with the dasync engine), it uses it's own co-routines. I don't know whether this can influence LuaJIT.

The segmentation fault disappeared after disabling the SSL_MODE_ASYNC. In addition, the frequency of this exception will reduce if disables JIT.

Our LuaJIT version is https://github.com/openresty/luajit2/releases/tag/v2.1-20171103 .
The Linux Kernel version is 4.9.0.

I also opened an issue in here: openssl/openssl#6864 .

Is there any idea for the fixup or work-around? Thanks!

Valgrind errors on ppc64le with gcc and clang builds

I am trying to build Luajit on ppc64le. I had used the ppc64le supported code. The code is building without issues.
But I am seeing few failures when Valgrind is enabled with gcc or clang compiler.
I am sharing the test suit run here (removed the few test cases output which are passed to minimize log).
I checked the code but I could not notice the susceptible code line which could be causing memory leak. However I had fixed one error related to unfinalized variable.
Please have a look and let me know suggestions or if it could be ok to live with these errors? Note that I had not seen these errors on AMD build.

Build commands (same as Travis build using valgrind with gcc/clang)

export JOBS=3
export LUAJIT_PREFIX=/opt/luajit21
export LUAJIT_SYSM_PREFIX=/opt/luajit21-sysm
export LUAJIT_COMMON_XCFLAGS="-DLUA_USE_APICHECK -DLUA_USE_ASSERT -DLUAJIT_NUMMODE=2 -O1"
export LUAJIT_XCFLAGS="-DLUAJIT_USE_VALGRIND -DLUAJIT_USE_SYSMALLOC -DLUAJIT_ENABLE_LUA52COMPAT $LUAJIT_COMMON_XCFLAGS"
export LUA52=1
export FLAGS=-v
export TRAVIS_COMPILER=gcc
export CC=${CC:-gcc}
export CC_FOR_BUILD=${CC_FOR_BUILD:-gcc}
gcc --version
make -j$JOBS CCDEBUG=-g Q= PREFIX=$LUAJIT_PREFIX CC=$CC XCFLAGS="$LUAJIT_XCFLAGS" VERBOSE=1
make install PREFIX=$LUAJIT_PREFIX

Test case execution log -

./run-tests $FLAGS $LUAJIT_PREFIX
=== test/ffi/ffi_arith_ptr.lua
=== test/ffi/ffi_convert.lua
==558== Invalid read of size 4
==558== at 0x1003B234: lj_cconv_ct_tv (lj_cconv.c:628)
==558== by 0x10038B27: lj_cdata_set (lj_cdata.c:296)
==558== by 0x10026C0B: lj_cf_ffi_meta___newindex (lib_ffi.c:178)
==558== by 0x10029AFF: lj_BC_FUNCC (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==558== by 0x10014E5B: lua_pcall (lj_api.c:1129)
==558== by 0x1000422F: docall (luajit.c:121)
==558== by 0x100059B7: handle_script (luajit.c:292)
==558== by 0x100059B7: pmain (luajit.c:553)
==558== by 0x10029AFF: lj_BC_FUNCC (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==558== by 0x10014F17: lua_cpcall (lj_api.c:1153)
==558== by 0x10005B4B: main (luajit.c:582)
==558== Address 0x4457840 is 2,848 bytes inside a block of size 4,096 free'd
==558== at 0x408712C: realloc (vg_replace_malloc.c:836)
==558== by 0x1002261F: mem_alloc (lib_aux.c:336)
==558== by 0x1002E3A3: lj_mem_realloc (lj_gc.c:818)
==558== by 0x1002E597: lj_mem_grow (lj_gc.c:850)
==558== by 0x1001FB0B: lj_ctype_intern (lj_ctype.c:198)
==558== by 0x1003ACA7: lj_cconv_ct_tv (lj_cconv.c:562)
==558== by 0x10038B27: lj_cdata_set (lj_cdata.c:296)
==558== by 0x10026C0B: lj_cf_ffi_meta___newindex (lib_ffi.c:178)
==558== by 0x10029AFF: lj_BC_FUNCC (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==558== by 0x10014E5B: lua_pcall (lj_api.c:1129)
==558== by 0x1000422F: docall (luajit.c:121)
==558== by 0x100059B7: handle_script (luajit.c:292)
==558== by 0x100059B7: pmain (luajit.c:553)
==558== by 0x10029AFF: lj_BC_FUNCC (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==558== by 0x10014F17: lua_cpcall (lj_api.c:1153)
==558== by 0x10005B4B: main (luajit.c:582)
==558== Block was alloc'd at
==558== at 0x408712C: realloc (vg_replace_malloc.c:836)
==558== by 0x1002261F: mem_alloc (lib_aux.c:336)
==558== by 0x1002E3A3: lj_mem_realloc (lj_gc.c:818)
==558== by 0x1002E597: lj_mem_grow (lj_gc.c:850)
==558== by 0x1001F953: lj_ctype_new (lj_ctype.c:167)
==558== by 0x10042A6B: cp_struct_name (lj_cparse.c:1204)
==558== by 0x10043823: cp_decl_enum (lj_cparse.c:1408)
==558== by 0x10043823: cp_decl_spec (lj_cparse.c:1504)
==558== by 0x1004497F: cp_decl_multi (lj_cparse.c:1802)
==558== by 0x10044E2F: cpcparser (lj_cparse.c:1878)
==558== by 0x1002A25B: lj_vm_cpcall (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==558== by 0x10044F03: lj_cparse (lj_cparse.c:1891)
==558== by 0x10023763: lj_cf_ffi_cdef (lib_ffi.c:487)
==558== by 0x10029AFF: lj_BC_FUNCC (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==558== by 0x10014E5B: lua_pcall (lj_api.c:1129)
==558== by 0x1000422F: docall (luajit.c:121)
==558== by 0x100059B7: handle_script (luajit.c:292)
==558== by 0x100059B7: pmain (luajit.c:553)
==558== by 0x10029AFF: lj_BC_FUNCC (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==558== by 0x10014F17: lua_cpcall (lj_api.c:1153)
==558== by 0x10005B4B: main (luajit.c:582)
==558==
{
<insert_a_suppression_name_here>
Memcheck:Addr4
fun:lj_cconv_ct_tv
fun:lj_cdata_set
fun:lj_cf_ffi_meta___newindex
fun:lj_BC_FUNCC
fun:lua_pcall
fun:docall
fun:handle_script
fun:pmain
fun:lj_BC_FUNCC
fun:lua_cpcall
fun:main
}
==558== Invalid read of size 4
==558== at 0x10038F34: lj_cconv_ct_ct (lj_cconv.c:121)
==558== by 0x1003B2A3: lj_cconv_ct_tv (lj_cconv.c:629)
==558== by 0x10038B27: lj_cdata_set (lj_cdata.c:296)
==558== by 0x10026C0B: lj_cf_ffi_meta___newindex (lib_ffi.c:178)
==558== by 0x10029AFF: lj_BC_FUNCC (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==558== by 0x10014E5B: lua_pcall (lj_api.c:1129)
==558== by 0x1000422F: docall (luajit.c:121)
==558== by 0x100059B7: handle_script (luajit.c:292)
==558== by 0x100059B7: pmain (luajit.c:553)
==558== by 0x10029AFF: lj_BC_FUNCC (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==558== by 0x10014F17: lua_cpcall (lj_api.c:1153)
==558== by 0x10005B4B: main (luajit.c:582)
==558== Address 0x4457844 is 2,852 bytes inside a block of size 4,096 free'd
==558== at 0x408712C: realloc (vg_replace_malloc.c:836)
==558== by 0x1002261F: mem_alloc (lib_aux.c:336)
==558== by 0x1002E3A3: lj_mem_realloc (lj_gc.c:818)
==558== by 0x1002E597: lj_mem_grow (lj_gc.c:850)
==558== by 0x1001FB0B: lj_ctype_intern (lj_ctype.c:198)
==558== by 0x1003ACA7: lj_cconv_ct_tv (lj_cconv.c:562)
==558== by 0x10038B27: lj_cdata_set (lj_cdata.c:296)
==558== by 0x10026C0B: lj_cf_ffi_meta___newindex (lib_ffi.c:178)
==558== by 0x10029AFF: lj_BC_FUNCC (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==558== by 0x10014E5B: lua_pcall (lj_api.c:1129)
==558== by 0x1000422F: docall (luajit.c:121)
==558== by 0x100059B7: handle_script (luajit.c:292)
==558== by 0x100059B7: pmain (luajit.c:553)
==558== by 0x10029AFF: lj_BC_FUNCC (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==558== by 0x10014F17: lua_cpcall (lj_api.c:1153)
==558== by 0x10005B4B: main (luajit.c:582)
==558== Block was alloc'd at
==558== at 0x408712C: realloc (vg_replace_malloc.c:836)
==558== by 0x1002261F: mem_alloc (lib_aux.c:336)
==558== by 0x1002E3A3: lj_mem_realloc (lj_gc.c:818)
==558== by 0x1002E597: lj_mem_grow (lj_gc.c:850)
==558== by 0x1001F953: lj_ctype_new (lj_ctype.c:167)
==558== by 0x10042A6B: cp_struct_name (lj_cparse.c:1204)
==558== by 0x10043823: cp_decl_enum (lj_cparse.c:1408)
==558== by 0x10043823: cp_decl_spec (lj_cparse.c:1504)
==558== by 0x1004497F: cp_decl_multi (lj_cparse.c:1802)
==558== by 0x10044E2F: cpcparser (lj_cparse.c:1878)
==558== by 0x1002A25B: lj_vm_cpcall (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==558== by 0x10044F03: lj_cparse (lj_cparse.c:1891)
==558== by 0x10023763: lj_cf_ffi_cdef (lib_ffi.c:487)
==558== by 0x10029AFF: lj_BC_FUNCC (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==558== by 0x10014E5B: lua_pcall (lj_api.c:1129)
==558== by 0x1000422F: docall (luajit.c:121)
==558== by 0x100059B7: handle_script (luajit.c:292)
==558== by 0x100059B7: pmain (luajit.c:553)
==558== by 0x10029AFF: lj_BC_FUNCC (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==558== by 0x10014F17: lua_cpcall (lj_api.c:1153)
==558== by 0x10005B4B: main (luajit.c:582)
==558==
{
<insert_a_suppression_name_here>
Memcheck:Addr4
fun:lj_cconv_ct_ct
fun:lj_cconv_ct_tv
fun:lj_cdata_set
fun:lj_cf_ffi_meta___newindex
fun:lj_BC_FUNCC
fun:lua_pcall
fun:docall
fun:handle_script
fun:pmain
fun:lj_BC_FUNCC
fun:lua_cpcall
fun:main
}
==558== Invalid read of size 4
==558== at 0x10038F3C: lj_cconv_ct_ct (lj_cconv.c:122)
==558== by 0x1003B2A3: lj_cconv_ct_tv (lj_cconv.c:629)
==558== by 0x10038B27: lj_cdata_set (lj_cdata.c:296)
==558== by 0x10026C0B: lj_cf_ffi_meta___newindex (lib_ffi.c:178)
==558== by 0x10029AFF: lj_BC_FUNCC (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==558== by 0x10014E5B: lua_pcall (lj_api.c:1129)
==558== by 0x1000422F: docall (luajit.c:121)
==558== by 0x100059B7: handle_script (luajit.c:292)
==558== by 0x100059B7: pmain (luajit.c:553)
==558== by 0x10029AFF: lj_BC_FUNCC (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==558== by 0x10014F17: lua_cpcall (lj_api.c:1153)
==558== by 0x10005B4B: main (luajit.c:582)
==558== Address 0x4457840 is 2,848 bytes inside a block of size 4,096 free'd
==558== at 0x408712C: realloc (vg_replace_malloc.c:836)
==558== by 0x1002261F: mem_alloc (lib_aux.c:336)
==558== by 0x1002E3A3: lj_mem_realloc (lj_gc.c:818)
==558== by 0x1002E597: lj_mem_grow (lj_gc.c:850)
==558== by 0x1001FB0B: lj_ctype_intern (lj_ctype.c:198)
==558== by 0x1003ACA7: lj_cconv_ct_tv (lj_cconv.c:562)
==558== by 0x10038B27: lj_cdata_set (lj_cdata.c:296)
==558== by 0x10026C0B: lj_cf_ffi_meta___newindex (lib_ffi.c:178)
==558== by 0x10029AFF: lj_BC_FUNCC (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==558== by 0x10014E5B: lua_pcall (lj_api.c:1129)
==558== by 0x1000422F: docall (luajit.c:121)
==558== by 0x100059B7: handle_script (luajit.c:292)
==558== by 0x100059B7: pmain (luajit.c:553)
==558== by 0x10029AFF: lj_BC_FUNCC (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==558== by 0x10014F17: lua_cpcall (lj_api.c:1153)
==558== by 0x10005B4B: main (luajit.c:582)
==558== Block was alloc'd at
==558== at 0x408712C: realloc (vg_replace_malloc.c:836)
==558== by 0x1002261F: mem_alloc (lib_aux.c:336)
==558== by 0x1002E3A3: lj_mem_realloc (lj_gc.c:818)
==558== by 0x1002E597: lj_mem_grow (lj_gc.c:850)
==558== by 0x1001F953: lj_ctype_new (lj_ctype.c:167)
==558== by 0x10042A6B: cp_struct_name (lj_cparse.c:1204)
==558== by 0x10043823: cp_decl_enum (lj_cparse.c:1408)
==558== by 0x10043823: cp_decl_spec (lj_cparse.c:1504)
==558== by 0x1004497F: cp_decl_multi (lj_cparse.c:1802)
==558== by 0x10044E2F: cpcparser (lj_cparse.c:1878)
==558== by 0x1002A25B: lj_vm_cpcall (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==558== by 0x10044F03: lj_cparse (lj_cparse.c:1891)
==558== by 0x10023763: lj_cf_ffi_cdef (lib_ffi.c:487)
==558== by 0x10029AFF: lj_BC_FUNCC (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==558== by 0x10014E5B: lua_pcall (lj_api.c:1129)
==558== by 0x1000422F: docall (luajit.c:121)
==558== by 0x100059B7: handle_script (luajit.c:292)
==558== by 0x100059B7: pmain (luajit.c:553)
==558== by 0x10029AFF: lj_BC_FUNCC (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==558== by 0x10014F17: lua_cpcall (lj_api.c:1153)
==558== by 0x10005B4B: main (luajit.c:582)
==558==
{
<insert_a_suppression_name_here>
Memcheck:Addr4
fun:lj_cconv_ct_ct
fun:lj_cconv_ct_tv
fun:lj_cdata_set
fun:lj_cf_ffi_meta___newindex
fun:lj_BC_FUNCC
fun:lua_pcall
fun:docall
fun:handle_script
fun:pmain
fun:lj_BC_FUNCC
fun:lua_cpcall
fun:main
}
==558== Invalid read of size 4
==558== at 0x10038B70: ctype_child (lj_ctype.h:411)
==558== by 0x10038B70: cconv_childqual (lj_cconv.c:60)
==558== by 0x10038DAB: lj_cconv_compatptr (lj_cconv.c:80)
==558== by 0x10039AE7: lj_cconv_ct_ct (lj_cconv.c:338)
==558== by 0x1003B2A3: lj_cconv_ct_tv (lj_cconv.c:629)
==558== by 0x10038B27: lj_cdata_set (lj_cdata.c:296)
==558== by 0x10026C0B: lj_cf_ffi_meta___newindex (lib_ffi.c:178)
==558== by 0x10029AFF: lj_BC_FUNCC (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==558== by 0x10014E5B: lua_pcall (lj_api.c:1129)
==558== by 0x1000422F: docall (luajit.c:121)
==558== by 0x100059B7: handle_script (luajit.c:292)
==558== by 0x100059B7: pmain (luajit.c:553)
==558== by 0x10029AFF: lj_BC_FUNCC (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==558== by 0x10014F17: lua_cpcall (lj_api.c:1153)
==558== by 0x10005B4B: main (luajit.c:582)
==558== Address 0x4457840 is 2,848 bytes inside a block of size 4,096 free'd
==558== at 0x408712C: realloc (vg_replace_malloc.c:836)
==558== by 0x1002261F: mem_alloc (lib_aux.c:336)
==558== by 0x1002E3A3: lj_mem_realloc (lj_gc.c:818)
==558== by 0x1002E597: lj_mem_grow (lj_gc.c:850)
==558== by 0x1001FB0B: lj_ctype_intern (lj_ctype.c:198)
==558== by 0x1003ACA7: lj_cconv_ct_tv (lj_cconv.c:562)
==558== by 0x10038B27: lj_cdata_set (lj_cdata.c:296)
==558== by 0x10026C0B: lj_cf_ffi_meta___newindex (lib_ffi.c:178)
==558== by 0x10029AFF: lj_BC_FUNCC (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==558== by 0x10014E5B: lua_pcall (lj_api.c:1129)
==558== by 0x1000422F: docall (luajit.c:121)
==558== by 0x100059B7: handle_script (luajit.c:292)
==558== by 0x100059B7: pmain (luajit.c:553)
==558== by 0x10029AFF: lj_BC_FUNCC (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==558== by 0x10014F17: lua_cpcall (lj_api.c:1153)
==558== by 0x10005B4B: main (luajit.c:582)
==558== Block was alloc'd at
==558== at 0x408712C: realloc (vg_replace_malloc.c:836)
==558== by 0x1002261F: mem_alloc (lib_aux.c:336)
==558== by 0x1002E3A3: lj_mem_realloc (lj_gc.c:818)
==558== by 0x1002E597: lj_mem_grow (lj_gc.c:850)
==558== by 0x1001F953: lj_ctype_new (lj_ctype.c:167)
==558== by 0x10042A6B: cp_struct_name (lj_cparse.c:1204)
==558== by 0x10043823: cp_decl_enum (lj_cparse.c:1408)
==558== by 0x10043823: cp_decl_spec (lj_cparse.c:1504)
==558== by 0x1004497F: cp_decl_multi (lj_cparse.c:1802)
==558== by 0x10044E2F: cpcparser (lj_cparse.c:1878)
==558== by 0x1002A25B: lj_vm_cpcall (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==558== by 0x10044F03: lj_cparse (lj_cparse.c:1891)
==558== by 0x10023763: lj_cf_ffi_cdef (lib_ffi.c:487)
==558== by 0x10029AFF: lj_BC_FUNCC (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==558== by 0x10014E5B: lua_pcall (lj_api.c:1129)
==558== by 0x1000422F: docall (luajit.c:121)
==558== by 0x100059B7: handle_script (luajit.c:292)
==558== by 0x100059B7: pmain (luajit.c:553)
==558== by 0x10029AFF: lj_BC_FUNCC (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==558== by 0x10014F17: lua_cpcall (lj_api.c:1153)
==558== by 0x10005B4B: main (luajit.c:582)
==558==
{
<insert_a_suppression_name_here>
Memcheck:Addr4
fun:ctype_child
fun:cconv_childqual
fun:lj_cconv_compatptr
fun:lj_cconv_ct_ct
fun:lj_cconv_ct_tv
fun:lj_cdata_set
fun:lj_cf_ffi_meta___newindex
fun:lj_BC_FUNCC
fun:lua_pcall
fun:docall
fun:handle_script
fun:pmain
fun:lj_BC_FUNCC
fun:lua_cpcall
fun:main
}
Failed test when running valgrind --gen-suppressions=all --error-exitcode=2 --num-callers=100 --leak-check=full --show-possibly-lost=no --suppressions=/usr/LuaJIT_2_BUILD/luajit2-test-suite/valgrind.suppress -q /opt/luajit21/bin/luajit-2.1.0-beta3 ffi_convert.lua 1: 512
=== test/ffi/ffi_copy_fill.lua
=== test/ffi/ffi_enum.lua
=== test/ffi/ffi_err.lua
==561== Invalid read of size 4
==561== at 0x1002A290: lj_cont_dispatch (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==561== by 0x10029AFF: lj_BC_FUNCC (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==561== by 0x1000422F: docall (luajit.c:121)
==561== by 0x100059B7: handle_script (luajit.c:292)
==561== by 0x100059B7: pmain (luajit.c:553)
==561== by 0x10029AFF: lj_BC_FUNCC (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==561== by 0x10014F17: lua_cpcall (lj_api.c:1153)
==561== by 0x10005B4B: main (luajit.c:582)
==561== Address 0x4428840 is 0 bytes after a block of size 16 alloc'd
==561== at 0x4084168: malloc (vg_replace_malloc.c:308)
==561== by 0x408709F: realloc (vg_replace_malloc.c:836)
==561== by 0x1002261F: mem_alloc (lib_aux.c:336)
==561== by 0x1002E4A7: lj_mem_newgco (lj_gc.c:831)
==561== by 0x1003F04B: lj_cdata_new (lj_cdata.h:45)
==561== by 0x1003F04B: lj_clib_index (lj_clib.c:384)
==561== by 0x1002584B: ffi_clib_index (lib_ffi.c:370)
==561== by 0x10025A6B: lj_cf_ffi_clib___index (lib_ffi.c:375)
==561== by 0x10029AFF: lj_BC_FUNCC (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==561== by 0x10014E5B: lua_pcall (lj_api.c:1129)
==561== by 0x1000422F: docall (luajit.c:121)
==561== by 0x100059B7: handle_script (luajit.c:292)
==561== by 0x100059B7: pmain (luajit.c:553)
==561== by 0x10029AFF: lj_BC_FUNCC (in /opt/luajit21/bin/luajit-2.1.0-beta3)
==561== by 0x10014F17: lua_cpcall (lj_api.c:1153)
==561== by 0x10005B4B: main (luajit.c:582)
==561==
{
<insert_a_suppression_name_here>
Memcheck:Addr4
fun:lj_cont_dispatch
fun:lj_BC_FUNCC
fun:docall
fun:handle_script
fun:pmain
fun:lj_BC_FUNCC
fun:lua_cpcall
fun:main
}
Failed test when running valgrind --gen-suppressions=all --error-exitcode=2 --num-callers=100 --leak-check=full --show-possibly-lost=no --suppressions=/usr/LuaJIT_2_BUILD/luajit2-test-suite/valgrind.suppress -q /opt/luajit21/bin/luajit-2.1.0-beta3 ffi_err.lua 1: 512
=== test/ffi/ffi_gcstep_recursive.lua
=== test/ffi/unsink_64_kptr.lua
=== test/misc/ack.lua
Ack(3,1): 13
=== test/misc/ack_notail.lua
Ack(3,1): 13
=== test/misc/alias_alloc.lua
=== test/misc/table_chain_bug_LuaJIT_494.lua
/opt/luajit21/bin/luajit-2.1.0-beta3: table_chain_bug_LuaJIT_494.lua:130: 3
stack traceback:
[C]: in function 'assert'
table_chain_bug_LuaJIT_494.lua:130: in main chunk
[C]: at 0x10004fcc
Failed test when running valgrind --gen-suppressions=all --error-exitcode=2 --num-callers=100 --leak-check=full --show-possibly-lost=no --suppressions=/usr/LuaJIT_2_BUILD/luajit2-test-suite/valgrind.suppress -q /opt/luajit21/bin/luajit-2.1.0-beta3 table_chain_bug_LuaJIT_494.lua 1: 256
=== test/misc/table_insert.lua
=== test/misc/table_misc.lua
=== test/misc/table_remove.lua
=== test/misc/tak.lua
2
=== test/misc/tcall_base.lua
=== test/unportable/math_special.lua
3 tests failed.
bash-4.2#

module 'table.clone' not found

I am trying to use table.clone function same as your given example

  local tab_clone = require "table.clone"
      local x = {x=12, y={5, 6, 7}}
      local y = tab_clone(x)

but getting error:

module 'table.clone' not found:
	no field package.preload['table.clone']
	no file '/usr/local/openresty/lualib/table/clone.lua'
	no file 'data/lua/table/clone.lua'
	no file 'data/lua/doubleclick/table/clone.lua'
	no file 'config/initializers/table/clone.lua'
	no file 'code/common/table/clone.lua'
	no file 'code/bases/table/clone.lua'
	no file 'code/counters/table/clone.lua'
	no file 'code/files/table/clone.lua'
	no file 'code/files/maps/table/clone.lua'
	no file 'code/caches/table/clone.lua'
	no file 'code/caches/targeting/table/clone.lua'
	no file 'code/requests/table/clone.lua'
	no file 'code/responses/table/clone.lua'
	no file 'code/stages/table/clone.lua'
	no file 'code/lib/table/clone.lua'
	no file 'code/redises/table/clone.lua'
	no file 'code/exchanges/table/clone.lua'
	no file '/usr/share/lua/5.1/table/clone.lua'
	no file '/usr/share/lua/5.1/table/clone/init.lua'
	no file '/usr/lib64/lua/5.1/table/clone.lua'
	no file '/usr/lib64/lua/5.1/table/clone/init.lua'
	no file 'code/lib/features/table/clone.lua'
	no file '/usr/local/openresty/lualib/table/clone.so'
	no file '/usr/local/lib/lua/5.1/table/clone.so'
	no file '/usr/local/lib/lua/5.1/socket/table/clone.so'
	no file '/usr/lib/lua/5.1/table/clone.so'
	no file '/usr/lib64/lua/5.1/table/clone.so'
	no file '/usr/local/openresty/lualib/table.so'
	no file '/usr/local/lib/lua/5.1/table.so'
	no file '/usr/local/lib/lua/5.1/socket/table.so'
	no file '/usr/lib/lua/5.1/table.so'
	no file '/usr/lib64/lua/5.1/table.so'

I am running it on local VM with CentOS 6.7 kernel version: 2.6.32-573.7.1.el6.x86_64
nginx version:

$] nginx -V
nginx version: openresty/1.13.6.1
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC)
built with OpenSSL 1.0.2n  7 Dec 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt=-O2 --add-module=../ngx_devel_kit-0.3.0 --add-module=../echo-nginx-module-0.61 --add-module=../xss-nginx-module-0.05 --add-module=../ngx_coolkit-0.2rc3 --add-module=../set-misc-nginx-module-0.31 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.07 --add-module=../srcache-nginx-module-0.31 --add-module=../ngx_lua-0.10.11 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.33 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.18 --add-module=../redis2-nginx-module-0.14 --add-module=../redis-nginx-module-0.3.7 --add-module=../rds-json-nginx-module-0.15 --add-module=../rds-csv-nginx-module-0.08 --add-module=../ngx_stream_lua-0.0.3 --with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib --sbin-path=/usr/sbin --with-http_geoip_module --pid-path=/var/run/nginx.pid --with-http_stub_status_module --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-openssl=/home/platform/installers/openresty-1.13.6.1/../../openssl-1.0.2n --with-stream --with-stream_ssl_module

string.find returns random values

Under some circumstances string.find returns random values from memory. I managed to create a short script to reproduce this issue.

Script:

jit.opt.start("hotloop=1")

local iteration = 0
local function test(value)
  iteration = iteration + 1
  --print("a") -- printing fixes wrong behavior
  local pos_c = string.find(value, "c", 1, true)
  --assert(pos_c == 3, "pos=" .. pos_c)
  --pos_c = 3 -- use of constant fixes wrong behavior
  local value2 = string.sub(value, 1, pos_c - 1)
  local pos_b = string.find(value2, "b", 2, true)
  assert(pos_b == 2, "dot1=" .. pos_b)
end

local function test_loop()
  for _ = 1, 20 do
    test("abc")
  end
end

test("abc")

local _, err = pcall(test_loop)
print(iteration)
print(err or "ok")

Results of running this script via luajit program on various environments:

  • Docker: openresty/openresty:1.13.6.2-xenial
    4
    test.lua:12: dot1=2442
    
  • Docker: openresty/openresty:1.15.8.1rc1-0-bionic
    4
    test.lua:12: dot1=-614
    
  • real system: custom build of OpenResty 1.13.6.2
    4
    lua-bug.lua:12: dot1=2442
    

Results are somewhat random when run in OpenResty, but are 100% reproducible when run from commandline. Looks like compilation breaks something.

Weird test failure for ARM build when running the official test suite

When running the test file test/misc/compare.lua in the test suite below with the ARM hard-float build of LuaJIT,

https://github.com/openresty/luajit2-test-suite

we see the following test failure:

/opt/luajit-arm/bin/luajit-2.1.0-beta3: compare.lua:227: -2147483590
stack traceback:
	[C]: in function 'assert'
	compare.lua:227: in main chunk
	[C]: at 0x00014c88
Failed test when running /home/agentzh/git/luajit2-test-suite/arm-luajit compare.lua 1: 256

As we can see that the value to be checked by < 0 is indeed negative. Disabling the JIT compiler of LuaJIT can no longer reproduce this failure. Looks like a bug in the JIT compiler.

The official v2.1 branch of LuaJIT also exhibits this bug, so it was not a regression introduced by us.

Change 97369c4 is probably incorrect

I was looking at patches to pull into stock luajit and found the following:

commit 97369c4 (tag: v2.1-20160517)
Author: Yichun Zhang (agentzh)
Date: Tue May 17 14:25:11 2016 -0700

removed the GCC 4 requirement for x86 for older systems like Solaris i386.

The change claims to remove the gcc 4.0 minimum requirement check for x86 but the check is in #if LJ_TARGET_X64, which it doesn't look right since it should not be processed for i386.

I could not find a related PR or issue for this, so can you please help me understand this change better? Thanks!

Nginx process endlessly stuck in err_unwind function causes 100% CPU

openresty version : openresty-1.13.6.1
error.log:nginx: lua atpanic: Lua VM crashed, reason: not enough memory
STACK1:
Traceback (most recent call last):

File "luajit21.py", line 588, in invoke

bt = lj_debug_dumpstack(L, 0, 30, base, full)

File "luajit21.py", line 423, in lj_debug_dumpstack

frame, size = lj_debug_frame(L, base, level, bot)

File "luajit21.py", line 218, in lj_debug_frame

if frame_gc(frame) == obj2gco(L):

File "luajit21.py", line 177, in frame_gc

return gcref(frame['fr']['func'])

File "luajit21.py", line 170, in gcref

return r['gcptr32'].cast(typ("uintptr_t")).cast(typ("GCobj*"))

g
gdb.MemoryError: Cannot access memory at address 0xfffffffffffffff8
E
Error occurred in Python command: Cannot access memory at address 0xfffffffffffffff8

STACK2:
#0 err_unwind (L=L@entry=0x41e9f378, stopcf=0x7ffcddad1520, errcode=errcode@entry=0) at lj_err.c:109

#1 0x00007f988b3504a5 in lj_err_unwind_dwarf (version=, actions=1, uexclass=5500374307216568836, uex=0x7f988c51e760, ctx=0x7ffcddad1170) at lj_err.c:240

#2 0x00007f988a347c33 in _Unwind_RaiseException () from /lib64/libgcc_s.so.1

#3 0x00007f988b350329 in err_raise_ext (errcode=4) at lj_err.c:301

#4 lj_err_throw (L=L@entry=0x41e9f378, errcode=errcode@entry=4) at lj_err.c:515

#5 0x00007f988b350563 in lj_err_mem (L=L@entry=0x41e9f378) at lj_err.c:551

#6 0x00007f988b350000 in lj_mem_newgco (L=L@entry=0x41e9f378, size=20) at lj_gc.c:833

#7 0x00007f988b3530ec in func_newL (L=L@entry=0x41e9f378, pt=pt@entry=0x41ee8010, env=0x41ea09d8) at lj_func.c:122

#8 0x00007f988b353310 in lj_func_newL_gc (L=0x41e9f378, pt=, parent=0x415cde28) at lj_func.c:160

#9 0x00007f988b34bbe9 in lj_BC_FNEW () from /usr/local/NSP/luajit/lib/libluajit-5.1.so.2

#10 0x00007f988b35d0bd in lua_pcall (L=L@entry=0x41e9f378, nargs=nargs@entry=0, nresults=nresults@entry=1, errfunc=errfunc@entry=0) at lj_api.c:1129

#11 0x00000000004f9c75 in ngx_http_lua_cache_load_code (log=log@entry=0x2062db70, L=L@entry=0x41e9f378, key=key@entry=0x21327480 "nhlf_cdbb7e422b70672672ea5d04e77ae42c")

at ../ngx_lua-0.10.11/src/ngx_http_lua_cache.c:56

#12 0x00000000004f9f1c in ngx_http_lua_cache_loadfile (log=0x2062db70, L=L@entry=0x41e9f378, script=0x31727c38 "/usr/local/NSP/etc/router/router_ext.luac",

cache_key=0x21327480 "nhlf_cdbb7e422b70672672ea5d04e77ae42c") at ../ngx_lua-0.10.11/src/ngx_http_lua_cache.c:232

#13 0x00000000004fb9c7 in ngx_http_lua_access_handler_file (r=0x31726cf0) at ../ngx_lua-0.10.11/src/ngx_http_lua_accessby.c:219

#14 0x00000000004fb5d0 in ngx_http_lua_access_handler (r=0x31726cf0) at ../ngx_lua-0.10.11/src/ngx_http_lua_accessby.c:163

#15 0x0000000000459dbb in ngx_http_core_access_phase (r=, ph=0x17ab770) at src/http/ngx_http_core_module.c:1087

#16 0x000000000045562d in ngx_http_core_run_phases (r=r@entry=0x31726cf0) at src/http/ngx_http_core_module.c:862

#17 0x0000000000455722 in ngx_http_handler (r=r@entry=0x31726cf0) at src/http/ngx_http_core_module.c:845

#18 0x000000000046024e in ngx_http_process_request (r=0x31726cf0) at src/http/ngx_http_request.c:1986

#19 0x0000000000460ac7 in ngx_http_process_request_line (rev=0x7f981e7851c8) at src/http/ngx_http_request.c:1076

#20 0x000000000044a09c in ngx_epoll_process_events (cycle=, timer=, flags=) at src/event/modules/ngx_epoll_module.c:968

#21 0x00000000004413df in ngx_process_events_and_timers (cycle=cycle@entry=0x15ac050) at src/event/ngx_event.c:266

#22 0x0000000000447f21 in ngx_worker_process_cycle (cycle=cycle@entry=0x15ac050, data=data@entry=0x17) at src/os/unix/ngx_process_cycle.c:821

#23 0x00000000004468c6 in ngx_spawn_process (cycle=cycle@entry=0x15ac050, proc=proc@entry=0x447ea0 <ngx_worker_process_cycle>, data=data@entry=0x17,

name=name@entry=0x5a58e5 "worker process", respawn=respawn@entry=-4) at src/os/unix/ngx_process.c:198

#24 0x0000000000448240 in ngx_start_worker_processes (cycle=cycle@entry=0x15ac050, n=32, type=type@entry=-4) at src/os/unix/ngx_process_cycle.c:396

#25 0x0000000000448ef5 in ngx_master_process_cycle (cycle=0x15ac050, cycle@entry=0x15a6230) at src/os/unix/ngx_process_cycle.c:250

#26 0x0000000000421583 in main (argc=, argv=) at src/core/nginx.c:387

Hardening build results

Debian 10 Buster x64

# gcc --version
gcc (Debian 8.3.0-6) 8.3.0

Debian hardening-check tool complains on default build result like that:

# hardening-check /opt/luajit21/bin/luajit-2.1.0-beta3
/opt/luajit21/bin/luajit-2.1.0-beta3:
 Position Independent Executable: yes
 Stack protected: no, not found!
 Fortify Source functions: no, only unprotected functions found!
 Read-only relocations: yes
 Immediate binding: no, not found!

I've tried to play with different build options to overcome the situation:

export LUAJIT_PREFIX=/opt/luajit21
export LUAJIT_COMMON_XCFLAGS="-DLUAJIT_ENABLE_LUA52COMPAT -DLUA_USE_APICHECK -DLUA_USE_ASSERT -DLUAJIT_NUMMODE=2 -msse4.2 -O1"
export LUAJIT_XCFLAGS="$LUAJIT_COMMON_XCFLAGS"

export CFLAGS="-fstack-protector -fstack-protector-strong --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Werror=implicit-function-declaration -Winit-self -Wp,-D_FORTIFY_SOURCE=2 -fPIC" 
export LDFLAGS="-Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie"

make -j `nproc` PREFIX=$LUAJIT_PREFIX XCFLAGS="$LUAJIT_XCFLAGS"

make install PREFIX=$LUAJIT_PREFIX

Bright side: hardening-check complains less:

# hardening-check /opt/luajit21/bin/luajit-2.1.0-beta3
/opt/luajit21/bin/luajit-2.1.0-beta3:
 Position Independent Executable: yes
 Stack protected: no, not found!
 Fortify Source functions: yes (some protected functions found)
 Read-only relocations: yes
 Immediate binding: yes

Dark side: 5 tests has failed:

=== test/misc/meta_comp_jit.lua
/opt/luajit21/bin/luajit-2.1.0-beta3: meta_comp_jit.lua:91: assertion failed!
stack traceback:
        [C]: in function 'assert'
        meta_comp_jit.lua:91: in main chunk
        [C]: at 0x55ebe02c40af
Failed test when running /opt/luajit21/bin/luajit-2.1.0-beta3 meta_comp_jit.lua 1: 256
...
=== test/misc/parse_misc.lua
/opt/luajit21/bin/luajit-2.1.0-beta3: parse_misc.lua:10: assertion failed!
stack traceback:
        [C]: in function 'assert'
        parse_misc.lua:10: in main chunk
        [C]: at 0x55a43ac3c0af
Failed test when running /opt/luajit21/bin/luajit-2.1.0-beta3 parse_misc.lua 1: 256
...
=== test/misc/goto.lua
/opt/luajit21/bin/luajit-2.1.0-beta3: goto.lua:9: assertion failed!
stack traceback:
        [C]: in function 'assert'
        goto.lua:9: in function 'expect'
        goto.lua:33: in main chunk
        [C]: at 0x55a3051030af
Failed test when running /opt/luajit21/bin/luajit-2.1.0-beta3 goto.lua 1: 256
...
=== test/misc/meta_len.lua
/opt/luajit21/bin/luajit-2.1.0-beta3: meta_len.lua:8: assertion failed!
stack traceback:
        [C]: in function 'assert'
        meta_len.lua:8: in function '__len'
        meta_len.lua:27: in main chunk
        [C]: at 0x55b3025850af
Failed test when running /opt/luajit21/bin/luajit-2.1.0-beta3 meta_len.lua 1: 256
...
=== test/misc/libfuncs.lua
/opt/luajit21/bin/luajit-2.1.0-beta3: libfuncs.lua:24: got: "_G:_VERSION:arg:assert:collectgarbage:coroutine:debug:dofile:error:gcinfo:getfenv:getmetatable:io:ipairs:load:loadfile:loadstring:math:module:newproxy:next:os:package:pairs:pcall:print:rawequal:rawget:rawlen:rawset:require:select:setfenv:setmetatable:string:table:tonumber:tostring:type:unpack:xpcall"
expected: "_G:_VERSION:arg:assert:collectgarbage:coroutine:debug:dofile:error:gcinfo:getfenv:getmetatable:io:ipairs:load:loadfile:loadstring:math:module:newproxy:next:os:package:pairs:pcall:print:rawequal:rawget:rawset:require:select:setfenv:setmetatable:string:table:tonumber:tostring:type:unpack:xpcall"
stack traceback:
        [C]: in function 'error'
        libfuncs.lua:8: in function 'check'
        libfuncs.lua:24: in main chunk
        [C]: at 0x5628a55890af
Failed test when running /opt/luajit21/bin/luajit-2.1.0-beta3 libfuncs.lua 1: 256
...

Is it worth to continue investigation?
Are there any chances to success?
Or such kind of hardenization contradict with LuaJIT internals?

something is wrong when using tostring method with big number

luajit2/src/host/minlua.c:145
#define lua_number2str(s,n)sprintf((s),"%.14g",(n))

As illustrate blow, it makes number bigger than 10e14 to string in scientific notation format.
however, if we use the result as a parameter to call hincrby method of redis, it will cause a error, namely, the value is not a number of out of range

lj_str_new hash conflict is serious when length larger than 128

bad

at lj_str_hash_128_above :

 lj_str_hash_128_above(const char* str,  uint32_t len)
  chunk_num = 16;
  chunk_sz = len / chunk_num;
  chunk_sz_log2 = log2_floor(chunk_sz);

  pos1 = get_random_pos_unsafe(chunk_sz_log2, 0);
  pos2 = get_random_pos_unsafe(chunk_sz_log2, 1);
 /* loop over 14 chunks, 2 chunks at a time */
  for (i = 0, chunk_ptr = str; i < (chunk_num / 2 - 1);
       **chunk_ptr += chunk_sz**, i++) {

    v = *cast_uint64p(chunk_ptr + pos1);
    h1 = _mm_crc32_u64(h1, v);

    v = *cast_uint64p(chunk_ptr + chunk_sz + pos2);
    h2 = _mm_crc32_u64(h2, v);
  }
  1. when len is same, the chunk_sz, chunk_sz_log2, pos1, pos2 are always same
  2. in loop, should we set chunk_ptr += 2*chunk_sz, the loop only cover half string

when i use sock:receive(len), recv the same length(527) strings which are similar(changed 36 bytes at second half), the hash conflict is very frequency, and cpu can reach high(100).

It is terrible in my test, it stop all the thing (because recv is not blocked) and can only recv 200 msg/s. it run too many str_fastcmp at lj_str_new.
if (sx->len == len && sx->hash == h && str_fastcmp(str, strdata(sx), len) == 0) {

Repo status

There's a new version of luajit with many fixes. Is this repo maintained any more?

Processing Utf-16

Hello
How print strings , that are in utf-16 encode
for example \U041C\U043E\U0441\U043A\U0432\U0430
I use this lib https://github.com/bungle/lua-resty-unistring
and this is my code

local us = require "unistring"
local sprintf = string.format
sprintf( ISSUER: %s ,
      us.str.u16_to_u8("\041C\043E\0441\043A\0432\0430"))

And I get error
unistring/str.lua:65: declaration specifier expected near ')
How to resolve it?

resty modules not in seasrch path

HI!

I did compile openresty as: $ ./configure --prefix=$HOME/openresty; make install
Then run: $ ~/openresty/luajit/bin/luajit

local mysql = require "resty.mysql"

stdin:1: module 'resty.mysql' not found:
no field package.preload['resty.mysql']
no file './resty/mysql.lua'
no file '/home/foo/openresty/luajit/share/luajit-2.1.0-beta1/resty/mysql.lua'
no file '/usr/local/share/lua/5.1/resty/mysql.lua'
no file '/usr/local/share/lua/5.1/resty/mysql/init.lua'
no file '/home/foo/openresty/luajit/share/lua/5.1/resty/mysql.lua'
no file '/home/foo/openresty/luajit/share/lua/5.1/resty/mysql/init.lua'
no file './resty/mysql.so'
no file '/usr/local/lib/lua/5.1/resty/mysql.so'
no file '/home/foo/openresty/luajit/lib/lua/5.1/resty/mysql.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
no file './resty.so'
no file '/usr/local/lib/lua/5.1/resty.so'
no file '/home/foo/openresty/luajit/lib/lua/5.1/resty.so'
no file '/usr/local/lib/lua/5.1/loadall.so'

Why path "{openresty-prefix}/lualib" is not included by default in luajit openresty??? This is incorrect.

P.S.

As I see in http://luajit.org/install.html that possible to

make PREFIX={openresty-prefix}/lualib (not to be confused with make **install** PREFIX=...)

I think that needs to add in ./configure script. May be new option "--with-luajit-extralib=..." with default?

Building luajit2 on Raspbian Stretch: Error: DASM error 11001109

Hi! I am trying to build the latest repo on Raspbian Stretch (fully up to date) and encountering this:

$ pwd
/home/pi/eotk/opt.d/nginx-1.15.8/luajit2

$ git pull
Already up-to-date.

$ git status
On branch v2.1-agentzh
Your branch is up-to-date with 'origin/v2.1-agentzh'.
nothing to commit, working tree clean

$ make clean
make -C src clean
make[1]: Entering directory '/big/home/pi/eotk/opt.d/nginx-1.15.8/luajit2/src'
rm -f luajit libluajit.a libluajit.so host/minilua host/buildvm lj_vm.S lj_bcdef.h lj_ffdef.h lj_libdef.h lj_recdef.h lj_folddef.h host/buildvm_arch.h jit/vmdef.lua *.o host/*.o *.obj *.lib *.exp *.dll *.exe *.manifest *.pdb *.ilk
make[1]: Leaving directory '/big/home/pi/eotk/opt.d/nginx-1.15.8/luajit2/src'

$ make
==== Building LuaJIT 2.1.0-beta3 ====
make -C src
make[1]: Entering directory '/big/home/pi/eotk/opt.d/nginx-1.15.8/luajit2/src'
HOSTCC    host/minilua.o
HOSTLINK  host/minilua
DYNASM    host/buildvm_arch.h
HOSTCC    host/buildvm.o
HOSTCC    host/buildvm_asm.o
HOSTCC    host/buildvm_peobj.o
HOSTCC    host/buildvm_lib.o
HOSTCC    host/buildvm_fold.o
HOSTLINK  host/buildvm
BUILDVM   lj_vm.S
Error: DASM error 11001109
Makefile:650: recipe for target 'lj_vm.S' failed
make[1]: *** [lj_vm.S] Error 1
make[1]: Leaving directory '/big/home/pi/eotk/opt.d/nginx-1.15.8/luajit2/src'
Makefile:112: recipe for target 'default' failed
make: *** [default] Error 2

I'm not really sure where to go with this, I've dug into buildvm.c a bit, and 11001109 seems to be a complex status code returned by one of two possible functions?

some test cases can't pass in ARM, but in X86_64 is OK.

OS: centos 7.6
ARCH: aarch64(ARM)

LuaJIT compile command:

make TARGET_STRIP=@: CCDEBUG=-g CC=cc XCFLAGS="-DLUA_USE_APICHECK -DLUA_USE_ASSERT -DLUAJIT_NUMMODE=2 -g -O1 -std=gnu99"

only two cases occurs exception:

=== test/ffi/ffi_jit_struct.lua
/DATA/yfli1/test/upngx-test/luajit-test-suite/luajit/bin/luajit-2.1.0-beta3: bad light userdata pointer
stack traceback:
	[C]: in function 'alloc'
	catch_cpp.lua:22: in main chunk
	[C]: at 0x00405004
Failed test when running /DATA/yfli1/test/upngx-test/luajit-test-suite/luajit/bin/luajit-2.1.0-beta3 catch_cpp.lua 1: 256

=== test/misc/catch_wrap.lua
/DATA/yfli1/test/upngx-test/luajit-test-suite/luajit/bin/luajit-2.1.0-beta3: bad light userdata pointer
stack traceback:
	[C]: in function 'wrapon'
	catch_wrap.lua:3: in main chunk
	[C]: at 0x00405004
Failed test when running /DATA/yfli1/test/upngx-test/luajit-test-suite/luajit/bin/luajit-2.1.0-beta3 catch_wrap.lua 1: 256

After upgrade to latest version, nginx start failed

Compile with latest lua-nginx-module version and luajit v2.1-20181029.

When nginx starting, log return

/usr/local/nginx/sbin/nginx: symbol lookup error: /usr/local/nginx/sbin/nginx: undefined symbol: lua_getexdata

luajit2-2.1-20180420 is working fine.

Failed test when running ffi_bit64.lua in v2.1-20200102

Debian 10 Buster x64

# gcc --version
gcc (Debian 8.3.0-6) 8.3.0

On clean system:

git clone https://github.com/openresty/luajit2.git
cd luajit2
git checkout v2.1-20200102
export LUAJIT_PREFIX=/opt/luajit21
export LUAJIT_COMMON_XCFLAGS="-DLUA_USE_APICHECK -DLUA_USE_ASSERT -DLUAJIT_NUMMODE=2 -msse4.2 -O1"
export LUAJIT_XCFLAGS="$LUAJIT_COMMON_XCFLAGS"

make -j `nproc` PREFIX=$LUAJIT_PREFIX XCFLAGS="$LUAJIT_XCFLAGS"
make install PREFIX=$LUAJIT_PREFIX

git clone https://github.com/openresty/luajit2-test-suite.git ../luajit2-test-suite
cd ../luajit2-test-suite
./run-tests -j 4 /opt/luajit21

As a result, I've got:

...
=== test/ffi/ffi_bit64.lua
/opt/luajit21/bin/luajit-2.1.0-beta3: ffi_bit64.lua:18: assertion failed!
stack traceback:
        [C]: in function 'assert'
        ffi_bit64.lua:18: in main chunk
        [C]: at 0x557ea2555190
Failed test when running /opt/luajit21/bin/luajit-2.1.0-beta3 ffi_bit64.lua 1: 256
...

test/ffi/ffi_bit64.lua:18 is:

assert(tostring(band(1ll, 1, 1ull, -1)) == "1ULL")

What's wrong with my setup?
How can I overcome this issue?

Actual result of this snippet:

local bit = require("bit")
local band = bit.band
print(tostring(band(1ll, 1, 1ull, -1)))

is 0ULL

Sync with upstream?

It seems, Mike pulled some PRs, and commited some changes in 2.1 branch (well, actually, in 2.0 too) few weeks ago.
Wouldn't you pull changes here?

not correct of the isarray function example

current isarray function example is

local isarray = require "table.isarray"

print(isarray{"a", true, 3.14})  -- true
print(isarray{"dog" = 3})  -- false
print(isarray{})  -- true

That is not the correct lua syntax. It should be

local isarray = require "table.isarray"

print(isarray({"a", true, 3.14}))  -- true
print(isarray({dog = 3}))  -- false
print(isarray({}))  -- true

Openresty dosnt detect luajit2

root@docker-container:~# nginx -V
nginx version: nginx/1.17.1
built by gcc 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1) 
built with OpenSSL 1.1.1  11 Sep 2018
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx
--add-module=/tmp/build/nginx/simplresty-ngx_devel_kit
--add-module=/tmp/build/nginx/openresty-lua-nginx-module
--add-module=/tmp/build/nginx/headers-more-nginx-module
--add-module=/tmp/build/nginx/set-misc-nginx-module
--add-module=/tmp/build/nginx/ngx_http_geoip2_module
--sbin-path=/usr/sbin/nginx
--modules-path=/usr/lib/nginx/modules
--conf-path=/etc/nginx/nginx.conf
--error-log-path=/var/log/nginx/error.log
--http-log-path=/var/log/nginx/access.log
--pid-path=/var/run/nginx.pid
--lock-path=/var/run/nginx.lock
--http-client-body-temp-path=/var/cache/nginx/client_temp
--http-proxy-temp-path=/var/cache/nginx/proxy_temp
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp
--http-scgi-temp-path=/var/cache/nginx/scgi_temp
--user=nginx --group=nginx --with-compat --with-file-aio
--with-threads --with-http_addition_module
--with-http_auth_request_module --with-http_dav_module
--with-http_flv_module --with-http_gunzip_module
--with-http_gzip_static_module --with-http_mp4_module
--with-http_random_index_module --with-http_realip_module
--with-http_secure_link_module --with-http_slice_module
--with-http_ssl_module --with-http_stub_status_module
--with-http_sub_module --with-http_v2_module --with-mail
--with-mail_ssl_module --with-stream
--with-stream_realip_module --with-stream_ssl_module
--with-stream_ssl_preread_module --with-cc-opt='-g -O2
-fdebug-prefix-map=/tmp/build/nginx/nginx-1.17.1=.
-fstack-protector-strong -Wformat -Werror=format-security
-Wp,-D_FORTIFY_SOURCE=2 -fPIC'
--with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro
-Wl,-z,now -Wl,--as-needed -pie'
root@docker-container:~# luajit -v
LuaJIT 2.1.0-beta3 -- Copyright (C) 2005-2017 Mike Pall.
http://luajit.org/
root@docker-container:~# service nginx restart 
* Restarting nginx
nginx
nginx: [alert] detected a LuaJIT version which is not
OpenResty's; many optimizations will be disabled and
performance will be compromised (see
https://github.com/openresty/luajit2 for OpenResty's LuaJIT
or, even better, consider using the OpenResty releases from
https://openresty.org/en/download.html)
[ OK ]

I use docker clean installation of ubuntu 18.04 download source package of nginx and recompile debian package via luajit2 it's seems work but why dosnt detect i use openresty/luajit2 ? It's says i use normal luajit packages.

Any guide,

Also i submit new google group to why open resty dosnt provide deb-src for ubuntu/debian packages?

luajit and ffi went wrong in while block

I develop a red-black tree base on luajit, but sometime could not found the minium node in the tree, The code behind would assert failed.
If add a line to the while block or use jit.off() to disable jit, it would work well.

        while node.left ~= sentinel do
            --If add a line here, it would work well even jit.on
            --print('node:', node)
            node = node.left
        end
        assert(node.left == sentinel)

OS: Ubuntu 16.04 or ArchLinux .
Code is Here, extra code is removed.

local ffi = require "ffi"


ffi.cdef[[
    typedef struct rbtree_node_s rbtree_node;
    struct rbtree_node_s {
        int                     key;
        struct rbtree_node_s    *left;
    };
]]


--for debug
local function traverse(array, size)
    for i = 0, size + 1 do
        print('i:', i, ' node:', array[i], ' nodekey:', array[i].key, ' node.left:', array[i].left)
    end
end


local function test()
    local size = 24

    local q = ffi.new("rbtree_node[?]", size + 2)
    ffi.fill(q, ffi.sizeof("rbtree_node", size + 2), 0)

    local sentinel = q[0]
    local root = q[1]
    root.key = 1
    root.left = sentinel

    for i = 2, size do
        q[i].key = i
        q[i-1].left = q[i]
        q[i].left = sentinel

        local node = root
        while node.left ~= sentinel do
            --If add a line here, it would work well even jit.on
            --print('node:', node)
            node = node.left
        end

        --print('index:', i)
        --print('node:', node)
        --print('node.key:', node.key)
        --print('node.left:', node.left)
        --traverse(q, size)
        assert(node == q[i])
        assert(node.left == sentinel)
    end
end


print('jit.off')
jit.off(test)
test()

print('jit.on')
jit.on(test)
test()

error on exdata.lua

Hi,

I'm trying to install manually. However I keep getting error

nginx: [error] failed to run the Lua code for coroutine_api: 2: coroutine_api:2: module 'thread.exdata' not found:
        no field package.preload['thread.exdata']
        no file './thread/exdata.lua'
        no file '/usr/share/luajit-2.1.0-beta3/thread/exdata.lua'
        no file '/usr/local/share/lua/5.1/thread/exdata.lua'
        no file '/usr/local/share/lua/5.1/thread/exdata/init.lua'
        no file '/usr/share/lua/5.1/thread/exdata.lua'
        no file '/usr/share/lua/5.1/thread/exdata/init.lua'
        no file './thread/exdata.so'
        no file '/usr/local/lib/lua/5.1/thread/exdata.so'
        no file '/usr/lib/x86_64-linux-gnu/lua/5.1/thread/exdata.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'
        no file './thread.so'
        no file '/usr/local/lib/lua/5.1/thread.so'
        no file '/usr/lib/x86_64-linux-gnu/lua/5.1/thread.so'
        no file '/usr/local/lib/lua/5.1/loadall.so'

Please kindly advice

Move openresty-specific language extensions under a special configuration?

I was thinking of ways to incorporate the openresty-specific language extensions such as thread.exdata and the various table.* functions and it seems to me that the best way would be to put it under a conditional build flag (-DOPENRESTY_EXTENSIONS or similar). This would be set by default in luajit2 and disabled by default in my fork.

Does that sound like a reasonable approach? If yes then I'll first post patches to put the bits under conditional macros and then incorporate these features into my fork.

Add a markdown README

Let's add a README.md file for better documentation rendering. The original README can be left intact so that we would get less merge conflicts every time we sync with the upstream LuaJIT repo.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.