OSDev.org

The Place to Start for Operating System Developers
It is currently Mon Mar 18, 2024 11:55 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: C++ How Do I Disable C++ Runtime Support in the Compiler?
PostPosted: Sat Apr 30, 2022 7:58 am 
Offline

Joined: Fri Apr 01, 2022 10:06 am
Posts: 23
Location: Türkiye, Uşak/Merkez
How Do I Disable C++ Runtime Support in the Compiler?

_________________
M. Alp


Top
 Profile  
 
 Post subject: Re: C++ How Do I Disable C++ Runtime Support in the Compiler
PostPosted: Sat Apr 30, 2022 12:28 pm 
Offline
Member
Member

Joined: Fri May 11, 2018 6:51 am
Posts: 274
If you use GCC or Clang:
Code:
-fno-exceptions -fno-rtti

Note that if you wanna compile C++ code in a kernel, you might need many other additional flags like:
Code:
-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


Top
 Profile  
 
 Post subject: Re: C++ How Do I Disable C++ Runtime Support in the Compiler
PostPosted: Sat Apr 30, 2022 5:05 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5069
vvaltchev wrote:
Code:
-ffreestanding -fno-builtin

There's no need to specify "-fno-builtin" when you specify "-ffreestanding".

vvaltchev wrote:
Code:
-mno-80387 -mno-mmx -mno-sse -mno-avx

Recent versions of GCC and Clang support "-mgeneral-regs-only" on x86 targets to disable all instruction sets that use extra registers.

It's also a really good idea to use a cross-compiler.


Top
 Profile  
 
 Post subject: Re: C++ How Do I Disable C++ Runtime Support in the Compiler
PostPosted: Sun May 01, 2022 2:54 am 
Offline

Joined: Fri Apr 01, 2022 10:06 am
Posts: 23
Location: Türkiye, Uşak/Merkez
vvaltchev wrote:
If you use GCC or Clang:
Code:
-fno-exceptions -fno-rtti

Note that if you wanna compile C++ code in a kernel, you might need many other additional flags like:
Code:
-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


Top
 Profile  
 
 Post subject: Re: C++ How Do I Disable C++ Runtime Support in the Compiler
PostPosted: Sun May 01, 2022 3:07 pm 
Offline
Member
Member

Joined: Fri May 11, 2018 6:51 am
Posts: 274
Octocontrabass wrote:
Good point! Not sure why I used them both.

Octocontrabass wrote:
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.

Octocontrabass wrote:
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


Top
 Profile  
 
 Post subject: Re: C++ How Do I Disable C++ Runtime Support in the Compiler
PostPosted: Sun May 01, 2022 7:37 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5069
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.


Top
 Profile  
 
 Post subject: Re: C++ How Do I Disable C++ Runtime Support in the Compiler
PostPosted: Mon May 02, 2022 5:02 am 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: C++ How Do I Disable C++ Runtime Support in the Compiler
PostPosted: Mon May 02, 2022 10:37 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5069
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.


Top
 Profile  
 
 Post subject: Re: C++ How Do I Disable C++ Runtime Support in the Compiler
PostPosted: Mon May 02, 2022 12:59 pm 
Offline
Member
Member

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group