From 53a1b956bb87d479e0c82ed559373c4ba2dfc6e5 Mon Sep 17 00:00:00 2001 From: Hugo Musso Gualandi Date: Wed, 21 Jul 2021 19:46:19 -0300 Subject: [PATCH 01/10] Move pallenelib to inside the Lua interpreter This set of commits gets rid of the separate pallenelib library. This is part of the ongoing effort to simplify the build and installation process for Pallene (see #16, #153). The pallene_core files are now going to be part of our the custom installation of Lua. Unfortunately, for some reason it is not working. When I compile the custom Lua, the `pallene_symbols` are not being exported by the custom Lua executable. We'll need to figure out what is the problem. TODO: - [] Find out why the symbols are not being exported - [] Fix compilation warnings that appeared because of -Wextra - [] Update the ".patch" file we use when updating to a new Lua version - [] Delete the "runtime" folder, and - [] Update the installation instructions in the README. --- Makefile | 31 ------------------------------ lint-project | 2 +- pallene/c_compiler.lua | 1 - vm/src/Makefile | 7 +++++-- {runtime => vm/src}/pallene_core.c | 0 {runtime => vm/src}/pallene_core.h | 0 6 files changed, 6 insertions(+), 35 deletions(-) delete mode 100644 Makefile rename {runtime => vm/src}/pallene_core.c (100%) rename {runtime => vm/src}/pallene_core.h (100%) diff --git a/Makefile b/Makefile deleted file mode 100644 index 3c2ccd73..00000000 --- a/Makefile +++ /dev/null @@ -1,31 +0,0 @@ -CPPFLAGS:=-I./vm/src -CFLAGS:=--std=c99 -g -Wall -O2 -fPIC - -.PHONY: default clean linux-readline lua-linux-readline macosx lua-macosx - -default: - @echo "Please do 'make PLATFORM' where PLATFORM is one of these:" - @echo " linux-readline linux-noreadline macosx" - -clean: - cd vm/src && $(MAKE) clean - rm -f ./runtime/*.o ./runtime/*.a - -linux-readline: runtime/pallenelib.a lua-linux-readline -linux-noreadline: runtime/pallenelib.a lua-linux-noreadline -macosx: runtime/pallenelib.a lua-macosx - -lua-linux-readline: - cd vm/src && $(MAKE) linux-readline - -lua-linux-noreadline: - cd vm/src && $(MAKE) linux-noreadline - -lua-macosx: - cd vm/src && $(MAKE) macosx - -runtime/pallene_core.o: runtime/pallene_core.c runtime/pallene_core.h - -runtime/pallenelib.a: runtime/pallene_core.o - $(AR) rc $@ $^ - ranlib $@ diff --git a/lint-project b/lint-project index d7794d42..eccaf87a 100755 --- a/lint-project +++ b/lint-project @@ -20,7 +20,7 @@ echo "=== Other checks ===" for file in \ pallene/*.lua spec/*.lua \ examples/*/*.lua examples/*/*.pln \ - runtime/*.c runtime/*.h + vm/src/pallene_core.c vm/src/pallene_core.h do if grep "^$tab" "$file"; then error "File $file has tab-based indentation" diff --git a/pallene/c_compiler.lua b/pallene/c_compiler.lua index d70c60dd..4157576c 100644 --- a/pallene/c_compiler.lua +++ b/pallene/c_compiler.lua @@ -71,7 +71,6 @@ function c_compiler.compile_o_to_so(in_filename, out_filename) c_compiler.CFLAGS_SHARED, "-o", util.shell_quote(out_filename), util.shell_quote(in_filename), - "runtime/pallenelib.a" }) end diff --git a/vm/src/Makefile b/vm/src/Makefile index f78c0b83..d314278a 100644 --- a/vm/src/Makefile +++ b/vm/src/Makefile @@ -26,14 +26,14 @@ MYLIBS= MYOBJS= # Special flags for compiler modules; -Os reduces code size. -CMCFLAGS= +CMCFLAGS= # == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE ======= PLATS= guess aix bsd c89 freebsd generic linux linux-readline macosx mingw posix solaris LUA_A= liblua.a -CORE_O= lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o lundump.o lvm.o lzio.o +CORE_O= lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o lundump.o lvm.o lzio.o pallene_core.o LIB_O= lauxlib.o lbaselib.o lcorolib.o ldblib.o liolib.o lmathlib.o loadlib.o loslib.o lstrlib.o ltablib.o lutf8lib.o linit.o BASE_O= $(CORE_O) $(LIB_O) $(MYOBJS) @@ -218,5 +218,8 @@ lvm.o: lvm.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ ltable.h lvm.h ljumptab.h lzio.o: lzio.c lprefix.h lua.h luaconf.h llimits.h lmem.h lstate.h \ lobject.h ltm.h lzio.h +pallene_core.o: pallene_core.c pallene_core.h lapi.h ldo.h lfunc.h \ + lobject.h lstate.h lstring.h ltable.h lvm.h lmem.h lobject.h lstate.h \ + lstring.h ltm.h ltable.h # (end of Makefile) diff --git a/runtime/pallene_core.c b/vm/src/pallene_core.c similarity index 100% rename from runtime/pallene_core.c rename to vm/src/pallene_core.c diff --git a/runtime/pallene_core.h b/vm/src/pallene_core.h similarity index 100% rename from runtime/pallene_core.h rename to vm/src/pallene_core.h From 461b9fb2aeb4cf29f61ce97c7c48b41fd3a42f45 Mon Sep 17 00:00:00 2001 From: Hugo Musso Gualandi Date: Thu, 22 Jul 2021 17:07:06 -0300 Subject: [PATCH 02/10] Update README compilation instructions --- .github/workflows/ci.yml | 2 +- README.md | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4509f216..d54fa56d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,7 +40,7 @@ jobs: - name: Build run: | luarocks make - make linux-noreadline + (cd vm && make linux) - name: Install Busted run: luarocks install busted diff --git a/README.md b/README.md index 981e393e..09191bbe 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ sudo apt install parallel # for Ubuntu & Debian-based distros sudo dnf install parallel # for Fedora ``` -Pallene requires Lua 5.3 to be installed on your system. +Pallene requires Lua 5.3 or newer to be installed on your system. You can either install it [from source](https://www.lua.org/ftp/) or via the package manager for your Linux distro. If you install via the package manager then make sure to also install the Lua headers, which are often in a separate "development" package. @@ -70,18 +70,18 @@ $ echo 'eval `luarocks path`' >> ~/.bashrc ``` For further information, consult the [Luarocks documentation](https://github.com/luarocks/luarocks/wiki/path). -### Compiling the runtime libraries +### Compiling the custom interpreter -Pallene must be run against a custom-built version of the Lua interpreter, as -well as the Pallene runtime library. Both of these are written in C and must be -compiled before the Pallene compiler can be used. +Pallene must be run against a custom-built version of the Lua interpreter. +This custom version of Lua 5.4 doesn't have to be the same one that you will use to run the compiler itself, +or to install the Luarocks packages. -These two components can be built through the Makefile we provide. The command -to be used depends on your operating system: +To compile the custom version of Lua, follow the instructions found the vm/doc/readme.html. +For Linux, these are the commands you need to run: ```sh -make linux-readline # for Linux -make macosx # for MacOS +cd vm +make linux-readline -j ``` ## Usage From d0366130bc119003d9a9e27641cdfa1cc0f1842e Mon Sep 17 00:00:00 2001 From: Hugo Musso Gualandi Date: Thu, 22 Jul 2021 18:09:51 -0300 Subject: [PATCH 03/10] Linker Hack This workaround ensures that the pallene_core. symbols are included in the compiled executable. By default, these symbols were not being included because they are not used anywhere else in the Lua executable. They are only intended for dynamically linked modules. One possible way to avoid this would be to pass some special flags to the linker, such as -Wl,--whole-archive. However, I'm worried that this might only work with a GCC toolchain on Linux. The proposed hack is something that I hope might be more portable. However, I would certainly be very happy if we could find an alternative less hacky solution. --- vm/src/lua.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/vm/src/lua.c b/vm/src/lua.c index 46b48dba..0df0abb2 100644 --- a/vm/src/lua.c +++ b/vm/src/lua.c @@ -657,3 +657,16 @@ int main (int argc, char **argv) { return (result && status == LUA_OK) ? EXIT_SUCCESS : EXIT_FAILURE; } +/* +** PALLENE LINKER HACK +** +** When we build the final "lua" executable, bundling it with the "liblua.a" library, the linker +** only includes symbols from the object files where at least one of the symbols of the module is +** used by the executable itself. This is a problem for the Pallene runtime library, because those +** symbols are only used by extension modules, which we expect to dynamically link. One hacky +** workaround I found is to force the "lua" executable to reference one of the symbols from the +** pallene_code, as done below. +*/ +char *pallene_tag_name(int); +char *(*PALLENE_LINKER_HACK)(int) = pallene_tag_name; + From 55472f36812533b58628264bead3b6f22506f78b Mon Sep 17 00:00:00 2001 From: Hugo Musso Gualandi Date: Thu, 22 Jul 2021 18:14:07 -0300 Subject: [PATCH 04/10] Add LUA_CORE mark to pallene_core --- vm/src/pallene_core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vm/src/pallene_core.c b/vm/src/pallene_core.c index de081c66..52cb2d5b 100644 --- a/vm/src/pallene_core.c +++ b/vm/src/pallene_core.c @@ -3,6 +3,8 @@ * Please refer to the LICENSE and AUTHORS files for details * SPDX-License-Identifier: MIT */ +#define LUA_CORE + #include "pallene_core.h" #include "lua.h" From d2fcf652322bfb10b9b50dd9866a06efc2817cae Mon Sep 17 00:00:00 2001 From: Hugo Musso Gualandi Date: Thu, 22 Jul 2021 21:06:10 -0300 Subject: [PATCH 05/10] Fix -Wextra warnings in pallenelib Now that pallenelib is compiled with the rest of the Lua interpreter we are compiling with -Wextra, which has revealed a couple of warnings. This commit fixes them. 1. The inline cache now has type int instead of size_t. This reflects how Lua itself uses int for this purpose. (For example, see the various places that use the sizenode macro) 2. In the implementation of io.write, the L parameter should be marked as unused. --- pallene/coder.lua | 4 ++-- vm/src/pallene_core.c | 1 + vm/src/pallene_core.h | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pallene/coder.lua b/pallene/coder.lua index 7381da17..29d3e0f5 100644 --- a/pallene/coder.lua +++ b/pallene/coder.lua @@ -1265,7 +1265,7 @@ gen_cmd["GetTable"] = function(self, cmd, _func) return util.render([[ { - static size_t cache = UINT_MAX; + static int cache = UINT_MAX; TValue *slot = pallene_getstr($field_len, $tab, $key, &cache); ${get_slot} } @@ -1289,7 +1289,7 @@ gen_cmd["SetTable"] = function(self, cmd, _func) return util.render([[ { TValue keyv; ${init_keyv} - static size_t cache = UINT_MAX; + static int cache = UINT_MAX; TValue *slot = pallene_getstr($field_len, $tab, $key, &cache); if (PALLENE_UNLIKELY(isabstkey(slot))) { TValue valv; ${init_valv} diff --git a/vm/src/pallene_core.c b/vm/src/pallene_core.c index 52cb2d5b..0d221539 100644 --- a/vm/src/pallene_core.c +++ b/vm/src/pallene_core.c @@ -161,6 +161,7 @@ void pallene_grow_array(lua_State *L, const char* file, int line, Table *arr, un void pallene_io_write(lua_State *L, TString *str) { + (void) L; const char *s = getstr(str); size_t len = tsslen(str); fwrite(s, 1, len, stdout); diff --git a/vm/src/pallene_core.h b/vm/src/pallene_core.h index 42cf664d..0a92b762 100644 --- a/vm/src/pallene_core.h +++ b/vm/src/pallene_core.h @@ -245,9 +245,9 @@ void pallene_renormalize_array( static const TValue PALLENE_ABSENTKEY = {ABSTKEYCONSTANT}; static inline -TValue *pallene_getshortstr(Table *t, TString *key, size_t *restrict cache) +TValue *pallene_getshortstr(Table *t, TString *key, int *restrict cache) { - if (*cache < sizenode(t)) { + if (0 <= *cache && *cache < sizenode(t)) { Node *n = gnode(t, *cache); if (keyisshrstr(n) && eqshrstr(keystrval(n), key)) return gval(n); @@ -273,7 +273,7 @@ TValue *pallene_getshortstr(Table *t, TString *key, size_t *restrict cache) } static inline -TValue *pallene_getstr(size_t len, Table *t, TString *key, size_t *cache) +TValue *pallene_getstr(size_t len, Table *t, TString *key, int *cache) { if (len <= LUAI_MAXSHORTLEN) { return pallene_getshortstr(t, key, cache); From 5e09590b7d7dbe9328a022db706147ba41b794c2 Mon Sep 17 00:00:00 2001 From: Hugo Musso Gualandi Date: Thu, 22 Jul 2021 21:20:15 -0300 Subject: [PATCH 06/10] New instructions for updating Pallene to the next Lua version Previously, all we had to do was a small change in the luaconf. Now there are more things to do: add the pallene_core files, update the makefile, add the linker hack. Because these changes broke the "patch" file that we had, I deleted that patch file and replaced it with manual instructions. When we update to the next release (5.4.4, or maybe 5.5?) we could consider creating a new "patch" file. It's easier to create that patch file after we apply the changes on a fresh version of Lua. --- runtime/0001-Update-LUAI_FUNC.patch | 22 --------------- vm/PALLENE-UPDATING | 42 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 22 deletions(-) delete mode 100644 runtime/0001-Update-LUAI_FUNC.patch create mode 100644 vm/PALLENE-UPDATING diff --git a/runtime/0001-Update-LUAI_FUNC.patch b/runtime/0001-Update-LUAI_FUNC.patch deleted file mode 100644 index c6c11ab4..00000000 --- a/runtime/0001-Update-LUAI_FUNC.patch +++ /dev/null @@ -1,22 +0,0 @@ -# -# Use this patch when upgrading to a new version of Lua. -# To apply the patch, run `git apply patchfile.patch`. -# -diff --git a/vm/src/luaconf.h b/vm/src/luaconf.h -index bdf927e..088200a 100644 ---- a/vm/src/luaconf.h -+++ b/vm/src/luaconf.h -@@ -315,12 +315,7 @@ - ** give a warning about it. To avoid these warnings, change to the - ** default definition. - */ --#if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \ -- defined(__ELF__) /* { */ --#define LUAI_FUNC __attribute__((visibility("internal"))) extern --#else /* }{ */ --#define LUAI_FUNC extern --#endif /* } */ -+#define LUAI_FUNC LUA_API /* Pallene exports everything */ - - #define LUAI_DDEC(dec) LUAI_FUNC dec - #define LUAI_DDEF /* empty */ diff --git a/vm/PALLENE-UPDATING b/vm/PALLENE-UPDATING new file mode 100644 index 00000000..bfcb3569 --- /dev/null +++ b/vm/PALLENE-UPDATING @@ -0,0 +1,42 @@ +This file describes the adaptations we made to the Lua interpreter. +For the next release, we should consider preparing a proper patch file. + +1) Make everything public in the luaconf.h + + #if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \ + defined(__ELF__) /* { */ + #define LUAI_FUNC __attribute__((visibility("internal"))) extern + #else /* }{ */ + #define LUAI_FUNC extern + #endif /* } */ + --- + #define LUAI_FUNC LUA_API /* Pallene exports everything */ + +2) Add the Linker Hack to the lua.c + + /* + ** PALLENE LINKER HACK + ** + ** When we build the final "lua" executable, bundling it with the "liblua.a" library, the linker + ** only includes symbols from the object files where at least one of the symbols of the module is + ** used by the executable itself. This is a problem for the Pallene runtime library, because those + ** symbols are only used by extension modules, which we expect to dynamically link. One hacky + ** workaround I found is to force the "lua" executable to reference one of the symbols from the + ** pallene_code, as done below. + */ + char *pallene_tag_name(int); + char *(*PALLENE_LINKER_HACK)(int) = pallene_tag_name; + +3) Copy the pallene_core files + + vm/src/pallene_core.h + vm/src/pallene_core.c + +4) Update the src/Makefile + + - Add pallene_core.o to the CORE_O list + - Add the pallene_core.o target + + pallene_core.o: pallene_core.c pallene_core.h lapi.h ldo.h lfunc.h \ + lobject.h lstate.h lstring.h ltable.h lvm.h lmem.h lobject.h lstate.h \ + lstring.h ltm.h ltable.h From 7fe53dd054d47c6d96dfe4f0217f9ae28ec2363b Mon Sep 17 00:00:00 2001 From: Hugo Musso Gualandi Date: Fri, 23 Jul 2021 11:29:49 -0300 Subject: [PATCH 07/10] Comments from code review --- pallene/coder.lua | 4 ++-- vm/src/lua.c | 2 +- vm/src/pallene_core.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pallene/coder.lua b/pallene/coder.lua index 29d3e0f5..979bdbc1 100644 --- a/pallene/coder.lua +++ b/pallene/coder.lua @@ -1265,7 +1265,7 @@ gen_cmd["GetTable"] = function(self, cmd, _func) return util.render([[ { - static int cache = UINT_MAX; + static int cache = -1; TValue *slot = pallene_getstr($field_len, $tab, $key, &cache); ${get_slot} } @@ -1289,7 +1289,7 @@ gen_cmd["SetTable"] = function(self, cmd, _func) return util.render([[ { TValue keyv; ${init_keyv} - static int cache = UINT_MAX; + static int cache = -1; TValue *slot = pallene_getstr($field_len, $tab, $key, &cache); if (PALLENE_UNLIKELY(isabstkey(slot))) { TValue valv; ${init_valv} diff --git a/vm/src/lua.c b/vm/src/lua.c index 0df0abb2..736628d1 100644 --- a/vm/src/lua.c +++ b/vm/src/lua.c @@ -665,7 +665,7 @@ int main (int argc, char **argv) { ** used by the executable itself. This is a problem for the Pallene runtime library, because those ** symbols are only used by extension modules, which we expect to dynamically link. One hacky ** workaround I found is to force the "lua" executable to reference one of the symbols from the -** pallene_code, as done below. +** pallene_core, as done below. */ char *pallene_tag_name(int); char *(*PALLENE_LINKER_HACK)(int) = pallene_tag_name; diff --git a/vm/src/pallene_core.c b/vm/src/pallene_core.c index 0d221539..9c09bf6e 100644 --- a/vm/src/pallene_core.c +++ b/vm/src/pallene_core.c @@ -161,7 +161,7 @@ void pallene_grow_array(lua_State *L, const char* file, int line, Table *arr, un void pallene_io_write(lua_State *L, TString *str) { - (void) L; + (void) L; /* unused parameter */ const char *s = getstr(str); size_t len = tsslen(str); fwrite(s, 1, len, stdout); From 3165127f1ae358921e9a50f073de5d80787a384c Mon Sep 17 00:00:00 2001 From: Hugo Musso Gualandi Date: Sat, 24 Jul 2021 15:29:56 -0300 Subject: [PATCH 08/10] Reimplement linker hack I think this version of the linker hack has a better change of working on more compilers. If the symbols from lapi.o are being exported, then including Pallene symbols there should probably do the trick! As a bonus, we can get away with not modifying the makefile. --- vm/PALLENE-UPDATING | 22 +--------------------- vm/src/Makefile | 7 ++----- vm/src/lapi.c | 14 ++++++++++++++ vm/src/lua.c | 13 ------------- vm/src/pallene_core.h | 8 +++++++- 5 files changed, 24 insertions(+), 40 deletions(-) diff --git a/vm/PALLENE-UPDATING b/vm/PALLENE-UPDATING index bfcb3569..5b657ccb 100644 --- a/vm/PALLENE-UPDATING +++ b/vm/PALLENE-UPDATING @@ -14,29 +14,9 @@ For the next release, we should consider preparing a proper patch file. 2) Add the Linker Hack to the lua.c - /* - ** PALLENE LINKER HACK - ** - ** When we build the final "lua" executable, bundling it with the "liblua.a" library, the linker - ** only includes symbols from the object files where at least one of the symbols of the module is - ** used by the executable itself. This is a problem for the Pallene runtime library, because those - ** symbols are only used by extension modules, which we expect to dynamically link. One hacky - ** workaround I found is to force the "lua" executable to reference one of the symbols from the - ** pallene_code, as done below. - */ - char *pallene_tag_name(int); - char *(*PALLENE_LINKER_HACK)(int) = pallene_tag_name; + See the end of the "lapi.c" 3) Copy the pallene_core files vm/src/pallene_core.h vm/src/pallene_core.c - -4) Update the src/Makefile - - - Add pallene_core.o to the CORE_O list - - Add the pallene_core.o target - - pallene_core.o: pallene_core.c pallene_core.h lapi.h ldo.h lfunc.h \ - lobject.h lstate.h lstring.h ltable.h lvm.h lmem.h lobject.h lstate.h \ - lstring.h ltm.h ltable.h diff --git a/vm/src/Makefile b/vm/src/Makefile index d314278a..f78c0b83 100644 --- a/vm/src/Makefile +++ b/vm/src/Makefile @@ -26,14 +26,14 @@ MYLIBS= MYOBJS= # Special flags for compiler modules; -Os reduces code size. -CMCFLAGS= +CMCFLAGS= # == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE ======= PLATS= guess aix bsd c89 freebsd generic linux linux-readline macosx mingw posix solaris LUA_A= liblua.a -CORE_O= lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o lundump.o lvm.o lzio.o pallene_core.o +CORE_O= lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o lundump.o lvm.o lzio.o LIB_O= lauxlib.o lbaselib.o lcorolib.o ldblib.o liolib.o lmathlib.o loadlib.o loslib.o lstrlib.o ltablib.o lutf8lib.o linit.o BASE_O= $(CORE_O) $(LIB_O) $(MYOBJS) @@ -218,8 +218,5 @@ lvm.o: lvm.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ ltable.h lvm.h ljumptab.h lzio.o: lzio.c lprefix.h lua.h luaconf.h llimits.h lmem.h lstate.h \ lobject.h ltm.h lzio.h -pallene_core.o: pallene_core.c pallene_core.h lapi.h ldo.h lfunc.h \ - lobject.h lstate.h lstring.h ltable.h lvm.h lmem.h lobject.h lstate.h \ - lstring.h ltm.h ltable.h # (end of Makefile) diff --git a/vm/src/lapi.c b/vm/src/lapi.c index f8f70cd0..9087f20d 100644 --- a/vm/src/lapi.c +++ b/vm/src/lapi.c @@ -1453,3 +1453,17 @@ LUA_API void lua_upvaluejoin (lua_State *L, int fidx1, int n1, } +/* +** PALLENE LINKER HACK +** +** When we build the final "lua" executable, bundling it with the "liblua.a" library, the linker +** only includes symbols from the object files where at least one of the symbols of the module is +** used by the executable itself. This is a problem for the Pallene runtime library, because those +** symbols are only going to be used by the extension modules, which we expect to dynamically link. +** The hacky workaround that we found is to compile the pallene_core stuff as part of the lapi.o, +** isntead of its own object file. +** +** As a bonus, we also avoid having to modify the Makefile. Conveniently, the set of header files +** that lapi.c depends on is a superset of the header files that pallene_core.c needs. +*/ +#include "pallene_core.c" diff --git a/vm/src/lua.c b/vm/src/lua.c index 736628d1..46b48dba 100644 --- a/vm/src/lua.c +++ b/vm/src/lua.c @@ -657,16 +657,3 @@ int main (int argc, char **argv) { return (result && status == LUA_OK) ? EXIT_SUCCESS : EXIT_FAILURE; } -/* -** PALLENE LINKER HACK -** -** When we build the final "lua" executable, bundling it with the "liblua.a" library, the linker -** only includes symbols from the object files where at least one of the symbols of the module is -** used by the executable itself. This is a problem for the Pallene runtime library, because those -** symbols are only used by extension modules, which we expect to dynamically link. One hacky -** workaround I found is to force the "lua" executable to reference one of the symbols from the -** pallene_core, as done below. -*/ -char *pallene_tag_name(int); -char *(*PALLENE_LINKER_HACK)(int) = pallene_tag_name; - diff --git a/vm/src/pallene_core.h b/vm/src/pallene_core.h index 0a92b762..75b28fde 100644 --- a/vm/src/pallene_core.h +++ b/vm/src/pallene_core.h @@ -6,23 +6,29 @@ #ifndef PALLENE_CORE_H #define PALLENE_CORE_H +// This list on includes should include basically everything we need. +// It is copied from lapi.c (grep for PALLENE LINKER HACK for more details) + #include "lua.h" #include "lauxlib.h" #include "lualib.h" #include "lapi.h" +#include "ldebug.h" #include "ldo.h" #include "lfunc.h" #include "lgc.h" +#include "lmem.h" #include "lobject.h" #include "lstate.h" #include "lstring.h" #include "ltable.h" +#include "ltm.h" +#include "lundump.h" #include "lvm.h" #include - #define PALLENE_NORETURN __attribute__((noreturn)) #define PALLENE_UNREACHABLE __builtin_unreachable() From 2c9e3318be5730ff7b9f667385b4f3f745a4fb26 Mon Sep 17 00:00:00 2001 From: Hugo Musso Gualandi Date: Sun, 25 Jul 2021 11:43:47 -0300 Subject: [PATCH 09/10] Add a link to the Lua manual --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 09191bbe..eee52311 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,8 @@ Pallene must be run against a custom-built version of the Lua interpreter. This custom version of Lua 5.4 doesn't have to be the same one that you will use to run the compiler itself, or to install the Luarocks packages. -To compile the custom version of Lua, follow the instructions found the vm/doc/readme.html. +To compile the custom version of Lua, follow the instructions found the [Lua README](https://www.lua.org/manual/5.4/readme.html), also found in the vm/doc/readme.html file. + For Linux, these are the commands you need to run: ```sh From 2f85fc47ab50086f7d9269405f1a544970509b3f Mon Sep 17 00:00:00 2001 From: Hugo Musso Gualandi Date: Sun, 25 Jul 2021 11:50:02 -0300 Subject: [PATCH 10/10] Install all the internal header files, including the pallene_core.h --- vm/Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vm/Makefile b/vm/Makefile index fed75b3c..3d2dc63f 100644 --- a/vm/Makefile +++ b/vm/Makefile @@ -40,7 +40,11 @@ PLATS= guess aix bsd c89 freebsd generic linux linux-readline macosx mingw posix # What to install. TO_BIN= lua luac -TO_INC= lua.h luaconf.h lualib.h lauxlib.h lua.hpp +TO_INC= lua.hpp \ + lapi.h lauxlib.h lcode.h lctype.h ldebug.h ldo.h lfunc.h lgc.h ljumptab.h \ + llex.h llimits.h lmem.h lobject.h lopcodes.h lopnames.h lparser.h lprefix.h \ + lstate.h lstring.h ltable.h ltm.h luaconf.h lua.h lualib.h lundump.h lvm.h \ + lzio.h pallene_core.h TO_LIB= liblua.a TO_MAN= lua.1 luac.1