Rework NODEMCU_MODULE() to not pull in extra gunk.

Third time lucky. I hope. Hi Terry.
This commit is contained in:
Johny Mattsson 2015-12-18 13:10:48 +11:00
parent 7e02935a27
commit 9003d3e8fb
3 changed files with 26 additions and 25 deletions

View File

@ -88,8 +88,11 @@ COMPONENTS_eagle.app.v6 = \
tsl2561/tsl2561lib.a \ tsl2561/tsl2561lib.a \
modules/libmodules.a \ modules/libmodules.a \
# Special consideration for modules to support NODEMCU_MODULE handling # Inspect the modules library and work out which modules need to be linked.
MODULES_LIB = $(filter %modules.a, $(DEP_LIBS_eagle.app.v6)) # For each enabled module, a symbol name of the form XYZ_module_selected is
# returned. At link time those names are declared undefined, so those (and
# only those) modules are pulled in.
SELECTED_MODULE_SYMS=$(filter %_module_selected %module_selected1,$(shell $(NM) modules/.output/$(TARGET)/$(FLAVOR)/lib/libmodules.a))
LINKFLAGS_eagle.app.v6 = \ LINKFLAGS_eagle.app.v6 = \
-Wl,--gc-sections \ -Wl,--gc-sections \
@ -100,9 +103,7 @@ LINKFLAGS_eagle.app.v6 = \
-Wl,--no-check-sections \ -Wl,--no-check-sections \
-Wl,--wrap=_xtos_set_exception_handler \ -Wl,--wrap=_xtos_set_exception_handler \
-Wl,-static \ -Wl,-static \
-Wl,--whole-archive \ $(addprefix -u , $(SELECTED_MODULE_SYMS)) \
$(MODULES_LIB) \
-Wl,--no-whole-archive \
-Wl,--start-group \ -Wl,--start-group \
-lc \ -lc \
-lgcc \ -lgcc \

View File

@ -34,37 +34,37 @@
* a foo function in your module. * a foo function in your module.
*/ */
#define MODULE_STRIFY__(x) #x
#define MODULE_STRIFY_(x) MODULE_STRIFY__(x)
#define MODULE_EXPAND_(x) x #define MODULE_EXPAND_(x) x
#define MODULE_PASTE_(x,y) x##y #define MODULE_PASTE_(x,y) x##y
#define MODULE_EXPAND_PASTE_(x,y) MODULE_PASTE_(x,y)
/* Given an uppercase name XYZ, look at the corresponding LUA_USE_MODULES_XYZ #define LOCK_IN_SECTION(s) __attribute__((used,unused,section(s)))
* and append that to the section name prefix (e.g. "lua_libs"). For an
* included module, this will yield either ".lua_libs" (for an empty #define) /* For the ROM table, we name the variable according to ( | denotes concat):
* or ".lua_libs1" (if #defined to 1). The linker script will then * cfgname | _module_selected | LUA_USE_MODULES_##cfgname
* pick up all items in those sections and construct an array for us. * where the LUA_USE_MODULES_XYZ macro is first expanded to yield either
* A non-included module ZZZ ends up in a section named * an empty string (or 1) if the module has been enabled, or the literal
* ".lua_libsLUA_USE_MODULES_ZZZ" which gets discarded by the linker (together * LUA_USE_MOUDLE_XYZ in the case it hasn't. Thus, the name of the variable
* with the associated module code). * ends up looking either like XYZ_module_enabled, or if not enabled,
* XYZ_module_enabledLUA_USE_MODULES_XYZ. This forms the basis for
* letting the build system detect automatically (via nm) which modules need
* to be linked in.
*/ */
#define PICK_SECTION_(pfx, name) \
pfx MODULE_STRIFY_(MODULE_EXPAND_(LUA_USE_MODULES_ ## name))
#define NODEMCU_MODULE(cfgname, luaname, map, initfunc) \ #define NODEMCU_MODULE(cfgname, luaname, map, initfunc) \
static const __attribute__((used,unused,section(PICK_SECTION_(".lua_libs",cfgname)))) \ const LOCK_IN_SECTION(".lua_libs") \
luaL_Reg MODULE_PASTE_(lua_lib_,cfgname) = { luaname, initfunc }; \ luaL_Reg MODULE_PASTE_(lua_lib_,cfgname) = { luaname, initfunc }; \
static const __attribute__((used,unused,section(PICK_SECTION_(".lua_rotable",cfgname)))) \ const LOCK_IN_SECTION(".lua_rotable") \
luaR_table MODULE_PASTE_(lua_rotable_,cfgname) = { luaname, map } luaR_table MODULE_EXPAND_PASTE_(cfgname,MODULE_EXPAND_PASTE_(_module_selected,MODULE_PASTE_(LUA_USE_MODULES_,cfgname))) \
= { luaname, map }
/* System module registration support, not using LUA_USE_MODULES_XYZ. */ /* System module registration support, not using LUA_USE_MODULES_XYZ. */
#define BUILTIN_LIB_INIT(name, luaname, initfunc) \ #define BUILTIN_LIB_INIT(name, luaname, initfunc) \
static const __attribute__((used,unused,section(".lua_libs"))) \ const LOCK_IN_SECTION(".lua_libs") \
luaL_Reg MODULE_PASTE_(lua_lib_,name) = { luaname, initfunc } luaL_Reg MODULE_PASTE_(lua_lib_,name) = { luaname, initfunc }
#define BUILTIN_LIB(name, luaname, map) \ #define BUILTIN_LIB(name, luaname, map) \
static const __attribute__((used,unused,section(".lua_rotable"))) \ const LOCK_IN_SECTION(".lua_rotable") \
luaR_table MODULE_PASTE_(lua_rotable_,name) = { luaname, map } luaR_table MODULE_PASTE_(lua_rotable_,name) = { luaname, map }
#if !(MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2) #if !(MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2)

View File

@ -83,10 +83,10 @@ SECTIONS
. = ALIGN(4); . = ALIGN(4);
lua_libs = ABSOLUTE(.); lua_libs = ABSOLUTE(.);
/* Allow either empty define or defined-to-1 to include the module */ /* Allow either empty define or defined-to-1 to include the module */
KEEP(*(.lua_libs .lua_libs1)) KEEP(*(.lua_libs))
LONG(0) LONG(0) /* Null-terminate the array */ LONG(0) LONG(0) /* Null-terminate the array */
lua_rotable = ABSOLUTE(.); lua_rotable = ABSOLUTE(.);
KEEP(*(.lua_rotable .lua_rotable1)) KEEP(*(.lua_rotable))
LONG(0) LONG(0) /* Null-terminate the array */ LONG(0) LONG(0) /* Null-terminate the array */
/* These are *only* pulled in by Lua, and therefore safe to put in flash */ /* These are *only* pulled in by Lua, and therefore safe to put in flash */