This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit abbe0df26d2caccd0d7e5de0b7a987bca0202163
Author: Marco Casaroli <[email protected]>
AuthorDate: Sun Aug 2 21:30:02 2026 +0200

    !arch/arm: Use r9 as the PIC base register.
    
    ARM PIC has used r10 as the base register, but the tree has never been
    consistent about it.  Toolchain.defs gives CONFIG_BUILD_PIC
    -mpic-register=r9 and CONFIG_PIC -mpic-register=r10, twenty-five lines
    apart, and arm_initialstate.c sets REG_R9 from inline assembly under one
    and REG_PIC under the other, with a comment reading "Set the PIC base
    register (probably R10)".  This settles it on r9 for all of PIC: NXFLAT,
    ELF PIC and CONFIG_BUILD_PIC alike.
    
    r9 is the right choice rather than an arbitrary one.  It is the AAPCS
    platform register, the "static base", and it is what GCC itself picks
    for -msingle-pic-base on an EABI target; r10 is the non-EABI default.
    
    It also removes a combination that cannot build today.  Stack checking
    adds -ffixed-r10 in armv7-m/Toolchain.defs and armv8-m/Toolchain.defs,
    while CONFIG_PIC adds -mpic-register=r10, and GCC rejects the pair with
    "unable to use 'r10' for PIC register".  The comment above REG_PIC has
    always said the register "can be R9 if stack checking is enabled", but
    the definition was unconditionally REG_R10, so it would have named the
    wrong register even had the build succeeded.
    
    The thunk generator moves with the firmware.  NXFLAT import stubs had
    the register baked in as "add ip,ip,sl", so a module built for r9 would
    load and then branch to a wild address on its first call out.  The stubs
    now come from NXFLAT_PIC_REG in the in-tree tool, which is built only
    when CONFIG_NXFLAT is set, following the
    CONFIG_BOARD_ETC_ROMFS_PASSWD_ENABLE precedent in tools/Unix.mk.
    
    That leaves modules built before this change, and they are the reason
    for the ABI marker.  The NXFLAT header cannot carry a version: h_magic
    is written by ldnxflat, which is GPL, derived from elf2flt, and stays
    out of this repository, so it can never be changed in step with the
    loader.  The import table can, because both of its ends are in-tree --
    mknxflat emits it and nxflat_bindimports() reads it -- and ldnxflat
    passes it through untouched.  So every module now imports
    __nxflat_abi_v2, the base firmware defines it, and a module that does
    not import it is refused.
    
    Making the marker a real exported symbol rather than a name the loader
    special-cases is what keeps it out of the build system's way: a board's
    symbol table picks it up exactly as it picks up printf, so mksymtab.sh
    and its equivalents need no change.  It also gives the reverse direction
    a diagnosis for free -- a module built against a newer ABI than its
    firmware fails with "Exported symbol __nxflat_abi_v2 not found".
    
    Most of the remaining churn is boards restating a default.  ARCHPICFLAGS
    is a "?=" default so that a board only speaks up when it differs, and
    twenty-six were assigning the value the default already had.  MKNXFLAT
    gets the same treatment: thirteen boards named the same tool, and the
    only thing that varies is ARM versus Thumb-2, which falls out of
    CONFIG_ARM_THUMB.  LDNXFLAT gains a default too -- it stays an
    out-of-tree PATH lookup, but naming it centrally fixes boards that never
    assigned it, where it expanded to nothing and handed make a recipe
    beginning "-e", whose leading dash make ate as "ignore errors".
    
    The non-ARM boards carrying -mpic-register=r10 lose it: it is an
    ARM-only option, reachable only through CPICFLAGS, which is only used to
    build NXFLAT modules, and no non-ARM board enables NXFLAT.
    
    Boards keep nothing about PIC flags any more.  ARCHPICFLAGS was set by
    sixty-three of them and only ever fed CPICFLAGS, which is only used to
    build NXFLAT modules; no board outside arch/arm enables NXFLAT, so every
    non-ARM copy was setting a variable nothing read.  Those are removed
    rather than moved somewhere more central, which would only make dead
    text look load-bearing.  LDNXFLAT goes the same way as MKNXFLAT, for the
    same reason: thirteen boards named the same tool that Toolchain.defs now
    names once.
    
    One of them was not merely redundant.  am67/t3-gem-o1 asked for
    "-mpic-register=r10 -ffixed-r10", which GCC refuses outright with
    "unable to use 'r10' for PIC register" -- the very combination the
    filter-out machinery in Toolchain.defs exists to prevent.  It has
    survived because that board does not build NXFLAT modules, so the flags
    are never handed to a compiler.  Renaming the register would have
    carried the fault forward unchanged, so the line goes.
    
    Tested on lm3s6965-ek:qemu-nxflat under QEMU, configured and built with
    no overrides.  The nxflat example runs the errno, hello and struct
    modules with output identical to the same config built from master.
    Built with the old out-of-tree thunk generator instead, the same
    firmware refuses all three with ENOEXEC rather than locking up in a
    HardFault, which is what this change is for.  mps3-an547:picostest,
    which is CONFIG_PIC without CONFIG_NXFLAT, builds clean and does not
    build the thunk generator.
    
    The .def files pick up two cosmetic changes here alongside the register:
    a "Dyanamic" typo that codespell rejects, and a reworded comment in each
    thunk_*.c.  Neither appears in the emitted thunk -- both are in C
    comments -- so the generated text is still what the upstream tool
    produces, modulo the register itself.
    
    BREAKING CHANGE: ARM PIC moves from r10 to r9.  An NXFLAT module built
    before this change has r10 baked into its import stubs and will not run
    against a firmware carrying it; the two cannot be mixed.  The module is
    refused with ENOEXEC rather than branching to a wild address, by way of the
    __nxflat_abi_v2 marker described below.
    
    Quick fix: rebuild the module against this tree.  Its source needs no
    change.  A board that reserved r10 by hand, or that assigned ARCHPICFLAGS
    or MKNXFLAT to restate a default, should drop those assignments; nothing
    else is affected, and CONFIG_PIC without CONFIG_NXFLAT needs no action.
    
    Assisted-by: Claude Opus 5 (1M context) <[email protected]>
    Signed-off-by: Marco Casaroli <[email protected]>
---
 Documentation/components/filesystem/nxflat.rst     |  8 ++--
 Documentation/components/nxflat.rst                | 24 +++++-----
 .../guides/porting-case-studies/port_arm_cm4.rst   |  2 +-
 arch/arm/include/arch.h                            | 10 ++--
 arch/arm/include/arm/irq.h                         |  6 +--
 arch/arm/include/armv6-m/irq.h                     |  6 +--
 arch/arm/include/armv7-a/irq.h                     |  6 +--
 arch/arm/include/armv7-m/irq.h                     |  6 +--
 arch/arm/include/armv7-r/irq.h                     |  6 +--
 arch/arm/include/armv8-m/irq.h                     |  6 +--
 arch/arm/include/armv8-r/irq.h                     |  6 +--
 arch/arm/include/tlsr82/irq.h                      |  6 +--
 arch/arm/src/arm/arm_initialstate.c                |  4 +-
 arch/arm/src/armv6-m/arm_initialstate.c            |  4 +-
 arch/arm/src/armv7-a/arm_initialstate.c            |  4 +-
 arch/arm/src/armv7-m/arm_initialstate.c            |  4 +-
 arch/arm/src/armv7-r/arm_initialstate.c            |  4 +-
 arch/arm/src/armv8-m/arm_initialstate.c            |  4 +-
 arch/arm/src/armv8-r/arm_initialstate.c            |  4 +-
 arch/arm/src/cmake/elf.cmake                       |  7 ++-
 arch/arm/src/common/Toolchain.defs                 | 55 +++++++++++++++-------
 arch/arm/src/tlsr82/tc32/tc32_initialstate.c       |  4 +-
 binfmt/libnxflat/libnxflat_bind.c                  | 47 ++++++++++++++++++
 boards/arm/am67/t3-gem-o1/scripts/Make.defs        |  1 -
 boards/arm/cxd56xx/spresense/scripts/Make.defs     |  2 -
 boards/arm/dm320/ntosd-dm320/scripts/Make.defs     |  2 -
 .../arm/imxrt/imxrt1050-evk/configs/knsh/Make.defs |  2 -
 .../arm/imxrt/imxrt1060-evk/configs/knsh/Make.defs |  2 -
 .../arm/imxrt/imxrt1064-evk/configs/knsh/Make.defs |  2 -
 .../arm/imxrt/imxrt1170-evk/configs/knsh/Make.defs |  2 -
 .../lpc4088-devkit/configs/knsh/Make.defs          |  2 -
 .../lpc4088-quickstart/configs/knsh/Make.defs      |  2 -
 .../lpcxpresso-lpc1768/configs/thttpd/Make.defs    |  4 --
 .../configs/thttpd-binfs/Make.defs                 |  4 --
 .../configs/thttpd-nxflat/Make.defs                |  4 --
 .../olimex-lpc1766stk/scripts/Make.defs            |  2 -
 .../lpc17xx_40xx/open1788/configs/knsh/Make.defs   |  2 -
 .../open1788/configs/knxterm/Make.defs             |  2 -
 .../lpc17xx_40xx/pnev5180b/configs/knsh/Make.defs  |  2 -
 .../lpc17xx_40xx/zkit-arm-1769/scripts/Make.defs   |  2 -
 boards/arm/lpc31xx/ea3131/configs/pgnsh/Make.defs  |  2 -
 boards/arm/moxart/moxa/scripts/Make.defs           |  2 -
 .../rp23xx/pimoroni-pico-2-plus/scripts/Make.defs  |  2 -
 .../rp23xx/raspberrypi-pico-2/scripts/Make.defs    |  2 -
 boards/arm/rp23xx/xiao-rp2350/scripts/Make.defs    |  2 -
 .../arm/s32k3xx/mr-canhubk3/configs/knsh/Make.defs |  2 -
 boards/arm/sam34/sam3u-ek/configs/knsh/Make.defs   |  2 -
 .../sama5/sama5d3-xplained/configs/knsh/Make.defs  |  2 -
 boards/arm/sama5/sama5d4-ek/configs/knsh/Make.defs |  2 -
 .../arm/samv7/samv71-xult/configs/knsh/Make.defs   |  2 -
 boards/arm/stm32f1/shenzhou/scripts/Make.defs      |  2 -
 .../olimex-stm32-p407/configs/kelf/Make.defs       |  2 -
 .../olimex-stm32-p407/configs/kmodule/Make.defs    |  2 -
 .../olimex-stm32-p407/configs/knsh/Make.defs       |  2 -
 .../stm32f4/stm3240g-eval/configs/knxwm/Make.defs  |  2 -
 .../stm32f4discovery/configs/kostest/Make.defs     |  2 -
 .../stm32f4/stm32f4discovery/src/CMakeLists.txt    |  2 +-
 .../stm32h7/devebox-stm32h743/scripts/Make.defs    |  2 -
 .../stm32l476vg-disco/configs/knsh/Make.defs       |  2 -
 .../stm32l4r9ai-disco/configs/knsh/Make.defs       |  2 -
 boards/arm/tiva/eagle100/scripts/Make.defs         |  2 -
 boards/avr/at32uc3/avr32dev1/scripts/Make.defs     |  1 -
 boards/avr/at32uc3/mizar32a/scripts/Make.defs      |  1 -
 boards/hc/m9s12/demo9s12ne64/scripts/Make.defs     |  1 -
 boards/hc/m9s12/ne64badge/scripts/Make.defs        |  1 -
 boards/or1k/mor1kx/or1k/scripts/Make.defs          |  1 -
 boards/renesas/m16c/skp16c26/scripts/Make.defs     |  1 -
 .../renesas/rx65n/rx65n-grrose/scripts/Make.defs   |  1 -
 .../renesas/rx65n/rx65n-rsk1mb/scripts/Make.defs   |  1 -
 .../renesas/rx65n/rx65n-rsk2mb/scripts/Make.defs   |  1 -
 boards/renesas/rx65n/rx65n/scripts/Make.defs       |  1 -
 boards/renesas/sh1/us7032evb1/scripts/Make.defs    |  1 -
 boards/risc-v/bl602/bl602evb/scripts/Make.defs     |  1 -
 boards/risc-v/bl808/ox64/scripts/Make.defs         |  1 -
 boards/risc-v/eic7700x/starpro64/scripts/Make.defs |  1 -
 .../esp32c3-legacy-devkit-rust-1/scripts/Make.defs |  1 -
 .../esp32c3-legacy-devkit/scripts/Make.defs        |  1 -
 .../risc-v/esp32c3/esp32-c3-zero/scripts/Make.defs |  1 -
 .../esp32c3/esp32c3-devkit/scripts/Make.defs       |  1 -
 .../risc-v/esp32c3/esp32c3-xiao/scripts/Make.defs  |  1 -
 .../esp32c6/esp32c6-devkitc/scripts/Make.defs      |  1 -
 .../esp32c6/esp32c6-devkitm/scripts/Make.defs      |  1 -
 .../risc-v/esp32c6/esp32c6-xiao/scripts/Make.defs  |  1 -
 .../esp32h2/esp32h2-devkit/scripts/Make.defs       |  1 -
 .../esp32p4-function-ev-board/scripts/Make.defs    |  1 -
 .../esp32p4-pico-wifi-wareshare/scripts/Make.defs  |  1 -
 .../risc-v/esp32p4/esp32p4-tab5/scripts/Make.defs  |  1 -
 boards/risc-v/fe310/hifive1-revb/scripts/Make.defs |  1 -
 boards/risc-v/jh7110/star64/scripts/Make.defs      |  1 -
 boards/risc-v/k230/canmv230/scripts/Make.defs      |  1 -
 boards/risc-v/litex/arty_a7/scripts/Make.defs      |  1 -
 boards/risc-v/qemu-rv/rv-virt/scripts/Make.defs    |  1 -
 .../raspberrypi-pico-2-rv/scripts/Make.defs        |  1 -
 boards/risc-v/sg2000/milkv_duos/scripts/Make.defs  |  1 -
 boards/sim/sim/sim/scripts/Make.defs               |  1 -
 .../xtensa/esp32/esp32-2432S028/scripts/Make.defs  |  1 -
 .../xtensa/esp32/esp32-audio-kit/scripts/Make.defs |  1 -
 .../xtensa/esp32/esp32-devkitc/scripts/Make.defs   |  1 -
 .../esp32/esp32-ethernet-kit/scripts/Make.defs     |  1 -
 boards/xtensa/esp32/esp32-lyrat/scripts/Make.defs  |  1 -
 .../xtensa/esp32/esp32-pico-kit/scripts/Make.defs  |  1 -
 .../esp32/esp32-sparrow-kit/scripts/Make.defs      |  1 -
 .../esp32/esp32-wrover-kit/scripts/Make.defs       |  1 -
 .../esp32/heltec_wifi_lora32/scripts/Make.defs     |  1 -
 .../esp32/lilygo_tbeam_lora_gps/scripts/Make.defs  |  1 -
 .../xtensa/esp32/ttgo_eink5_v2/scripts/Make.defs   |  1 -
 .../xtensa/esp32/ttgo_lora_esp32/scripts/Make.defs |  1 -
 .../esp32/ttgo_t_display_esp32/scripts/Make.defs   |  1 -
 .../esp32s2/esp32s2-kaluga-1/scripts/Make.defs     |  1 -
 .../esp32s2/esp32s2-saola-1/scripts/Make.defs      |  1 -
 .../esp32s2/franzininho-wifi/scripts/Make.defs     |  1 -
 .../esp32s3/esp32s3-8048S043/scripts/Make.defs     |  1 -
 .../xtensa/esp32s3/esp32s3-box/scripts/Make.defs   |  1 -
 .../esp32s3/esp32s3-devkit/scripts/Make.defs       |  1 -
 .../xtensa/esp32s3/esp32s3-eye/scripts/Make.defs   |  1 -
 .../esp32s3/esp32s3-korvo-2/scripts/Make.defs      |  1 -
 .../esp32s3/esp32s3-lcd-ev/scripts/Make.defs       |  1 -
 .../esp32s3/esp32s3-lhcbit/scripts/Make.defs       |  1 -
 .../esp32s3/esp32s3-m5-cardputer/scripts/Make.defs |  1 -
 .../esp32s3/esp32s3-meadow/scripts/Make.defs       |  1 -
 .../esp32s3/esp32s3-ws-lcd128/scripts/Make.defs    |  1 -
 .../xtensa/esp32s3/esp32s3-xiao/scripts/Make.defs  |  1 -
 .../esp32s3/lckfb-szpi-esp32s3/scripts/Make.defs   |  1 -
 include/nxflat.h                                   | 20 ++++++++
 tools/Unix.mk                                      | 15 +++++-
 tools/nxflat/dyncall_skeleton_arm.def              | 10 ++--
 tools/nxflat/dyncall_skeleton_thumb2.def           | 10 ++--
 tools/nxflat/mknxflat.c                            | 36 +++++++++-----
 tools/nxflat/nxflat_thunk.h                        | 27 +++++++++++
 tools/nxflat/thunk_arm.c                           | 12 ++++-
 tools/nxflat/thunk_thumb2.c                        | 12 ++++-
 131 files changed, 269 insertions(+), 249 deletions(-)

