C++ How Do I Disable C++ Runtime Support in the Compiler?
-
- Posts: 23
- Joined: Fri Apr 01, 2022 10:06 am
- Location: Türkiye, Uşak/Merkez
C++ How Do I Disable C++ Runtime Support in the Compiler?
How Do I Disable C++ Runtime Support in the Compiler?
M. Alp
Re: C++ How Do I Disable C++ Runtime Support in the Compiler
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:
That list is still incomplete, but many other flags depend on what you need/want to achieve.
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
Tilck, a Tiny Linux-Compatible Kernel: https://github.com/vvaltchev/tilck
-
- Member
- Posts: 5512
- Joined: Mon Mar 25, 2013 7:01 pm
Re: C++ How Do I Disable C++ Runtime Support in the Compiler
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
It's also a really good idea to use a cross-compiler.
-
- Posts: 23
- Joined: Fri Apr 01, 2022 10:06 am
- Location: Türkiye, Uşak/Merkez
Re: C++ How Do I Disable C++ Runtime Support in the Compiler
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
M. Alp
Re: C++ How Do I Disable C++ Runtime Support in the Compiler
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.
Tilck, a Tiny Linux-Compatible Kernel: https://github.com/vvaltchev/tilck
-
- Member
- Posts: 5512
- Joined: Mon Mar 25, 2013 7:01 pm
Re: C++ How Do I Disable C++ Runtime Support in the 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.
Re: C++ How Do I Disable C++ Runtime Support in the 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.
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
Sad story.
Tilck, a Tiny Linux-Compatible Kernel: https://github.com/vvaltchev/tilck
-
- Member
- Posts: 5512
- Joined: Mon Mar 25, 2013 7:01 pm
Re: C++ How Do I Disable C++ Runtime Support in the 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
Re: C++ How Do I Disable C++ Runtime Support in the Compiler
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
Tilck, a Tiny Linux-Compatible Kernel: https://github.com/vvaltchev/tilck