diff --git a/components/lua/lua-5.1/host/lflashimg.c b/components/lua/lua-5.1/host/lflashimg.c index 65edf07e..b8ab0a2b 100644 --- a/components/lua/lua-5.1/host/lflashimg.c +++ b/components/lua/lua-5.1/host/lflashimg.c @@ -181,23 +181,26 @@ static void addTS(lua_State *L, TString *ts) { * Enumerate all of the Protos in the Proto hiearchy and scan contents to collect * all referenced strings in a Lua Array at ToS. */ -static void scanProtoStrings(lua_State *L, const Proto* f) { +static void scanProtoStrings(lua_State *L, const Proto* f, int strip) { /* Table at L->Top[-1] is used to collect the strings */ int i; if (f->source) addTS(L, f->source); - if (f->packedlineinfo) + if (f->packedlineinfo && !strip) addTS(L, luaS_new(L, cast(const char *, f->packedlineinfo))); for (i = 0; i < f->sizek; i++) { if (ttisstring(f->k + i)) addTS(L, rawtsvalue(f->k + i)); } - for (i = 0; i < f->sizeupvalues; i++) addTS(L, f->upvalues[i]); - for (i = 0; i < f->sizelocvars; i++) addTS(L, f->locvars[i].varname); - for (i = 0; i < f->sizep; i++) scanProtoStrings(L, f->p[i]); + if (!strip) + { + for (i = 0; i < f->sizeupvalues; i++) addTS(L, f->upvalues[i]); + for (i = 0; i < f->sizelocvars; i++) addTS(L, f->locvars[i].varname); + } + for (i = 0; i < f->sizep; i++) scanProtoStrings(L, f->p[i], strip); } @@ -218,7 +221,10 @@ static void createROstrt(lua_State *L, FlashHeader *fh) { DBG_PRINT("Found: %s\n",getstr(rawtsvalue(L->top-2))); lua_pop(L, 1); // dump the value } - fh->nROsize = 2<nROuse); + // Ensure at least 30% overprovisioning, to reduce pathological chaining if nROuse is just under a power of 2 + fh->nROsize = 2<nROuse*1.3)); + DBG_PRINT("nROsize=%u, nROuse=%u\n",(unsigned)fh->nROsize,(unsigned)fh->nROuse); + FlashAddr *hashTab = flashAlloc(L, fh->nROsize * WORDSIZE); toFlashAddr(L, fh->pROhash, hashTab); @@ -354,13 +360,23 @@ static void *flashCopy(lua_State* L, int n, const char *fmt, void *src) { return dest; } +static void stripdebug (Proto *f) { + // Yes, this is leaking memory. In the cross compiler, that's *host* memory, and we don't care. + // It's more hassle than it's worth to stop it from doing so. + f->packedlineinfo = NULL; + f->locvars = NULL; + f->upvalues = NULL; + f->sizelocvars = 0; + f->sizeupvalues = 0; +} + /* The debug optimised version has a different Proto layout */ #define PROTO_COPY_MASK "AHAAAAAASIIIIIIIAI" /* * Do the actual prototype copy. */ -static void *functionToFlash(lua_State* L, const Proto* orig) { +static void *functionToFlash(lua_State* L, const Proto* orig, int strip) { Proto f; int i; @@ -372,36 +388,43 @@ static void *functionToFlash(lua_State* L, const Proto* orig) { if (f.sizep) { /* clone included Protos */ Proto **p = luaM_newvector(L, f.sizep, Proto *); for (i=0; imainProto, functionToFlash(L, main)); + toFlashAddr(L, fh->mainProto, functionToFlash(L, main, strip)); fh->flash_sig = FLASH_SIG + (address ? FLASH_SIG_ABSOLUTE : 0); fh->flash_size = curOffset*WORDSIZE; + printf("Flash image size: %u bytes (%.2fkiB, %.1f%% of available size of %ukiB)\n", ++ (unsigned)fh->flash_size,(double)fh->flash_size/1024.0,(double)fh->flash_size/(double)maxSize*100.0,(unsigned)(maxSize>>10)); if (fh->flash_size>maxSize) { fatal ("The image is too large for specfied LFS size"); }