* Added own custom version of Lua

* Updated Lua to produce architecture-independent bytecode
* Updated Lua to load bytecode from different endianess
* Updated Lua to use optimized integer arithmetic for CPUs without an FPU
* Updated haserl-lua to fit to optimized Lua version (hopefully this should fix: "bad header in precompiled chunk" on some platforms)
* Luci core will now be bytecompiled and stripped by default to save disk space and CPU time
This commit is contained in:
Steven Barth 2008-04-05 15:12:02 +00:00
parent 55c2ac261f
commit 6adf7451cf
8 changed files with 4224 additions and 5 deletions

View file

@ -15,7 +15,7 @@ PKG_SOURCE:=$(PKG_SOURCE_SUBDIR).tar.gz
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/ipkg-install
MAKE_ACTION:=dist-source
MAKE_ACTION:=dist-compile LUAC=$(BUILD_DIR_HOST)/lua-luci/luac
include $(INCLUDE_DIR)/package.mk
@ -23,7 +23,7 @@ define Package/ffluci
SECTION:=admin
CATEGORY:=Administration
TITLE:=FFLuCI
DEPENDS:=+liblua +luaposix +haserl-lua
DEPENDS:=+luaposix +haserl-lua
MAINTAINER:=Steven Barth <steven-at-midlink-dot-org>
endef

View file

@ -24,7 +24,7 @@ define Package/haserl-lua
CATEGORY:=Utilities
TITLE:=A CGI wrapper to embed shell scripts in HTML documents
URL:=http://haserl.sourceforge.net/
DEPENDS:=+liblua
DEPENDS:=+liblua-luci
endef
CONFIGURE_ARGS += \

View file