diff --git a/Documentation/components/filesystem/nxflat.rst 
b/Documentation/components/filesystem/nxflat.rst
index 6d0b2206295..094b9310793 100644
--- a/Documentation/components/filesystem/nxflat.rst
+++ b/Documentation/components/filesystem/nxflat.rst
@@ -160,14 +160,14 @@ indeed, a solution to the above NXFLAT problem in newer
 compilers. You simply need to modify the board Make.defs 
 file like:
 
-1. ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
+1. ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r9
 
 .. code-block:: bash
 
-    +ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10 
-mno-pic-data-is-text-relative
+    +ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r9 
-mno-pic-data-is-text-relative
 
-NOTE the minor difference from the post: NuttX uses ``r10`` as 
-the PIC base register by default in all configurations.
+NuttX uses ``r9`` as the PIC base register in all configurations,
+which matches the register named in the post above.
 
 See this `thread <https://groups.google.com/forum/>`_ for additional 
information.
 
diff --git a/Documentation/components/nxflat.rst 
b/Documentation/components/nxflat.rst
index 755af04e431..c7ff5de8bae 100644
--- a/Documentation/components/nxflat.rst
+++ b/Documentation/components/nxflat.rst
@@ -290,7 +290,7 @@ CFLAGS must be provided. First, the option ``-fpic`` is 
required to tell
 the compiler to generate position independent code (other GCC options,
 like ``-fno-jump-tables`` might also be desirable). For ARM compilers,
 two additional compilation options are required: ``-msingle-pic-base``
-and ``-mpic-register=r10``.  On ARM these are supplied centrally rather
+and ``-mpic-register=r9``.  On ARM these are supplied centrally rather
 than per board; see `Where the ARM PIC flags come from`_ below.
 
 **Target 2**. Given the ``hello.r1`` relocatable object, this target
@@ -338,25 +338,25 @@ On ARM the compilation flags described under **Target 1** 
are supplied by
 ``arch/arm/src/common/Toolchain.defs``, not by each board.  A board only has
 to say something when it differs from the default::
 
-  ARCHPICFLAGS ?= -fpic -msingle-pic-base -mpic-register=r10
+  ARCHPICFLAGS ?= -fpic -msingle-pic-base -mpic-register=r9
 
-  CPICFLAGS   = $(ARCHPICFLAGS) $(filter-out --fixed-r10,$(CFLAGS))
-  CXXPICFLAGS = $(ARCHPICFLAGS) $(filter-out --fixed-r10,$(CXXFLAGS))
+  CPICFLAGS   = $(ARCHPICFLAGS) $(filter-out --fixed-r9,$(CFLAGS))
+  CXXPICFLAGS = $(ARCHPICFLAGS) $(filter-out --fixed-r9,$(CXXFLAGS))
 
 ``ARCHPICFLAGS`` uses ``?=``, and the two derived variables use deferred
 ``=``, so a board that includes this file may still override
 ``ARCHPICFLAGS`` afterwards or append to it, and ``CFLAGS`` is whatever the
-board finally set it to.  A few boards do differ: one adds ``-ffixed-r10``
+board finally set it to.  A few boards do differ: one adds ``-ffixed-r9``
 and one conditionally adds ``-mno-pic-data-is-text-relative``.
 
-Reserving r10 in the base firmware
-----------------------------------
+Reserving r9 in the base firmware
+---------------------------------
 
-A module reaches its data through r10, and the base firmware has to leave
+A module reaches its data through r9, and the base firmware has to leave
 that register alone -- otherwise a call *back* from the firmware into module
 code arrives with the wrong data base.  ``qsort()`` with a comparison
 function inside the module is the usual way to meet this.  Under
-``CONFIG_PIC`` the firmware is therefore built with ``--fixed-r10``.
+``CONFIG_PIC`` the firmware is therefore built with ``--fixed-r9``.
 
 That flag goes into ``ARCHCFLAGS`` rather than ``CFLAGS``, because nearly
 every board ``Make.defs`` includes ``Toolchain.defs`` and then assigns::
@@ -369,8 +369,8 @@ remote from the cause: everything builds, and only a 
callback into module
 code misbehaves.
 
 The two sides of that contract cannot both appear on one command line.  A
-module gets r10 through ``-mpic-register=r10``, and GCC rejects it alongside
-``--fixed-r10`` with *"unable to use 'r10' for PIC register"*.  Since
+module gets r9 through ``-mpic-register=r9``, and GCC rejects it alongside
+``--fixed-r9`` with *"unable to use 'r9' for PIC register"*.  Since
 ``CPICFLAGS``, ``CXXPICFLAGS``, ``CELFFLAGS`` and ``CXXELFFLAGS`` all derive
 from ``CFLAGS``, the flag is filtered back out where they are defined,
 rather than in every board that builds modules.
@@ -429,7 +429,7 @@ contiguous (virtual) address space like::
   .data
   .bss
 
-It assumes that the PIC base register (usually r10 for ARM) points to
+It assumes that the PIC base register (r9 for ARM) points to
 the base of ``.text`` so that any address in ``.text``, ``.got``,
 ``.data``, ``.bss`` can be found with an offset from the same base
 address. But that is not the memory arrangement that we need in the XIP
diff --git a/Documentation/guides/porting-case-studies/port_arm_cm4.rst 
b/Documentation/guides/porting-case-studies/port_arm_cm4.rst
index 410b21b7b3b..742d15b5ec2 100644
--- a/Documentation/guides/porting-case-studies/port_arm_cm4.rst
+++ b/Documentation/guides/porting-case-studies/port_arm_cm4.rst
@@ -641,7 +641,7 @@ Appendix : out-of-tree code
   +
   +ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)
   +
-  +ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
+  +ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r9
   +
   +CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS) -pipe
   +CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/arch/arm/include/arch.h b/arch/arm/include/arch.h
index 3450f5c50df..786f7e6cbd2 100644
--- a/arch/arm/include/arch.h
+++ b/arch/arm/include/arch.h
@@ -43,12 +43,14 @@
 
 #ifdef CONFIG_PIC
 
-/* This identifies the register the is used by the processor as the PIC base
- * register.  It is usually r9 or r10
+/* This identifies the register that is used by the processor as the PIC base
+ * register.  r9 is the AAPCS platform register (the "static base"), which is
+ * also what GCC picks for -msingle-pic-base on an EABI target, so the whole
+ * of PIC uses it: NXFLAT, ELF PIC, and CONFIG_BUILD_PIC alike.
  */
 
-#define PIC_REG         r10
-#define PIC_REG_STRING "r10"
+#define PIC_REG         r9
+#define PIC_REG_STRING "r9"
 
 /* Macros to get and set the PIC base register.  picbase is assumed to be
  * of type (void*) and that it will fit into a uint32_t.  These must be
diff --git a/arch/arm/include/arm/irq.h b/arch/arm/include/arm/irq.h
index 61b68a1cae2..ae79890a483 100644
--- a/arch/arm/include/arm/irq.h
+++ b/arch/arm/include/arm/irq.h
@@ -96,11 +96,11 @@
 #define REG_LR              REG_R14
 #define REG_PC              REG_R15
 
-/* The PIC register is usually R10. It can be R9 is stack checking is enabled
- * or if the user changes it with -mpic-register on the GCC command line.
+/* The PIC base register is R9, the AAPCS platform register.  See PIC_REG
+ * in arch/arm/include/arch.h; every PIC binary format uses the same one.
  */
 
-#define REG_PIC             REG_R10
+#define REG_PIC             REG_R9
 
 /****************************************************************************
  * Public Types
diff --git a/arch/arm/include/armv6-m/irq.h b/arch/arm/include/armv6-m/irq.h
index 7a83579d1b5..0ba5a426c47 100644
--- a/arch/arm/include/armv6-m/irq.h
+++ b/arch/arm/include/armv6-m/irq.h
@@ -123,11 +123,11 @@
 #define REG_LR              REG_R14
 #define REG_PC              REG_R15
 
-/* The PIC register is usually R10. It can be R9 is stack checking is enabled
- * or if the user changes it with -mpic-register on the GCC command line.
+/* The PIC base register is R9, the AAPCS platform register.  See PIC_REG
+ * in arch/arm/include/arch.h; every PIC binary format uses the same one.
  */
 
-#define REG_PIC             REG_R10
+#define REG_PIC             REG_R9
 
 /* CONTROL register */
 
diff --git a/arch/arm/include/armv7-a/irq.h b/arch/arm/include/armv7-a/irq.h
index b9f973b627b..bf1a5083dcb 100644
--- a/arch/arm/include/armv7-a/irq.h
+++ b/arch/arm/include/armv7-a/irq.h
@@ -200,11 +200,11 @@
 #define REG_LR              REG_R14
 #define REG_PC              REG_R15
 
-/* The PIC register is usually R10. It can be R9 is stack checking is enabled
- * or if the user changes it with -mpic-register on the GCC command line.
+/* The PIC base register is R9, the AAPCS platform register.  See PIC_REG
+ * in arch/arm/include/arch.h; every PIC binary format uses the same one.
  */
 
-#define REG_PIC             REG_R10
+#define REG_PIC             REG_R9
 
 /* Multiprocessor Affinity Register (MPIDR): CRn=c0, opc1=0, CRm=c0, opc2=5 */
 
diff --git a/arch/arm/include/armv7-m/irq.h b/arch/arm/include/armv7-m/irq.h
index 1f37bb6fbb5..cfb3d686dbe 100644
--- a/arch/arm/include/armv7-m/irq.h
+++ b/arch/arm/include/armv7-m/irq.h
@@ -180,11 +180,11 @@
 #define REG_LR              REG_R14
 #define REG_PC              REG_R15
 
-/* The PIC register is usually R10. It can be R9 is stack checking is enabled
- * or if the user changes it with -mpic-register on the GCC command line.
+/* The PIC base register is R9, the AAPCS platform register.  See PIC_REG
+ * in arch/arm/include/arch.h; every PIC binary format uses the same one.
  */
 
-#define REG_PIC             REG_R10
+#define REG_PIC             REG_R9
 
 /* CONTROL register */
 
diff --git a/arch/arm/include/armv7-r/irq.h b/arch/arm/include/armv7-r/irq.h
index 2e0706e1c92..c038ce445d1 100644
--- a/arch/arm/include/armv7-r/irq.h
+++ b/arch/arm/include/armv7-r/irq.h
@@ -200,11 +200,11 @@
 #define REG_LR              REG_R14
 #define REG_PC              REG_R15
 
-/* The PIC register is usually R10. It can be R9 is stack checking is enabled
- * or if the user changes it with -mpic-register on the GCC command line.
+/* The PIC base register is R9, the AAPCS platform register.  See PIC_REG
+ * in arch/arm/include/arch.h; every PIC binary format uses the same one.
  */
 
-#define REG_PIC             REG_R10
+#define REG_PIC             REG_R9
 
 /* Multiprocessor Affinity Register (MPIDR): CRn=c0, opc1=0, CRm=c0, opc2=5 */
 
diff --git a/arch/arm/include/armv8-m/irq.h b/arch/arm/include/armv8-m/irq.h
index 3d4290eeb7f..a7abf1c7962 100644
--- a/arch/arm/include/armv8-m/irq.h
+++ b/arch/arm/include/armv8-m/irq.h
@@ -186,11 +186,11 @@
 #define REG_LR              REG_R14
 #define REG_PC              REG_R15
 
-/* The PIC register is usually R10. It can be R9 is stack checking is enabled
- * or if the user changes it with -mpic-register on the GCC command line.
+/* The PIC base register is R9, the AAPCS platform register.  See PIC_REG
+ * in arch/arm/include/arch.h; every PIC binary format uses the same one.
  */
 
-#define REG_PIC             REG_R10
+#define REG_PIC             REG_R9
 
 /* CONTROL register */
 
diff --git a/arch/arm/include/armv8-r/irq.h b/arch/arm/include/armv8-r/irq.h
index bc6f282360d..45340dd94e1 100644
--- a/arch/arm/include/armv8-r/irq.h
+++ b/arch/arm/include/armv8-r/irq.h
@@ -200,11 +200,11 @@
 #define REG_LR              REG_R14
 #define REG_PC              REG_R15
 
-/* The PIC register is usually R10. It can be R9 is stack checking is enabled
- * or if the user changes it with -mpic-register on the GCC command line.
+/* The PIC base register is R9, the AAPCS platform register.  See PIC_REG
+ * in arch/arm/include/arch.h; every PIC binary format uses the same one.
  */
 
-#define REG_PIC             REG_R10
+#define REG_PIC             REG_R9
 
 /* Multiprocessor Affinity Register (MPIDR): CRn=c0, opc1=0, CRm=c0, opc2=5 */
 
diff --git a/arch/arm/include/tlsr82/irq.h b/arch/arm/include/tlsr82/irq.h
index a8a551cbe3e..39aaffaaafb 100644
--- a/arch/arm/include/tlsr82/irq.h
+++ b/arch/arm/include/tlsr82/irq.h
@@ -127,11 +127,11 @@
 #define REG_LR              REG_R14
 #define REG_PC              REG_R15
 
-/* The PIC register is usually R10. It can be R9 is stack checking is enabled
- * or if the user changes it with -mpic-register on the GCC command line.
+/* The PIC base register is R9, the AAPCS platform register.  See PIC_REG
+ * in arch/arm/include/arch.h; every PIC binary format uses the same one.
  */
 
-#define REG_PIC             REG_R10
+#define REG_PIC             REG_R9
 
 /****************************************************************************
  * Public Types
diff --git a/arch/arm/src/arm/arm_initialstate.c 
b/arch/arm/src/arm/arm_initialstate.c
index f8deb39b7af..fa1e990a60f 100644
--- a/arch/arm/src/arm/arm_initialstate.c
+++ b/arch/arm/src/arm/arm_initialstate.c
@@ -108,8 +108,8 @@ void up_initial_state(struct tcb_s *tcb)
 #ifdef CONFIG_PIC
   if (tcb->dspace != NULL)
     {
-      /* Set the PIC base register (probably R10) to the address of the
-       * alloacated D-Space region.
+      /* Set the PIC base register (R9) to the address of the allocated
+       * D-Space region.
        */
 
       xcp->regs[REG_PIC] = (uint32_t)tcb->dspace->region;
