C++ How Do I Disable C++ Runtime Support in the Compiler?

All off topic discussions go here. Everything from the funny thing your cat did to your favorite tv shows. Non-programming computer questions are ok too.
Post Reply
Mehmetdev1
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?

Post by Mehmetdev1 »

How Do I Disable C++ Runtime Support in the Compiler?
M. Alp
vvaltchev
Member
Member
Posts: 274
Joined: Fri May 11, 2018 6:51 am

Re: C++ How Do I Disable C++ Runtime Support in the Compiler

Post by vvaltchev »

If you use GCC or Clang:

Code: Select all

-fno-exceptions -fno-rtti
Note that if you wanna compile C++ code in a kernel, you might need many other additional flags like:

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
That list is still incomplete, but many other flags depend on what you need/want to achieve.
Tilck, a Tiny Linux-Compatible Kernel: https://github.com/vvaltchev/tilck
Mehmetdev1
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

Post by Mehmetdev1 »

vvaltchev wrote:If you use GCC or Clang:

Code: Select all

-fno-exceptions -fno-rtti
Note that if you wanna compile C++ code in a kernel, you might need many other additional flags like:

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
That list is still incomplete, but many other flags depend on what you need/want to achieve.
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.
M. Alp
vvaltchev
Member
Member
Posts: 274
Joined: Fri May 11, 2018 6:51 am

Re: C++ How Do I Disable C++ Runtime Support in the Compiler

Post by vvaltchev »

Good point! Not sure why I used them both.
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?
Tilck, a Tiny Linux-Compatible Kernel: https://github.com/vvaltchev/tilck
Octocontrabass
Member
Member
Posts: 5517
Joined: Mon Mar 25, 2013 7:01 pm

Re: C++ How Do I Disable C++ Runtime Support in the Compiler

Post by Octocontrabass »

vvaltchev wrote:I do 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
Member
Member
Posts: 274
Joined: Fri May 11, 2018 6:51 am

Re: C++ How Do I Disable C++ Runtime Support in the Compiler

Post by vvaltchev »

Octocontrabass wrote:
vvaltchev wrote:I do 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.
Ah OK, thanks.

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
Octocontrabass
Member
Member
Posts: 5517
Joined: Mon Mar 25, 2013 7:01 pm

Re: C++ How Do I Disable C++ Runtime Support in the Compiler

Post by Octocontrabass »

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
Your Clang is too old. Try Clang 13.
vvaltchev
Member
Member
Posts: 274
Joined: Fri May 11, 2018 6:51 am

Re: C++ How Do I Disable C++ Runtime Support in the Compiler

Post by vvaltchev »

Octocontrabass wrote:
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
Your Clang is too old. Try Clang 13.
Oh, that's great to hear. Thanks!!
Tilck, a Tiny Linux-Compatible Kernel: https://github.com/vvaltchev/tilck
Post Reply