Re: Are compilation of both cc1 and cc1plus based on the concept of function?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2017-02-16 12:54 -0500,yin liu wrote:

> I have another question, so, if the compilation of gcc is based on
> the function, then how do they tackle the dependencies of function
> and data? 

There is no "dependencies" of function and data. When function
foo calls function bar, GCC just put a "call" instruction in object
code of foo. Even if bar hasn't been compiled yet, GCC can compile
foo. So there is no dependencies.

If bar use '#include bar.h' directive to get foo's prototype, there is
a source file dependency. It should be tackle by "make", not by GCC.
GCC can automatically generate the file dependency with option
'-M'. But it's not "function" dependency.

If bar is an 'extern' function, GCC won't know the address of bar.
But it would still compile foo normally, just leave the symbol
'bar' unresolved. There is a symbol dependency. It would be later
resolved by the linker 'ld'. But it's not "function" dependency.

Although logically there may be dependencies of functions
(for example we can draw a call graph), but the compiler doesn't
care.

> For example, two functions may share with same global data.

GCC just compile the two functions *independently*. If that
global data is "extern", the address would be resolved by "ld".
If we have multiple threads, it's the programmer's mission to
synchronize the access to global data. GCC doesn't know any
dependencies.

-- 
Xi Ruoyao <ryxi@xxxxxxxxxxxxxxxxx>
School of Aerospace Science and Technology, Xidian University




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux