symtab/, tools/: NuttX provides lists of available syscalls and library functions and tools to process them. The lists can be used to build symbol table which allows runtime program loading which can reuse functions already compiled into NuttX system image. List processing, compilation and linking to the final system image has been possible only under manual control until now.

Provided changes add option (CONFIG_EXECFUNCS_GENERATE_SYSTEM_SYMTAB) to build complete list of available functions and syscalls automatically.  The symbolic table is generated in form libsymtab.a which can be reused by application or directly pull in when "g_symtab" and "g_nsymbols" variables are requested by EXECFUNCS configuration.

I have tried to follow mechanisms for library compilation in different kernel protection modes but tested only flat no-MMU build. The basic assumption is that this library and libraries providing syscall stubs and C-library functions are available in user-space context and initial application (usually NSH) registers the symbol table through IOCTL.  The table can be reused then by another applications in their address space as kernel allows. Simple for flat or protected mode, I am not sure if really support in MMU mode. It is highly probable that I have made some mistake, overlooked something, but functionality is optional (should not cause troubles in any mode if disabled) and main purpose is to lower memory overhead when more applications are loaded on memory constrained system which usually use direct kernel calling without protection or address space separation. If the table should be provided by kernel to applications then makefiles has to be adjusted.
This commit is contained in:
Pavel Pisa 2019-08-13 09:09:43 -06:00 committed by Gregory Nutt
parent e3c2a0238a
commit 380198c985
8 changed files with 154 additions and 5 deletions

View File

@ -76,6 +76,19 @@ config EXECFUNCS_NSYMBOLS_VAR
symbols in that table. This selection provides the name of an 'int'
variable that contains the number of symbols in the symbol table.
config EXECFUNCS_GENERATE_SYSTEM_SYMTAB
bool "Generate and include system symbol table"
default n
---help---
Generate symbol table which includes symbols for all available
syscalls, libc and libm functions. It makes system significantly
larger but actual applications can reuse maximum from the system
image.
The symbol table array is named g_symtab and variable holding
number of exported symbols g_nsymbols. It matches expected defaults
from entries above. But they can be changed and generated symbol table
can be used as template by application.
endif # EXECFUNCS_HAVE_SYMTAB
endif # LIBC_EXECFUNCS

12
symtab/.gitignore vendored Normal file
View File

