Skip to content

Commit b0436d2

Browse files
authored
Merge branch 'LuaJIT:v2.1' into v2.1
2 parents 04daa26 + fe71d0f commit b0436d2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1080
-595
lines changed

Makefile

+6-4
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ export MULTILIB= lib
3737
DPREFIX= $(DESTDIR)$(PREFIX)
3838
INSTALL_BIN= $(DPREFIX)/bin
3939
INSTALL_LIB= $(DPREFIX)/$(MULTILIB)
40-
INSTALL_SHARE= $(DPREFIX)/share
40+
INSTALL_SHARE_= $(PREFIX)/share
41+
INSTALL_SHARE= $(DESTDIR)$(INSTALL_SHARE_)
4142
INSTALL_DEFINC= $(DPREFIX)/include/luajit-$(MMVERSION)
4243
INSTALL_INC= $(INSTALL_DEFINC)
4344

44-
INSTALL_LJLIBD= $(INSTALL_SHARE)/luajit-$(MMVERSION)
45-
INSTALL_JITLIB= $(INSTALL_LJLIBD)/jit
45+
export INSTALL_LJLIBD= $(INSTALL_SHARE_)/luajit-$(MMVERSION)
46+
INSTALL_JITLIB= $(DESTDIR)$(INSTALL_LJLIBD)/jit
4647
INSTALL_LMODD= $(INSTALL_SHARE)/lua
4748
INSTALL_LMOD= $(INSTALL_LMODD)/$(ABIVER)
4849
INSTALL_CMODD= $(INSTALL_LIB)/lua
@@ -71,7 +72,7 @@ INSTALL_PC= $(INSTALL_PKGCONFIG)/$(INSTALL_PCNAME)
7172

7273
INSTALL_DIRS= $(INSTALL_BIN) $(INSTALL_LIB) $(INSTALL_INC) $(INSTALL_MAN) \
7374
$(INSTALL_PKGCONFIG) $(INSTALL_JITLIB) $(INSTALL_LMOD) $(INSTALL_CMOD)
74-
UNINSTALL_DIRS= $(INSTALL_JITLIB) $(INSTALL_LJLIBD) $(INSTALL_INC) \
75+
UNINSTALL_DIRS= $(INSTALL_JITLIB) $(DESTDIR)$(INSTALL_LJLIBD) $(INSTALL_INC) \
7576
$(INSTALL_LMOD) $(INSTALL_LMODD) $(INSTALL_CMOD) $(INSTALL_CMODD)
7677

7778
RM= rm -f
@@ -114,6 +115,7 @@ ifeq (Darwin,$(TARGET_SYS))
114115
INSTALL_SOSHORT1= $(INSTALL_DYLIBSHORT1)
115116
INSTALL_SOSHORT2= $(INSTALL_DYLIBSHORT2)
116117
LDCONFIG= :
118+
SED_PC+= -e "s| -Wl,-E||"
117119
endif
118120

119121
##############################################################################

doc/ext_buffer.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ <h1>String Buffer Library</h1>
8585
</p>
8686
<p>
8787
The string buffer library also includes a high-performance
88-
<a href="serialize">serializer</a> for Lua objects.
88+
<a href="#serialize">serializer</a> for Lua objects.
8989
</p>
9090

9191
<h2 id="use">Using the String Buffer Library</h2>
@@ -588,9 +588,9 @@ <h3 id="serialize_format">Serialization Format Specification</h3>
588588
tab → 0x08 // Empty table
589589
| 0x09 h.U h*{object object} // Key/value hash
590590
| 0x0a a.U a*object // 0-based array
591-
| 0x0b a.U a*object h.U h*{object object} // Mixed
591+
| 0x0b a.U h.U a*object h*{object object} // Mixed
592592
| 0x0c a.U (a-1)*object // 1-based array
593-
| 0x0d a.U (a-1)*object h.U h*{object object} // Mixed
593+
| 0x0d a.U h.U (a-1)*object h*{object object} // Mixed
594594
tab_mt → 0x0e (index-1).U tab // Metatable dict entry
595595

