This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: suggestion for GCC (1)


ali hagigat <hagigatali@gmail.com> writes:

> 1) What is a built-in function in gcc (and in the manual of gcc)?

It is a function which gcc has special knowledge about.  Many of the
builtin functions start with __builtin_, such as
__builtin_return_address.  Others are defined in relevant language
standards, such as memcpy.  Others are widely used and are recognized
when not in strict standard compliance mode, such as alloca.

> Is it a function which its C/Assembly code is inside the code of the
> compiler?

Sometimes.

> or Its code is some where on hard disk and inside a library
> function?

Sometimes.

> or the code of the built in function is on hard disk but
> when we build a program we do not need to link the library of that
> function and the compiler automatically finds the code of that
> function from a library function on hard disk and adds it to our
> program automatically?

Sometimes, if you treat the compiler linking against -lgcc and -lc by
default to be automatically finding the code of the function.

> 2) Ian said in one message that some supporting routine is necessary
> for nested functions. What does a nested function mean? It means we
> have a C function and then it calls another function inside by its
> name?

http://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html

> 3) Ian told that the functions like memcpy should be optimized and
> they are target dependent and we do not make them as built in. It is
> unacceptable in my opinion.

The memcpy function is a builtin function by the definition above: gcc
knows about it specially.  In fact, memcpy is a special case in that gcc
both recognizes it specially in source code, and gcc also generates
calls to it in some cases.

> We are talking about a great new feature for gcc, embedded programming
> and writing firmwares, not optimization, which gives gcc a great power
> and it is a new branch of programming. The fact that the code may be
> slower or it takes more memory is a secondary trivial problem in this
> case to me.

gcc has supported embedded programming and writing firmware for many
years, that is nothing new.  It is the case that gcc always requires
some supporting code when doing embedded programming.  At the very least
something has to load the program on the board and clear the BSS
section.  That supporting code has to also provide memcpy.

Many people use the newlib and libgloss projects to provide this
supporting code for embedded systems.  See http://sourceware.org/newlib/ .

> Besides compiler must be able to translate a code for a specific CPU,
> why gcc is dependent to some thing except CPU?!!! Dependent to what?
> (To me gcc has a bug which is dependent to some definitions outside
> its code, It is a software issue which can be corrected)

It is not a bug that a compiler requires supporting libraries.  It is
the normal case and it is true of all compilers.  You are confusing the
compiler proper, which is gcc, with a complete development system.  A
complete development system also includes an assembler, a linker,
various libraries, a debugger, etc.  gcc is just a compiler, not a
complete development system.

> 4) does gcc have any extension to produce stand alone code in open
> source space you may aware of( for a free standing environment without
> libraries).

Not all by itself without any support, no.

> 5) Ian said:
> "The compiler does by default treat functions like memcpy as builtins,
> and ..."
> If memcpy is built in why gcc still generates some calls to memcpy
> and memcpy should be provided some how as the manual of gcc says?

Where does the manual say that?

> 6) Where is memcpy at last? is it in libgcc, libc or it is built in?

It in libc and it is builtin.

> 7) Can i link only libgcc with my code in case of -nostdlib? and every
> thing is OK? I write libgcc.a on my command line and every thing is
> OK?

No, you need more than that.

> 8) When exactly compiler generates call to mem functions like memcpy,
> memcmp, memset, memmove? Would you please write a complete list of the
> cases when compiler does that for -nostdlib. Why the manual of gcc
> does not talk about such an important subject.

http://gcc.gnu.org/onlinedocs/gccint/Libgcc.html

If you find places where the documentation should be improved, I would
encourage you to contribute a patch.

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]