Page 3 of 3
Re: implementing a linux-based os from scratch, how to start
Posted: Tue Jan 14, 2020 3:00 am
by Octocontrabass
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.
Re: implementing a linux-based os from scratch, how to start
Posted: Tue Jan 14, 2020 3:53 am
by mmdmine
I am not as serious as you on this project. I'll implement everything needed by compiler. no matter.
Re: implementing a linux-based os from scratch, how to start
Posted: Tue Jan 14, 2020 7:01 am
by bzt
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
Re: implementing a linux-based os from scratch, how to start
Posted: Tue Jan 14, 2020 7:58 am
by Octocontrabass
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.
Re: implementing a linux-based os from scratch, how to start
Posted: Tue Jan 14, 2020 2:29 pm
by nullplan
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.
Re: implementing a linux-based os from scratch, how to start
Posted: Wed Jan 15, 2020 2:13 am
by Octocontrabass
That's fair. GCC and Clang seem to assume you'll compile your standard C library in hosted mode, though.