596596
int64 → 0x10 int.L // FFI int64_t

doc/ext_ffi_semantics.html

+13
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,19 @@ <h3 id="convert_vararg">Conversions for vararg C&nbsp;function arguments</h3>
440440
conversion rule applies. A vararg C&nbsp;function expecting an integer
441441
will see a garbled or uninitialized value.
442442
</p>
443+
<p>
444+
Note: this is the only place where creating a boxed scalar number type is
445+
actually useful. <b>Never use <tt>ffi.new("int")</tt>, <tt>ffi.new("float")</tt>
446+
etc. anywhere else!</b>
447+
</p>
448+
<p style="font-size: 8pt;">
449+
Ditto for <tt>ffi.cast()</tt>. Explicitly boxing scalars <b>does not</b>
450+
improve performance or force <tt>int</tt> or <tt>float</tt> arithmetic! It
451+
just adds costly boxing, unboxing and conversions steps. And it may lead
452+
to surprise results, because
453+
<a href="#cdata_arith">cdata arithmetic on scalar numbers</a>
454+
is always performed on 64 bit integers.
455+
</p>
443456

444457
<h2 id="init">Initializers</h2>
445458
<p>

doc/extensions.html

+45-14
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,33 @@ <h3 id="xpcall"><tt>xpcall(f, err [,args...])</tt> passes arguments</h3>
160160
which is called in a protected context.
161161
</p>
162162

163-
<h3 id="load"><tt>loadfile()</tt> etc. handle UTF-8 source code</h3>
163+
<h3 id="load"><tt>load*()</tt> handle UTF-8 source code</h3>
164164
<p>
165165
Non-ASCII characters are handled transparently by the Lua source code parser.
166166
This allows the use of UTF-8 characters in identifiers and strings.
167167
A UTF-8 BOM is skipped at the start of the source code.
168168
</p>
169169

170+
<h3 id="load_mode"><tt>load*()</tt> add a mode parameter</h3>
171+
<p>
172+
As an extension from Lua 5.2, the functions <tt>loadstring()</tt>,
173+
<tt>loadfile()</tt> and (new) <tt>load()</tt> add an optional
174+
<tt>mode</tt> parameter.
175+
</p>
176+
<p>
177+
The default mode string is <tt>"bt"</tt>, which allows loading of both
178+
source code and bytecode. Use <tt>"t"</tt> to allow only source code
179+
or <tt>"b"</tt> to allow only bytecode to be loaded.
180+
</p>
181+
<p>
182+
By default, the <tt>load*</tt> functions generate the native bytecode format.
183+
For cross-compilation purposes, add <tt>W</tt> to the mode string to
184+
force the 32 bit format and <tt>X</tt> to force the 64 bit format.
185+
Add both to force the opposite format. Note that non-native bytecode
186+
generated by <tt>load*</tt> cannot be run, but can still be passed
187+
to <tt>string.dump</tt>.
188+
</p>
189+
170190
<h3 id="tostring"><tt>tostring()</tt> etc. canonicalize NaN and &plusmn;Inf</h3>
171191
<p>
172192
All number-to-string conversions consistently convert non-finite numbers
@@ -186,26 +206,33 @@ <h3 id="tonumber"><tt>tonumber()</tt> etc. use builtin string to number conversi
186206
numbers (e.g. <tt>0x1.5p-3</tt>).
187207
</p>
188208

