mirror of
https://github.com/apache/nuttx.git
synced 2026-10-06 11:03:16 +08:00
tools/nxflat: Import the NXFLAT thunk generator.
An NXFLAT module reaches the base firmware through a "thunk" file: one assembly stub per imported function, generated by mknxflat. That tool has always lived outside this repository, in the NuttX buildroot NXFLAT toolchain, so building an NXFLAT module needs a separate checkout and a separate build of a tool that links against libbfd. libbfd is why it stayed out. It is GPL, which an Apache project cannot depend on, and it is awkward to obtain besides -- a stock binutils install often ships libbfd without the libiberty it needs to link. But the dependency was never deep. mknxflat used libbfd for eight calls, all of them opening the file and walking the symbol table; it never relocates or rewrites anything. That is replaced here by reading the ELF symbol table directly, which removes the dependency outright and costs about a hundred lines. The emitted text is unchanged. The format strings live in the .def files, which are carried here byte-for-byte from upstream, and the selection rule for what becomes a thunk is the upstream one: everything undefined that is not explicitly an object. Symbol typing cannot be trusted for this -- imported functions are routinely emitted as STT_NOTYPE rather than STT_FUNC, while a weakly defined object does appear as an undefined object -- so the test is on what a symbol is not. Upstream chose the instruction set at compile time through an "arch" symlink pointing at either arm/ or thumb2/. A symlink cannot be carried in the repository, and one host binary has to serve boards of both flavours, since lpc31xx is ARM while lpc17xx, tiva, stm32f1 and rp23xx are Thumb-2. That choice becomes a runtime "-a" option. The "-f" option, which read further command line arguments from a file, is dropped; nothing in the tree used it. This commit changes no output. Against the upstream tool, for both architectures, with and without -w, over modules exercising the plain, weak and non-returning thunk paths, the generated thunk files are byte-identical. Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
This commit is contained in:
committed by
Xiang Xiao
parent
df8538608e
commit
8d08885d0f
@@ -7,6 +7,7 @@
|
||||
/gencromfs
|
||||
/initialconfig
|
||||
/mkconfig
|
||||
/mknxflat
|
||||
/mkdeps
|
||||
/cnvwindeps
|
||||
/logparser
|
||||
|
||||
+17
-2
@@ -39,14 +39,15 @@ all: b16$(HOSTEXEEXT) bdf-converter$(HOSTEXEEXT) cmpconfig$(HOSTEXEEXT) \
|
||||
initialconfig$(HOSTEXEEXT) gencromfs$(HOSTEXEEXT) \
|
||||
convert-comments$(HOSTEXEEXT) lowhex$(HOSTEXEEXT) \
|
||||
detab$(HOSTEXEEXT) rmcr$(HOSTEXEEXT) incdir$(HOSTEXEEXT) \
|
||||
jlink-nuttx$(HOSTDYNEXT)
|
||||
mknxflat$(HOSTEXEEXT) jlink-nuttx$(HOSTDYNEXT)
|
||||
default: mkconfig$(HOSTEXEEXT) mksyscall$(HOSTEXEEXT) mkdeps$(HOSTEXEEXT) \
|
||||
cnvwindeps$(HOSTEXEEXT) incdir$(HOSTEXEEXT)
|
||||
|
||||
ifdef HOSTEXEEXT
|
||||
.PHONY: b16 bdf-converter cmpconfig clean configure kconfig2html mkconfig \
|
||||
mkdeps mksymtab mksyscall mkversion mkpasswd cnvwindeps nxstyle \
|
||||
initialconfig gencromfs convert-comments lowhex detab rmcr incdir
|
||||
initialconfig gencromfs convert-comments lowhex detab rmcr incdir \
|
||||
mknxflat
|
||||
endif
|
||||
ifdef HOSTDYNEXT
|
||||
.PHONY: jlink-nuttx
|
||||
@@ -134,6 +135,18 @@ ifdef HOSTEXEEXT
|
||||
mksymtab: mksymtab$(HOSTEXEEXT)
|
||||
endif
|
||||
|
||||
# mknxflat - Generate the thunk file for an NXFLAT module
|
||||
|
||||
MKNXFLAT_SRCS = nxflat/mknxflat.c nxflat/thunk_arm.c nxflat/thunk_thumb2.c
|
||||
|
||||
mknxflat$(HOSTEXEEXT): $(MKNXFLAT_SRCS)
|
||||
$(Q) $(HOSTCC) $(HOSTCFLAGS) -Inxflat -o mknxflat$(HOSTEXEEXT) \
|
||||
$(MKNXFLAT_SRCS)
|
||||
|
||||
ifdef HOSTEXEEXT
|
||||
mknxflat: mknxflat$(HOSTEXEEXT)
|
||||
endif
|
||||
|
||||
# bdf-converter - Converts a BDF font to the NuttX font format
|
||||
|
||||
bdf-converter$(HOSTEXEEXT): bdf-converter.c
|
||||
@@ -270,6 +283,8 @@ clean:
|
||||
$(call DELFILE, Make.dep)
|
||||
$(call DELFILE, mkconfig)
|
||||
$(call DELFILE, mkconfig.exe)
|
||||
$(call DELFILE, mknxflat)
|
||||
$(call DELFILE, mknxflat.exe)
|
||||
$(call DELFILE, mkdeps)
|
||||
$(call DELFILE, mkdeps.exe)
|
||||
$(call DELFILE, mksymtab)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,79 @@
|
||||
/****************************************************************************
|
||||
* tools/nxflat/nxflat_thunk.h
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
* SPDX-FileCopyrightText: 2009, 2018 Gregory Nutt. All rights reserved.
|
||||
* SPDX-FileCopyrightText: 2002, 2006 Cadenux, LLC. All rights reserved.
|
||||
* SPDX-FileContributor: 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __TOOLS_NXFLAT_NXFLAT_THUNK_H
|
||||
#define __TOOLS_NXFLAT_NXFLAT_THUNK_H
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* The set of format strings that make up one architecture's thunk file.
|
||||
*
|
||||
* The upstream tool selected these at compile time through an "arch"
|
||||
* symlink pointing at either arm/ or thumb2/. A symlink cannot be carried
|
||||
* in the repository, and one host binary has to serve boards of both
|
||||
* flavours -- lpc31xx is ARM while lpc17xx, tiva, stm32f1 and rp23xx are
|
||||
* Thumb-2 -- so the choice moves to a runtime "-a" option instead. The
|
||||
* .def files themselves are unmodified, so the emitted text is unchanged.
|
||||
*/
|
||||
|
||||
struct nxflat_thunk_s
|
||||
{
|
||||
const char *file_prologue;
|
||||
const char *import_prologue;
|
||||
const char *import_name_strtab_prologue;
|
||||
const char *import_name_strtab_format;
|
||||
const char *dynimport_decl_prologue;
|
||||
const char *dynimport_decl_format;
|
||||
const char *dynimport_array_prologue;
|
||||
const char *dynimport_array_format;
|
||||
const char *dynimport_array_epilogue;
|
||||
const char *dyncall_decl_prologue;
|
||||
const char *dyncall_format;
|
||||
const char *nonreturning_dyncall_format;
|
||||
const char *file_epilogue;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
extern const struct nxflat_thunk_s g_thunk_arm;
|
||||
extern const struct nxflat_thunk_s g_thunk_thumb2;
|
||||
|
||||
#endif /* __TOOLS_NXFLAT_NXFLAT_THUNK_H */
|
||||
@@ -0,0 +1,62 @@
|
||||
/****************************************************************************
|
||||
* tools/nxflat/thunk_arm.c
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
* SPDX-FileCopyrightText: 2009, 2018 Gregory Nutt. All rights reserved.
|
||||
* SPDX-FileCopyrightText: 2002, 2006 Cadenux, LLC. All rights reserved.
|
||||
* SPDX-FileContributor: 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. See the .def file
|
||||
* included below, which is carried unmodified from the upstream NuttX
|
||||
* buildroot NXFLAT toolchain.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include "nxflat_thunk.h"
|
||||
|
||||
/* The format strings are file-scope statics inside the .def, so each
|
||||
* architecture gets its own translation unit and the two sets cannot
|
||||
* collide. The .def is byte-for-byte the upstream file.
|
||||
*/
|
||||
|
||||
#include "dyncall_skeleton_arm.def"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
const struct nxflat_thunk_s g_thunk_arm =
|
||||
{
|
||||
file_prologue,
|
||||
import_prologue,
|
||||
import_name_strtab_prologue,
|
||||
import_name_strtab_format,
|
||||
dynimport_decl_prologue,
|
||||
dynimport_decl_format,
|
||||
dynimport_array_prologue,
|
||||
dynimport_array_format,
|
||||
dynimport_array_epilogue,
|
||||
dyncall_decl_prologue,
|
||||
dyncall_format,
|
||||
nonreturning_dyncall_format,
|
||||
file_epilogue
|
||||
};
|
||||
@@ -0,0 +1,62 @@
|
||||
/****************************************************************************
|
||||
* tools/nxflat/thunk_thumb2.c
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
* SPDX-FileCopyrightText: 2009, 2018 Gregory Nutt. All rights reserved.
|
||||
* SPDX-FileCopyrightText: 2002, 2006 Cadenux, LLC. All rights reserved.
|
||||
* SPDX-FileContributor: 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. See the .def file
|
||||
* included below, which is carried unmodified from the upstream NuttX
|
||||
* buildroot NXFLAT toolchain.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include "nxflat_thunk.h"
|
||||
|
||||
/* The format strings are file-scope statics inside the .def, so each
|
||||
* architecture gets its own translation unit and the two sets cannot
|
||||
* collide. The .def is byte-for-byte the upstream file.
|
||||
*/
|
||||
|
||||
#include "dyncall_skeleton_thumb2.def"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
const struct nxflat_thunk_s g_thunk_thumb2 =
|
||||
{
|
||||
file_prologue,
|
||||
import_prologue,
|
||||
import_name_strtab_prologue,
|
||||
import_name_strtab_format,
|
||||
dynimport_decl_prologue,
|
||||
dynimport_decl_format,
|
||||
dynimport_array_prologue,
|
||||
dynimport_array_format,
|
||||
dynimport_array_epilogue,
|
||||
dyncall_decl_prologue,
|
||||
dyncall_format,
|
||||
nonreturning_dyncall_format,
|
||||
file_epilogue
|
||||
};
|
||||
Reference in New Issue
Block a user