Difference between revisions of "C++ support"
(Created page with "= Introduction = Despite the fact that ERIKA is implemented using the C and the Assembly programming languages, it has <u>experimental</u> support to link applications implem...") |
|||
(9 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
Despite the fact that ERIKA is implemented using the C and the Assembly programming languages, | Despite the fact that ERIKA is implemented using the C and the Assembly programming languages, | ||
− | it has <u>experimental</u> support | + | it has <u>experimental</u> support for linking applications implemented using the C++ language. |
= Basic support = | = Basic support = | ||
Line 24: | Line 24: | ||
shown [https://github.com/evidence/linux-jailhouse-jetson/commit/d191fdb65584ce98183281d9e05c593a6ae9b235 here]. | shown [https://github.com/evidence/linux-jailhouse-jetson/commit/d191fdb65584ce98183281d9e05c593a6ae9b235 here]. | ||
− | This is the basic list of the features | + | This is the basic list of the supported features: |
<ul> | <ul> | ||
<li> Normal classes | <li> Normal classes | ||
Line 33: | Line 33: | ||
= STL support = | = STL support = | ||
− | + | In addition to the steps described in the previous section, if you also want to support the STL features provided by the bare-metal [https://sourceware.org/newlib/ newlib] | |
− | toolchain ( | + | toolchain (e.g., the one provided by [https://www.linaro.org/latest/downloads/ Linaro's bare-metal gcc toolchain for ARM]), you |
have to modify the linker script to set the <code>end</code> symbol: | have to modify the linker script to set the <code>end</code> symbol: | ||
Line 40: | Line 40: | ||
*(.data) | *(.data) | ||
} | } | ||
− | + | ||
. = ALIGN(8); | . = ALIGN(8); | ||
/* "end" is used by newlib's syscalls */ | /* "end" is used by newlib's syscalls */ | ||
PROVIDE(end = .); | PROVIDE(end = .); | ||
− | + | ||
. = ALIGN(16); | . = ALIGN(16); | ||
stack_bottom = .; | stack_bottom = .; | ||
. = ALIGN(4096); | . = ALIGN(4096); | ||
− | . = . + 0x10000; | + | . = . + 0x10000; /* <-- grow this value as much as you can, depending on free RAM availability */ |
stack_top = .; | stack_top = .; | ||
− | + | '''Note''': with this approach, stack and heap basically share the same memory area. This means that if the stack or the heap grows "too much" it can overwrite the other one. | |
+ | It is therefore important to move the stack top (i.e. <code>0x10000</code> in the example) as much as possible. | ||
+ | |||
− | CFLAGS = "-I/path/to/aarch64-elf/aarch64-elf/include/c++/ | + | Then, add the paths and names of the C++ libraries into the OIL file. |
− | CFLAGS = "-I/path/to/aarch64-elf/aarch64-elf/include/c++/ | + | For example, in case of the Linaro ARM toolchain: |
+ | |||
+ | CFLAGS = "-I/path/to/aarch64-elf/aarch64-elf/include/c++/version/"; | ||
+ | CFLAGS = "-I/path/to/aarch64-elf/aarch64-elf/include/c++/version/aarch64-elf/"; | ||
CFLAGS = "-I/path/to/aarch64-elf/aarch64-elf/libc/usr/include/"; | CFLAGS = "-I/path/to/aarch64-elf/aarch64-elf/libc/usr/include/"; | ||
− | + | ||
LDFLAGS = "-L /path/to/aarch64-elf/aarch64-elf/libc/usr/lib"; | LDFLAGS = "-L /path/to/aarch64-elf/aarch64-elf/libc/usr/lib"; | ||
LDFLAGS = "-L /path/to/aarch64-elf/aarch64-elf/lib/"; | LDFLAGS = "-L /path/to/aarch64-elf/aarch64-elf/lib/"; | ||
− | + | ||
LIBS = "-l:libc.a"; | LIBS = "-l:libc.a"; | ||
LIBS = "-l:libgcc.a"; | LIBS = "-l:libgcc.a"; | ||
LIBS = "-l:librdimon.a"; | LIBS = "-l:librdimon.a"; | ||
LIBS = "-l:libsupc++.a"; | LIBS = "-l:libsupc++.a"; | ||
+ | |||
+ | [[Category:Tutorial]] |
Latest revision as of 11:16, 13 February 2019
Introduction
Despite the fact that ERIKA is implemented using the C and the Assembly programming languages, it has experimental support for linking applications implemented using the C++ language.
Basic support
The .cpp
file extension is automatically recognized and handled by the Makefiles.
Put in the OIL file the following information:
CFLAGS = "-std=c++11"; CFLAGS = "-fno-exceptions"; CFLAGS = "-mstrict-align";
Moreover, embed through the following braces any C symbol that must be linked to the application (e.g. idle_hook
, tasks, etc.)
extern "C"{ //... }
The main
function can be left outside the braces.
This must be done also for external libraries. In case of Jailhouse, for example, the inmate library must be modified as shown here.
This is the basic list of the supported features:
- Normal classes
- Template metaprogramming
- C++11: lambda expressions, type deduction (i.e.
auto
)
STL support
In addition to the steps described in the previous section, if you also want to support the STL features provided by the bare-metal newlib
toolchain (e.g., the one provided by Linaro's bare-metal gcc toolchain for ARM), you
have to modify the linker script to set the end
symbol:
.data : { *(.data) } . = ALIGN(8); /* "end" is used by newlib's syscalls */ PROVIDE(end = .); . = ALIGN(16); stack_bottom = .; . = ALIGN(4096); . = . + 0x10000; /* <-- grow this value as much as you can, depending on free RAM availability */ stack_top = .;
Note: with this approach, stack and heap basically share the same memory area. This means that if the stack or the heap grows "too much" it can overwrite the other one.
It is therefore important to move the stack top (i.e. 0x10000
in the example) as much as possible.
Then, add the paths and names of the C++ libraries into the OIL file.
For example, in case of the Linaro ARM toolchain:
CFLAGS = "-I/path/to/aarch64-elf/aarch64-elf/include/c++/version/"; CFLAGS = "-I/path/to/aarch64-elf/aarch64-elf/include/c++/version/aarch64-elf/"; CFLAGS = "-I/path/to/aarch64-elf/aarch64-elf/libc/usr/include/"; LDFLAGS = "-L /path/to/aarch64-elf/aarch64-elf/libc/usr/lib"; LDFLAGS = "-L /path/to/aarch64-elf/aarch64-elf/lib/"; LIBS = "-l:libc.a"; LIBS = "-l:libgcc.a"; LIBS = "-l:librdimon.a"; LIBS = "-l:libsupc++.a";