189-
<h3 id="string_dump"><tt>string.dump(f [,strip])</tt> generates portable bytecode</h3>
209+
<h3 id="string_dump"><tt>string.dump(f [,mode])</tt> generates portable bytecode</h3>
190210
<p>
191211
An extra argument has been added to <tt>string.dump()</tt>. If set to
192-
<tt>true</tt>, 'stripped' bytecode without debug information is
193-
generated. This speeds up later bytecode loading and reduces memory
194-
usage. See also the
212+
<tt>true</tt> or to a string which contains the character <tt>s</tt>,
213+
'stripped' bytecode without debug information is generated. This speeds
214+
up later bytecode loading and reduces memory usage. See also the
195215
<a href="running.html#opt_b"><tt>-b</tt> command line option</a>.
196216
</p>
197217
<p>
198218
The generated bytecode is portable and can be loaded on any architecture
199-
that LuaJIT supports, independent of word size or endianess. However, the
200-
bytecode compatibility versions must match. Bytecode stays compatible
201-
for dot releases (x.y.0 &rarr; x.y.1), but may change with major or
202-
minor releases (2.0 &rarr; 2.1) or between any beta release. Foreign
203-
bytecode (e.g. from Lua 5.1) is incompatible and cannot be loaded.
219+
that LuaJIT supports. However, the bytecode compatibility versions must
220+
match. Bytecode only stays compatible within a major+minor version
221+
(x.y.aaa &rarr; x.y.bbb), except for development branches. Foreign bytecode
222+
(e.g. from Lua 5.1) is incompatible and cannot be loaded.
204223
</p>
205224
<p>
206225
Note: <tt>LJ_GC64</tt> mode requires a different frame layout, which implies
207-
a different, incompatible bytecode format for all 64 bit ports. This may be
208-
rectified in the future.
226+
a different, incompatible bytecode format between 32 bit and 64 bit ports.
227+
This may be rectified in the future. In the meantime, use the <tt>W</tt>
228+
and </tt>X</tt> <a href="#load_mode">modes of the <tt>load*</tt> functions</a>
229+
for cross-compilation purposes.
230+
</p>
231+
<p>
232+
Due to VM hardening, bytecode is not deterministic. Add <tt>d</tt> to the
233+
mode string to dump it in a deterministic manner: identical source code
234+
always gives a byte-for-byte identical bytecode dump. This feature is
235+
mainly useful for reproducible builds.
209236
</p>
210237

211238
<h3 id="table_new"><tt>table.new(narray, nhash)</tt> allocates a pre-sized table</h3>
@@ -238,7 +265,7 @@ <h3 id="math_random">Enhanced PRNG for <tt>math.random()</tt></h3>
238265
LuaJIT uses a Tausworthe PRNG with period 2^223 to implement
239266
<tt>math.random()</tt> and <tt>math.randomseed()</tt>. The quality of
240267
the PRNG results is much superior compared to the standard Lua
241-
implementation, which uses the platform-specific ANSI rand().
268+
implementation, which uses the platform-specific ANSI <tt>rand()</tt>.
242269
</p>
243270
<p>
244271
The PRNG generates the same sequences from the same seeds on all
@@ -249,6 +276,10 @@ <h3 id="math_random">Enhanced PRNG for <tt>math.random()</tt></h3>
249276
preserve uniformity.
250277
</p>
251278
<p>
279+
Call <tt>math.randomseed()</tt> without any arguments to seed it from
280+
system entropy.
281+
</p>
282+
<p>
252283
Important: Neither this nor any other PRNG based on the simplistic
253284
<tt>math.random()</tt> API is suitable for cryptographic use.
254285
</p>
@@ -286,7 +317,7 @@ <h2 id="lua52">Extensions from Lua 5.2</h2>
286317
</p>
287318
<ul>
288319
<li><tt>goto</tt> and <tt>::labels::</tt>.</li>
289-
<li>Hex escapes <tt>'\x3F'</tt> and <tt>'\*'</tt> escape in strings.</li>
320+
<li>Hex escapes <tt>'\x3F'</tt> and <tt>'\z'</tt> escape in strings.</li>
290321
<li><tt>load(string|reader [, chunkname [,mode [,env]]])</tt>.</li>
291322
<li><tt>loadstring()</tt> is an alias for <tt>load()</tt>.</li>
292323
<li><tt>loadfile(filename [,mode [,env]])</tt>.</li>

doc/install.html

