diff --git a/libs/libc/unistd/Kconfig b/libs/libc/unistd/Kconfig index 1c9795f4d0..ff38e78947 100644 --- a/libs/libc/unistd/Kconfig +++ b/libs/libc/unistd/Kconfig @@ -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 diff --git a/symtab/.gitignore b/symtab/.gitignore new file mode 100644 index 0000000000..eca9a5068e --- /dev/null +++ b/symtab/.gitignore @@ -0,0 +1,12 @@ +/Make.dep +/.depend +/*.src +/*.obj +/*.asm +/*.rel +/*.lst +/*.sym +/*.adb +/*.lib +/symtab.c +/tmp.csv diff --git a/symtab/Makefile b/symtab/Makefile new file mode 100644 index 0000000000..c4429949b2 --- /dev/null +++ b/symtab/Makefile @@ -0,0 +1,94 @@ +############################################################################ +# symtab/Makefile +# +# Copyright (C) 2019 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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 + diff --git a/tools/Directories.mk b/tools/Directories.mk index 2017cdd186..2afec5151b 100644 --- a/tools/Directories.mk +++ b/tools/Directories.mk @@ -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 # @@ -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) diff --git a/tools/FlatLibs.mk b/tools/FlatLibs.mk index 6e7091c152..783dbbf4fb 100644 --- a/tools/FlatLibs.mk +++ b/tools/FlatLibs.mk @@ -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 # @@ -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) diff --git a/tools/KernelLibs.mk b/tools/KernelLibs.mk index 4a8600ec90..3ae86a987c 100644 --- a/tools/KernelLibs.mk +++ b/tools/KernelLibs.mk @@ -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 # # 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) diff --git a/tools/LibTargets.mk b/tools/LibTargets.mk index d979af2ab5..1a656d94cb 100644 --- a/tools/LibTargets.mk +++ b/tools/LibTargets.mk @@ -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 # # 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 diff --git a/tools/ProtectedLibs.mk b/tools/ProtectedLibs.mk index e4c352f09f..4adb31b1ec 100644 --- a/tools/ProtectedLibs.mk +++ b/tools/ProtectedLibs.mk @@ -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 # @@ -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)