diff --git a/arch/arm/src/armv6-m/arm_initialstate.c 
b/arch/arm/src/armv6-m/arm_initialstate.c
index 4953e93860b..2040d616902 100644
--- a/arch/arm/src/armv6-m/arm_initialstate.c
+++ b/arch/arm/src/armv6-m/arm_initialstate.c
@@ -119,8 +119,8 @@ void up_initial_state(struct tcb_s *tcb)
 #ifdef CONFIG_PIC
   if (tcb->dspace != NULL)
     {
-      /* Set the PIC base register (probably R10) to the address of the
-       * alloacated D-Space region.
+      /* Set the PIC base register (R9) to the address of the allocated
+       * D-Space region.
        */
 
       xcp->regs[REG_PIC] = (uint32_t)tcb->dspace->region;
diff --git a/arch/arm/src/armv7-a/arm_initialstate.c 
b/arch/arm/src/armv7-a/arm_initialstate.c
index d66ff59150e..c0f9dd469e4 100644
--- a/arch/arm/src/armv7-a/arm_initialstate.c
+++ b/arch/arm/src/armv7-a/arm_initialstate.c
@@ -115,8 +115,8 @@ void up_initial_state(struct tcb_s *tcb)
 #ifdef CONFIG_PIC
   if (tcb->dspace != NULL)
     {
-      /* Set the PIC base register (probably R10) to the address of the
-       * alloacated D-Space region.
+      /* Set the PIC base register (R9) to the address of the allocated
+       * D-Space region.
        */
 
       xcp->regs[REG_PIC] = (uint32_t)tcb->dspace->region;
diff --git a/arch/arm/src/armv7-m/arm_initialstate.c 
b/arch/arm/src/armv7-m/arm_initialstate.c
index 0cab69f30d8..43b96b615ee 100644
--- a/arch/arm/src/armv7-m/arm_initialstate.c
+++ b/arch/arm/src/armv7-m/arm_initialstate.c
@@ -126,8 +126,8 @@ void up_initial_state(struct tcb_s *tcb)
 #ifdef CONFIG_PIC
   if (tcb->dspace != NULL)
     {
-      /* Set the PIC base register (probably R10) to the address of the
-       * alloacated D-Space region.
+      /* Set the PIC base register (R9) to the address of the allocated
+       * D-Space region.
        */
 
       xcp->regs[REG_PIC] = (uint32_t)tcb->dspace->region;
diff --git a/arch/arm/src/armv7-r/arm_initialstate.c 
b/arch/arm/src/armv7-r/arm_initialstate.c
index b1b6a8ac382..17b01c2327b 100644
--- a/arch/arm/src/armv7-r/arm_initialstate.c
+++ b/arch/arm/src/armv7-r/arm_initialstate.c
@@ -108,8 +108,8 @@ void up_initial_state(struct tcb_s *tcb)
 #ifdef CONFIG_PIC
   if (tcb->dspace != NULL)
     {
-      /* Set the PIC base register (probably R10) to the address of the
-       * alloacated D-Space region.
+      /* Set the PIC base register (R9) to the address of the allocated
+       * D-Space region.
        */
 
       xcp->regs[REG_PIC] = (uint32_t)tcb->dspace->region;
diff --git a/arch/arm/src/armv8-m/arm_initialstate.c 
b/arch/arm/src/armv8-m/arm_initialstate.c
index 962050fa2c0..fc316998ed7 100644
--- a/arch/arm/src/armv8-m/arm_initialstate.c
+++ b/arch/arm/src/armv8-m/arm_initialstate.c
@@ -137,8 +137,8 @@ void up_initial_state(struct tcb_s *tcb)
 #ifdef CONFIG_PIC
   if (tcb->dspace != NULL)
     {
-      /* Set the PIC base register (probably R10) to the address of the
-       * alloacated D-Space region.
+      /* Set the PIC base register (R9) to the address of the allocated
+       * D-Space region.
        */
 
       xcp->regs[REG_PIC] = (uint32_t)tcb->dspace->region;
diff --git a/arch/arm/src/armv8-r/arm_initialstate.c 
b/arch/arm/src/armv8-r/arm_initialstate.c
index a8d91713d99..89d39d501e9 100644
--- a/arch/arm/src/armv8-r/arm_initialstate.c
+++ b/arch/arm/src/armv8-r/arm_initialstate.c
@@ -108,8 +108,8 @@ void up_initial_state(struct tcb_s *tcb)
 #ifdef CONFIG_PIC
   if (tcb->dspace != NULL)
     {
-      /* Set the PIC base register (probably R10) to the address of the
-       * alloacated D-Space region.
+      /* Set the PIC base register (R9) to the address of the allocated
+       * D-Space region.
        */
 
       xcp->regs[REG_PIC] = (uint32_t)tcb->dspace->region;
diff --git a/arch/arm/src/cmake/elf.cmake b/arch/arm/src/cmake/elf.cmake
index bd5a4bedef0..7108aa4c174 100644
--- a/arch/arm/src/cmake/elf.cmake
+++ b/arch/arm/src/cmake/elf.cmake
@@ -27,7 +27,12 @@ nuttx_mod_compile_options(-fvisibility=hidden -mlong-calls)
 nuttx_elf_compile_options_ifdef(CONFIG_UNWINDER_ARM -fno-unwind-tables
                                 -fno-asynchronous-unwind-tables)
 
-nuttx_elf_compile_options_ifdef(CONFIG_PIC --fixed-r10 -mpic-register=r10)
+# An ELF module needs r9 as its PIC base, so it must not also have the register
+# fixed: GCC rejects that pair with "unable to use 'r9' for PIC register".  
This
+# mirrors CELFFLAGS in common/Toolchain.defs, which filters --fixed-r9 back out
+# of the inherited CFLAGS for the same reason.
+
+nuttx_elf_compile_options_ifdef(CONFIG_PIC -mpic-register=r9)
 
 nuttx_elf_link_options_ifdef(
   CONFIG_PIC --unresolved-symbols=ignore-in-object-files --emit-relocs)
diff --git a/arch/arm/src/common/Toolchain.defs 
b/arch/arm/src/common/Toolchain.defs
index c535bde05aa..734762fbb30 100644
--- a/arch/arm/src/common/Toolchain.defs
+++ b/arch/arm/src/common/Toolchain.defs
@@ -569,26 +569,47 @@ PICFLAGS = -fpic -fPIE -mno-pic-data-is-text-relative 
-msingle-pic-base
 
 # Flags for building PIC modules (NXFLAT).  These were repeated verbatim in
 # every ARM board Make.defs; they live here so a board only has to say
-# something when it differs, and so the interaction with --fixed-r10 below
+# something when it differs, and so the interaction with --fixed-r9 below
 # can be handled in one place instead of 260.
 #
 # A board that needs to differ can still assign ARCHPICFLAGS after including
 # this file, which overrides the default, or append to it.
 
-ARCHPICFLAGS ?= -fpic -msingle-pic-base -mpic-register=r10
+ARCHPICFLAGS ?= -fpic -msingle-pic-base -mpic-register=r9
 
-# --fixed-r10 reserves r10 across the base firmware so a callback into
-# module code arrives with the module's data base intact.  A module is the
-# other side of that contract: it gets r10 via -mpic-register=r10, and GCC
-# rejects a command line carrying both with "unable to use 'r10' for PIC
-# register".  Since these derive from CFLAGS, the flag has to come back out
-# here.
+# mknxflat generates a module's import thunks, and the instruction set it
+# emits them in has to match the module.  Supplied centrally for the same
+# reason as ARCHPICFLAGS above: every board that builds NXFLAT modules was
+# naming the same tool, and only the ARM/Thumb-2 choice actually varies.
+# Boards using the ARM instruction set -- dm320, lpc31xx and moxart -- fall
+# out of CONFIG_ARM_THUMB rather than having to say anything.
+
+ifeq ($(CONFIG_NXFLAT),y)
+  ifeq ($(CONFIG_ARM_THUMB),y)
+    MKNXFLAT ?= $(TOPDIR)$(DELIM)tools$(DELIM)mknxflat$(HOSTEXEEXT) -a thumb2
+  else
+    MKNXFLAT ?= $(TOPDIR)$(DELIM)tools$(DELIM)mknxflat$(HOSTEXEEXT) -a arm
+  endif
+
+  # ldnxflat is still an out-of-tree tool, so this is a PATH lookup.  It is
+  # named here only so that a board which never assigned it -- lm3s6965-ek
+  # is one -- does not expand it to nothing and hand make a recipe starting
+  # with '-e', whose leading dash make then eats as "ignore errors".
+
+  LDNXFLAT ?= ldnxflat
+endif
+
+# --fixed-r9 reserves r9 across the base firmware so a callback into module
+# code arrives with the module's data base intact.  A module is the other
+# side of that contract: it gets r9 via -mpic-register=r9, and GCC rejects a
+# command line carrying both with "unable to use 'r9' for PIC register".
+# Since these derive from CFLAGS, the flag has to come back out here.
 #
 # Both are deferred assignments, so CFLAGS and CXXFLAGS are whatever the
 # board finally set them to, even though this file is included first.
 
-CPICFLAGS = $(ARCHPICFLAGS) $(filter-out --fixed-r10,$(CFLAGS))
-CXXPICFLAGS = $(ARCHPICFLAGS) $(filter-out --fixed-r10,$(CXXFLAGS))
+CPICFLAGS = $(ARCHPICFLAGS) $(filter-out --fixed-r9,$(CFLAGS))
+CXXPICFLAGS = $(ARCHPICFLAGS) $(filter-out --fixed-r9,$(CXXFLAGS))
 
 ifneq ($(CONFIG_BUILD_PIC),)
   ARCHCFLAGS += $(PICFLAGS) -mpic-register=r9
@@ -603,22 +624,22 @@ LDMODULEFLAGS = -r -T $(call 
CONVERT_PATH,$(TOPDIR)/libs/libc/elf/gnu-elf.ld)
 
 # ELF module definitions
 
-# --fixed-r10 is filtered out for the same reason as in CPICFLAGS above:
-# under CONFIG_PIC these gain -mpic-register=r10, which GCC will not
+# --fixed-r9 is filtered out for the same reason as in CPICFLAGS above:
+# under CONFIG_PIC these gain -mpic-register=r9, which GCC will not
 # accept alongside it.
 
-CELFFLAGS = $(filter-out --fixed-r10,$(CFLAGS)) -fvisibility=hidden \
+CELFFLAGS = $(filter-out --fixed-r9,$(CFLAGS)) -fvisibility=hidden \
             -mlong-calls # --target1-abs
-CXXELFFLAGS = $(filter-out --fixed-r10,$(CXXFLAGS)) -fvisibility=hidden \
+CXXELFFLAGS = $(filter-out --fixed-r9,$(CXXFLAGS)) -fvisibility=hidden \
               -mlong-calls
 
 ifeq ($(CONFIG_PIC),y)
   # ARCHCFLAGS, not CFLAGS: board Make.defs reassign CFLAGS with ':='
   # after including this file, which would discard the flag.
 
-  ARCHCFLAGS += --fixed-r10
-  CELFFLAGS += $(PICFLAGS) -mpic-register=r10
-  CXXELFFLAGS += $(PICFLAGS) -mpic-register=r10
+  ARCHCFLAGS += --fixed-r9
+  CELFFLAGS += $(PICFLAGS) -mpic-register=r9
+  CXXELFFLAGS += $(PICFLAGS) -mpic-register=r9
 
   # Generate an executable elf, need to ignore undefined symbols
   LDELFFLAGS += --unresolved-symbols=ignore-in-object-files --emit-relocs
diff --git a/arch/arm/src/tlsr82/tc32/tc32_initialstate.c 
b/arch/arm/src/tlsr82/tc32/tc32_initialstate.c
index 78d05c4f072..05f388215ea 100644
--- a/arch/arm/src/tlsr82/tc32/tc32_initialstate.c
+++ b/arch/arm/src/tlsr82/tc32/tc32_initialstate.c
@@ -111,8 +111,8 @@ void up_initial_state(struct tcb_s *tcb)
 #ifdef CONFIG_PIC
   if (tcb->dspace != NULL)
     {
-      /* Set the PIC base register (probably R10) to the address of the
-       * alloacated D-Space region.
+      /* Set the PIC base register (R9) to the address of the allocated
+       * D-Space region.
        */
 
       xcp->regs[REG_PIC] = (uint32_t)tcb->dspace->region;
diff --git a/binfmt/libnxflat/libnxflat_bind.c 
b/binfmt/libnxflat/libnxflat_bind.c
index d6cda5c4370..73a75f55b21 100644
--- a/binfmt/libnxflat/libnxflat_bind.c
+++ b/binfmt/libnxflat/libnxflat_bind.c
@@ -29,6 +29,7 @@
 
 #include <inttypes.h>
 #include <stdint.h>
+#include <stdbool.h>
 #include <string.h>
 #include <nxflat.h>
 #include <errno.h>
@@ -60,6 +61,22 @@
 #  define nxflat_dumpbuffer(m,b,n)
 #endif
 
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/* The module ABI marker.  Every module built by tools/nxflat/mknxflat
+ * imports this, and a board's exported symbol table picks it up the same
+ * way it picks up any other imported name, so nothing has to special-case
+ * it in the build.  Its value is never used; only its presence matters.
+ *
+ * A module built against a newer ABI than the firmware therefore fails
+ * with "Exported symbol __nxflat_abi_vN not found", which names the
+ * problem, and a module built against an older one is caught below.
+ */
+
+void *NXFLAT_ABI_MARKER;
+
 /****************************************************************************
  * Private Functions
  ****************************************************************************/
@@ -384,6 +401,7 @@ static inline int nxflat_bindimports(FAR struct 
nxflat_loadinfo_s *loadinfo,
   FAR char *symname;
   uint32_t offset;
   uint16_t nimports;
+  bool     abi_ok = false;
 #ifdef CONFIG_ARCH_ADDRENV
   int      ret;
 #endif
@@ -461,6 +479,17 @@ static inline int nxflat_bindimports(FAR struct 
nxflat_loadinfo_s *loadinfo,
           symname = (FAR char *)
             (offset + loadinfo->ispace + sizeof(struct nxflat_hdr_s));
 
+          /* Note the ABI marker as it goes past.  It resolves like any
+           * other import -- the base firmware defines it below -- so the
+           * only thing special about it is that its absence means the
+           * module was built before the ABI it names.
+           */
+
+          if (strcmp(symname, NXFLAT_ABI_SYMBOL) == 0)
+            {
+              abi_ok = true;
+            }
+
           /* Find the exported symbol value for this symbol name. */
 
           symbol = symtab_findbyname(exports, symname, nexports);
@@ -484,6 +513,24 @@ static inline int nxflat_bindimports(FAR struct 
nxflat_loadinfo_s *loadinfo,
 
   /* Dump the relocation import table */
 
+  /* A module that never declared the ABI was built by a toolchain older
+   * than the move of the PIC base register to r9.  Its import thunks add
+   * r10, so it would load here and then branch to a wild address on its
+   * first call into the base firmware.  Refuse it while there is still
+   * something useful to say about it.
+   */
+
+  if (!abi_ok)
+    {
+      berr("ERROR: Module does not declare " NXFLAT_ABI_SYMBOL ": it was "
+           "built by a toolchain predating the r9 PIC base register.  "
+           "Rebuild it.\n");
+#ifdef CONFIG_ARCH_ADDRENV
+      nxflat_addrenv_restore(loadinfo);
+#endif
+      return -ENOEXEC;
+    }
+
 #ifdef CONFIG_NXFLAT_DUMPBUFFER
   if (nimports > 0)
     {
diff --git a/boards/arm/am67/t3-gem-o1/scripts/Make.defs 
b/boards/arm/am67/t3-gem-o1/scripts/Make.defs
index a17824ff401..dd3d7507c95 100644
--- a/boards/arm/am67/t3-gem-o1/scripts/Make.defs
+++ b/boards/arm/am67/t3-gem-o1/scripts/Make.defs
@@ -27,7 +27,6 @@ include $(TOPDIR)/arch/arm/src/armv7-r/Toolchain.defs
 LDSCRIPT = sdram.ld
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)
 
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10 -ffixed-r10
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
 CPPFLAGS := $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
diff --git a/boards/arm/cxd56xx/spresense/scripts/Make.defs 
b/boards/arm/cxd56xx/spresense/scripts/Make.defs
index 936ca6d4881..c0f46863b65 100644
--- a/boards/arm/cxd56xx/spresense/scripts/Make.defs
+++ b/boards/arm/cxd56xx/spresense/scripts/Make.defs
@@ -35,8 +35,6 @@ endif
 
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)
 
-MKNXFLAT = mknxflat
-LDNXFLAT = ldnxflat
 
 ARCHCFLAGS += -mabi=aapcs
 
diff --git a/boards/arm/dm320/ntosd-dm320/scripts/Make.defs 
b/boards/arm/dm320/ntosd-dm320/scripts/Make.defs
index 1e5c6aea09a..61237c3ea64 100644
--- a/boards/arm/dm320/ntosd-dm320/scripts/Make.defs
+++ b/boards/arm/dm320/ntosd-dm320/scripts/Make.defs
@@ -26,8 +26,6 @@ include $(TOPDIR)/arch/arm/src/arm/Toolchain.defs
 
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)sdram.ld
 
-MKNXFLAT = mknxflat
-LDNXFLAT = ldnxflat
 
 ARCHCCVERSION = ${shell $(CC) -v 2>&1 | sed -n '/^gcc version/p' | sed -e 
's/^gcc version \([0-9\.]\)/\1/g' -e 's/[-\ ].*//g' -e '1q'}
 ARCHCCMAJOR = ${shell echo $(ARCHCCVERSION) | cut -d'.' -f1}
diff --git a/boards/arm/imxrt/imxrt1050-evk/configs/knsh/Make.defs 
b/boards/arm/imxrt/imxrt1050-evk/configs/knsh/Make.defs
index 63f4c620904..4f43409b4eb 100644
--- a/boards/arm/imxrt/imxrt1050-evk/configs/knsh/Make.defs
+++ b/boards/arm/imxrt/imxrt1050-evk/configs/knsh/Make.defs
@@ -28,8 +28,6 @@ LDSCRIPT2 = kernel-space.ld
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT1)
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT2)
 
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
-
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
 CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
diff --git a/boards/arm/imxrt/imxrt1060-evk/configs/knsh/Make.defs 
b/boards/arm/imxrt/imxrt1060-evk/configs/knsh/Make.defs
index 471d9edf964..948fe457d93 100644
--- a/boards/arm/imxrt/imxrt1060-evk/configs/knsh/Make.defs
+++ b/boards/arm/imxrt/imxrt1060-evk/configs/knsh/Make.defs
@@ -28,8 +28,6 @@ LDSCRIPT2 = kernel-space.ld
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT1)
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT2)
 
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
-
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
 CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
diff --git a/boards/arm/imxrt/imxrt1064-evk/configs/knsh/Make.defs 
b/boards/arm/imxrt/imxrt1064-evk/configs/knsh/Make.defs
index 7e0a4738463..41d406fe7bd 100644
--- a/boards/arm/imxrt/imxrt1064-evk/configs/knsh/Make.defs
+++ b/boards/arm/imxrt/imxrt1064-evk/configs/knsh/Make.defs
@@ -28,8 +28,6 @@ LDSCRIPT2 = kernel-space.ld
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT1)
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT2)
 
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
-
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
 CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
diff --git a/boards/arm/imxrt/imxrt1170-evk/configs/knsh/Make.defs 
b/boards/arm/imxrt/imxrt1170-evk/configs/knsh/Make.defs
index b07e57507b3..0aa64e70257 100644
--- a/boards/arm/imxrt/imxrt1170-evk/configs/knsh/Make.defs
+++ b/boards/arm/imxrt/imxrt1170-evk/configs/knsh/Make.defs
@@ -28,8 +28,6 @@ LDSCRIPT2 = kernel-space.ld
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT1)
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT2)
 
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
-
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS) -pipe
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
 CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe
