1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--Converted with LaTeX2HTML 2002-2-1 (1.70)
original version by: Nikos Drakos, CBLU, University of Leeds
* revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>Basics of Compilation and Linkage</TITLE>
<META NAME="description" CONTENT="Basics of Compilation and Linkage">
<META NAME="keywords" CONTENT="users_guide">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META NAME="Generator" CONTENT="LaTeX2HTML v2002-2-1">
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
<LINK REL="STYLESHEET" HREF="users_guide.css">
<LINK REL="next" HREF="node191.html">
<LINK REL="previous" HREF="node189.html">
<LINK REL="up" HREF="node189.html">
<LINK REL="next" HREF="node191.html">
</HEAD>
<BODY >
<DIV CLASS="navigation"><!--Navigation Panel-->
<A NAME="tex2html3567"
HREF="node191.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A>
<A NAME="tex2html3561"
HREF="node189.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A>
<A NAME="tex2html3555"
HREF="node189.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A>
<A NAME="tex2html3563"
HREF="node14.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A>
<A NAME="tex2html3565"
HREF="node317.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A>
<BR>
<B> Next:</B> <A NAME="tex2html3568"
HREF="node191.html">Circular Dependencies and Single-Pass</A>
<B> Up:</B> <A NAME="tex2html3562"
HREF="node189.html">Grouping compiled assets into</A>
<B> Previous:</B> <A NAME="tex2html3556"
HREF="node189.html">Grouping compiled assets into</A>
<B> <A NAME="tex2html3564"
HREF="node14.html">Contents</A></B>
<B> <A NAME="tex2html3566"
HREF="node317.html">Index</A></B>
<BR>
<BR></DIV>
<!--End of Navigation Panel-->
<H2><A NAME="SECTION04121000000000000000"></A><A NAME="ss:compilebootcamp"></A>
<BR>
Basics of Compilation and Linkage
</H2>
<P>
What we generally think of as a compiler is really an ensemble of related
tools. Generally there is a preprocessing step where very simple transformations
occur (e.g. #define, #include directives and others). Next, the compiler
proper executes and typically transforms your sourcecode into assembler or
some other intermediate form. Optimizers work on this intermediate form and
do perform additional transformations. Most big vendors of C, C++, and Fortran
compilers have a common optimizer for all languages. Next, assemblers transform
the optimized codes into platform-specific binaries. But this is not the end.
The binaries may be linked together into libraries or programs. Libraries can
be linked against other libraries, and eventually multiple programs.
The main difference is that a program has additional instructions to bootstrap
itself, do some interaction with the operating system, receive an argument list,
and call <TT>main()</TT>. To see all this in action, try building a ``hello world''
type program in your favorite language, and run the ``compiler'' with an additional
flag such as <TT><B>-v</B></TT>, <TT><B><code>--</code>verbose</B></TT>, or whatever.
<P>
For example, this is what I get from a g77 compiler.
<BLOCKQUOTE>
<TT> <TT>%</TT> <TT><B>g77 hello_world.f</B></TT>
<BR><TT>%</TT> <TT><B>./a.out</B></TT>
<BR>
Hello World!
<TT>%</TT> <TT><B>g77 -v hello_world.f</B></TT>
<BR>
Driving: g77 -v hello_world.f -lfrtbegin -lg2c -lm -shared-libgcc
<BR>
Reading specs from /usr/local/gcc/3.2/lib/gcc-lib/i686-pc-linux-gnu/3.2/specs
<BR>
Configured with: ../gcc-3.2/configure -prefix=/usr/local/gcc/3.2
<BR>
Thread model: posix
<BR>
gcc version 3.2
<BR> /usr/local/gcc/3.2/lib/gcc-lib/i686-pc-linux-gnu/3.2/f771 hello_world.f -quiet -dumpbase hello_world.f -version -o /tmp/ccp2GBGE.s
<BR>
GNU F77 version 3.2 (i686-pc-linux-gnu)
<BR>
compiled by GNU C version 3.2.
<BR>
as -traditional-format -V -Qy -o /tmp/ccEiIsHc.o /tmp/ccp2GBGE.s
<BR>
GNU assembler version 2.11.90.0.8 (i386-redhat-linux) using BFD version 2.11.90.0.8
<BR> /usr/local/gcc/3.2/lib/gcc-lib/i686-pc-linux-gnu/3.2/collect2 -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o /usr/local/gcc/3.2/lib/gcc-lib/i686-pc-linux-gnu/3.2/crtbegin.o -L/usr/local/gcc/3.2/lib/gcc-lib/i686-pc-linux-gnu/3.2 -L/usr/local/gcc/3.2/lib/gcc-lib/i686-pc-linux-gnu/3.2/../../.. /tmp/ccEiIsHc.o -lfrtbegin -lg2c -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/local/gcc/3.2/lib/gcc-lib/i686-pc-linux-gnu/3.2/crtend.o /usr/lib/crtn.o
<BR>
</TT></BLOCKQUOTE>
<P>
For the purposes of this discussion, we will make a big distinction between
linking to build a library and linking to build and executable. Even though
these transformations have similar names, they perform very different kinds
of transformations to the code.
<P>
<DIV CLASS="navigation"><HR>
<!--Navigation Panel-->
<A NAME="tex2html3567"
HREF="node191.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A>
<A NAME="tex2html3561"
HREF="node189.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A>
<A NAME="tex2html3555"
HREF="node189.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A>
<A NAME="tex2html3563"
HREF="node14.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A>
<A NAME="tex2html3565"
HREF="node317.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A>
<BR>
<B> Next:</B> <A NAME="tex2html3568"
HREF="node191.html">Circular Dependencies and Single-Pass</A>
<B> Up:</B> <A NAME="tex2html3562"
HREF="node189.html">Grouping compiled assets into</A>
<B> Previous:</B> <A NAME="tex2html3556"
HREF="node189.html">Grouping compiled assets into</A>
<B> <A NAME="tex2html3564"
HREF="node14.html">Contents</A></B>
<B> <A NAME="tex2html3566"
HREF="node317.html">Index</A></B> </DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<br><br>babel-0.10.2<br>users_guide Last Modified 2005-03-23<br><br><a href="http://www.llnl.gov/CASC/components">http://www.llnl.gov/CASC/components</a><br><a href="mailto:components@llnl.gov">components@llnl.gov</a>
</ADDRESS>
</BODY>
</HTML>
|