Questions tagged [freestanding]

A freestanding implementation of C/C++ is an implementation that can work without an operating system and has an implementation-defined set of libraries. Commonly found in embedded development environments.

The C++ standard defines hosted and freestanding implementations as follows (§1.4/7)

Two kinds of implementations are defined: a hosted implementation and a freestanding implementation. For a hosted implementation, this International Standard defines the set of available libraries. A freestanding implementation is one in which execution may take place without the benefit of an operating system, and has an implementation-defined set of libraries that includes certain language-support libraries (§17.6.1.3).

Use this tag to mark C/C++ questions (together with general and and optionally with tags for specific language standards, for example or ) where these constraints may apply.

Also, make sure the question explicitly states which libraries are and are not available (besides the minimal language support headers that are required).

References:

39 questions
2
votes
1 answer

error: function declared 'ms_abi' here was previously declared without calling convention (clang)

when I try to compile C code that includes another C header I get this error: x86_64-uefi/../../libk/string.h:9:10: error: function declared 'ms_abi' here was previously declared without calling convention KABI int memcmp(const void *d1,…
Rottenheimer2
  • 425
  • 1
  • 5
  • 13
2
votes
1 answer

How to compile C to raw binary in OSX?

Im following a tutorial on how to create an OS from scratch. I'm at the point where I need to start writing code in C but I need to compile it, in free standing mode, to raw binary. The commands given are: gcc -ffreestanding -c kernel.c -o…
Chuck Onwuzuruike
  • 344
  • 1
  • 4
  • 12
1
vote
2 answers

Implementing PRI macros 'portably'

The C99 specified inttypes.h header includes macros for providing format specifiers for the fixed-width integer types provided by stdint.h (beginning with PRI). While stdint.h is on the 'freestanding' list of headers and thus is always provided by…
Fraggle
  • 55
  • 4
1
vote
1 answer

How can I detect if C malloc available for freestanding target platform?

In C, how can I detect if a some form of malloc has been made available, regardless of target platform or compiler? Is it enough to detect _STDLIB_H_? I would like to include a header utility function that uses malloc but only if it's already made…
codechimp
  • 1,509
  • 1
  • 14
  • 21
1
vote
0 answers

gcc: freestanding option with higher optimisation results in larger code

When compiling with higher optimisation flags (eg: -O3), gcc will assemble code like this: extern unsigned char g_wibble[200]; int test(void) { int i; for (i = 0; i < sizeof(g_wibble); i++) g_wibble[i] = 0; return 0; } in a…
carveone
  • 889
  • 9
  • 16
1
vote
1 answer

Custom memory allocator for real-mode DOS .COM (freestanding) -- how to debug?

A little background first: stumbling upon this blog post, I learned it was possible to create DOS .COM files with the GNU linker and it's not even rocket science. Using clang and the -m16 switch (creating real-mode compatible 32bit code by prefixing…
user2371524
1
vote
1 answer

Freestanding ARM C++ Code - empty .ctors section

I'm writing C++ code to run in a freestanding environment (basically an ARM board). It's been going well except I've run into a stumbling block - global static constructors. To my understanding the .ctors section contains a list of addresses to each…
Matthew Iselin
  • 10,400
  • 4
  • 51
  • 62
0
votes
0 answers

GCC cross-compiler for a freestanding environemnt, "__float128 is not suppported for this target" is reported as an error when you include

When building GCC cross-compiler (C++) for a freestanding environemnt, "__float128 is not suppported for this target" is reported as an error when you include . When building GCC cross-compiler for a freestanding environemnt, "__float128 is not…
Happy Jerry
  • 164
  • 1
  • 8
0
votes
1 answer

Unable to find uint8_t despite having build the freestanding libs for C++

Edit: Is this related to this bug report? Unable to find uint8_t despite having build the freestanding libs for C++ The error I get is: FAILED: CMakeFiles/nak.dir/Kernel/src/kernel.cpp.o…
Happy Jerry
  • 164
  • 1
  • 8
0
votes
0 answers

RISC-V toolchain: lds file may make some irrelevant instructions

I want to use risc-v toolchain to compile a simple c code to test my processor. And I refer to PicoRV32's firmware file for my own test.lds : SECTIONS { .memory : { . = 0x000000; *(.init); *(.text); *(*); …
0
votes
1 answer

How to compile C++ freestanding / baremetal with g++?

C++ has many aspects, included by default, that are not desirable or even functional on embedded bare metal / free standing platforms. How can I configure g++ to compile C++ in a manner suitable for embedded bare-metal / freestanding?
SRobertJames
  • 8,210
  • 14
  • 60
  • 107
0
votes
0 answers

Freestanding C: Why does this function fail to return data depending on the structure of the array?

I'm currently watching a Udemy tutorial on basic graphical OS development, which has just begun to explain how to render text in VBE graphical mode using bitmap fonts. The presenter creates a function (auto-generated by a python script) to return a…
0
votes
1 answer

Character apparently doesn't get translated to its ASCII value in a C kernel

I'm developing a basic C kernel in a Kali machine and testing it inside QEMU. This is the kernel code: void kernel_main(); void print(); void print() { char* vidMem = (char*)0xb8000; *vidMem = "A"; vidMem++; *vidMem = 0x0f; } void…
0xPictor
  • 63
  • 6
0
votes
2 answers

Computer dedicated to one program

I would like to have a computer running only one program, so whenever the computer boots, it executes that program. For example: Computer board from Tesla car, common supermarket systems One example of how I use that: Develop a system to make a…
0
votes
1 answer

Subtleties dealing with cross compilation, freestanding libgcc, etc

I have a few questions about https://wiki.osdev.org/Meaty_Skeleton, which says: The GCC documentation explicitly states that libgcc requires the freestanding environment to supply the memcmp, memcpy, memmove, and memset functions, as well as…
Suraaj K S
  • 600
  • 3
  • 21