diff --git a/boards/arm/lpc17xx_40xx/lpc4088-devkit/configs/knsh/Make.defs 
b/boards/arm/lpc17xx_40xx/lpc4088-devkit/configs/knsh/Make.defs
index 9da03dbc649..c8cb6fb68fa 100644
--- a/boards/arm/lpc17xx_40xx/lpc4088-devkit/configs/knsh/Make.defs
+++ b/boards/arm/lpc17xx_40xx/lpc4088-devkit/configs/knsh/Make.defs
@@ -25,8 +25,6 @@ include $(TOPDIR)/arch/arm/src/armv7-m/Toolchain.defs
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)memory.ld
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)kernel-space.ld
 
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
-
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
 CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
diff --git a/boards/arm/lpc17xx_40xx/lpc4088-quickstart/configs/knsh/Make.defs 
b/boards/arm/lpc17xx_40xx/lpc4088-quickstart/configs/knsh/Make.defs
index 2e977c10741..86b4e6f6632 100644
--- a/boards/arm/lpc17xx_40xx/lpc4088-quickstart/configs/knsh/Make.defs
+++ b/boards/arm/lpc17xx_40xx/lpc4088-quickstart/configs/knsh/Make.defs
@@ -25,8 +25,6 @@ include $(TOPDIR)/arch/arm/src/armv7-m/Toolchain.defs
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)memory.ld
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)kernel-space.ld
 
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
-
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
 CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
diff --git 
a/boards/arm/lpc17xx_40xx/lpcxpresso-lpc1768/configs/thttpd/Make.defs 
b/boards/arm/lpc17xx_40xx/lpcxpresso-lpc1768/configs/thttpd/Make.defs
index ae1e3d36446..1716e72c516 100644
--- a/boards/arm/lpc17xx_40xx/lpcxpresso-lpc1768/configs/thttpd/Make.defs
+++ b/boards/arm/lpc17xx_40xx/lpcxpresso-lpc1768/configs/thttpd/Make.defs
@@ -25,10 +25,6 @@ include $(TOPDIR)/arch/arm/src/armv7-m/Toolchain.defs
 NXFLATLDSCRIPT = -T $(call 
CONVERT_PATH,$(TOPDIR)$(DELIM)binfmt$(DELIM)libnxflat$(DELIM)gnu-nxflat-gotoff.ld)
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)ld.script
 
-MKNXFLAT = mknxflat
-LDNXFLAT = ldnxflat
-
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git 
a/boards/arm/lpc17xx_40xx/olimex-lpc1766stk/configs/thttpd-binfs/Make.defs 
b/boards/arm/lpc17xx_40xx/olimex-lpc1766stk/configs/thttpd-binfs/Make.defs
index 278a392cb08..d4bdbc4312f 100644
--- a/boards/arm/lpc17xx_40xx/olimex-lpc1766stk/configs/thttpd-binfs/Make.defs
+++ b/boards/arm/lpc17xx_40xx/olimex-lpc1766stk/configs/thttpd-binfs/Make.defs
@@ -24,10 +24,6 @@ include $(TOPDIR)/arch/arm/src/armv7-m/Toolchain.defs
 
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)ld.script
 
-MKNXFLAT = mknxflat
-LDNXFLAT = ldnxflat
-
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git 
a/boards/arm/lpc17xx_40xx/olimex-lpc1766stk/configs/thttpd-nxflat/Make.defs 
b/boards/arm/lpc17xx_40xx/olimex-lpc1766stk/configs/thttpd-nxflat/Make.defs
index d8b04e9ed40..e41cbcf38d8 100644
--- a/boards/arm/lpc17xx_40xx/olimex-lpc1766stk/configs/thttpd-nxflat/Make.defs
+++ b/boards/arm/lpc17xx_40xx/olimex-lpc1766stk/configs/thttpd-nxflat/Make.defs
@@ -24,10 +24,6 @@ include $(TOPDIR)/arch/arm/src/armv7-m/Toolchain.defs
 
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)ld.script
 
-MKNXFLAT = mknxflat
-LDNXFLAT = ldnxflat
-
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/arm/lpc17xx_40xx/olimex-lpc1766stk/scripts/Make.defs 
b/boards/arm/lpc17xx_40xx/olimex-lpc1766stk/scripts/Make.defs
index 01fce495598..56783e1858a 100644
--- a/boards/arm/lpc17xx_40xx/olimex-lpc1766stk/scripts/Make.defs
+++ b/boards/arm/lpc17xx_40xx/olimex-lpc1766stk/scripts/Make.defs
@@ -26,8 +26,6 @@ include $(TOPDIR)/arch/arm/src/armv7-m/Toolchain.defs
 
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)ld.script
 
-MKNXFLAT = mknxflat
-LDNXFLAT = ldnxflat
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
diff --git a/boards/arm/lpc17xx_40xx/open1788/configs/knsh/Make.defs 
b/boards/arm/lpc17xx_40xx/open1788/configs/knsh/Make.defs
index 3bea3a0ad5b..589ce3019b2 100644
--- a/boards/arm/lpc17xx_40xx/open1788/configs/knsh/Make.defs
+++ b/boards/arm/lpc17xx_40xx/open1788/configs/knsh/Make.defs
@@ -25,8 +25,6 @@ include $(TOPDIR)/arch/arm/src/armv7-m/Toolchain.defs
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)memory.ld
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)kernel-space.ld
 
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
-
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
 CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
diff --git a/boards/arm/lpc17xx_40xx/open1788/configs/knxterm/Make.defs 
b/boards/arm/lpc17xx_40xx/open1788/configs/knxterm/Make.defs
index 17437d4efd1..7b5eed58d3b 100644
--- a/boards/arm/lpc17xx_40xx/open1788/configs/knxterm/Make.defs
+++ b/boards/arm/lpc17xx_40xx/open1788/configs/knxterm/Make.defs
@@ -25,8 +25,6 @@ include $(TOPDIR)/arch/arm/src/armv7-m/Toolchain.defs
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)memory.ld
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)kernel-space.ld
 
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
-
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
 CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
diff --git a/boards/arm/lpc17xx_40xx/pnev5180b/configs/knsh/Make.defs 
b/boards/arm/lpc17xx_40xx/pnev5180b/configs/knsh/Make.defs
index 408da24d82a..bed1fad0714 100644
--- a/boards/arm/lpc17xx_40xx/pnev5180b/configs/knsh/Make.defs
+++ b/boards/arm/lpc17xx_40xx/pnev5180b/configs/knsh/Make.defs
@@ -25,8 +25,6 @@ include $(TOPDIR)/arch/arm/src/armv7-m/Toolchain.defs
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)memory.ld
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)kernel-space.ld
 
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
-
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
 CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
diff --git a/boards/arm/lpc17xx_40xx/zkit-arm-1769/scripts/Make.defs 
b/boards/arm/lpc17xx_40xx/zkit-arm-1769/scripts/Make.defs
index 6787bb34f08..1699a8934d7 100644
--- a/boards/arm/lpc17xx_40xx/zkit-arm-1769/scripts/Make.defs
+++ b/boards/arm/lpc17xx_40xx/zkit-arm-1769/scripts/Make.defs
@@ -27,8 +27,6 @@ include $(TOPDIR)/arch/arm/src/armv7-m/Toolchain.defs
 NXFLATLDSCRIPT = -T $(call 
CONVERT_PATH,$(TOPDIR)$(DELIM)binfmt$(DELIM)libnxflat$(DELIM)gnu-nxflat-gotoff.ld)
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)ld.script
 
-MKNXFLAT = mknxflat
-LDNXFLAT = ldnxflat
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
diff --git a/boards/arm/lpc31xx/ea3131/configs/pgnsh/Make.defs 
b/boards/arm/lpc31xx/ea3131/configs/pgnsh/Make.defs
index 6be0fbb810a..838c1e486b6 100644
--- a/boards/arm/lpc31xx/ea3131/configs/pgnsh/Make.defs
+++ b/boards/arm/lpc31xx/ea3131/configs/pgnsh/Make.defs
@@ -41,8 +41,6 @@ else
   ARCHCPUFLAGS = -mapcs-32 -mtune=arm9tdmi -march=armv5te -msoft-float
 endif
 
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
-
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
 CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
diff --git a/boards/arm/moxart/moxa/scripts/Make.defs 
b/boards/arm/moxart/moxa/scripts/Make.defs
index 503b4d4a1ba..bcb7793acb7 100644
--- a/boards/arm/moxart/moxa/scripts/Make.defs
+++ b/boards/arm/moxart/moxa/scripts/Make.defs
@@ -34,8 +34,6 @@ CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) 
$(ARCHCPUFLAGS) $(ARCHXXINCLUDES
 CPPFLAGS := $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
 AFLAGS := $(CFLAGS) -D__ASSEMBLY__
 
-MKNXFLAT = mknxflat
-LDNXFLAT = ldnxflat
 
 NXFLATLDFLAGS1 = -r -d -warn-common
 NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) 
-T$(TOPDIR)/binfmt/libnxflat/gnu-nxflat-pcrel.ld -no-check-sections
diff --git a/boards/arm/rp23xx/pimoroni-pico-2-plus/scripts/Make.defs 
b/boards/arm/rp23xx/pimoroni-pico-2-plus/scripts/Make.defs
index fa4bfae9c51..51fa9c5bca2 100644
--- a/boards/arm/rp23xx/pimoroni-pico-2-plus/scripts/Make.defs
+++ b/boards/arm/rp23xx/pimoroni-pico-2-plus/scripts/Make.defs
@@ -38,8 +38,6 @@ CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) 
$(ARCHCPUFLAGS) $(ARCHXXINCLUDES
 CPPFLAGS := $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
 AFLAGS := $(CFLAGS) -D__ASSEMBLY__
 
-MKNXFLAT = mknxflat
-LDNXFLAT = ldnxflat
 
 NXFLATLDFLAGS1 = -r -d -warn-common
 NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) 
-T$(TOPDIR)/binfmt/libnxflat/gnu-nxflat-pcrel.ld -no-check-sections
diff --git a/boards/arm/rp23xx/raspberrypi-pico-2/scripts/Make.defs 
b/boards/arm/rp23xx/raspberrypi-pico-2/scripts/Make.defs
index c50a89026bc..cd582cf6043 100644
--- a/boards/arm/rp23xx/raspberrypi-pico-2/scripts/Make.defs
+++ b/boards/arm/rp23xx/raspberrypi-pico-2/scripts/Make.defs
@@ -38,8 +38,6 @@ CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) 
$(ARCHCPUFLAGS) $(ARCHXXINCLUDES
 CPPFLAGS := $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
 AFLAGS := $(CFLAGS) -D__ASSEMBLY__
 
-MKNXFLAT = mknxflat
-LDNXFLAT = ldnxflat
 
 NXFLATLDFLAGS1 = -r -d -warn-common
 NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) 
-T$(TOPDIR)/binfmt/libnxflat/gnu-nxflat-pcrel.ld -no-check-sections
diff --git a/boards/arm/rp23xx/xiao-rp2350/scripts/Make.defs 
b/boards/arm/rp23xx/xiao-rp2350/scripts/Make.defs
index ccf52abfac7..b649916383c 100644
--- a/boards/arm/rp23xx/xiao-rp2350/scripts/Make.defs
+++ b/boards/arm/rp23xx/xiao-rp2350/scripts/Make.defs
@@ -38,8 +38,6 @@ CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) 
$(ARCHCPUFLAGS) $(ARCHXXINCLUDES
 CPPFLAGS := $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
 AFLAGS := $(CFLAGS) -D__ASSEMBLY__
 
-MKNXFLAT = mknxflat
-LDNXFLAT = ldnxflat
 
 NXFLATLDFLAGS1 = -r -d -warn-common
 NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) 
-T$(TOPDIR)/binfmt/libnxflat/gnu-nxflat-pcrel.ld -no-check-sections
diff --git a/boards/arm/s32k3xx/mr-canhubk3/configs/knsh/Make.defs 
b/boards/arm/s32k3xx/mr-canhubk3/configs/knsh/Make.defs
index 50e56ffedfc..4a36ec50fa1 100644
--- a/boards/arm/s32k3xx/mr-canhubk3/configs/knsh/Make.defs
+++ b/boards/arm/s32k3xx/mr-canhubk3/configs/knsh/Make.defs
@@ -28,8 +28,6 @@ LDSCRIPT2 = kernel-space.ld
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT1)
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT2)
 
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
-
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
 CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
diff --git a/boards/arm/sam34/sam3u-ek/configs/knsh/Make.defs 
b/boards/arm/sam34/sam3u-ek/configs/knsh/Make.defs
index 3e6db6ea308..5cbc0bac7fb 100644
--- a/boards/arm/sam34/sam3u-ek/configs/knsh/Make.defs
+++ b/boards/arm/sam34/sam3u-ek/configs/knsh/Make.defs
@@ -25,8 +25,6 @@ include $(TOPDIR)/arch/arm/src/armv7-m/Toolchain.defs
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)memory.ld
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)kernel-space.ld
 
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
-
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
 CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
diff --git a/boards/arm/sama5/sama5d3-xplained/configs/knsh/Make.defs 
b/boards/arm/sama5/sama5d3-xplained/configs/knsh/Make.defs
index 7a229551c78..12bb8e1ae72 100644
--- a/boards/arm/sama5/sama5d3-xplained/configs/knsh/Make.defs
+++ b/boards/arm/sama5/sama5d3-xplained/configs/knsh/Make.defs
@@ -32,8 +32,6 @@ endif
 
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)
 
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
-
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
 CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
