examples/fdpicxip: Demonstrate FDPIC modules executed in place.
The FDPIC counterpart of examples/nxflatxip, kept separate from it: that
example is about NXFLAT, and mixing the two module formats into one program
would leave neither demonstrating anything clearly.
Four subcommands, each showing one property of the loader. 'qsort' is the
simplest case it has -- one self-contained module, two concurrent instances,
one shared copy of the text in flash and a private copy of the data each,
with the pin count showing the extent held in place while they run and
released after. 'solib' adds a shared library, so two objects are mapped
and each instance still gets its own copy of both objects' data. 'cxx' is
the same in C++, which additionally requires global constructors to have run
in dependency order before main. 'jmprel' is a module whose imports are all
in DT_JMPREL rather than DT_REL.
The modules are embedded as headers rather than built as part of the app:
linking one needs arm-uclinuxfdpiceabi binutils, which the tree does not
require, so the headers are committed and both this example and
testing/fs/xipfs build with a plain toolchain.
Their sources are in modules/, with a makefile that rebuilds every header
from them on an explicit 'make regen NUTTX_DIR=...' and is never invoked by
the application build. It drives nuttx/tools/fdpic and writes the headers
this example needs alongside the ones testing/fs/xipfs needs, so one source
tree serves both and the two cannot drift apart. CPU is cortex-m3 there
deliberately: a v7-M module runs on the v8-M targets too, so one set of blobs
serves both the RP2350 and mps2-an500, while a cortex-m33 build produces
blobs the Cortex-M7 cannot execute at all.
This demonstrates; it does not assert. The assertions are in the fdpic and
reject sections of apps/testing/fs/xipfs.
Verified on a Pimoroni Pico Plus 2: all four subcommands, and nxflatxip
unaffected alongside them. Also verified on mps2-an500 under QEMU, which is
a Cortex-M7 -- a different core generation from the RP2350's Cortex-M33.
Assisted-by: Claude Code:claude-opus-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-07-30 13:40:04 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
* apps/examples/fdpicxip/modules/cxxuser.cpp
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*
|
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
|
* License. You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
|
* under the License.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/* A C++ module using a C++ shared library.
|
|
|
|
|
*
|
|
|
|
|
* Two instances of this run at once in the demo. Between them they show
|
|
|
|
|
* the three things that have to hold:
|
|
|
|
|
*
|
|
|
|
|
* - constructors ran, in both objects. Neither magic can be right by
|
|
|
|
|
* accident: an unconstructed global is zero.
|
|
|
|
|
* - the library's constructors ran before this module's, which is the
|
examples/fdpicxip, testing/fs/xipfs: A DT_NEEDED library is one instance.
Both the demo and the test asserted that each running instance of a module
gets its own copy of a library named in DT_NEEDED: two instances adding
their own seed each saw a total of seed*3.
That was true of the loader that walked DT_NEEDED itself. The loader now
hands the work to dlopen(), which returns the object already in the module
registry rather than loading a second copy of it, so there is one library
and one set of its globals, shared by every module that names it. The
module's own data stays private per instance, because exec() loads the
module afresh each time.
What an instance can still assert on its own is that every add it made
landed in the library, so that is what it checks; the totals interleave and
the final one counts both. The test additionally checks the consequences:
the library is pinned once rather than once per instance, and its
destructor runs once, at the last close, holding what both instances built
up.
USER_FAIL_PRIVATE becomes USER_FAIL_SHARED rather than gaining a
companion. The bit is a private protocol between cxxuser.cpp, which sets
it, and testing/fs/xipfs, which reads it; nothing else names it, and the
property it used to report no longer exists.
Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-08-04 09:42:33 +02:00
|
|
|
* ordering DT_NEEDED implies and the loader has to honour. They ran
|
|
|
|
|
* once, for the one library, not once per instance.
|
|
|
|
|
* - the library is one object shared by both instances. DT_NEEDED is
|
|
|
|
|
* loaded with dlopen(), which returns what is already in the module
|
|
|
|
|
* registry, so the totals interleave rather than each reaching seed*3.
|
|
|
|
|
* Each instance can still see every add it made.
|
examples/fdpicxip: Demonstrate FDPIC modules executed in place.
The FDPIC counterpart of examples/nxflatxip, kept separate from it: that
example is about NXFLAT, and mixing the two module formats into one program
would leave neither demonstrating anything clearly.
Four subcommands, each showing one property of the loader. 'qsort' is the
simplest case it has -- one self-contained module, two concurrent instances,
one shared copy of the text in flash and a private copy of the data each,
with the pin count showing the extent held in place while they run and
released after. 'solib' adds a shared library, so two objects are mapped
and each instance still gets its own copy of both objects' data. 'cxx' is
the same in C++, which additionally requires global constructors to have run
in dependency order before main. 'jmprel' is a module whose imports are all
in DT_JMPREL rather than DT_REL.
The modules are embedded as headers rather than built as part of the app:
linking one needs arm-uclinuxfdpiceabi binutils, which the tree does not
require, so the headers are committed and both this example and
testing/fs/xipfs build with a plain toolchain.
Their sources are in modules/, with a makefile that rebuilds every header
from them on an explicit 'make regen NUTTX_DIR=...' and is never invoked by
the application build. It drives nuttx/tools/fdpic and writes the headers
this example needs alongside the ones testing/fs/xipfs needs, so one source
tree serves both and the two cannot drift apart. CPU is cortex-m3 there
deliberately: a v7-M module runs on the v8-M targets too, so one set of blobs
serves both the RP2350 and mps2-an500, while a cortex-m33 build produces
blobs the Cortex-M7 cannot execute at all.
This demonstrates; it does not assert. The assertions are in the fdpic and
reject sections of apps/testing/fs/xipfs.
Verified on a Pimoroni Pico Plus 2: all four subcommands, and nxflatxip
unaffected alongside them. Also verified on mps2-an500 under QEMU, which is
a Cortex-M7 -- a different core generation from the RP2350's Cortex-M33.
Assisted-by: Claude Code:claude-opus-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-07-30 13:40:04 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <syslog.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
|
{
|
|
|
|
|
int shape_add(int by);
|
|
|
|
|
int shape_total(void);
|
|
|
|
|
bool shape_constructed(void);
|
|
|
|
|
void shape_marker(const char *path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define USER_MAGIC 0x0c1a55
|
|
|
|
|
|
|
|
|
|
class Instance
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Instance() : m_magic(USER_MAGIC), m_libwasready(shape_constructed())
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool constructed() const
|
|
|
|
|
{
|
|
|
|
|
return m_magic == USER_MAGIC;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Whether the library was already constructed when this object's own
|
|
|
|
|
* constructor ran. Sampling it here is the only way to observe the
|
|
|
|
|
* ordering: by the time main() runs, both have been constructed either
|
|
|
|
|
* way.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
bool libwasready() const
|
|
|
|
|
{
|
|
|
|
|
return m_libwasready;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
int m_magic;
|
|
|
|
|
bool m_libwasready;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static Instance g_self;
|
|
|
|
|
|
|
|
|
|
/* Exit status is a bitmask of what failed, so one run reports on all four
|
|
|
|
|
* properties independently. Kept in step with the reader in
|
|
|
|
|
* apps/testing/fs/xipfs/.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#define USER_FAIL_OWN_CTOR 0x01
|
|
|
|
|
#define USER_FAIL_LIB_CTOR 0x02
|
|
|
|
|
#define USER_FAIL_ORDER 0x04
|
examples/fdpicxip, testing/fs/xipfs: A DT_NEEDED library is one instance.
Both the demo and the test asserted that each running instance of a module
gets its own copy of a library named in DT_NEEDED: two instances adding
their own seed each saw a total of seed*3.
That was true of the loader that walked DT_NEEDED itself. The loader now
hands the work to dlopen(), which returns the object already in the module
registry rather than loading a second copy of it, so there is one library
and one set of its globals, shared by every module that names it. The
module's own data stays private per instance, because exec() loads the
module afresh each time.
What an instance can still assert on its own is that every add it made
landed in the library, so that is what it checks; the totals interleave and
the final one counts both. The test additionally checks the consequences:
the library is pinned once rather than once per instance, and its
destructor runs once, at the last close, holding what both instances built
up.
USER_FAIL_PRIVATE becomes USER_FAIL_SHARED rather than gaining a
companion. The bit is a private protocol between cxxuser.cpp, which sets
it, and testing/fs/xipfs, which reads it; nothing else names it, and the
property it used to report no longer exists.
Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-08-04 09:42:33 +02:00
|
|
|
#define USER_FAIL_SHARED 0x08
|
examples/fdpicxip: Demonstrate FDPIC modules executed in place.
The FDPIC counterpart of examples/nxflatxip, kept separate from it: that
example is about NXFLAT, and mixing the two module formats into one program
would leave neither demonstrating anything clearly.
Four subcommands, each showing one property of the loader. 'qsort' is the
simplest case it has -- one self-contained module, two concurrent instances,
one shared copy of the text in flash and a private copy of the data each,
with the pin count showing the extent held in place while they run and
released after. 'solib' adds a shared library, so two objects are mapped
and each instance still gets its own copy of both objects' data. 'cxx' is
the same in C++, which additionally requires global constructors to have run
in dependency order before main. 'jmprel' is a module whose imports are all
in DT_JMPREL rather than DT_REL.
The modules are embedded as headers rather than built as part of the app:
linking one needs arm-uclinuxfdpiceabi binutils, which the tree does not
require, so the headers are committed and both this example and
testing/fs/xipfs build with a plain toolchain.
Their sources are in modules/, with a makefile that rebuilds every header
from them on an explicit 'make regen NUTTX_DIR=...' and is never invoked by
the application build. It drives nuttx/tools/fdpic and writes the headers
this example needs alongside the ones testing/fs/xipfs needs, so one source
tree serves both and the two cannot drift apart. CPU is cortex-m3 there
deliberately: a v7-M module runs on the v8-M targets too, so one set of blobs
serves both the RP2350 and mps2-an500, while a cortex-m33 build produces
blobs the Cortex-M7 cannot execute at all.
This demonstrates; it does not assert. The assertions are in the fdpic and
reject sections of apps/testing/fs/xipfs.
Verified on a Pimoroni Pico Plus 2: all four subcommands, and nxflatxip
unaffected alongside them. Also verified on mps2-an500 under QEMU, which is
a Cortex-M7 -- a different core generation from the RP2350's Cortex-M33.
Assisted-by: Claude Code:claude-opus-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-07-30 13:40:04 +02:00
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: record
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* Write a number to a file, for a caller that cannot rely on this task's
|
|
|
|
|
* exit status.
|
|
|
|
|
*
|
|
|
|
|
* It cannot, in general. waitpid() only retains the status of a child
|
|
|
|
|
* that has already exited when CONFIG_SCHED_CHILD_STATUS is set, and that
|
|
|
|
|
* depends on CONFIG_SCHED_HAVE_PARENT. With two instances running for
|
|
|
|
|
* the same length of time, the second has always exited by the time the
|
|
|
|
|
* first waitpid() returns, so its status is simply gone. A file survives
|
|
|
|
|
* the task, and survives the module being unloaded.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void record(const char *path, int value)
|
|
|
|
|
{
|
|
|
|
|
char text[16];
|
|
|
|
|
int len;
|
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
|
|
if (path == NULL)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
len = snprintf(text, sizeof(text), "%d", value);
|
|
|
|
|
|
|
|
|
|
fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
|
|
|
|
if (fd < 0)
|
|
|
|
|
{
|
|
|
|
|
syslog(LOG_INFO, "[user] cannot record to %s\n", path);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* xipfs wants the size declared up front so it can reserve one
|
|
|
|
|
* contiguous extent.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (ftruncate(fd, len) >= 0)
|
|
|
|
|
{
|
|
|
|
|
write(fd, text, len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extern "C" int main(int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
int seed = (argc > 1) ? atoi(argv[1]) : 1;
|
|
|
|
|
int fails = 0;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
/* Optional second argument: a path for the library's destructor to record
|
|
|
|
|
* its final total in. A destructor runs at unload, after this task is
|
|
|
|
|
* gone, so leaving a file behind is the only way a test can observe that
|
|
|
|
|
* it ran at all. The demo omits it and reads the log instead.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (argc > 2)
|
|
|
|
|
{
|
|
|
|
|
shape_marker(argv[2]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
syslog(LOG_INFO, "[user %d] own ctor ran: %s, library ctor ran: %s, "
|
|
|
|
|
"library first: %s\n",
|
|
|
|
|
seed,
|
|
|
|
|
g_self.constructed() ? "yes" : "NO",
|
|
|
|
|
shape_constructed() ? "yes" : "NO",
|
|
|
|
|
g_self.libwasready() ? "yes" : "NO");
|
|
|
|
|
|
|
|
|
|
/* Every check runs and contributes a bit, rather than the first failure
|
|
|
|
|
* returning early. A caller that reports these individually can then say
|
|
|
|
|
* which property broke instead of just that something did -- and none of
|
|
|
|
|
* its assertions pass merely because an earlier one stopped the run.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (!g_self.constructed())
|
|
|
|
|
{
|
|
|
|
|
fails |= USER_FAIL_OWN_CTOR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!shape_constructed())
|
|
|
|
|
{
|
|
|
|
|
fails |= USER_FAIL_LIB_CTOR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!g_self.libwasready())
|
|
|
|
|
{
|
|
|
|
|
fails |= USER_FAIL_ORDER;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
|
{
|
|
|
|
|
shape_add(seed);
|
|
|
|
|
usleep(100000);
|
|
|
|
|
}
|
|
|
|
|
|
examples/fdpicxip, testing/fs/xipfs: A DT_NEEDED library is one instance.
Both the demo and the test asserted that each running instance of a module
gets its own copy of a library named in DT_NEEDED: two instances adding
their own seed each saw a total of seed*3.
That was true of the loader that walked DT_NEEDED itself. The loader now
hands the work to dlopen(), which returns the object already in the module
registry rather than loading a second copy of it, so there is one library
and one set of its globals, shared by every module that names it. The
module's own data stays private per instance, because exec() loads the
module afresh each time.
What an instance can still assert on its own is that every add it made
landed in the library, so that is what it checks; the totals interleave and
the final one counts both. The test additionally checks the consequences:
the library is pinned once rather than once per instance, and its
destructor runs once, at the last close, holding what both instances built
up.
USER_FAIL_PRIVATE becomes USER_FAIL_SHARED rather than gaining a
companion. The bit is a private protocol between cxxuser.cpp, which sets
it, and testing/fs/xipfs, which reads it; nothing else names it, and the
property it used to report no longer exists.
Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-08-04 09:42:33 +02:00
|
|
|
/* The other instance is adding to the same library at the same time, so
|
|
|
|
|
* the total is not this instance's alone. What must hold is that every
|
|
|
|
|
* add this instance made landed in it.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (shape_total() < seed * 3)
|
examples/fdpicxip: Demonstrate FDPIC modules executed in place.
The FDPIC counterpart of examples/nxflatxip, kept separate from it: that
example is about NXFLAT, and mixing the two module formats into one program
would leave neither demonstrating anything clearly.
Four subcommands, each showing one property of the loader. 'qsort' is the
simplest case it has -- one self-contained module, two concurrent instances,
one shared copy of the text in flash and a private copy of the data each,
with the pin count showing the extent held in place while they run and
released after. 'solib' adds a shared library, so two objects are mapped
and each instance still gets its own copy of both objects' data. 'cxx' is
the same in C++, which additionally requires global constructors to have run
in dependency order before main. 'jmprel' is a module whose imports are all
in DT_JMPREL rather than DT_REL.
The modules are embedded as headers rather than built as part of the app:
linking one needs arm-uclinuxfdpiceabi binutils, which the tree does not
require, so the headers are committed and both this example and
testing/fs/xipfs build with a plain toolchain.
Their sources are in modules/, with a makefile that rebuilds every header
from them on an explicit 'make regen NUTTX_DIR=...' and is never invoked by
the application build. It drives nuttx/tools/fdpic and writes the headers
this example needs alongside the ones testing/fs/xipfs needs, so one source
tree serves both and the two cannot drift apart. CPU is cortex-m3 there
deliberately: a v7-M module runs on the v8-M targets too, so one set of blobs
serves both the RP2350 and mps2-an500, while a cortex-m33 build produces
blobs the Cortex-M7 cannot execute at all.
This demonstrates; it does not assert. The assertions are in the fdpic and
reject sections of apps/testing/fs/xipfs.
Verified on a Pimoroni Pico Plus 2: all four subcommands, and nxflatxip
unaffected alongside them. Also verified on mps2-an500 under QEMU, which is
a Cortex-M7 -- a different core generation from the RP2350's Cortex-M33.
Assisted-by: Claude Code:claude-opus-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-07-30 13:40:04 +02:00
|
|
|
{
|
examples/fdpicxip, testing/fs/xipfs: A DT_NEEDED library is one instance.
Both the demo and the test asserted that each running instance of a module
gets its own copy of a library named in DT_NEEDED: two instances adding
their own seed each saw a total of seed*3.
That was true of the loader that walked DT_NEEDED itself. The loader now
hands the work to dlopen(), which returns the object already in the module
registry rather than loading a second copy of it, so there is one library
and one set of its globals, shared by every module that names it. The
module's own data stays private per instance, because exec() loads the
module afresh each time.
What an instance can still assert on its own is that every add it made
landed in the library, so that is what it checks; the totals interleave and
the final one counts both. The test additionally checks the consequences:
the library is pinned once rather than once per instance, and its
destructor runs once, at the last close, holding what both instances built
up.
USER_FAIL_PRIVATE becomes USER_FAIL_SHARED rather than gaining a
companion. The bit is a private protocol between cxxuser.cpp, which sets
it, and testing/fs/xipfs, which reads it; nothing else names it, and the
property it used to report no longer exists.
Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-08-04 09:42:33 +02:00
|
|
|
fails |= USER_FAIL_SHARED;
|
examples/fdpicxip: Demonstrate FDPIC modules executed in place.
The FDPIC counterpart of examples/nxflatxip, kept separate from it: that
example is about NXFLAT, and mixing the two module formats into one program
would leave neither demonstrating anything clearly.
Four subcommands, each showing one property of the loader. 'qsort' is the
simplest case it has -- one self-contained module, two concurrent instances,
one shared copy of the text in flash and a private copy of the data each,
with the pin count showing the extent held in place while they run and
released after. 'solib' adds a shared library, so two objects are mapped
and each instance still gets its own copy of both objects' data. 'cxx' is
the same in C++, which additionally requires global constructors to have run
in dependency order before main. 'jmprel' is a module whose imports are all
in DT_JMPREL rather than DT_REL.
The modules are embedded as headers rather than built as part of the app:
linking one needs arm-uclinuxfdpiceabi binutils, which the tree does not
require, so the headers are committed and both this example and
testing/fs/xipfs build with a plain toolchain.
Their sources are in modules/, with a makefile that rebuilds every header
from them on an explicit 'make regen NUTTX_DIR=...' and is never invoked by
the application build. It drives nuttx/tools/fdpic and writes the headers
this example needs alongside the ones testing/fs/xipfs needs, so one source
tree serves both and the two cannot drift apart. CPU is cortex-m3 there
deliberately: a v7-M module runs on the v8-M targets too, so one set of blobs
serves both the RP2350 and mps2-an500, while a cortex-m33 build produces
blobs the Cortex-M7 cannot execute at all.
This demonstrates; it does not assert. The assertions are in the fdpic and
reject sections of apps/testing/fs/xipfs.
Verified on a Pimoroni Pico Plus 2: all four subcommands, and nxflatxip
unaffected alongside them. Also verified on mps2-an500 under QEMU, which is
a Cortex-M7 -- a different core generation from the RP2350's Cortex-M33.
Assisted-by: Claude Code:claude-opus-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-07-30 13:40:04 +02:00
|
|
|
}
|
|
|
|
|
|
examples/fdpicxip, testing/fs/xipfs: A DT_NEEDED library is one instance.
Both the demo and the test asserted that each running instance of a module
gets its own copy of a library named in DT_NEEDED: two instances adding
their own seed each saw a total of seed*3.
That was true of the loader that walked DT_NEEDED itself. The loader now
hands the work to dlopen(), which returns the object already in the module
registry rather than loading a second copy of it, so there is one library
and one set of its globals, shared by every module that names it. The
module's own data stays private per instance, because exec() loads the
module afresh each time.
What an instance can still assert on its own is that every add it made
landed in the library, so that is what it checks; the totals interleave and
the final one counts both. The test additionally checks the consequences:
the library is pinned once rather than once per instance, and its
destructor runs once, at the last close, holding what both instances built
up.
USER_FAIL_PRIVATE becomes USER_FAIL_SHARED rather than gaining a
companion. The bit is a private protocol between cxxuser.cpp, which sets
it, and testing/fs/xipfs, which reads it; nothing else names it, and the
property it used to report no longer exists.
Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-08-04 09:42:33 +02:00
|
|
|
syslog(LOG_INFO, "[user %d] library total = %d (at least %d) -- %s\n",
|
examples/fdpicxip: Demonstrate FDPIC modules executed in place.
The FDPIC counterpart of examples/nxflatxip, kept separate from it: that
example is about NXFLAT, and mixing the two module formats into one program
would leave neither demonstrating anything clearly.
Four subcommands, each showing one property of the loader. 'qsort' is the
simplest case it has -- one self-contained module, two concurrent instances,
one shared copy of the text in flash and a private copy of the data each,
with the pin count showing the extent held in place while they run and
released after. 'solib' adds a shared library, so two objects are mapped
and each instance still gets its own copy of both objects' data. 'cxx' is
the same in C++, which additionally requires global constructors to have run
in dependency order before main. 'jmprel' is a module whose imports are all
in DT_JMPREL rather than DT_REL.
The modules are embedded as headers rather than built as part of the app:
linking one needs arm-uclinuxfdpiceabi binutils, which the tree does not
require, so the headers are committed and both this example and
testing/fs/xipfs build with a plain toolchain.
Their sources are in modules/, with a makefile that rebuilds every header
from them on an explicit 'make regen NUTTX_DIR=...' and is never invoked by
the application build. It drives nuttx/tools/fdpic and writes the headers
this example needs alongside the ones testing/fs/xipfs needs, so one source
tree serves both and the two cannot drift apart. CPU is cortex-m3 there
deliberately: a v7-M module runs on the v8-M targets too, so one set of blobs
serves both the RP2350 and mps2-an500, while a cortex-m33 build produces
blobs the Cortex-M7 cannot execute at all.
This demonstrates; it does not assert. The assertions are in the fdpic and
reject sections of apps/testing/fs/xipfs.
Verified on a Pimoroni Pico Plus 2: all four subcommands, and nxflatxip
unaffected alongside them. Also verified on mps2-an500 under QEMU, which is
a Cortex-M7 -- a different core generation from the RP2350's Cortex-M33.
Assisted-by: Claude Code:claude-opus-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-07-30 13:40:04 +02:00
|
|
|
seed, shape_total(), seed * 3,
|
|
|
|
|
fails == 0 ? "PASS" : "FAIL");
|
|
|
|
|
|
|
|
|
|
/* Optional third argument: where to record the bitmask, for a caller that
|
|
|
|
|
* cannot rely on the exit status surviving. See record() above.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (argc > 3)
|
|
|
|
|
{
|
|
|
|
|
record(argv[3], fails);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fails;
|
|
|
|
|
}
|