Skip to content

Commit 47d2e53

Browse files
committed
vcpkg: update LuaJIT to port-version 3 with Linux GC64 and safe getenv
Two Linux-specific fixes applied via the build system and a new patch: 1. LUAJIT_ENABLE_GC64: LuaJIT statically linked into a dlopen'd shared library is loaded at a high virtual address. Without GC64, LuaJIT requires all GC memory within 4GB of its code section, which fails at these addresses and crashes in lua_newstate. 2. 006-fix-getenvcopy-linux.patch: The pob-wide-crt patch defines _lua_getenvcopy on non-Windows as strdup(getenv(name)). When the env var is unset, getenv returns NULL and strdup(NULL) is undefined behaviour, crashing in luaopen_package and lj_cf_os_getenv. Replace with a null-safe inline function. Also fix the circular luajit symlink in the install step and make the configure script executable before vcpkg_configure_make.
1 parent 19c3e65 commit 47d2e53

5 files changed

Lines changed: 58 additions & 2 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--- a/src/lj_utf8win.h
2+
+++ b/src/lj_utf8win.h
3+
@@ -18,7 +18,12 @@
4+
#else
5+
+#include <stdlib.h>
6+
+#include <string.h>
7+
#define _lua_fopen(path, mode) fopen(path, mode)
8+
-#define _lua_getenvcopy(name) strdup(getenv(name))
9+
-#define _lua_getenvfree(name) free(name)
10+
+static inline char* _lua_getenvcopy(const char* name) {
11+
+ const char* v = getenv(name);
12+
+ return v ? strdup(v) : NULL;
13+
+}
14+
+static inline void _lua_getenvfree(const char* v) { free((void*)v); }
15+
#define _lua_remove(path) remove(path)
16+
#define _lua_rename(oldpath, newpath) rename(oldpath, newpath)
17+
#define _lua_system(cmd) system(cmd)

vcpkg-ports/ports/luajit/2025-07-24_1/portfile.cmake

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ vcpkg_from_github(
1313
msvcbuild.patch
1414
003-do-not-set-macosx-deployment-target.patch
1515
pob-wide-crt.patch
16+
006-fix-getenvcopy-linux.patch
1617
${extra_patches}
1718
)
1819

@@ -62,6 +63,10 @@ else()
6263
set(strip_options " -x")
6364
elseif(VCPKG_TARGET_IS_LINUX)
6465
vcpkg_list(APPEND make_options "TARGET_SYS=Linux")
66+
# Enable GC64 mode so LuaJIT works when statically linked into a dlopen'd shared library.
67+
# Without GC64, LuaJIT requires all GC memory within 4GB of its code, which fails at
68+
# high virtual addresses common when a .so is loaded via dlopen.
69+
vcpkg_list(APPEND make_options "XCFLAGS=-DLUAJIT_ENABLE_GC64")
6570
elseif(VCPKG_TARGET_IS_WINDOWS)
6671
vcpkg_list(APPEND make_options "TARGET_SYS=Windows")
6772
set(strip_options " --strip-unneeded")
@@ -76,6 +81,7 @@ else()
7681
endif()
7782

7883
file(COPY "${CMAKE_CURRENT_LIST_DIR}/configure" DESTINATION "${SOURCE_PATH}")
84+
file(CHMOD "${SOURCE_PATH}/configure" PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
7985
vcpkg_configure_make(SOURCE_PATH "${SOURCE_PATH}"
8086
COPY_SOURCE
8187
OPTIONS
@@ -91,6 +97,26 @@ else()
9197
"TARGET_AR=${VCPKG_DETECTED_CMAKE_AR} rcus"
9298
"TARGET_STRIP=${VCPKG_DETECTED_CMAKE_STRIP}${strip_options}"
9399
)
100+
101+
# The install step creates a circular symlink bin/luajit -> luajit because
102+
# INSTALL_TNAME and INSTALL_TSYMNAME are both "luajit". Fix it by replacing
103+
# the broken symlink with the real binary from the build tree.
104+
foreach(BUILDTYPE "release" "debug")
105+
if(BUILDTYPE STREQUAL "release")
106+
set(BUILD_SUBDIR "x64-linux-rel")
107+
set(DEST_DIR "${CURRENT_PACKAGES_DIR}/bin")
108+
else()
109+
set(BUILD_SUBDIR "x64-linux-dbg")
110+
set(DEST_DIR "${CURRENT_PACKAGES_DIR}/debug/bin")
111+
endif()
112+
set(REAL_BIN "${CURRENT_BUILDTREES_DIR}/${BUILD_SUBDIR}/src/luajit")
113+
set(DEST_BIN "${DEST_DIR}/luajit")
114+
if(EXISTS "${REAL_BIN}")
115+
file(REMOVE "${DEST_BIN}")
116+
file(COPY "${REAL_BIN}" DESTINATION "${DEST_DIR}")
117+
file(CHMOD "${DEST_BIN}" PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
118+
endif()
119+
endforeach()
94120
endif()
95121

96122
file(REMOVE_RECURSE

vcpkg-ports/ports/luajit/2025-07-24_1/vcpkg.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "luajit",
33
"version-date": "2025-07-24",
4-
"port-version": 1,
4+
"port-version": 3,
55
"description": "LuaJIT is a Just-In-Time (JIT) compiler for the Lua programming language.",
66
"homepage": "https://github.com/LuaJIT/LuaJIT",
77
"license": "MIT",

vcpkg-ports/versions/baseline.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
"luajit": { "baseline": "2023-04-16", "port-version": 1 }
99
},
1010
"2025-10-07": {
11+
"angle": { "baseline": "chromium_5414", "port-version": 9 },
1112
"glfw3": { "baseline": "3.4", "port-version": 1 },
1213
"gli": { "baseline": "2021-07-06", "port-version": 3 },
13-
"luajit": { "baseline": "2025-07-24", "port-version": 1 }
14+
"luajit": { "baseline": "2025-07-24", "port-version": 3 },
15+
"openssl": { "baseline": "3.5.4", "port-version": 0 },
16+
"pthread-stubs": { "baseline": "0.4", "port-version": 0 }
1417
}
1518
}

vcpkg-ports/versions/l-/luajit.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
{
22
"versions": [
3+
{
4+
"version-date": "2025-07-24",
5+
"port-version": 3,
6+
"path": "$/ports/luajit/2025-07-24_1"
7+
},
8+
{
9+
"version-date": "2025-07-24",
10+
"port-version": 2,
11+
"path": "$/ports/luajit/2025-07-24_1"
12+
},
313
{
414
"version-date": "2025-07-24",
515
"port-version": 1,

0 commit comments

Comments
 (0)