Question about std::string
Closed this issue · 1 comments
This probably shows the depth of my ignorance about the compiler system, and happy to move it to a discussion group instead if that's more appropriate.
I was starting work on an example of how we might do dynamic configuration of compartments, and hit what I'm sure is noob issue with std:;string
If I change the examples/01.hello_world/hello.cc to try an use std::string
// Copyright Microsoft and CHERIoT Contributors.
// SPDX-License-Identifier: MIT
#include <compartment.h>
#include <debug.hh>
#include <fail-simulator-on-error.h>
#include <string>
/// Expose debugging features unconditionally for this compartment.
using Debug = ConditionalDebug<true, "Hello world compartment">;
/// Thread entry point.
void __cheri_compartment("hello") say_hello()
{
// Print hello world, along with the compartment's name to the default UART.
std::string msg = "Hello world";
Debug::log("{}", msg);
}
xmake gives:
error: /workspaces/cheriot-rtos/sdk/include/debug.hh:388:4: error: implicit instantiation of undefined template 'DebugFormatArgumentAdaptor<std::string>'
DebugFormatArgumentAdaptor<
...
If I remove the call to Debug so I just have the definition
std::string msg = "Hello world";
xmake fails with:
error: ld.lld: error: undefined symbol: strlen
>>> referenced by hello.cc:14
>>> build/cheriot/cheriot/release/hello.compartment:()
compile_commands.json includes the following - that I assume should be picking up strlen ?
{
"directory": "/workspaces/cheriot-rtos/examples/01.hello_world",
"arguments": ["/cheriot-tools/bin/clang", "-c", "-std=c2x", "-Qunused-arguments", "-target", "riscv32-unknown-unknown", "-mcpu=cheriot", "-mabi=cheriot", "-mxcheri-rvc", "-mrelax", "-fshort-wchar", "-nostdinc", "-Oz", "-g", "-ffunction-sections", "-fdata-sections", "-fomit-frame-pointer", "-fno-builtin", "-fno-exceptions", "-fno-asynchronous-unwind-tables", "-fno-c++-static-destructors", "-fno-rtti", "-Werror", "-I/workspaces/cheriot-rtos/sdk/include/c++-config", "-I/workspaces/cheriot-rtos/sdk/include/libc++", "-I/workspaces/cheriot-rtos/sdk/include", "-fvisibility=hidden", "-DNDEBUG", "-o", "build/.objs/string/cheriot/cheriot/release/__/__/sdk/lib/string/strlen.c.o", "../../sdk/lib/string/strlen.c"],
"file": "../../sdk/lib/string/strlen.c"
},
Feels like I'm missing something obvious about using std::string ?
Hi, the strlen function is provided by the string library.
We pay almost no penalty from splitting things into different libraries and so we’ve split the traditional libc up quite a lot, so you can build small, firmware images with only the subset that you need.
We should add an overload for the debug adaptor (patches welcome!) that forwards to the std::string_view
specialisation.
Putting add_deps(“string”)
in the firmware bit of the xmake.lua file should make the string bit work.