Browse Source

Bump binary version & smaller sizes for stripped binaries

pull/218/head
XmiliaH 8 months ago
parent
commit
5ca801596a
6 changed files with 43 additions and 9 deletions
  1. +14
    -0
      src/ldump.c
  2. +2
    -2
      src/lfunc.c
  3. +23
    -3
      src/lundump.c
  4. +1
    -1
      src/lundump.h
  5. +2
    -2
      src/ravi_jitshared.c
  6. +1
    -1
      tests/lua53/calls.lua

+ 14
- 0
src/ldump.c View File

@ -157,6 +157,13 @@ static void DumpDebug (const Proto *f, DumpState *D) {
DumpVector(f->lineinfo, n, D);
/* n = (D->strip) ? 0 : f->sizelocvars; */
n = f->sizelocvars;
if (D->strip) {
for (i = n - 1; i >= 0; i--) {
if (f->locvars[i].ravi_type_map != RAVI_TM_ANY)
break;
}
n = i + 1;
}
DumpInt(n, D);
for (i = 0; i < n; i++) {
DumpString((D->strip) ? NULL : f->locvars[i].varname, D);
@ -167,6 +174,13 @@ static void DumpDebug (const Proto *f, DumpState *D) {
}
/* n = (D->strip) ? 0 : f->sizeupvalues; */
n = f->sizeupvalues;
if (D->strip) {
for (i = n - 1; i >= 0; i--) {
if (f->upvalues[i].ravi_type_map != RAVI_TM_ANY)
break;
}
n = i + 1;
}
DumpInt(n, D);
for (i = 0; i < n; i++) {
DumpString((D->strip) ? NULL : f->upvalues[i].name, D);


+ 2
- 2
src/lfunc.c View File

@ -249,10 +249,10 @@ const char *luaF_getlocalname (const Proto *f, int local_number, int pc, ravi_ty
if (pc < f->locvars[i].endpc) { /* is variable active? */
local_number--;
if (local_number == 0) {
if (f->locvars[i].varname == NULL)
break;
*type = f->locvars[i].ravi_type_map;
*usertype = f->locvars[i].usertype;
if (f->locvars[i].varname == NULL)
return NULL;
return getstr(f->locvars[i].varname);
}
}


+ 23
- 3
src/lundump.c View File

@ -37,6 +37,7 @@ typedef struct {
lua_State *L;
ZIO *Z;
const char *name;
lu_byte version;
} LoadState;
@ -174,6 +175,7 @@ static void LoadUpvalues (LoadState *S, Proto *f) {
f->sizeupvalues = n;
for (i = 0; i < n; i++) {
f->upvalues[i].name = NULL;
f->upvalues[i].ravi_type_map = RAVI_TM_ANY;
f->upvalues[i].usertype = NULL;
}
for (i = 0; i < n; i++) {
@ -183,6 +185,23 @@ static void LoadUpvalues (LoadState *S, Proto *f) {
}
}
static ravi_type_map ravi_map_old_type_to_new(lu_byte type) {
switch (type) {
case 0: return RAVI_TM_ANY;
case 1: return RAVI_TM_INTEGER;
case 2: return RAVI_TM_FLOAT;
case 3: return RAVI_TM_INTEGER_ARRAY;
case 4: return RAVI_TM_FLOAT_ARRAY;
case 5: return RAVI_TM_FUNCTION | RAVI_TM_NIL;
case 6: return RAVI_TM_TABLE;
case 7: return RAVI_TM_STRING | RAVI_TM_NIL;
case 8: return RAVI_TM_NIL;
case 9: return RAVI_TM_BOOLEAN | RAVI_TM_NIL;
case 10: return RAVI_TM_USERDATA | RAVI_TM_NIL;
default: return RAVI_TM_ANY;
}
}
static void LoadDebug (LoadState *S, Proto *f) {
int i, n;
n = LoadInt(S);
@ -200,13 +219,13 @@ static void LoadDebug (LoadState *S, Proto *f) {
f->locvars[i].varname = LoadString(S);
f->locvars[i].startpc = LoadInt(S);
f->locvars[i].endpc = LoadInt(S);
f->locvars[i].ravi_type_map = LoadInt(S);
f->locvars[i].ravi_type_map = S->version == 0 ? ravi_map_old_type_to_new(LoadByte(S)) : LoadInt(S);
f->locvars[i].usertype = LoadString(S);
}
n = LoadInt(S);
for (i = 0; i < n; i++) {
f->upvalues[i].name = LoadString(S);
f->upvalues[i].ravi_type_map = LoadInt(S);
f->upvalues[i].ravi_type_map = S->version == 0 ? ravi_map_old_type_to_new(LoadByte(S)) : LoadInt(S);
f->upvalues[i].usertype = LoadString(S);
}
}
@ -250,7 +269,8 @@ static void checkHeader (LoadState *S) {
checkliteral(S, LUA_SIGNATURE + 1, "not a"); /* 1st char already checked */
if (LoadByte(S) != LUAC_VERSION)
error(S, "version mismatch in");
if (LoadByte(S) != LUAC_FORMAT)
S->version = LoadByte(S);
if (S->version > LUAC_FORMAT)
error(S, "format mismatch in");
checkliteral(S, LUAC_DATA, "corrupted");
checksize(S, int);


+ 1
- 1
src/lundump.h View File

@ -20,7 +20,7 @@
#define MYINT(s) (s[0]-'0')
#define LUAC_VERSION (MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR))
#define LUAC_FORMAT 0 /* this is the official format */
#define LUAC_FORMAT 1 /* this is the official format */
/* load one chunk; from lundump.c */
LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name);


+ 2
- 2
src/ravi_jitshared.c View File

@ -1214,8 +1214,8 @@ static void initfn(struct function *fn, struct lua_State *L, struct Proto *p, co
fn->options = options;
snprintf(fn->fname, sizeof fn->fname, "%s", fname);
fn->jmps = calloc(p->sizecode, sizeof fn->jmps[0]);
if (p->sizelocvars)
fn->locals = calloc(p->sizelocvars, sizeof fn->locals[0]);
if (p->maxstacksize)
fn->locals = calloc(p->maxstacksize, sizeof fn->locals[0]);
else
fn->locals = NULL;
membuff_init(&fn->prologue, strlen(Lua_header) + 4096);


+ 1
- 1
tests/lua53/calls.lua View File

@ -367,7 +367,7 @@ do
local header = string.pack("c5BBc6BBBBBj",
"\27Ravi", -- signature
5*16 + 3, -- version 5.3
0, -- format
1, -- format
"\x19\x93\r\n\x1a\n", -- data
string.packsize("i"), -- sizeof(int)
string.packsize("T"), -- sizeof(size_t)


Loading…
Cancel
Save