+1
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ <h2 id="cross">Cross-compiling LuaJIT</h2>
269269
<li>Yes, you need a toolchain for both your host <em>and</em> your target!</li>
270270
<li>Both host and target architectures must have the same pointer size.</li>
271271
<li>E.g. if you want to cross-compile to a 32 bit target on a 64 bit host, you need to install the multilib development package (e.g. <tt>libc6-dev-i386</tt> on Debian/Ubuntu) and build a 32 bit host part (<tt>HOST_CC="gcc -m32"</tt>).</li>
272+
<li>On some distro versions, multilib conflicts with cross-compilers. The workaround is to install the x86 cross-compiler package <tt>gcc-i686-linux-gnu</tt> and use it to build the host part (<tt>HOST_CC=i686-linux-gnu-gcc</tt>).</li>
272273
<li>64 bit targets always require compilation on a 64 bit host.</li>
273274
</ul>
274275
<p>

doc/running.html

+5-1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ <h3 id="opt_b"><tt>-b[options] input output</tt></h3>
106106
<li><tt>-l</tt> &mdash; Only list bytecode.</li>
107107
<li><tt>-s</tt> &mdash; Strip debug info (this is the default).</li>
108108
<li><tt>-g</tt> &mdash; Keep debug info.</li>
109+
<li><tt>-W</tt> &mdash; Generate 32 bit (non-GC64) bytecode.</li>
110+
<li><tt>-X</tt> &mdash; Generate 64 bit (GC64) bytecode.</li>
111+
<li><tt>-d</tt> &mdash; Generate bytecode in deterministic manner.</li>
109112
<li><tt>-n name</tt> &mdash; Set module name (default: auto-detect from input name)</li>
110113
<li><tt>-t type</tt> &mdash; Set output file type (default: auto-detect from output name).</li>
111114
<li><tt>-a arch</tt> &mdash; Override architecture for object files (default: native).</li>
@@ -120,7 +123,8 @@ <h3 id="opt_b"><tt>-b[options] input output</tt></h3>
120123
</p>
121124
<ul>
122125
<li><tt>c</tt> &mdash; C source file, exported bytecode data.</li>
123-
<li><tt>h</tt> &mdash; C header file, static bytecode data.</li>
126+
<li><tt>cc</tt> &mdash; C++ source file, exported bytecode data.</li>
127+
<li><tt>h</tt> &mdash; C/C++ header file, static bytecode data.</li>
124128
<li><tt>obj</tt> or <tt>o</tt> &mdash; Object file, exported bytecode data
125129
(OS- and architecture-specific).</li>
126130
<li><tt>raw</tt> or any other extension &mdash; Raw bytecode file (portable).

dynasm/dasm_x86.lua

