Exclude built in functions?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
TheUnbeliever

Exclude built in functions?

Post by TheUnbeliever »

What other parameters do I need to add to the following in order to ignore built in functions - I'm moving along with my OS, slowly but surely, and now when I try to compile my kernel, I get errors of something like 'Parameter type mismatch with built in function setmem()' when I include my system.h with the reference to my setmem functions.

This is using the cross compiler using precisely the same version of binutils and gcc as specified in the Wiki, compiled under Fedora Core 3, with I believe GCC 3.4.2.

/usr/cross/bin/i586-elf-gcc-3.4.0 -std=c99 -Wall -Werror -nostdlib -nostartfiles -nodefaultlibs -I./
durand
Member
Member
Posts: 193
Joined: Wed Dec 21, 2005 12:00 am
Location: South Africa
Contact:

Re:Exclude built in functions?

Post by durand »

These are the parameters I use for my kernel compile:

-nostartfiles -nostdlib -nodefaultlibs -nostdinc
-fno-builtin -fvolatile -fvolatile-global -fvolatile-static

Seems to work....
Tora OS

Re:Exclude built in functions?

Post by Tora OS »

i use:
-fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin
mystran

Re:Exclude built in functions?

Post by mystran »

Well, my set of flags is more or less:

Code: Select all

CODEGEN = -pipe -march=i486 -O3 -fno-omit-frame-pointer \
          -mpreferred-stack-boundary=2 -fno-strict-aliasing
NOLIBS = -nostdinc -nostdlib -fno-builtin -ffreestanding -fno-common
Both variables are given to compiler. They are separated mainly make the Makefile more manageable.

-pipe just makes gcc use pipes instead of temporary files

-march=i486 says it's ok to use 486-only stuff (this could probably be higher.. but)

-O3 is maximum optimization level (4-6 don't add anything)

-fno-omit-frame-pointer tells gcc to leave frame pointers alone, so I can dump stack on panic. Could be omitted for production compiles. This is explicitly there because -O3 turns enables the optimization otherwise.

-mpreferred-stack-boundary=2 aligns stack boundaries to 2^2 = 4 bytes. That's minimum correct alignment for ia-32. The default would be 4 (=2^4=16 bytes), but I prefer not to waste stack space (so I can have smaller kernel stacks) and don't need bigger alignment for anything.

-fno-strict-aliasing is needed because I do some fancy stuff with pointers and integers, and generally violate all kinds of aliasing rules.

-nostdinc disable standard includes

-nostdlib disables standard libraries (libC etc.)

-fno-builtin tells gcc not to expect it's "builtins" to work

-ffreestanding isn't really needed on Linux I believe, but..

-fno-common is really just there as a sanity check, so I don't accidentally share a variable unintentionally between to units

I also use:

Code: Select all

INCLUDES = -I. -Iinclude
WARNINGS = -Werror -Wall -Wstrict-prototypes -Wpointer-arith -Wcast-align -Wcast-qual
First one gives us a new include path (the standard was disabled), and the second causes tons of warnings to be emitted, and made fatal, mainly to sanitycheck that everything is really what it looks like.

Btw: -fvolatile* might not be good idea. This can cause quite a dramatic speed hit in places where it's not really needed. Personally I prefer to declare any volatile stuff explicitly as volatile. I find the flag useful mainly when a bug looks like it might be caused by a missing 'volatile'-qualifier (if it's fixed by the flag, then something isn't declared properly).
durand
Member
Member
Posts: 193
Joined: Wed Dec 21, 2005 12:00 am
Location: South Africa
Contact:

Re:Exclude built in functions?

Post by durand »

Thanks. I'll remove the volatile stuff and be specific in the source about which variables are... All my stuff is locked, so it shouldn't cause any problems.
CopperMan

Re:Exclude built in functions?

Post by CopperMan »

Just add

-fno-builtin

to Your compile command, shall be ok.

P.S. Even after that You can use built-in functions :

Code: Select all

__builtin_memset();
__builtin_memcpy();
instead of writing your ones.
pini

Re:Exclude built in functions?

Post by pini »

Actually, -ffreestanding should also do the trick.
It tells gcc that no environnment of any kind is to be expected when compiling (and this flag implies -fno-builtin).
According to gcc man page, it's particularly useful for... kernel programming :)
TheUnbeliever

Re:Exclude built in functions?

Post by TheUnbeliever »

A good variety of information and answers here. Thanks, I'll try this out tomorrow. :D
Post Reply