OSDev.org
https://forum.osdev.org/

implementing a linux-based os from scratch, how to start?
https://forum.osdev.org/viewtopic.php?f=1&t=36399
Page 3 of 3

Author:  Octocontrabass [ Tue Jan 14, 2020 3:00 am ]
Post subject:  Re: implementing a linux-based os from scratch, how to start

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.

Author:  mmdmine [ Tue Jan 14, 2020 3:53 am ]
Post subject:  Re: implementing a linux-based os from scratch, how to start

I am not as serious as you on this project. I'll implement everything needed by compiler. no matter.

Author:  bzt [ Tue Jan 14, 2020 7:01 am ]
Post subject:  Re: implementing a linux-based os from scratch, how to start

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

Author:  Octocontrabass [ Tue Jan 14, 2020 7:58 am ]
Post subject:  Re: implementing a linux-based os from scratch, how to start

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.

Author:  nullplan [ Tue Jan 14, 2020 2:29 pm ]
Post subject:  Re: implementing a linux-based os from scratch, how to start

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.

Author:  Octocontrabass [ Wed Jan 15, 2020 2:13 am ]
Post subject:  Re: implementing a linux-based os from scratch, how to start

That's fair. GCC and Clang seem to assume you'll compile your standard C library in hosted mode, though.

Page 3 of 3 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/