@ -0,0 +1,12 @@
diff -ur haserl-0.9.23.orig/src/haserl_lualib.inc haserl-0.9.23/src/haserl_lualib.inc
--- haserl-0.9.23.orig/src/haserl_lualib.inc 2008-04-05 16:40:35.000000000 +0200
+++ haserl-0.9.23/src/haserl_lualib.inc 2008-04-05 16:41:37.000000000 +0200
@@ -1,7 +1,7 @@
/* This file was automatically generated from haserl_lualib.lua. DO NOT EDIT */
static const unsigned char haserl_lualib[] = {
- 27, 76,117, 97, 81, 0, 1, 4, 4, 4, 8, 0, 19, 0, 0, 0,
+ 27, 76,117, 97, 81, 0, 1, 4, 4, 4, 8, 4, 19, 0, 0, 0,
64,104, 97,115,101,114,108, 95,108,117, 97,108,105, 98, 46,108,
117, 97, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 16,
0, 0, 0, 10, 0, 0, 0, 74, 0, 0, 0,138, 0, 0, 0,135,

View file

@ -0,0 +1,149 @@
#
# Copyright (C) 2006 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
# $Id: Makefile 10499 2008-02-19 23:40:28Z nico $
include $(TOPDIR)/rules.mk
PKG_NAME:=lua
PKG_VERSION:=5.1.3
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://www.lua.org/ftp/ \
http://ftp.gwdg.de/pub/languages/lua/ \
http://mirrors.dotsrc.org/lua/ \
http://www.tecgraf.puc-rio.br/lua/ftp/
PKG_MD5SUM:=a70a8dfaa150e047866dc01a46272599
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/ipkg-install
X_HOST_DIR:=$(BUILD_DIR_HOST)/$(PKG_NAME)-luci
include $(INCLUDE_DIR)/package.mk
define Package/lua-luci/Default
SUBMENU:=LUA
SECTION:=lang
CATEGORY:=Languages
TITLE:=LUA programming language
URL:=http://www.lua.org/
endef
define Package/lua-luci/Default/description
Lua is a powerful light-weight programming language designed for extending
applications. Lua is also frequently used as a general-purpose, stand-alone
language. Lua is free software.
endef
define Package/liblua-luci
$(call Package/lua-luci/Default)
SUBMENU:=
SECTION:=libs
CATEGORY:=Libraries
TITLE+= (libraries)
endef
define Package/liblua-luci/description
$(call Package/lua-luci/Default/description)
This package contains the LUA shared libraries, needed by other programs.
endef
define Package/lua-luci
$(call Package/lua-luci/Default)
DEPENDS:=+liblua-luci +libreadline +libncurses
TITLE+= (interpreter)
endef
define Package/lua-luci/description
$(call Package/lua-luci/Default/description)
This package contains the LUA language interpreter.
endef
define Package/luac-luci
$(call Package/lua-luci/Default)
DEPENDS:=+liblua-luci
TITLE+= (compiler)
endef
define Package/luac/description
$(call Package/lua-luci/Default/description)
This package contains the LUA language compiler.
endef
define Package/lua-luci-examples
$(call Package/lua-luci/Default)
DEPENDS:=lua-luci
TITLE+= (examples)
endef
define Package/lua-luci-examples/description
$(call Package/lua-luci/Default/description)
This package contains LUA language examples.
endef
define Build/Configure
endef
define Build/Compile
cp $(PKG_BUILD_DIR)/src $(PKG_BUILD_DIR)/src-host -R
$(MAKE) -C $(PKG_BUILD_DIR) \
CC="$(TARGET_CROSS)gcc" \
LD="$(TARGET_CROSS)ld" \
AR="$(TARGET_CROSS)ar rcu" \
RANLIB="$(TARGET_CROSS)ranlib" \
INSTALL_ROOT=/usr \
MYCFLAGS="$(TARGET_CPPFLAGS) $(TARGET_CFLAGS)" \
MYLDFLAGS="$(TARGET_LDFLAGS)" \
PKG_VERSION=$(PKG_VERSION) \
all linux
rm -rf $(PKG_INSTALL_DIR)
mkdir -p $(PKG_INSTALL_DIR)
$(MAKE) -C $(PKG_BUILD_DIR) \
INSTALL_TOP="$(PKG_INSTALL_DIR)/usr" \
install
$(MAKE) -C $(PKG_BUILD_DIR)/src-host luac-host
mkdir -p $(X_HOST_DIR)
cp $(PKG_BUILD_DIR)/src-host/luac-host $(X_HOST_DIR)/luac
endef
define Build/InstallDev
mkdir -p $(1)/usr/include
$(CP) $(PKG_INSTALL_DIR)/usr/include/lua{,lib,conf}.h $(1)/usr/include/
$(CP) $(PKG_INSTALL_DIR)/usr/include/lauxlib.h $(1)/usr/include/
$(CP) $(PKG_INSTALL_DIR)/usr/include/lnum_config.h $(1)/usr/include/
mkdir -p $(1)/usr/lib
$(CP) $(PKG_INSTALL_DIR)/usr/lib/liblua.{a,so.*} $(1)/usr/lib/
ln -sf liblua.so.$(PKG_VERSION) $(1)/usr/lib/liblua.so
ln -sf liblua.so.$(PKG_VERSION) $(1)/usr/lib/liblualib.so
endef
define Package/liblua-luci/install
$(INSTALL_DIR) $(1)/usr/lib
$(CP) $(PKG_INSTALL_DIR)/usr/lib/liblua.so.* $(1)/usr/lib/
endef
define Package/lua-luci/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/lua $(1)/usr/bin/
endef
define Package/luac-luci/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/luac $(1)/usr/bin/
endef
define Package/lua-luci-examples/install
$(INSTALL_DIR) $(1)/usr/share/lua/examples
$(INSTALL_DATA) $(PKG_BUILD_DIR)/test/*.lua \
$(1)/usr/share/lua/examples/
endef
$(eval $(call BuildPackage,liblua-luci))
$(eval $(call BuildPackage,lua-luci))
$(eval $(call BuildPackage,luac-luci))
$(eval $(call BuildPackage,lua-luci-examples))

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,139 @@
diff -ur lua-5.1.3-pt1/Makefile lua-5.1.3-pt2/Makefile
--- lua-5.1.3-pt1/Makefile 2008-04-05 14:23:14.000000000 +0200
+++ lua-5.1.3-pt2/Makefile 2008-04-05 15:13:38.000000000 +0200
@@ -37,8 +37,8 @@
# What to install.
TO_BIN= lua luac
-TO_INC= lua.h luaconf.h lualib.h lauxlib.h ../etc/lua.hpp
-TO_LIB= liblua.a
+TO_INC= lua.h luaconf.h lualib.h lauxlib.h ../etc/lua.hpp lnum_config.h
+TO_LIB= liblua.a liblua.so liblua.so.$R
TO_MAN= lua.1 luac.1
# Lua version and release.
diff -ur lua-5.1.3-pt1/src/ldo.h lua-5.1.3-pt2/src/ldo.h
--- lua-5.1.3-pt1/src/ldo.h 2008-04-05 14:23:14.000000000 +0200
+++ lua-5.1.3-pt2/src/ldo.h 2008-04-05 14:25:40.000000000 +0200
@@ -46,7 +46,7 @@
LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult);
LUAI_FUNC void luaD_reallocCI (lua_State *L, int newsize);
LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize);
-LUAI_FUNC void luaD_growstack (lua_State *L, int n);
+LUA_API void luaD_growstack (lua_State *L, int n);
LUAI_FUNC void luaD_throw (lua_State *L, int errcode);
LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);
diff -ur lua-5.1.3-pt1/src/lfunc.h lua-5.1.3-pt2/src/lfunc.h
--- lua-5.1.3-pt1/src/lfunc.h 2008-04-05 14:23:14.000000000 +0200
+++ lua-5.1.3-pt2/src/lfunc.h 2008-04-05 14:25:40.000000000 +0200
@@ -18,7 +18,7 @@
cast(int, sizeof(TValue *)*((n)-1)))
-LUAI_FUNC Proto *luaF_newproto (lua_State *L);
+LUA_API Proto *luaF_newproto (lua_State *L);
LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e);
LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e);
LUAI_FUNC UpVal *luaF_newupval (lua_State *L);
diff -ur lua-5.1.3-pt1/src/lmem.h lua-5.1.3-pt2/src/lmem.h
--- lua-5.1.3-pt1/src/lmem.h 2008-04-05 14:23:14.000000000 +0200
+++ lua-5.1.3-pt2/src/lmem.h 2008-04-05 14:25:40.000000000 +0200
@@ -38,9 +38,9 @@
((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t))))
-LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize,
+LUA_API void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize,
size_t size);
-LUAI_FUNC void *luaM_toobig (lua_State *L);
+LUA_API void *luaM_toobig (lua_State *L);
LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size,
size_t size_elem, int limit,
const char *errormsg);
diff -ur lua-5.1.3-pt1/src/lstring.h lua-5.1.3-pt2/src/lstring.h
--- lua-5.1.3-pt1/src/lstring.h 2008-04-05 14:23:14.000000000 +0200
+++ lua-5.1.3-pt2/src/lstring.h 2008-04-05 14:25:40.000000000 +0200
@@ -25,7 +25,7 @@
LUAI_FUNC void luaS_resize (lua_State *L, int newsize);
LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e);
-LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l);
+LUA_API TString *luaS_newlstr (lua_State *L, const char *str, size_t l);
#endif
diff -ur lua-5.1.3-pt1/src/lundump.h lua-5.1.3-pt2/src/lundump.h
--- lua-5.1.3-pt1/src/lundump.h 2008-04-05 14:23:14.000000000 +0200
+++ lua-5.1.3-pt2/src/lundump.h 2008-04-05 14:25:40.000000000 +0200
@@ -17,7 +17,7 @@
LUAI_FUNC void luaU_header (char* h);
/* dump one chunk; from ldump.c */
-LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip);
+LUA_API int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip);
#ifdef luac_c
/* print one chunk; from print.c */
diff -ur lua-5.1.3-pt1/src/Makefile lua-5.1.3-pt2/src/Makefile
--- lua-5.1.3-pt1/src/Makefile 2008-04-05 14:23:31.000000000 +0200
+++ lua-5.1.3-pt2/src/Makefile 2008-04-05 14:25:40.000000000 +0200
@@ -23,6 +23,7 @@
PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris
LUA_A= liblua.a
+LUA_SO= liblua.so
CORE_O= lapi.o lcode.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 lnum.o
@@ -33,11 +34,12 @@
LUA_O= lua.o
LUAC_T= luac
-LUAC_O= luac.o print.o
+LUAC_O= luac.o print.o lopcodes.o
ALL_O= $(CORE_O) $(LIB_O) $(LUA_O) $(LUAC_O)
-ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T)
+ALL_T= $(LUA_A) $(LUA_SO) $(LUA_T) $(LUAC_T)
ALL_A= $(LUA_A)
+ALL_SO= $(LUA_SO)
default: $(PLAT)
@@ -47,14 +49,23 @@
a: $(ALL_A)
+so: $(ALL_SO)
+
$(LUA_A): $(CORE_O) $(LIB_O)
$(AR) $@ $?
$(RANLIB) $@
-$(LUA_T): $(LUA_O) $(LUA_A)
- $(CC) -o $@ $(MYLDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)
+$(LUA_SO): $(CORE_O) $(LIB_O)
+ $(LD) -o $@.$(PKG_VERSION) -shared -soname="$@.$(PKG_VERSION)" $?
+ ln -fs $@.$(PKG_VERSION) $@
+
+$(LUA_T): $(LUA_O) $(LUA_SO)
+ $(CC) -o $@ -L. -llua $(MYLDFLAGS) $(LUA_O) $(LIBS)
+
+$(LUAC_T): $(LUAC_O) $(LUA_SO)
+ $(CC) -o $@ -L. -llua $(MYLDFLAGS) $(LUAC_O) $(LIBS)
-$(LUAC_T): $(LUAC_O) $(LUA_A)
+$(LUAC_T)-host: $(LUAC_O) $(LUA_A)
$(CC) -o $@ $(MYLDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS)
clean:
@@ -96,7 +107,7 @@
$(MAKE) all MYCFLAGS=
linux:
- $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses"
+ $(MAKE) all MYCFLAGS+=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses"
macosx:
$(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-lreadline"

View file

@ -0,0 +1,113 @@
diff -ur lua-5.1.3-pt2/src/ldump.c lua-5.1.3-pt3/src/ldump.c
--- lua-5.1.3-pt2/src/ldump.c 2008-04-05 14:25:13.000000000 +0200
+++ lua-5.1.3-pt3/src/ldump.c 2008-04-05 14:28:27.000000000 +0200
@@ -67,12 +67,12 @@
{
if (s==NULL || getstr(s)==NULL)
{
- size_t size=0;
+ unsigned int size=0;
DumpVar(size,D);
}
else
{
- size_t size=s->tsv.len+1; /* include trailing '\0' */
+ unsigned int size=s->tsv.len+1; /* include trailing '\0' */
DumpVar(size,D);
DumpBlock(getstr(s),size,D);
}
diff -ur lua-5.1.3-pt2/src/lundump.c lua-5.1.3-pt3/src/lundump.c
--- lua-5.1.3-pt2/src/lundump.c 2008-04-05 14:25:13.000000000 +0200
+++ lua-5.1.3-pt3/src/lundump.c 2008-04-05 14:28:27.000000000 +0200
@@ -25,6 +25,7 @@
ZIO* Z;
Mbuffer* b;
const char* name;
+ int swap;
} LoadState;
#ifdef LUAC_TRUST_BINARIES
@@ -40,7 +41,6 @@
}
#endif
-#define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size))
#define LoadByte(S) (lu_byte)LoadChar(S)
#define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x))
#define LoadVector(S,b,n,size) LoadMem(S,b,n,size)
@@ -52,6 +52,49 @@
IF (r!=0, "unexpected end");
}
+static void LoadMem (LoadState* S, void* b, int n, size_t size)
+{
+ LoadBlock(S,b,n*size);
+ if (S->swap)
+ {
+ char* p=(char*) b;
+ char c;
+ switch (size)
+ {
+ case 1:
+ break;
+ case 2:
+ while (n--)
+ {
+ c=p[0]; p[0]=p[1]; p[1]=c;
+ p+=2;
+ }
+ break;
+ case 4:
+ while (n--)
+ {
+ c=p[0]; p[0]=p[3]; p[3]=c;
+ c=p[1]; p[1]=p[2]; p[2]=c;
+ p+=4;
+ }
+ break;
+ case 8:
+ while (n--)
+ {
+ c=p[0]; p[0]=p[7]; p[7]=c;
+ c=p[1]; p[1]=p[6]; p[6]=c;
+ c=p[2]; p[2]=p[5]; p[5]=c;
+ c=p[3]; p[3]=p[4]; p[4]=c;
+ p+=8;
+ }
+ break;
+ default:
+ IF(1, "bad size");
+ break;
+ }
+ }
+}
+
static int LoadChar(LoadState* S)
{
char x;
@@ -83,7 +126,7 @@
static TString* LoadString(LoadState* S)
{
- size_t size;
+ unsigned int size;
LoadVar(S,size);
if (size==0)
return NULL;
@@ -194,6 +237,7 @@
char s[LUAC_HEADERSIZE];
luaU_header(h);
LoadBlock(S,s,LUAC_HEADERSIZE);
+ S->swap=(s[6]!=h[6]); s[6]=h[6];
IF (memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header");
}
@@ -228,7 +272,7 @@
*h++=(char)LUAC_FORMAT;
*h++=(char)*(char*)&x; /* endianness */
*h++=(char)sizeof(int);
- *h++=(char)sizeof(size_t);
+ *h++=(char)sizeof(unsigned int);
*h++=(char)sizeof(Instruction);
*h++=(char)sizeof(lua_Number);

View file

@ -18,7 +18,7 @@ define Package/luaposix
CATEGORY:=Libraries
TITLE:=Lua Posix library
URL:=http://luaforge.net/projects/luaposix/
DEPENDS:=+liblua
DEPENDS:=+liblua-luci
MAINTAINER:=Steven Barth <steven-at-midlink-dot-org>
endef
@ -41,4 +41,4 @@ define Package/luaposix/install
$(INSTALL_BIN) $(PKG_BUILD_DIR)/posix.so $(1)/usr/lib/lua
endef
$(eval $(call BuildPackage,luaposix))
$(eval $(call BuildPackage,luaposix))