C++ How Do I Disable C++ Runtime Support in the Compiler?
Posted: Sat Apr 30, 2022 7:58 am
How Do I Disable C++ Runtime Support in the Compiler?
The Place to Start for Operating System Developers
http://forum.osdev.org./
Code: Select all
-fno-exceptions -fno-rtti
Code: Select all
-fno-use-cxa-atexit -ffreestanding -fno-builtin -mno-red-zone -fno-stack-protector -fno-asynchronous-unwind-tables -fno-pic -mno-80387 -mno-mmx -mno-sse -mno-avx
There's no need to specify "-fno-builtin" when you specify "-ffreestanding".vvaltchev wrote:Code: Select all
-ffreestanding -fno-builtin
Recent versions of GCC and Clang support "-mgeneral-regs-only" on x86 targets to disable all instruction sets that use extra registers.vvaltchev wrote:Code: Select all
-mno-80387 -mno-mmx -mno-sse -mno-avx
Now I Should Write The Commands You Have Written In A File And Use What Should I Do Also To Disable C++ Runtime Support, I also use all commands software and cross compiler Compilers I use: g++, Binultis, libc6-dev.vvaltchev wrote:If you use GCC or Clang:Note that if you wanna compile C++ code in a kernel, you might need many other additional flags like:Code: Select all
-fno-exceptions -fno-rtti
That list is still incomplete, but many other flags depend on what you need/want to achieve.Code: Select all
-fno-use-cxa-atexit -ffreestanding -fno-builtin -mno-red-zone -fno-stack-protector -fno-asynchronous-unwind-tables -fno-pic -mno-80387 -mno-mmx -mno-sse -mno-avx
Good point! Not sure why I used them both.Octocontrabass wrote:There's no need to specify "-fno-builtin" when you specify "-ffreestanding".
Thanks! That's a nice option I didn't know. It's a bit inconvenient to use it conditionally on the compiler version, but it's great. From what I'm seeing here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70738, it has been introduced in GCC 7.0.
I do use a cross-compiler. I download it pre-built from https://toolchains.bootlin.com/ and that's amazing. They have plenty of GCC toolchains for multiple architectures (and libc libraries) compiled to run on x86-64 hosts, which is exactly what I needed. I don't see much value in compiling my own toolchain just to make some basic options enabled by default. Note that I don't have a custom libc, I use libmusl with the Linux ABI. Therefore, the x86-i686--musl--stable-* toolchains are all I need. Do you still believe a custom toolchain would bring extra value in this case?Octocontrabass wrote:It's also a really good idea to use a cross-compiler.
That comment was directed more towards someone who is not using a cross-compiler. It sounds like you already have an appropriate compiler - I guess that's one benefit of writing an OS that's binary-compatible with Linux.vvaltchev wrote:I do use a cross-compiler.
Ah OK, thanks.Octocontrabass wrote:That comment was directed more towards someone who is not using a cross-compiler. It sounds like you already have an appropriate compiler - I guess that's one benefit of writing an OS that's binary-compatible with Linux.vvaltchev wrote:I do use a cross-compiler.
Your Clang is too old. Try Clang 13.vvaltchev wrote:Btw, I tried switching to -mgeneral-regs-only and discovered that clang supports that only on Aarch64. The patch adding general support for that flag has been abandoned: https://reviews.llvm.org/D38479
Oh, that's great to hear. Thanks!!Octocontrabass wrote:Your Clang is too old. Try Clang 13.vvaltchev wrote:Btw, I tried switching to -mgeneral-regs-only and discovered that clang supports that only on Aarch64. The patch adding general support for that flag has been abandoned: https://reviews.llvm.org/D38479