+9-3
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,11 @@ local function wputmrmsib(t, imark, s, vsreg, psz, sk)
627627
werror("NYI: rip-relative displacement followed by immediate")
628628
end
629629
-- The previous byte in the action buffer cannot be 0xe9 or 0x80-0x8f.
630-
wputlabel("REL_", disp[1], 2)
630+
if disp[2] == "iPJ" then
631+
waction("REL_A", disp[1])
632+
else
633+
wputlabel("REL_", disp[1], 2)
634+
end
631635
else
632636
wputdarg(disp)
633637
end
@@ -744,9 +748,9 @@ local function dispexpr(expr)
744748
return imm*map_opsizenum[ops]
745749
end
746750
local mode, iexpr = immexpr(dispt)
747-
if mode == "iJ" then
751+
if mode == "iJ" or mode == "iPJ" then
748752
if c == "-" then werror("cannot invert label reference") end
749-
return { iexpr }
753+
return { iexpr, mode }
750754
end
751755
return expr -- Need to return original signed expression.
752756
end
@@ -1147,6 +1151,8 @@ local map_op = {
11471151
rep_0 = "F3",
11481152
repe_0 = "F3",
11491153
repz_0 = "F3",
1154+
endbr32_0 = "F30F1EFB",
1155+
endbr64_0 = "F30F1EFA",
11501156
-- F4: *hlt
11511157
cmc_0 = "F5",
11521158
-- F6: test... mb,i; div... mb

dynasm/dynasm.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ local function wline(line, needindent)
7575
g_synclineno = g_synclineno + 1
7676
end
7777

78-
-- Write assembler line as a comment, if requestd.
78+
-- Write assembler line as a comment, if requested.
7979
local function wcomment(aline)
8080
if g_opt.comment then
8181
wline(g_opt.comment..aline..g_opt.endcomment, true)

src/Makefile

+5-2
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@ endif
301301
ifneq (,$(LMULTILIB))
302302
TARGET_XCFLAGS+= -DLUA_LMULTILIB=\"$(LMULTILIB)\"
303303
endif
304+
ifneq (,$(INSTALL_LJLIBD))
305+
TARGET_XCFLAGS+= -DLUA_LJDIR=\"$(INSTALL_LJLIBD)\"
306+
endif
304307

305308
##############################################################################
306309
# Target system detection.
@@ -322,13 +325,13 @@ ifeq (Darwin,$(TARGET_SYS))
322325
endif
323326
TARGET_STRIP+= -x
324327
TARGET_XCFLAGS+= -DLUAJIT_UNWIND_EXTERNAL
325-
TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC
328+
TARGET_XSHLDFLAGS= -dynamiclib -undefined dynamic_lookup -fPIC
326329
TARGET_DYNXLDOPTS=
327330
TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version $(MAJVER).$(MINVER) -current_version $(MAJVER).$(MINVER).255
328331
else
329332
ifeq (iOS,$(TARGET_SYS))
330333
TARGET_STRIP+= -x
331-
TARGET_XSHLDFLAGS= -dynamiclib -single_module -undefined dynamic_lookup -fPIC
334+
TARGET_XSHLDFLAGS= -dynamiclib -undefined dynamic_lookup -fPIC
332335
TARGET_DYNXLDOPTS=
333336
TARGET_XSHLDFLAGS+= -install_name $(TARGET_DYLIBPATH) -compatibility_version $(MAJVER).$(MINVER) -current_version $(MAJVER).$(MINVER).255
334337
ifeq (arm64,$(TARGET_LJARCH))

src/Makefile.dep

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ lib_jit.o: lib_jit.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \
3232
lj_target.h lj_target_*.h lj_trace.h lj_dispatch.h lj_traceerr.h \
3333
lj_vm.h lj_vmevent.h lj_lib.h luajit.h lj_libdef.h
3434
lib_math.o: lib_math.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h \
35-
lj_def.h lj_arch.h lj_lib.h lj_vm.h lj_prng.h lj_libdef.h
35+
lj_def.h lj_arch.h lj_err.h lj_errmsg.h lj_lib.h lj_vm.h lj_prng.h \
36+
lj_libdef.h
3637
lib_os.o: lib_os.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \
3738
lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_lib.h \
3839
lj_libdef.h
@@ -97,7 +98,7 @@ lj_crecord.o: lj_crecord.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
9798
lj_cdata.h lj_cparse.h lj_cconv.h lj_carith.h lj_clib.h lj_ccall.h \
9899
lj_ff.h lj_ffdef.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h lj_trace.h \
99100
lj_dispatch.h lj_traceerr.h lj_record.h lj_ffrecord.h lj_snap.h \
100-
lj_crecord.h lj_strfmt.h
101+
lj_crecord.h lj_strfmt.h lj_strscan.h
101102
lj_ctype.o: lj_ctype.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
102103
lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_strfmt.h lj_ctype.h \
103104
lj_ccallback.h lj_buf.h

src/host/buildvm_asm.c

+4
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,10 @@ void emit_asm(BuildCtx *ctx)
339339
fprintf(ctx->fp, "\t.ident \"%s\"\n", ctx->dasm_ident);
340340
break;
341341
case BUILD_machasm:
342+
#if defined(__apple_build_version__) && __apple_build_version__ >= 15000000 && __apple_build_version__ < 15000300
343+
/* Workaround for XCode 15.0 - 15.2. */
344+
fprintf(ctx->fp, "\t.subsections_via_symbols\n");
345+
#endif
342346
fprintf(ctx->fp,
343347
"\t.cstring\n"
344348
"\t.ascii \"%s\\0\"\n", ctx->dasm_ident);

0 commit comments

Comments
 (0)