diff --git a/boards/arm/sama5/sama5d4-ek/configs/knsh/Make.defs 
b/boards/arm/sama5/sama5d4-ek/configs/knsh/Make.defs
index 2d2ad887bdf..c325725fcca 100644
--- a/boards/arm/sama5/sama5d4-ek/configs/knsh/Make.defs
+++ b/boards/arm/sama5/sama5d4-ek/configs/knsh/Make.defs
@@ -36,8 +36,6 @@ endif
 
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)
 
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
-
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
 CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
diff --git a/boards/arm/samv7/samv71-xult/configs/knsh/Make.defs 
b/boards/arm/samv7/samv71-xult/configs/knsh/Make.defs
index 7eac71be7ab..bb85c2ca96a 100644
--- a/boards/arm/samv7/samv71-xult/configs/knsh/Make.defs
+++ b/boards/arm/samv7/samv71-xult/configs/knsh/Make.defs
@@ -41,8 +41,6 @@ else
   ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)kernel-space.ld
 endif
 
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
-
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
 CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
diff --git a/boards/arm/stm32f1/shenzhou/scripts/Make.defs 
b/boards/arm/stm32f1/shenzhou/scripts/Make.defs
index f0f931facc6..54e7e4962dc 100644
--- a/boards/arm/stm32f1/shenzhou/scripts/Make.defs
+++ b/boards/arm/stm32f1/shenzhou/scripts/Make.defs
@@ -34,8 +34,6 @@ endif
 
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)
 
-MKNXFLAT = mknxflat
-LDNXFLAT = ldnxflat
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
diff --git a/boards/arm/stm32f4/olimex-stm32-p407/configs/kelf/Make.defs 
b/boards/arm/stm32f4/olimex-stm32-p407/configs/kelf/Make.defs
index 9c06da91d4e..013f773a349 100644
--- a/boards/arm/stm32f4/olimex-stm32-p407/configs/kelf/Make.defs
+++ b/boards/arm/stm32f4/olimex-stm32-p407/configs/kelf/Make.defs
@@ -25,8 +25,6 @@ include $(TOPDIR)/arch/arm/src/armv7-m/Toolchain.defs
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)memory.ld
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)kernel-space.ld
 
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
-
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
 CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
diff --git a/boards/arm/stm32f4/olimex-stm32-p407/configs/kmodule/Make.defs 
b/boards/arm/stm32f4/olimex-stm32-p407/configs/kmodule/Make.defs
index 22979d8184d..eed982769a1 100644
--- a/boards/arm/stm32f4/olimex-stm32-p407/configs/kmodule/Make.defs
+++ b/boards/arm/stm32f4/olimex-stm32-p407/configs/kmodule/Make.defs
@@ -25,8 +25,6 @@ include $(TOPDIR)/arch/arm/src/armv7-m/Toolchain.defs
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)memory.ld
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)kernel-space.ld
 
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
-
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
 CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
diff --git a/boards/arm/stm32f4/olimex-stm32-p407/configs/knsh/Make.defs 
b/boards/arm/stm32f4/olimex-stm32-p407/configs/knsh/Make.defs
index f9a6444eca0..9b841d6f407 100644
--- a/boards/arm/stm32f4/olimex-stm32-p407/configs/knsh/Make.defs
+++ b/boards/arm/stm32f4/olimex-stm32-p407/configs/knsh/Make.defs
@@ -28,8 +28,6 @@ LDSCRIPT2 = kernel-space.ld
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT1)
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT2)
 
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
-
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
 CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
diff --git a/boards/arm/stm32f4/stm3240g-eval/configs/knxwm/Make.defs 
b/boards/arm/stm32f4/stm3240g-eval/configs/knxwm/Make.defs
index bdadecf8603..1140d8f4fac 100644
--- a/boards/arm/stm32f4/stm3240g-eval/configs/knxwm/Make.defs
+++ b/boards/arm/stm32f4/stm3240g-eval/configs/knxwm/Make.defs
@@ -26,8 +26,6 @@ ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)memory.ld
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)kernel-space.ld
 
 ARCHCXXFLAGS += -fpermissive
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
-
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
 CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
diff --git a/boards/arm/stm32f4/stm32f4discovery/configs/kostest/Make.defs 
b/boards/arm/stm32f4/stm32f4discovery/configs/kostest/Make.defs
index 8c981466a32..c89ccdb327f 100644
--- a/boards/arm/stm32f4/stm32f4discovery/configs/kostest/Make.defs
+++ b/boards/arm/stm32f4/stm32f4discovery/configs/kostest/Make.defs
@@ -28,8 +28,6 @@ LDSCRIPT2 = kernel-space.ld
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT1)
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT2)
 
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
-
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
 CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
diff --git a/boards/arm/stm32f4/stm32f4discovery/src/CMakeLists.txt 
b/boards/arm/stm32f4/stm32f4discovery/src/CMakeLists.txt
index 36cebfbb8cf..853db133b1a 100644
--- a/boards/arm/stm32f4/stm32f4discovery/src/CMakeLists.txt
+++ b/boards/arm/stm32f4/stm32f4discovery/src/CMakeLists.txt
@@ -182,7 +182,7 @@ set_property(
 
 # TODO: see where to put pic flags set_property(TARGET nuttx APPEND PROPERTY
 # NUTTX_COMPILE_OPTIONS $<$<NOT:$<COMPILE_LANGUAGE:ASM>>:-fpic 
-msingle-pic-base
-# -mpic-register=r10>)
+# -mpic-register=r9>)
 
 # ifeq ($(CONFIG_ARMV7M_TOOLCHAIN_CLANGL),y) ARCHCFLAGS += -nostdlib
 # -ffreestanding ARCHCXXFLAGS += -nostdlib -ffreestanding else ARCHCFLAGS +=
diff --git a/boards/arm/stm32h7/devebox-stm32h743/scripts/Make.defs 
b/boards/arm/stm32h7/devebox-stm32h743/scripts/Make.defs
index 69ef0f92023..e91c28ac69d 100644
--- a/boards/arm/stm32h7/devebox-stm32h743/scripts/Make.defs
+++ b/boards/arm/stm32h7/devebox-stm32h743/scripts/Make.defs
@@ -28,8 +28,6 @@ LDSCRIPT = flash.ld
 
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)
 
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
-
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS) -pipe
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
 CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe
diff --git a/boards/arm/stm32l4/stm32l476vg-disco/configs/knsh/Make.defs 
b/boards/arm/stm32l4/stm32l476vg-disco/configs/knsh/Make.defs
index 791ca4bdc6b..20c5b98f9a7 100644
--- a/boards/arm/stm32l4/stm32l476vg-disco/configs/knsh/Make.defs
+++ b/boards/arm/stm32l4/stm32l476vg-disco/configs/knsh/Make.defs
@@ -28,8 +28,6 @@ LDSCRIPT2 = kernel-space.ld
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT1)
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT2)
 
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
-
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
 CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
diff --git a/boards/arm/stm32l4/stm32l4r9ai-disco/configs/knsh/Make.defs 
b/boards/arm/stm32l4/stm32l4r9ai-disco/configs/knsh/Make.defs
index 6fac6302fa7..ed0a21f4292 100644
--- a/boards/arm/stm32l4/stm32l4r9ai-disco/configs/knsh/Make.defs
+++ b/boards/arm/stm32l4/stm32l4r9ai-disco/configs/knsh/Make.defs
@@ -28,8 +28,6 @@ LDSCRIPT2 = kernel-space.ld
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT1)
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT2)
 
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
-
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
 CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
diff --git a/boards/arm/tiva/eagle100/scripts/Make.defs 
b/boards/arm/tiva/eagle100/scripts/Make.defs
index 125af333f8d..358a3d25e41 100644
--- a/boards/arm/tiva/eagle100/scripts/Make.defs
+++ b/boards/arm/tiva/eagle100/scripts/Make.defs
@@ -31,8 +31,6 @@ CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) 
$(ARCHCPUFLAGS) $(ARCHXXINCLUDES
 CPPFLAGS := $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
 AFLAGS := $(CFLAGS) -D__ASSEMBLY__
 
-MKNXFLAT = mknxflat
-LDNXFLAT = ldnxflat
 
 NXFLATLDFLAGS1 = -r -d -warn-common
 NXFLATLDFLAGS2 = $(NXFLATLDFLAGS1) 
-T$(TOPDIR)/binfmt/libnxflat/gnu-nxflat-pcrel.ld -no-check-sections
diff --git a/boards/avr/at32uc3/avr32dev1/scripts/Make.defs 
b/boards/avr/at32uc3/avr32dev1/scripts/Make.defs
index 07f92e5ea93..64e31ad1f61 100644
--- a/boards/avr/at32uc3/avr32dev1/scripts/Make.defs
+++ b/boards/avr/at32uc3/avr32dev1/scripts/Make.defs
@@ -28,7 +28,6 @@ ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)avr32dev1.ld
 
 ARCHCFLAGS = -muse-rodata-section
 ARCHNOPICFLAGS = -fno-pic
-ARCHPICFLAGS = -fpic
 ARCHALLCFLAGS = $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
 ARCHALLCXXFLAGS = $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
 
diff --git a/boards/avr/at32uc3/mizar32a/scripts/Make.defs 
b/boards/avr/at32uc3/mizar32a/scripts/Make.defs
index 137bf8fb926..f374c3d22c8 100644
--- a/boards/avr/at32uc3/mizar32a/scripts/Make.defs
+++ b/boards/avr/at32uc3/mizar32a/scripts/Make.defs
@@ -28,7 +28,6 @@ ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)mizar32a.ld
 
 ARCHCFLAGS = -muse-rodata-section
 ARCHNOPICFLAGS = -fno-pic
-ARCHPICFLAGS = -fpic
 ARCHALLCFLAGS = $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe
 ARCHALLCXXFLAGS = $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe
 
diff --git a/boards/hc/m9s12/demo9s12ne64/scripts/Make.defs 
b/boards/hc/m9s12/demo9s12ne64/scripts/Make.defs
index 63e9f2ff0d2..55d43c86ff4 100644
--- a/boards/hc/m9s12/demo9s12ne64/scripts/Make.defs
+++ b/boards/hc/m9s12/demo9s12ne64/scripts/Make.defs
@@ -54,7 +54,6 @@ ARCHCFLAGS = -fno-common
 ARCHCXXFLAGS = -fno-common -fno-exceptions -fcheck-new
 ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow -Wundef
 ARCHWARNINGSXX = -Wall -Wshadow -Wundef
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHWARNINGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/hc/m9s12/ne64badge/scripts/Make.defs 
b/boards/hc/m9s12/ne64badge/scripts/Make.defs
index 1b9beb634e9..faef7bc49c6 100644
--- a/boards/hc/m9s12/ne64badge/scripts/Make.defs
+++ b/boards/hc/m9s12/ne64badge/scripts/Make.defs
@@ -54,7 +54,6 @@ ARCHCFLAGS = -fno-common
 ARCHCXXFLAGS = -fno-common -fno-exceptions -fcheck-new
 ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow -Wundef
 ARCHWARNINGSXX = -Wall -Wshadow -Wundef
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHWARNINGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) 
$(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/or1k/mor1kx/or1k/scripts/Make.defs 
b/boards/or1k/mor1kx/or1k/scripts/Make.defs
index 6241cc1cb9c..a7437ba82d1 100644
--- a/boards/or1k/mor1kx/or1k/scripts/Make.defs
+++ b/boards/or1k/mor1kx/or1k/scripts/Make.defs
@@ -27,7 +27,6 @@ include $(TOPDIR)/arch/or1k/src/mor1kx/Toolchain.defs
 LDSCRIPT = flash.ld
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)
 
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/renesas/m16c/skp16c26/scripts/Make.defs 
b/boards/renesas/m16c/skp16c26/scripts/Make.defs
index 941ab9815d4..8a8228d4e4a 100644
--- a/boards/renesas/m16c/skp16c26/scripts/Make.defs
+++ b/boards/renesas/m16c/skp16c26/scripts/Make.defs
@@ -41,7 +41,6 @@ ifneq ($(CONFIG_DEBUG_NOOPT),y)
 endif
 
 ARCHCPUFLAGS           = -mcpu=m16c
-ARCHPICFLAGS           = -fpic
 ARCHWARNINGS           = -Wall -Wstrict-prototypes -Wshadow -Wundef
 
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)skp16c26.ld
diff --git a/boards/renesas/rx65n/rx65n-grrose/scripts/Make.defs 
b/boards/renesas/rx65n/rx65n-grrose/scripts/Make.defs
index 7df89e540b4..bf0f578c3fb 100644
--- a/boards/renesas/rx65n/rx65n-grrose/scripts/Make.defs
+++ b/boards/renesas/rx65n/rx65n-grrose/scripts/Make.defs
@@ -46,7 +46,6 @@ ifneq ($(CONFIG_DEBUG_NOOPT),y)
   ARCHOPTIMIZATION += -Os -fno-strict-aliasing -fomit-frame-pointer
 endif
 
-ARCHPICFLAGS = -fpic
 ARCHCFLAGS = -fno-common -std=c99
 ARCHCPUFLAGS = -mcpu=rx64m
 ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow -Wundef
diff --git a/boards/renesas/rx65n/rx65n-rsk1mb/scripts/Make.defs 
b/boards/renesas/rx65n/rx65n-rsk1mb/scripts/Make.defs
index df2bd460b50..e00a3c9abef 100644
--- a/boards/renesas/rx65n/rx65n-rsk1mb/scripts/Make.defs
+++ b/boards/renesas/rx65n/rx65n-rsk1mb/scripts/Make.defs
@@ -46,7 +46,6 @@ ifneq ($(CONFIG_DEBUG_NOOPT),y)
   ARCHOPTIMIZATION += -Os -fno-strict-aliasing -fomit-frame-pointer
 endif
 
-ARCHPICFLAGS = -fpic
 ARCHCFLAGS = -fno-common -std=c99
 ARCHCPUFLAGS = -mcpu=rx64m
 ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow -Wundef
diff --git a/boards/renesas/rx65n/rx65n-rsk2mb/scripts/Make.defs 
b/boards/renesas/rx65n/rx65n-rsk2mb/scripts/Make.defs
index 92fe898cb51..2ca198d3784 100644
--- a/boards/renesas/rx65n/rx65n-rsk2mb/scripts/Make.defs
+++ b/boards/renesas/rx65n/rx65n-rsk2mb/scripts/Make.defs
@@ -46,7 +46,6 @@ ifneq ($(CONFIG_DEBUG_NOOPT),y)
   ARCHOPTIMIZATION += -Os -fno-strict-aliasing -fomit-frame-pointer
 endif
 
-ARCHPICFLAGS = -fpic
 ARCHCFLAGS = -fno-common -std=c99
 ARCHCPUFLAGS = -mcpu=rx64m
 ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow -Wundef
diff --git a/boards/renesas/rx65n/rx65n/scripts/Make.defs 
b/boards/renesas/rx65n/rx65n/scripts/Make.defs
index 09db0113da6..580b3f0301a 100644
--- a/boards/renesas/rx65n/rx65n/scripts/Make.defs
+++ b/boards/renesas/rx65n/rx65n/scripts/Make.defs
@@ -46,7 +46,6 @@ ifneq ($(CONFIG_DEBUG_NOOPT),y)
   ARCHOPTIMIZATION += -Os -fno-strict-aliasing -fomit-frame-pointer
 endif
 
-ARCHPICFLAGS = -fpic
 ARCHCFLAGS = -fno-common -std=c99
 ARCHCPUFLAGS = -mcpu=rx64m
 ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow -Wundef
diff --git a/boards/renesas/sh1/us7032evb1/scripts/Make.defs 
b/boards/renesas/sh1/us7032evb1/scripts/Make.defs
index 533181b7c8b..ec2629c37ae 100644
--- a/boards/renesas/sh1/us7032evb1/scripts/Make.defs
+++ b/boards/renesas/sh1/us7032evb1/scripts/Make.defs
@@ -32,7 +32,6 @@ ifneq ($(CONFIG_DEBUG_NOOPT),y)
 endif
 
 ARCHCPUFLAGS = -m1