@ -0,0 +1,12 @@
/Make.dep
/.depend
/*.src
/*.obj
/*.asm
/*.rel
/*.lst
/*.sym
/*.adb
/*.lib
/symtab.c
/tmp.csv

94
symtab/Makefile Normal file
View File

@ -0,0 +1,94 @@
############################################################################
# symtab/Makefile
#
# Copyright (C) 2019 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
###########################################################################
-include $(TOPDIR)/Make.defs
MKSYMTAB = $(TOPDIR)$(DELIM)tools$(DELIM)mksymtab$(HOSTEXEEXT)
CSVFILES = $(TOPDIR)$(DELIM)syscall$(DELIM)syscall.csv \
$(TOPDIR)$(DELIM)libs$(DELIM)libc$(DELIM)libc.csv \
$(TOPDIR)$(DELIM)libs$(DELIM)libc$(DELIM)math.csv
DEPPATH = --dep-path .
SYMTAB_CSRCS =
BIN = libsymtab$(LIBEXT)
ifeq ($(CONFIG_EXECFUNCS_GENERATE_SYSTEM_SYMTAB),y)
all: symtab.c $(BIN)
.PHONY: all
SYMTAB_CSRCS += symtab.c
SYMTAB_COBJS = $(SYMTAB_CSRCS:.c=$(OBJEXT))
SYMTAB_SRCS = $(SYMTAB_CSRCS)
SYMTAB_OBJS = $(SYMTAB_COBJS)
%$(OBJEXT): %.c
$(call COMPILE, $<, $@)
$(BIN): $(SYMTAB_OBJS)
$(call ARCHIVE, $@, $(SYMTAB_OBJS))
$(MKSYMTAB):
$(Q) $(MAKE) -C $(TOPDIR)$(DELIM)tools -f Makefile.host mksymtab
symtab.c : $(CSVFILES) $(MKSYMTAB)
$(Q) rm -f tmp.csv $@
$(Q) cat $(CSVFILES) | sort >tmp.csv
$(Q) $(MKSYMTAB) tmp.csv $@
$(Q) echo >>$@
$(Q) echo >>$@ 'int g_nsymbols = NSYMBOLS;'
else
all:
endif
.depend: Makefile $(SYMTAB_SRCS)
$(Q) $(MKDEP) $(DEPPATH) "$(CC)" -- $(CFLAGS) -- $(SYMTAB_SRCS) >Make.dep
$(Q) touch $@
depend: .depend
clean:
$(call DELFILE, $(BIN))
symtab.c
rm -f tmp.csv
distclean: clean
-include Make.dep

View File

@ -1,7 +1,7 @@
############################################################################
# tools/Directories.mk
#
# Copyright (C) 2007-2012, 2014, 2016-2018 Gregory Nutt. All rights
# Copyright (C) 2007-2012, 2014, 2016-2019 Gregory Nutt. All rights
# reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
@ -85,6 +85,12 @@ CONTEXTDIRS = boards $(APPDIR)
USERDIRS =
OTHERDIRS = pass1
ifeq ($(CONFIG_EXECFUNCS_GENERATE_SYSTEM_SYMTAB),y)
USERDIRS += symtab
else
OTHERDIRS += symtab
endif
ifeq ($(CONFIG_BUILD_PROTECTED),y)
USERDIRS += libs$(DELIM)libc mm $(USER_ADDONS)

View File

@ -1,7 +1,7 @@
############################################################################
# tools/FlatLibs.mk
#
# Copyright (C) 2007-2012, 2014, 2016-2018 Gregory Nutt. All rights
# Copyright (C) 2007-2012, 2014, 2016-2019 Gregory Nutt. All rights
# reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
@ -142,6 +142,12 @@ ifeq ($(CONFIG_LIBDSP),y)
NUTTXLIBS += staging$(DELIM)libdsp$(LIBEXT)
endif
# Add symbol table library
ifeq ($(CONFIG_EXECFUNCS_GENERATE_SYSTEM_SYMTAB),y)
NUTTXLIBS += staging$(DELIM)libsymtab$(LIBEXT)
endif
# Export all libraries
EXPORTLIBS = $(NUTTXLIBS)

View File

@ -1,7 +1,7 @@
############################################################################
# tools/KernelLibs.mk
#
# Copyright (C) 2014, 2016, 2018 Gregory Nutt. All rights reserved.
# Copyright (C) 2014, 2016, 2018-2019 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@ -136,6 +136,12 @@ ifeq ($(CONFIG_LIBDSP),y)
NUTTXLIBS += staging$(DELIM)libdsp$(LIBEXT)
endif
# Add symbol table library
ifeq ($(CONFIG_EXECFUNCS_GENERATE_SYSTEM_SYMTAB),y)
NUTTXLIBS += staging$(DELIM)libsymtab$(LIBEXT)
endif
# Export only the user libraries
EXPORTLIBS = $(USERLIBS)

View File

@ -1,7 +1,7 @@
############################################################################
# tools/LibTargets.mk
#
# Copyright (C) 2007-2012, 2014, 2018 Gregory Nutt. All rights reserved.
# Copyright (C) 2007-2012, 2014, 2019 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@ -200,6 +200,12 @@ syscall$(DELIM)libproxies$(LIBEXT): context
staging$(DELIM)libproxies$(LIBEXT): syscall$(DELIM)libproxies$(LIBEXT)
$(Q) $(call INSTALL_LIB,$<,$@)
symtab$(DELIM)libsymtab$(LIBEXT): context
$(Q) $(MAKE) -C symtab TOPDIR="$(TOPDIR)" libsymtab$(LIBEXT) KERNEL=n
staging$(DELIM)libsymtab$(LIBEXT): symtab$(DELIM)libsymtab$(LIBEXT)
$(Q) $(call INSTALL_LIB,$<,$@)
# Possible non-kernel builds
libs$(DELIM)libc$(DELIM)libc$(LIBEXT): context

View File

@ -1,7 +1,7 @@
############################################################################
# tools/ProtectedLibs.mk
#
# Copyright (C) 2007-2012, 2014, 2016-2018 Gregory Nutt. All rights
# Copyright (C) 2007-2012, 2014, 2016-2019 Gregory Nutt. All rights
# reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
@ -143,6 +143,12 @@ ifeq ($(CONFIG_LIBDSP),y)
NUTTXLIBS += staging$(DELIM)libdsp$(LIBEXT)
endif
# Add symbol table library
ifeq ($(CONFIG_EXECFUNCS_GENERATE_SYSTEM_SYMTAB),y)
NUTTXLIBS += staging$(DELIM)libsymtab$(LIBEXT)
endif
# Export only the user libraries
EXPORTLIBS = $(USERLIBS)