OSDev.org

The Place to Start for Operating System Developers
It is currently Sun Jan 19, 2020 8:14 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 36 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject: Re: implementing a linux-based os from scratch, how to start
PostPosted: Tue Jan 14, 2020 3:00 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 1764
bzt wrote:
FYI, it looks like Clang can be compiled to support builtins the same way as gcc does, using so called VARIANTs, read the comment on this test case for example.

The comment about variants is discussing using the same test code to test two different built-in functions, where one function is tested when VARIANT is defined, and the other is tested when VARIANT is not defined, such as in this test case. Built-in functions are always available in Clang, the same way they're always available in GCC. Both compilers will assume your hosted implementation follows the standard C library API unless you tell them otherwise with -fno-builtin. Both compilers will warn you if you try to redefine a built-in function with the wrong signature.

Here's an example of a built-in function in Clang.


Top
 Profile  
 
 Post subject: Re: implementing a linux-based os from scratch, how to start
PostPosted: Tue Jan 14, 2020 3:53 am 
Offline
Member
Member

Joined: Sat Dec 28, 2019 5:19 am
Posts: 37
Location: Iran
I am not as serious as you on this project. I'll implement everything needed by compiler. no matter.

_________________
https://mmdmine.github.io


Top
 Profile  
 
 Post subject: Re: implementing a linux-based os from scratch, how to start
PostPosted: Tue Jan 14, 2020 7:01 am 
Offline
Member
Member
User avatar

Joined: Thu Oct 13, 2016 4:55 pm
Posts: 469
Octocontrabass wrote:
Built-in functions are always available in Clang, the same way they're always available in GCC.
Now this is not true, see the example I've liked before. There's a Makefile for gcc and another for Clang, so you can test the same source with both easily.
Octocontrabass wrote:
Both compilers will assume your hosted implementation
That's the thing, we are not talking about hosted implementation, because you can't write a libc in a hosted environment, you must use freestanding.
Now I see why are you confused.

Cheers,
bzt


Top
 Profile  
 
 Post subject: Re: implementing a linux-based os from scratch, how to start
PostPosted: Tue Jan 14, 2020 7:58 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 1764
bzt wrote:
Octocontrabass wrote:
Built-in functions are always available in Clang, the same way they're always available in GCC.
Now this is not true, see the example I've liked before. There's a Makefile for gcc and another for Clang, so you can test the same source with both easily.

I didn't say they will always be inlined, just that they are always available. When they're not inlined, they behave as an ordinary function call. Did you try changing -O2 to -Os in your makefile yet?

bzt wrote:
That's the thing, we are not talking about hosted implementation, because you can't write a libc in a hosted environment, you must use freestanding.

Why? As long as you're careful to avoid including old headers, I see no reason why you couldn't.


Top
 Profile  
 
 Post subject: Re: implementing a linux-based os from scratch, how to start
PostPosted: Tue Jan 14, 2020 2:29 pm 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 334
Octocontrabass wrote:
Why? As long as you're careful to avoid including old headers, I see no reason why you couldn't.
Because, in a hosted environment, all the header files and all the identifiers from chapter 7 are reserved. Defining a function called "printf" is undefined behavior in hosted mode, since the identifier is reserved. Creating a "stdio.h" is undefined for the same reason. Etc. pp.


Top
 Profile  
 
 Post subject: Re: implementing a linux-based os from scratch, how to start
PostPosted: Wed Jan 15, 2020 2:13 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 1764
That's fair. GCC and Clang seem to assume you'll compile your standard C library in hosted mode, though.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 36 posts ]  Go to page Previous  1, 2, 3

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot], max, StudlyCaps and 13 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