-ARCHPICFLAGS = -fpic
 ARCHWARNINGS = -Wall -Wstrict-prototypes -Wshadow -Wundef
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)sdram.ld
 
diff --git a/boards/risc-v/bl602/bl602evb/scripts/Make.defs 
b/boards/risc-v/bl602/bl602evb/scripts/Make.defs
index f431ac7cafa..c2d8ac83e8b 100644
--- a/boards/risc-v/bl602/bl602evb/scripts/Make.defs
+++ b/boards/risc-v/bl602/bl602evb/scripts/Make.defs
@@ -31,7 +31,6 @@ LDSCRIPT = ld.script
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)
 
 ARCHCPUFLAGS += -mno-relax
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
 
 ifeq ($(CONFIG_STACK_OVERFLOW_CHECK),y)
   ARCHCFLAGS += -finstrument-functions -ffixed-s11
diff --git a/boards/risc-v/bl808/ox64/scripts/Make.defs 
b/boards/risc-v/bl808/ox64/scripts/Make.defs
index 3f58d8d898f..cfe3a2302b5 100644
--- a/boards/risc-v/bl808/ox64/scripts/Make.defs
+++ b/boards/risc-v/bl808/ox64/scripts/Make.defs
@@ -26,7 +26,6 @@ include $(TOPDIR)/arch/risc-v/src/common/Toolchain.defs
 
 LDSCRIPT = ld.script
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)
-ARCHPICFLAGS = -fpic -msingle-pic-base
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 
diff --git a/boards/risc-v/eic7700x/starpro64/scripts/Make.defs 
b/boards/risc-v/eic7700x/starpro64/scripts/Make.defs
index 92115f10410..d885c4a4f99 100644
--- a/boards/risc-v/eic7700x/starpro64/scripts/Make.defs
+++ b/boards/risc-v/eic7700x/starpro64/scripts/Make.defs
@@ -26,7 +26,6 @@ include $(TOPDIR)/arch/risc-v/src/common/Toolchain.defs
 
 LDSCRIPT = ld.script
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)
-ARCHPICFLAGS = -fpic -msingle-pic-base
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS) -pipe
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git 
a/boards/risc-v/esp32c3-legacy/esp32c3-legacy-devkit-rust-1/scripts/Make.defs 
b/boards/risc-v/esp32c3-legacy/esp32c3-legacy-devkit-rust-1/scripts/Make.defs
index 37192e755bc..a11dc5d7c4a 100644
--- 
a/boards/risc-v/esp32c3-legacy/esp32c3-legacy-devkit-rust-1/scripts/Make.defs
+++ 
b/boards/risc-v/esp32c3-legacy/esp32c3-legacy-devkit-rust-1/scripts/Make.defs
@@ -43,7 +43,6 @@ else
   endif
 endif
 
-ARCHPICFLAGS = -fpic
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git 
a/boards/risc-v/esp32c3-legacy/esp32c3-legacy-devkit/scripts/Make.defs 
b/boards/risc-v/esp32c3-legacy/esp32c3-legacy-devkit/scripts/Make.defs
index 22722a97704..8d5353f1594 100644
--- a/boards/risc-v/esp32c3-legacy/esp32c3-legacy-devkit/scripts/Make.defs
+++ b/boards/risc-v/esp32c3-legacy/esp32c3-legacy-devkit/scripts/Make.defs
@@ -43,7 +43,6 @@ else
   endif
 endif
 
-ARCHPICFLAGS = -fpic
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS) -Werror=return-type
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/risc-v/esp32c3/esp32-c3-zero/scripts/Make.defs 
b/boards/risc-v/esp32c3/esp32-c3-zero/scripts/Make.defs
index d03f1ce9362..2a8d0d887b2 100644
--- a/boards/risc-v/esp32c3/esp32-c3-zero/scripts/Make.defs
+++ b/boards/risc-v/esp32c3/esp32-c3-zero/scripts/Make.defs
@@ -43,7 +43,6 @@ else
   ARCHSCRIPT += $(call FINDSCRIPT,$(CHIP_SERIES)_legacy_sections.ld)
 endif
 
-ARCHPICFLAGS = -fpic
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS) -Werror=return-type
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/risc-v/esp32c3/esp32c3-devkit/scripts/Make.defs 
b/boards/risc-v/esp32c3/esp32c3-devkit/scripts/Make.defs
index 5bd6c9d784d..85cbd4718a9 100644
--- a/boards/risc-v/esp32c3/esp32c3-devkit/scripts/Make.defs
+++ b/boards/risc-v/esp32c3/esp32c3-devkit/scripts/Make.defs
@@ -43,7 +43,6 @@ else
   ARCHSCRIPT += $(call FINDSCRIPT,$(CHIP_SERIES)_legacy_sections.ld)
 endif
 
-ARCHPICFLAGS = -fpic
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS) -Werror=return-type
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/risc-v/esp32c3/esp32c3-xiao/scripts/Make.defs 
b/boards/risc-v/esp32c3/esp32c3-xiao/scripts/Make.defs
index 9f02ad2d5ba..9796d14ed81 100644
--- a/boards/risc-v/esp32c3/esp32c3-xiao/scripts/Make.defs
+++ b/boards/risc-v/esp32c3/esp32c3-xiao/scripts/Make.defs
@@ -43,7 +43,6 @@ else
   ARCHSCRIPT += $(call FINDSCRIPT,$(CHIP_SERIES)_legacy_sections.ld)
 endif
 
-ARCHPICFLAGS = -fpic
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS) -Werror=return-type
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/risc-v/esp32c6/esp32c6-devkitc/scripts/Make.defs 
b/boards/risc-v/esp32c6/esp32c6-devkitc/scripts/Make.defs
index f27259234aa..d2af1cb4ca3 100644
--- a/boards/risc-v/esp32c6/esp32c6-devkitc/scripts/Make.defs
+++ b/boards/risc-v/esp32c6/esp32c6-devkitc/scripts/Make.defs
@@ -43,7 +43,6 @@ else
   ARCHSCRIPT += $(call FINDSCRIPT,$(CHIP_SERIES)_legacy_sections.ld)
 endif
 
-ARCHPICFLAGS = -fpic
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS) -Werror=return-type
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/risc-v/esp32c6/esp32c6-devkitm/scripts/Make.defs 
b/boards/risc-v/esp32c6/esp32c6-devkitm/scripts/Make.defs
index 1fa5297fc01..0885244f0cd 100644
--- a/boards/risc-v/esp32c6/esp32c6-devkitm/scripts/Make.defs
+++ b/boards/risc-v/esp32c6/esp32c6-devkitm/scripts/Make.defs
@@ -43,7 +43,6 @@ else
   ARCHSCRIPT += $(call FINDSCRIPT,$(CHIP_SERIES)_legacy_sections.ld)
 endif
 
-ARCHPICFLAGS = -fpic
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS) -pipe -Werror=return-type
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/risc-v/esp32c6/esp32c6-xiao/scripts/Make.defs 
b/boards/risc-v/esp32c6/esp32c6-xiao/scripts/Make.defs
index a2bf50fe100..55a42752727 100644
--- a/boards/risc-v/esp32c6/esp32c6-xiao/scripts/Make.defs
+++ b/boards/risc-v/esp32c6/esp32c6-xiao/scripts/Make.defs
@@ -43,7 +43,6 @@ else
   ARCHSCRIPT += $(call FINDSCRIPT,$(CHIP_SERIES)_legacy_sections.ld)
 endif
 
-ARCHPICFLAGS = -fpic
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS) -Werror=return-type
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/risc-v/esp32h2/esp32h2-devkit/scripts/Make.defs 
b/boards/risc-v/esp32h2/esp32h2-devkit/scripts/Make.defs
index 61ff2c867b4..e4010eaedf7 100644
--- a/boards/risc-v/esp32h2/esp32h2-devkit/scripts/Make.defs
+++ b/boards/risc-v/esp32h2/esp32h2-devkit/scripts/Make.defs
@@ -44,7 +44,6 @@ else
   ARCHSCRIPT += $(call FINDSCRIPT,$(CHIP_SERIES)_legacy_sections.ld)
 endif
 
-ARCHPICFLAGS = -fpic
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS) -Werror=return-type
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/risc-v/esp32p4/esp32p4-function-ev-board/scripts/Make.defs 
b/boards/risc-v/esp32p4/esp32p4-function-ev-board/scripts/Make.defs
index 573d5bbbf4c..89fb8a54273 100644
--- a/boards/risc-v/esp32p4/esp32p4-function-ev-board/scripts/Make.defs
+++ b/boards/risc-v/esp32p4/esp32p4-function-ev-board/scripts/Make.defs
@@ -46,7 +46,6 @@ else ifeq ($(CONFIG_ESPRESSIF_SIMPLE_BOOT),y)
   ARCHSCRIPT += $(call FINDSCRIPT,$(CHIP_SERIES)_sections$(BOARD_REV).ld)
 endif
 
-ARCHPICFLAGS = -fpic
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS) -Werror=return-type
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git 
a/boards/risc-v/esp32p4/esp32p4-pico-wifi-wareshare/scripts/Make.defs 
b/boards/risc-v/esp32p4/esp32p4-pico-wifi-wareshare/scripts/Make.defs
index 52bfaa33811..5d8639df55f 100644
--- a/boards/risc-v/esp32p4/esp32p4-pico-wifi-wareshare/scripts/Make.defs
+++ b/boards/risc-v/esp32p4/esp32p4-pico-wifi-wareshare/scripts/Make.defs
@@ -46,7 +46,6 @@ else ifeq ($(CONFIG_ESPRESSIF_SIMPLE_BOOT),y)
   ARCHSCRIPT += $(call FINDSCRIPT,$(CHIP_SERIES)_sections$(BOARD_REV).ld)
 endif
 
-ARCHPICFLAGS = -fpic
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS) -Werror=return-type
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/risc-v/esp32p4/esp32p4-tab5/scripts/Make.defs 
b/boards/risc-v/esp32p4/esp32p4-tab5/scripts/Make.defs
index 2579d1ce72e..51e5bbbf46c 100644
--- a/boards/risc-v/esp32p4/esp32p4-tab5/scripts/Make.defs
+++ b/boards/risc-v/esp32p4/esp32p4-tab5/scripts/Make.defs
@@ -46,7 +46,6 @@ else ifeq ($(CONFIG_ESPRESSIF_SIMPLE_BOOT),y)
   ARCHSCRIPT += $(call FINDSCRIPT,$(CHIP_SERIES)_sections$(BOARD_REV).ld)
 endif
 
-ARCHPICFLAGS = -fpic
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS) -Werror=return-type
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/risc-v/fe310/hifive1-revb/scripts/Make.defs 
b/boards/risc-v/fe310/hifive1-revb/scripts/Make.defs
index f8479460f0a..30b318c26a1 100644
--- a/boards/risc-v/fe310/hifive1-revb/scripts/Make.defs
+++ b/boards/risc-v/fe310/hifive1-revb/scripts/Make.defs
@@ -32,7 +32,6 @@ endif
 
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)
 
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/risc-v/jh7110/star64/scripts/Make.defs 
b/boards/risc-v/jh7110/star64/scripts/Make.defs
index faf5104864a..f4aebc2d14c 100644
--- a/boards/risc-v/jh7110/star64/scripts/Make.defs
+++ b/boards/risc-v/jh7110/star64/scripts/Make.defs
@@ -26,7 +26,6 @@ include $(TOPDIR)/arch/risc-v/src/common/Toolchain.defs
 
 LDSCRIPT = ld.script
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)
-ARCHPICFLAGS = -fpic -msingle-pic-base
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/risc-v/k230/canmv230/scripts/Make.defs 
b/boards/risc-v/k230/canmv230/scripts/Make.defs
index 13a66680859..c4af2103c06 100644
--- a/boards/risc-v/k230/canmv230/scripts/Make.defs
+++ b/boards/risc-v/k230/canmv230/scripts/Make.defs
@@ -37,7 +37,6 @@ endif
 endif
 
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)
-ARCHPICFLAGS = -fpic -msingle-pic-base
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS) -pipe
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/risc-v/litex/arty_a7/scripts/Make.defs 
b/boards/risc-v/litex/arty_a7/scripts/Make.defs
index 207b83d03ef..2ae942bcddc 100644
--- a/boards/risc-v/litex/arty_a7/scripts/Make.defs
+++ b/boards/risc-v/litex/arty_a7/scripts/Make.defs
@@ -32,7 +32,6 @@ endif
 
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)
 
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/risc-v/qemu-rv/rv-virt/scripts/Make.defs 
b/boards/risc-v/qemu-rv/rv-virt/scripts/Make.defs
index 9b856a7a17b..b386933aaa8 100644
--- a/boards/risc-v/qemu-rv/rv-virt/scripts/Make.defs
+++ b/boards/risc-v/qemu-rv/rv-virt/scripts/Make.defs
@@ -37,7 +37,6 @@ endif
 endif
 
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)
-ARCHPICFLAGS = -fpic -msingle-pic-base
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/risc-v/rp23xx-rv/raspberrypi-pico-2-rv/scripts/Make.defs 
b/boards/risc-v/rp23xx-rv/raspberrypi-pico-2-rv/scripts/Make.defs
index db486037499..ae3e7b01623 100644
--- a/boards/risc-v/rp23xx-rv/raspberrypi-pico-2-rv/scripts/Make.defs
+++ b/boards/risc-v/rp23xx-rv/raspberrypi-pico-2-rv/scripts/Make.defs
@@ -33,7 +33,6 @@ endif
 
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)
 
-ARCHPICFLAGS = -fpic -msingle-pic-base -mpic-register=r10
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS) -pipe
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/risc-v/sg2000/milkv_duos/scripts/Make.defs 
b/boards/risc-v/sg2000/milkv_duos/scripts/Make.defs
index cd93e12b275..683f2d706b3 100644
--- a/boards/risc-v/sg2000/milkv_duos/scripts/Make.defs
+++ b/boards/risc-v/sg2000/milkv_duos/scripts/Make.defs
@@ -26,7 +26,6 @@ include $(TOPDIR)/arch/risc-v/src/common/Toolchain.defs
 
 LDSCRIPT = ld.script
 ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)
-ARCHPICFLAGS = -fpic -msingle-pic-base
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS) -pipe
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/sim/sim/sim/scripts/Make.defs 
b/boards/sim/sim/sim/scripts/Make.defs
index 0b61eaebddd..f3667253196 100644
--- a/boards/sim/sim/sim/scripts/Make.defs
+++ b/boards/sim/sim/sim/scripts/Make.defs
@@ -189,7 +189,6 @@ else ifeq ($(CONFIG_HOST_MACOS),y)
   LLVM_ABITYPE := sysv
 endif
 
-ARCHPICFLAGS = -fpic
 
 CC = $(CROSSDEV)cc
 CXX = $(CROSSDEV)c++
diff --git a/boards/xtensa/esp32/esp32-2432S028/scripts/Make.defs 
b/boards/xtensa/esp32/esp32-2432S028/scripts/Make.defs
index 708b3e97123..3ee9a7c5f30 100644
--- a/boards/xtensa/esp32/esp32-2432S028/scripts/Make.defs
+++ b/boards/xtensa/esp32/esp32-2432S028/scripts/Make.defs
@@ -41,7 +41,6 @@ else
   endif
 endif
 
-ARCHPICFLAGS = -fpic
 
 # if SPIRAM/PSRAM is used then we need to include a workaround
 
diff --git a/boards/xtensa/esp32/esp32-audio-kit/scripts/Make.defs 
b/boards/xtensa/esp32/esp32-audio-kit/scripts/Make.defs
index c29a96d0443..1f800c71de7 100644
--- a/boards/xtensa/esp32/esp32-audio-kit/scripts/Make.defs
+++ b/boards/xtensa/esp32/esp32-audio-kit/scripts/Make.defs
@@ -41,7 +41,6 @@ else
   endif
 endif
 
-ARCHPICFLAGS = -fpic
 
 # if SPIRAM/PSRAM is used then we need to include a workaround
 
diff --git a/boards/xtensa/esp32/esp32-devkitc/scripts/Make.defs 
b/boards/xtensa/esp32/esp32-devkitc/scripts/Make.defs
index 93b0935821c..2dea0bfe291 100644
--- a/boards/xtensa/esp32/esp32-devkitc/scripts/Make.defs
+++ b/boards/xtensa/esp32/esp32-devkitc/scripts/Make.defs
@@ -41,7 +41,6 @@ else
   endif
 endif
 
-ARCHPICFLAGS = -fpic
 
 # if SPIRAM/PSRAM is used then we need to include a workaround
 
diff --git a/boards/xtensa/esp32/esp32-ethernet-kit/scripts/Make.defs 
b/boards/xtensa/esp32/esp32-ethernet-kit/scripts/Make.defs
index 7a318591d8f..9172fa600d1 100644
--- a/boards/xtensa/esp32/esp32-ethernet-kit/scripts/Make.defs
+++ b/boards/xtensa/esp32/esp32-ethernet-kit/scripts/Make.defs
@@ -41,7 +41,6 @@ else
   endif
 endif
 
-ARCHPICFLAGS = -fpic
 
 # if SPIRAM/PSRAM is used then we need to include a workaround
 
diff --git a/boards/xtensa/esp32/esp32-lyrat/scripts/Make.defs 
b/boards/xtensa/esp32/esp32-lyrat/scripts/Make.defs
index 332bd3d994d..9c766b1fa45 100644
--- a/boards/xtensa/esp32/esp32-lyrat/scripts/Make.defs
+++ b/boards/xtensa/esp32/esp32-lyrat/scripts/Make.defs
@@ -41,7 +41,6 @@ else
   endif
 endif
 
-ARCHPICFLAGS = -fpic
 
 # if SPIRAM/PSRAM is used then we need to include a workaround
 
diff --git a/boards/xtensa/esp32/esp32-pico-kit/scripts/Make.defs 
b/boards/xtensa/esp32/esp32-pico-kit/scripts/Make.defs
index 692e1e492e5..fbeb5730edf 100644
--- a/boards/xtensa/esp32/esp32-pico-kit/scripts/Make.defs
+++ b/boards/xtensa/esp32/esp32-pico-kit/scripts/Make.defs
@@ -41,7 +41,6 @@ else
   endif
 endif
 
-ARCHPICFLAGS = -fpic
 
 # if SPIRAM/PSRAM is used then we need to include a workaround
 
diff --git a/boards/xtensa/esp32/esp32-sparrow-kit/scripts/Make.defs 
b/boards/xtensa/esp32/esp32-sparrow-kit/scripts/Make.defs
index 27e393d3527..422845482e1 100644
--- a/boards/xtensa/esp32/esp32-sparrow-kit/scripts/Make.defs
+++ b/boards/xtensa/esp32/esp32-sparrow-kit/scripts/Make.defs
@@ -41,7 +41,6 @@ else
   endif
 endif
 
-ARCHPICFLAGS = -fpic
 
 # if SPIRAM/PSRAM is used then we need to include a workaround
 
diff --git a/boards/xtensa/esp32/esp32-wrover-kit/scripts/Make.defs 
b/boards/xtensa/esp32/esp32-wrover-kit/scripts/Make.defs
index 4e8ce30a044..ba1de5aa517 100644
--- a/boards/xtensa/esp32/esp32-wrover-kit/scripts/Make.defs
+++ b/boards/xtensa/esp32/esp32-wrover-kit/scripts/Make.defs
@@ -41,7 +41,6 @@ else
   endif
 endif
 
-ARCHPICFLAGS = -fpic
 
 # if SPIRAM/PSRAM is used then we need to include a workaround
 
diff --git a/boards/xtensa/esp32/heltec_wifi_lora32/scripts/Make.defs 
b/boards/xtensa/esp32/heltec_wifi_lora32/scripts/Make.defs
index e4e3a185828..c5245c12325 100644
--- a/boards/xtensa/esp32/heltec_wifi_lora32/scripts/Make.defs
+++ b/boards/xtensa/esp32/heltec_wifi_lora32/scripts/Make.defs
@@ -41,7 +41,6 @@ else
   endif
 endif
 
-ARCHPICFLAGS = -fpic
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/xtensa/esp32/lilygo_tbeam_lora_gps/scripts/Make.defs 
b/boards/xtensa/esp32/lilygo_tbeam_lora_gps/scripts/Make.defs
index 3ba9ebf2737..d7e2c93fa1f 100644
--- a/boards/xtensa/esp32/lilygo_tbeam_lora_gps/scripts/Make.defs
+++ b/boards/xtensa/esp32/lilygo_tbeam_lora_gps/scripts/Make.defs
@@ -41,7 +41,6 @@ else
   endif
 endif
 
-ARCHPICFLAGS = -fpic
 
 # if SPIRAM/PSRAM is used then we need to include a workaround
 
diff --git a/boards/xtensa/esp32/ttgo_eink5_v2/scripts/Make.defs 
b/boards/xtensa/esp32/ttgo_eink5_v2/scripts/Make.defs
index 388cb0b078f..baaf36f6119 100644
--- a/boards/xtensa/esp32/ttgo_eink5_v2/scripts/Make.defs
+++ b/boards/xtensa/esp32/ttgo_eink5_v2/scripts/Make.defs
@@ -41,7 +41,6 @@ else
   endif
 endif
 
-ARCHPICFLAGS = -fpic
 
 # if SPIRAM/PSRAM is used then we need to include a workaround
 
diff --git a/boards/xtensa/esp32/ttgo_lora_esp32/scripts/Make.defs 
b/boards/xtensa/esp32/ttgo_lora_esp32/scripts/Make.defs
index 315d3333abb..4ba9bbec678 100644
--- a/boards/xtensa/esp32/ttgo_lora_esp32/scripts/Make.defs
+++ b/boards/xtensa/esp32/ttgo_lora_esp32/scripts/Make.defs
@@ -41,7 +41,6 @@ else
   endif
 endif
 
-ARCHPICFLAGS = -fpic
 
 # if SPIRAM/PSRAM is used then we need to include a workaround
 
diff --git a/boards/xtensa/esp32/ttgo_t_display_esp32/scripts/Make.defs 
b/boards/xtensa/esp32/ttgo_t_display_esp32/scripts/Make.defs
index a6cb1db5cac..e1f504fbb28 100644
--- a/boards/xtensa/esp32/ttgo_t_display_esp32/scripts/Make.defs
+++ b/boards/xtensa/esp32/ttgo_t_display_esp32/scripts/Make.defs
@@ -41,7 +41,6 @@ else
   endif
 endif
 
-ARCHPICFLAGS = -fpic
 
 # if SPIRAM/PSRAM is used then we need to include a workaround
 
diff --git a/boards/xtensa/esp32s2/esp32s2-kaluga-1/scripts/Make.defs 
b/boards/xtensa/esp32s2/esp32s2-kaluga-1/scripts/Make.defs
index 3e03cc8b3db..9969e935a3d 100644
--- a/boards/xtensa/esp32s2/esp32s2-kaluga-1/scripts/Make.defs
+++ b/boards/xtensa/esp32s2/esp32s2-kaluga-1/scripts/Make.defs
@@ -34,7 +34,6 @@ ARCHSCRIPT += 
$(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32s2_peripherals.ld
 ARCHSCRIPT += $(call FINDSCRIPT,flat_memory.ld)
 ARCHSCRIPT += $(call FINDSCRIPT,esp32s2_sections.ld)
 
-ARCHPICFLAGS = -fpic
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/xtensa/esp32s2/esp32s2-saola-1/scripts/Make.defs 
b/boards/xtensa/esp32s2/esp32s2-saola-1/scripts/Make.defs
index c60872364c8..01b7bd9f139 100644
--- a/boards/xtensa/esp32s2/esp32s2-saola-1/scripts/Make.defs
+++ b/boards/xtensa/esp32s2/esp32s2-saola-1/scripts/Make.defs
@@ -34,7 +34,6 @@ ARCHSCRIPT += 
$(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32s2_peripherals.ld
 ARCHSCRIPT += $(call FINDSCRIPT,flat_memory.ld)
 ARCHSCRIPT += $(call FINDSCRIPT,esp32s2_sections.ld)
 
-ARCHPICFLAGS = -fpic
 
 ifeq ($(CONFIG_DEBUG_FULLOPT),y)
   ARCHOPTIMIZATION += -fno-omit-frame-pointer
diff --git a/boards/xtensa/esp32s2/franzininho-wifi/scripts/Make.defs 
b/boards/xtensa/esp32s2/franzininho-wifi/scripts/Make.defs
index e55715acc72..e48003fe374 100644
--- a/boards/xtensa/esp32s2/franzininho-wifi/scripts/Make.defs
+++ b/boards/xtensa/esp32s2/franzininho-wifi/scripts/Make.defs
@@ -35,7 +35,6 @@ ARCHSCRIPT += $(call FINDSCRIPT,flat_memory.ld)
 ARCHSCRIPT += $(call FINDSCRIPT,esp32s2_sections.ld)
 
 
-ARCHPICFLAGS = -fpic
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/xtensa/esp32s3/esp32s3-8048S043/scripts/Make.defs 
b/boards/xtensa/esp32s3/esp32s3-8048S043/scripts/Make.defs
index df22216cd22..33998679b7e 100644
--- a/boards/xtensa/esp32s3/esp32s3-8048S043/scripts/Make.defs
+++ b/boards/xtensa/esp32s3/esp32s3-8048S043/scripts/Make.defs
@@ -47,7 +47,6 @@ ifneq ($(CONFIG_DEBUG_NOOPT),y)
   ARCHOPTIMIZATION += -fno-strength-reduce
 endif
 
-ARCHPICFLAGS = -fpic
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/xtensa/esp32s3/esp32s3-box/scripts/Make.defs 
b/boards/xtensa/esp32s3/esp32s3-box/scripts/Make.defs
index f001355d0cc..25b3cc4181c 100644
--- a/boards/xtensa/esp32s3/esp32s3-box/scripts/Make.defs
+++ b/boards/xtensa/esp32s3/esp32s3-box/scripts/Make.defs
@@ -47,7 +47,6 @@ ifneq ($(CONFIG_DEBUG_NOOPT),y)
   ARCHOPTIMIZATION += -fno-strength-reduce
 endif
 
-ARCHPICFLAGS = -fpic
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/xtensa/esp32s3/esp32s3-devkit/scripts/Make.defs 
b/boards/xtensa/esp32s3/esp32s3-devkit/scripts/Make.defs
index c0d223a3302..50ac3ee2b69 100644
--- a/boards/xtensa/esp32s3/esp32s3-devkit/scripts/Make.defs
+++ b/boards/xtensa/esp32s3/esp32s3-devkit/scripts/Make.defs
@@ -47,7 +47,6 @@ ifneq ($(CONFIG_DEBUG_NOOPT),y)
   ARCHOPTIMIZATION += -fno-strength-reduce
 endif
 
-ARCHPICFLAGS = -fpic
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/xtensa/esp32s3/esp32s3-eye/scripts/Make.defs 
b/boards/xtensa/esp32s3/esp32s3-eye/scripts/Make.defs
index 5b109216ab5..4eb7bdea258 100644
--- a/boards/xtensa/esp32s3/esp32s3-eye/scripts/Make.defs
+++ b/boards/xtensa/esp32s3/esp32s3-eye/scripts/Make.defs
@@ -47,7 +47,6 @@ ifneq ($(CONFIG_DEBUG_NOOPT),y)
   ARCHOPTIMIZATION += -fno-strength-reduce
 endif
 
-ARCHPICFLAGS = -fpic
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/xtensa/esp32s3/esp32s3-korvo-2/scripts/Make.defs 
b/boards/xtensa/esp32s3/esp32s3-korvo-2/scripts/Make.defs
index 1cdde66808a..430701deaa9 100644
--- a/boards/xtensa/esp32s3/esp32s3-korvo-2/scripts/Make.defs
+++ b/boards/xtensa/esp32s3/esp32s3-korvo-2/scripts/Make.defs
@@ -47,7 +47,6 @@ ifneq ($(CONFIG_DEBUG_NOOPT),y)
   ARCHOPTIMIZATION += -fno-strength-reduce
 endif
 
-ARCHPICFLAGS = -fpic
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS) -pipe
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/xtensa/esp32s3/esp32s3-lcd-ev/scripts/Make.defs 
b/boards/xtensa/esp32s3/esp32s3-lcd-ev/scripts/Make.defs
index 40bd65d059d..96ba2f7eba5 100644
--- a/boards/xtensa/esp32s3/esp32s3-lcd-ev/scripts/Make.defs
+++ b/boards/xtensa/esp32s3/esp32s3-lcd-ev/scripts/Make.defs
@@ -47,7 +47,6 @@ ifneq ($(CONFIG_DEBUG_NOOPT),y)
   ARCHOPTIMIZATION += -fno-strength-reduce
 endif
 
-ARCHPICFLAGS = -fpic
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/xtensa/esp32s3/esp32s3-lhcbit/scripts/Make.defs 
b/boards/xtensa/esp32s3/esp32s3-lhcbit/scripts/Make.defs
index 696a25653c3..37aa9f31b0e 100644
--- a/boards/xtensa/esp32s3/esp32s3-lhcbit/scripts/Make.defs
+++ b/boards/xtensa/esp32s3/esp32s3-lhcbit/scripts/Make.defs
@@ -47,7 +47,6 @@ ifneq ($(CONFIG_DEBUG_NOOPT),y)
   ARCHOPTIMIZATION += -fno-strength-reduce
 endif
 
-ARCHPICFLAGS = -fpic
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/xtensa/esp32s3/esp32s3-m5-cardputer/scripts/Make.defs 
b/boards/xtensa/esp32s3/esp32s3-m5-cardputer/scripts/Make.defs
index d22e3127143..701ed89afcb 100644
--- a/boards/xtensa/esp32s3/esp32s3-m5-cardputer/scripts/Make.defs
+++ b/boards/xtensa/esp32s3/esp32s3-m5-cardputer/scripts/Make.defs
@@ -47,7 +47,6 @@ ifneq ($(CONFIG_DEBUG_NOOPT),y)
   ARCHOPTIMIZATION += -fno-strength-reduce
 endif
 
-ARCHPICFLAGS = -fpic
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/xtensa/esp32s3/esp32s3-meadow/scripts/Make.defs 
b/boards/xtensa/esp32s3/esp32s3-meadow/scripts/Make.defs
index 6a4bc82715c..eef1ecaa235 100644
--- a/boards/xtensa/esp32s3/esp32s3-meadow/scripts/Make.defs
+++ b/boards/xtensa/esp32s3/esp32s3-meadow/scripts/Make.defs
@@ -47,7 +47,6 @@ ifneq ($(CONFIG_DEBUG_NOOPT),y)
   ARCHOPTIMIZATION += -fno-strength-reduce
 endif
 
-ARCHPICFLAGS = -fpic
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/xtensa/esp32s3/esp32s3-ws-lcd128/scripts/Make.defs 
b/boards/xtensa/esp32s3/esp32s3-ws-lcd128/scripts/Make.defs
index dc7d09f5ab7..2b2e7eec049 100644
--- a/boards/xtensa/esp32s3/esp32s3-ws-lcd128/scripts/Make.defs
+++ b/boards/xtensa/esp32s3/esp32s3-ws-lcd128/scripts/Make.defs
@@ -47,7 +47,6 @@ ifneq ($(CONFIG_DEBUG_NOOPT),y)
   ARCHOPTIMIZATION += -fno-strength-reduce
 endif
 
-ARCHPICFLAGS = -fpic
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/xtensa/esp32s3/esp32s3-xiao/scripts/Make.defs 
b/boards/xtensa/esp32s3/esp32s3-xiao/scripts/Make.defs
index 62ab9a5805f..5e591d98e67 100644
--- a/boards/xtensa/esp32s3/esp32s3-xiao/scripts/Make.defs
+++ b/boards/xtensa/esp32s3/esp32s3-xiao/scripts/Make.defs
@@ -47,7 +47,6 @@ ifneq ($(CONFIG_DEBUG_NOOPT),y)
   ARCHOPTIMIZATION += -fno-strength-reduce
 endif
 
-ARCHPICFLAGS = -fpic
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/boards/xtensa/esp32s3/lckfb-szpi-esp32s3/scripts/Make.defs 
b/boards/xtensa/esp32s3/lckfb-szpi-esp32s3/scripts/Make.defs
index ff7559bb644..d4a795a6f33 100644
--- a/boards/xtensa/esp32s3/lckfb-szpi-esp32s3/scripts/Make.defs
+++ b/boards/xtensa/esp32s3/lckfb-szpi-esp32s3/scripts/Make.defs
@@ -47,7 +47,6 @@ ifneq ($(CONFIG_DEBUG_NOOPT),y)
   ARCHOPTIMIZATION += -fno-strength-reduce
 endif
 
-ARCHPICFLAGS = -fpic
 
 CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) 
$(ARCHDEFINES) $(EXTRAFLAGS)
 CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
diff --git a/include/nxflat.h b/include/nxflat.h
index 9b93c7bf8f2..b87314fe0ff 100644
--- a/include/nxflat.h
+++ b/include/nxflat.h
@@ -39,6 +39,26 @@
 #define NXFLAT_MAX_STRING_SIZE 64     /* Largest size of string 
(w/zterminator) */
 #define NXFLAT_MAGIC          "NxFT"  /* NXFLAT magic number */
 
+/* Every module built by tools/nxflat/mknxflat imports this name, and the
+ * loader refuses a module that does not.
+ *
+ * The header cannot carry a version: h_magic is written by ldnxflat, which
+ * is GPL and stays out of this repository, so it can never be changed in
+ * step with the loader.  The import table can, because both ends of it are
+ * in-tree -- mknxflat emits it and nxflat_bindimports() reads it -- and
+ * ldnxflat passes it through untouched.
+ *
+ * Bump the generation when the module ABI changes.  v2 is the move of the
+ * PIC base register from r10 to r9; a v1 module's import thunks add the
+ * wrong register and would branch to a wild address on their first call
+ * into the base firmware.
+ *
+ * Must match NXFLAT_ABI_SYMBOL in tools/nxflat/nxflat_thunk.h.
+ */
+
+#define NXFLAT_ABI_SYMBOL     "__nxflat_abi_v2"
+#define NXFLAT_ABI_MARKER     __nxflat_abi_v2
+
 /****************************************************************************
  * Public Types
  ****************************************************************************/
diff --git a/tools/Unix.mk b/tools/Unix.mk
index 8424763d8d8..625772aaae8 100644
--- a/tools/Unix.mk
+++ b/tools/Unix.mk
@@ -286,6 +286,9 @@ tools/cnvwindeps$(HOSTEXEEXT):
 tools/mkpasswd$(HOSTEXEEXT):
        $(Q) $(MAKE) -C tools -f Makefile.host mkpasswd$(HOSTEXEEXT)
 
+tools/mknxflat$(HOSTEXEEXT):
+       $(Q) $(MAKE) -C tools -f Makefile.host mknxflat$(HOSTEXEEXT)
+
 # .dirlinks, and helpers
 #
 # Directories links.  Most of establishing the NuttX configuration involves
@@ -670,12 +673,20 @@ ifeq ($(CONFIG_BOARD_ETC_ROMFS_PASSWD_ENABLE),y)
 PASSWD_TOOL_DEP += tools/mkpasswd$(HOSTEXEEXT)
 endif
 
-pass1dep: context tools/mkdeps$(HOSTEXEEXT) tools/cnvwindeps$(HOSTEXEEXT) 
$(PASSWD_TOOL_DEP)
+# mknxflat generates the import thunks for an NXFLAT module, so it is only
+# needed by a configuration that builds them.
+
+NXFLAT_TOOL_DEP =
+ifeq ($(CONFIG_NXFLAT),y)
+NXFLAT_TOOL_DEP += tools/mknxflat$(HOSTEXEEXT)
+endif
+
+pass1dep: context tools/mkdeps$(HOSTEXEEXT) tools/cnvwindeps$(HOSTEXEEXT) 
$(PASSWD_TOOL_DEP) $(NXFLAT_TOOL_DEP)
        $(Q) for dir in $(USERDEPDIRS) ; do \
                $(MAKE) -C $$dir depend || exit; \
        done
 
-pass2dep: context tools/mkdeps$(HOSTEXEEXT) tools/cnvwindeps$(HOSTEXEEXT) 
$(PASSWD_TOOL_DEP)
+pass2dep: context tools/mkdeps$(HOSTEXEEXT) tools/cnvwindeps$(HOSTEXEEXT) 
$(PASSWD_TOOL_DEP) $(NXFLAT_TOOL_DEP)
        $(Q) for dir in $(KERNDEPDIRS) ; do \
                $(MAKE) -C $$dir EXTRAFLAGS="$(KDEFINE) $(EXTRAFLAGS)" depend 
|| exit; \
        done
diff --git a/tools/nxflat/dyncall_skeleton_arm.def 
b/tools/nxflat/dyncall_skeleton_arm.def
index 99a1fa1cbd8..98b4cb21fdb 100644
--- a/tools/nxflat/dyncall_skeleton_arm.def
+++ b/tools/nxflat/dyncall_skeleton_arm.def
@@ -120,7 +120,7 @@ static const char import_name_strtab_format[] =
   "\t.size\t__dynimport%04d, .-__dynimport%04d\n";
 
 /*******************************************************************
- * Dyanamic Call Information
+ * Dynamic Call Information
  *******************************************************************/
 
 static const char dynimport_decl_prologue[] =
@@ -176,7 +176,7 @@ static const char dyncall_format[] =
   "\t.type\t%s, function\n\n"
   "%s:\n"
   "\tldr\tip,.Ldyn%04d\n"
-  "\tadd\tip,ip,sl\n"
+  "\tadd\tip,ip," NXFLAT_PIC_REG "\n"
   "\tldr\tip,[ip,#4]\n"
   "\tBX(ip)\n"
   ".Ldyn%04d:\n"
@@ -189,7 +189,7 @@ static const char nonreturning_dyncall_format[] =
   "\t.type\t%s, function\n\n"
   "%s:\n"
   "\tldr\tip,.Ldyn%04d\n"
-  "\tadd\tip,ip,sl\n"
+  "\tadd\tip,ip," NXFLAT_PIC_REG "\n"
   "\tldr\tip,[ip,#4]\n"
   "\tBX(ip)\n"
   ".Ldyn%04d:\n"
@@ -204,7 +204,7 @@ static const char dyncall_format[] =
   "\t.type\t%s, function\n\n"
   "%s:\n"
   "\tldr\tip,.Ldyn%04d\n"
-  "\tadd\tip,ip,sl\n"
+  "\tadd\tip,ip," NXFLAT_PIC_REG "\n"
   "\tldr\tip,[ip,#4]\n"
   "\tBX(ip)\n"
   ".Ldyn%04d:\n"
@@ -217,7 +217,7 @@ static const char nonreturning_dyncall_format[] =
   "\t.type\t%s, function\n\n"
   "%s:\n"
   "\tldr\tip,.Ldyn%04d\n"
-  "\tadd\tip,ip,sl\n"
+  "\tadd\tip,ip," NXFLAT_PIC_REG "\n"
   "\tldr\tip,[ip,#4]\n"
   "\tBX(ip)\n"
   ".Ldyn%04d:\n"
diff --git a/tools/nxflat/dyncall_skeleton_thumb2.def 
b/tools/nxflat/dyncall_skeleton_thumb2.def
index 1c7b8402a32..5aa511739f2 100644
--- a/tools/nxflat/dyncall_skeleton_thumb2.def
+++ b/tools/nxflat/dyncall_skeleton_thumb2.def
@@ -87,7 +87,7 @@ static const char import_name_strtab_format[] =
   "\t.size\t__dynimport%04d, .-__dynimport%04d\n";
 
 /*******************************************************************
- * Dyanamic Call Information
+ * Dynamic Call Information
  *******************************************************************/
 
 static const char dynimport_decl_prologue[] =
@@ -144,7 +144,7 @@ static const char dyncall_format[] =
   "\t.thumb_func\n\n"
   "%s:\n"
   "\tldr\tip,.Ldyn%04d\n"
-  "\tadd\tip,ip,sl\n"
+  "\tadd\tip,ip," NXFLAT_PIC_REG "\n"
   "\tldr\tip,[ip,#4]\n"
   "\tbx\tip\n"
   ".Ldyn%04d:\n"
@@ -158,7 +158,7 @@ static const char nonreturning_dyncall_format[] =
   "\t.thumb_func\n\n"
   "%s:\n"
   "\tldr\tip,.Ldyn%04d\n"
-  "\tadd\tip,ip,sl\n"
+  "\tadd\tip,ip," NXFLAT_PIC_REG "\n"
   "\tldr\tip,[ip,#4]\n"
   "\tbx\tip\n"
   ".Ldyn%04d:\n"
@@ -174,7 +174,7 @@ static const char dyncall_format[] =
   "\t.thumb_func\n\n"
   "%s:\n"
   "\tldr\tip,.Ldyn%04d\n"
-  "\tadd\tip,ip,sl\n"
+  "\tadd\tip,ip," NXFLAT_PIC_REG "\n"
   "\tldr\tip,[ip,#4]\n"
   "\tbx\tip\n"
   ".Ldyn%04d:\n"
@@ -188,7 +188,7 @@ static const char nonreturning_dyncall_format[] =
   "\t.thumb_func\n\n"
   "%s:\n"
   "\tldr\tip,.Ldyn%04d\n"
-  "\tadd\tip,ip,sl\n"
+  "\tadd\tip,ip," NXFLAT_PIC_REG "\n"
   "\tldr\tip,[ip,#4]\n"
   "\tbx\tip\n"
   ".Ldyn%04d:\n"
diff --git a/tools/nxflat/mknxflat.c b/tools/nxflat/mknxflat.c
index b9df09d4bb8..467e2daa290 100644
--- a/tools/nxflat/mknxflat.c
+++ b/tools/nxflat/mknxflat.c
@@ -138,7 +138,7 @@ struct elf32_sym_s
 
 struct import_s
 {
-  char *name;
+  const char *name;
   int   is_object;
   int   is_weak;
 };
@@ -299,6 +299,9 @@ static void load_imports(void)
   size_t nsyms;
   size_t strsize;
   size_t i;
+  uint16_t probe;
+  int host_le;
+  int obj_le;
   int fd;
 
   fd = open(elf_filename, O_RDONLY);
@@ -325,13 +328,11 @@ static void load_imports(void)
 
   /* Decide whether the host and the object disagree about byte order */
 
-  {
-    const uint16_t probe = 1;
-    int host_le = *(const unsigned char *)&probe;
-    int obj_le  = (ehdr.e_ident[5] == ELFDATA2LSB);
+  probe   = 1;
+  host_le = *(const unsigned char *)&probe;
+  obj_le  = (ehdr.e_ident[5] == ELFDATA2LSB);
 
-    need_swap = (host_le != obj_le);
-  }
+  need_swap = (host_le != obj_le);
 
   /* Re-read the fields that mattered now that byte order is known */
 
@@ -415,13 +416,24 @@ static void load_imports(void)
 
   close(fd);
 
-  imports = calloc(nsyms, sizeof(struct import_s));
+  imports = calloc(nsyms + 1, sizeof(struct import_s));
   if (imports == NULL)
     {
       fprintf(stderr, "Failed to allocate import table\n");
       exit(3);
     }
 
+  /* The ABI marker goes first, so that every module has at least one
+   * import and the loader can tell what it was built for.  It is a marker
+   * rather than a real import: nothing calls it and no board exports it --
+   * the loader matches it by name and skips resolution.
+   */
+
+  imports[0].name      = NXFLAT_ABI_SYMBOL;
+  imports[0].is_object = 0;
+  imports[0].is_weak   = 0;
+  number_undefined     = 1;
+
   for (i = 0; i < nsyms; i++)
     {
       uint32_t st_name  = swap32(syms[i].st_name);
@@ -614,8 +626,8 @@ static void show_usage(void)
 {
   fprintf(stderr, "Usage: %s [options] <elf-filename>\n\n", program_name);
   fprintf(stderr, "Where options are one or more of the following.  Note\n");
-  fprintf(stderr, "that a space is always required between the option and\n");
-  fprintf(stderr, "any following arguments.\n\n");
+  fprintf(stderr, "that a space is always required between the\n");
+  fprintf(stderr, "option and any following arguments.\n\n");
   fprintf(stderr, "  -a <arch>\n");
   fprintf(stderr, "     Instruction set of the module: arm or thumb2\n");
   fprintf(stderr, "     [thumb2]\n");
@@ -624,8 +636,8 @@ static void show_usage(void)
   fprintf(stderr, "     Output to <out-filename> [stdout]\n");
   fprintf(stderr, "  -v Verbose output [no output]\n");
   fprintf(stderr, "  -w Import weakly declared functions, i.e., weakly\n");
-  fprintf(stderr, "     declared functions are expected to be provided at\n");
-  fprintf(stderr, "     load-time [not imported]\n");
+  fprintf(stderr, "     declared functions are expected to be\n");
+  fprintf(stderr, "     provided at load-time [not imported]\n");
   fprintf(stderr, "\n");
   exit(1);
 }
diff --git a/tools/nxflat/nxflat_thunk.h b/tools/nxflat/nxflat_thunk.h
index dd52b2197dd..b466279ca5b 100644
--- a/tools/nxflat/nxflat_thunk.h
+++ b/tools/nxflat/nxflat_thunk.h
@@ -23,6 +23,33 @@
 #ifndef __TOOLS_NXFLAT_NXFLAT_THUNK_H
 #define __TOOLS_NXFLAT_NXFLAT_THUNK_H
 
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* The register a module reaches its own data through, named here once so
+ * the thunk stubs and arch/arm cannot drift apart.  It must agree with
+ * PIC_REG in arch/arm/include/arch.h and with -mpic-register in
+ * arch/arm/src/common/Toolchain.defs: a module whose data accesses use one
+ * register and whose import thunks add another will load, and then branch
+ * to a wild address on its first call out.
+ */
+
+#define NXFLAT_PIC_REG "r9"
+
+/* Every module declares the module ABI it was built for by importing this
+ * name, and the loader refuses a module that does not.  That is the only
+ * version channel available: the NXFLAT header has no version field, and
+ * h_magic is written by ldnxflat, which is GPL and stays out of the
+ * repository, so it can never be changed in step with the loader.  The
+ * import table can, because mknxflat emits it and nxflat_bindimports()
+ * reads it, and ldnxflat passes it through untouched.
+ *
+ * Must match NXFLAT_ABI_SYMBOL in include/nxflat.h.
+ */
+
+#define NXFLAT_ABI_SYMBOL "__nxflat_abi_v2"
+
 /****************************************************************************
  * Public Types
  ****************************************************************************/
diff --git a/tools/nxflat/thunk_arm.c b/tools/nxflat/thunk_arm.c
index a7002887272..2957ed0cf85 100644
--- a/tools/nxflat/thunk_arm.c
+++ b/tools/nxflat/thunk_arm.c
@@ -26,13 +26,21 @@
 
 #include "nxflat_thunk.h"
 
-/* The format strings are file-scope statics inside the .def, so each
+/* The format strings have file scope 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.
+ * collide.  The .def is the upstream file, less one comment typo.
  */
 
 #include "dyncall_skeleton_arm.def"
 
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/* None: this translation unit exists only to give one architecture's
+ * format strings a scope of their own.
+ */
+
 /****************************************************************************
  * Public Data
  ****************************************************************************/
diff --git a/tools/nxflat/thunk_thumb2.c b/tools/nxflat/thunk_thumb2.c
index 5a2325d7de8..c4b1f25e927 100644
--- a/tools/nxflat/thunk_thumb2.c
+++ b/tools/nxflat/thunk_thumb2.c
@@ -26,13 +26,21 @@
 
 #include "nxflat_thunk.h"
 
-/* The format strings are file-scope statics inside the .def, so each
+/* The format strings have file scope 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.
+ * collide.  The .def is the upstream file, less one comment typo.
  */
 
 #include "dyncall_skeleton_thumb2.def"
 
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/* None: this translation unit exists only to give one architecture's
+ * format strings a scope of their own.
+ */
+
 /****************************************************************************
  * Public Data
  ****************************************************************************/

Reply via email to