GCC for Embedded Engineers
These components perform only a small slice of the work necessary to produce an executable. The preprocessor, for languages that support such a concept, runs before the compiler proper, performing text transformations before the compiler transforms the input into machine code for the target. During the compilation process, the compiler performs optimizations as specified by the user and produces a parse tree. The parse tree is translated into assembler code, and the assembler uses that input to make an object file. If the user wants to produce an executable binary, the object file is then passed to the linker to produce an executable.
After looking at all the components in a toolchain, the following section steps through the process GCC takes when compiling C source files into a binary. The process starts by invoking GCC with the files to be compiled and a parameter specifying output to be stored to thebinary:
armv5l-linux-gcc file1.c file2.c -o thebinary
GCC is actually a driver program that invokes the underlying compiler and binutils to produce the final executable. By looking at the extension of the input file and using the rules built in to the compiler, GCC determines what programs to run in what order to build the output. To see what happens in order to compile the file, add the -### parameter:
armv5l-linux-gcc -### file1.c file2.c -o thebinary
This produces virtual reams of output on the console. Much of the output has been clipped, saving untold virtual trees, to make it more readable for this example. The first information that appears describes the version of the compiler and how it was built—very important information when queried “was GCC built with thumb-interworking disabled?”
Target: armv5l-linux Configured with: <the contents of a autoconf command line> Thread model: posix gcc version 4.1.0 20060304 (TimeSys 4.1.0-3)
After outputting the state of the tool, the compilation process starts. Each source file is compiled with the cc1 compiler, the “real” compiler for the target architecture. When GCC was compiled, it was configured to pass certain parameters to cc1:
"/opt/timesys/toolchains/armv5l-linux/libexec/gcc/ ↪armv5l-linux/4.1.0/cc1.exe" "-quiet" "file1.c" ↪"-quiet" "-dumpbase" "file1.c" "-mcpu=xscale" ↪"-mfloat-abi=soft" "-auxbase" "file1" "-o" ↪"/cygdrive/c/DOCUME~1/GENESA~1.TIM/LOCALS~1/Temp/ccC39DVR.s"
Now the assembler takes over and turns the file into object code:
"/opt/timesys/toolchains/armv5l-linux/lib/gcc/ ↪armv5l-linux/4.1.0/../../../../armv5l-linux/bin/as.exe" ↪"-mcpu=xscale" "-mfloat-abi=soft" "-o" ↪"/cygdrive/c/DOCUME~1/GENESA~1.TIM/LOCALS~1/Temp/ccm4aB3B.o" ↪"/cygdrive/c/DOCUME~1/GENESA~1.TIM/LOCALS~1/Temp/ccC39DVR.s"
The same thing happens for the next file on the command line, file2.c. The command lines are the same as those for file1.c, but with different input and output filenames.
After compilation, collect2 performs a linking step and looks for initialization functions (called constructor functions, but not in the object-oriented sense) called before the “main” section of the program. collect2 gathers these functions together, creates a temporary source file, compiles it and links that to the rest of the program:
"/opt/timesys/toolchains/armv5l-linux/libexec/gcc/ ↪armv5l-linux/4.1.0/collect2.exe" "--eh-frame-hdr" ↪"-dynamic-linker" "/lib/ld-linux.so.2" "-X" "-m" ↪"armelf_linux" "-p" "-o" "binary" "/opt/timesys/ ↪toolchains/armv5l-linux/lib/gcc/armv5l-linux/ ↪4.1.0/../../../../armv5l-linux/lib/crt1.o" ↪"/opt/timesys/toolchains/armv5l-linux/lib/gcc/ ↪armv5l-linux/4.1.0/../../../../armv5l-linux/lib/crti.o" ↪"/opt/timesys/toolchains/armv5l-linux/lib/gcc/ ↪armv5l-linux/4.1.0/crtbegin.o" ↪"-L/opt/timesys/toolchains/armv5l-linux/lib/ ↪gcc/armv5l-linux/4.1.0" "-L/opt/timesys/ ↪toolchains/armv5l-linux/lib/gcc/armv5l-linux/ ↪4.1.0/../../../../armv5l-linux/lib" ↪"/cygdrive/c/DOCUME~1/GENESA~1.TIM/LOCALS~1/ ↪Temp/ccm4aB3B.o" "/cygdrive/c/DOCUME~1/ ↪GENESA~1.TIM/LOCALS~1/Temp/cc60Td3s.o" ↪"-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" ↪"-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" ↪"/opt/timesys/toolchains/armv5l-linux/lib/ ↪gcc/armv5l-linux/4.1.0/crtend.o" "/opt/timesys/ ↪toolchains/armv5l-linux/lib/gcc/armv5l-linux/ ↪4.1.0/../../../../armv5l-linux/lib/crtn.o"
There are some other nifty things in here that warrant pointing out:
1. Here's the option that specifies the dynamic linker to invoke when running the program on the target platform:
"-dynamic-linker" "/lib/ld-linux.so.2"
On Linux platforms, dynamically linked programs actually load by running a dynamic loader, making themselves a parameter of the linker, which does the work of loading the libraries into memory and fixing up the references. If this program isn't in the same place on the target machine, the program will fail to run with an “unable to execute program” error message. A misplaced linker on the target ensnares every embedded developer at least once.
2. These files contain the code before the programmer's entry point (typically main, but you can change that too) and handle things like initialization of globals, opening the standard file handles, making that nice array of parameters and other housekeeping functions:
crtbegin.o
crt1.o
crti.o
3. Likewise, these files contain the code after the last return, such as closing files and other housekeeping work. Like the prior items, these are cross-compiled during the GCC build:
crtend.o
crtn.o
And, that's it! At the end of this process, the output is a program ready for execution on the target platform.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
- Dynamic DNS—an Object Lesson in Problem Solving
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Using Salt Stack and Vagrant for Drupal Development
- New Products
- A Topic for Discussion - Open Source Feature-Richness?
- RSS Feeds
- Drupal Is a Framework: Why Everyone Needs to Understand This
- Validate an E-Mail Address with PHP, the Right Way
- Readers' Choice Awards
- Tech Tip: Really Simple HTTP Server with Python
- Reply to comment | Linux Journal
6 min 38 sec ago - All the articles you talked
2 hours 30 min ago - All the articles you talked
2 hours 33 min ago - All the articles you talked
2 hours 34 min ago - myip
6 hours 59 min ago - Keeping track of IP address
8 hours 50 min ago - Roll your own dynamic dns
14 hours 3 min ago - Please correct the URL for Salt Stack's web site
17 hours 15 min ago - Android is Linux -- why no better inter-operation
19 hours 30 min ago - Connecting Android device to desktop Linux via USB
19 hours 59 min ago




Comments
Tabela
Geçtiğimiz yerlerde her üç adımda bir gördüğümüz Tabela lar caddeleri renklendiren unsurlardır. Tabela lar caddeleri renklendirirken aynı zamandada insanların aradıkları yerleri bulmalarında son derece yardımcıdırlar. Geçen bir tatil yöresinde gezerken çok renkli, ışıklı çok güzel bir Tabela gördüm ve bayıldım.
Resmini çekeyim şu Tabela nın derken fotoğraf makinemin pili bitmiş ve çekemedim. Önümüzdeki sene gidebilirsem yine aynı şekilde bu Tabela nın resmini çekmeyi planlıyorum kimbilir belki önümüzdeki sene kısmet olur...
http://www.dikkatdizi.com
http://www.dikkatdizi.com
That's what i was looking for
That's what i was looking for =) Thanks
Medrano
You have given much
You have given much descriptive information,Thanks...
Sinema,Vizyondakiler,Sinemalar
really
You have given much descriptive information,Thanks...
Sinema,Vizyondakiler,Sinemalar
thanks for document
thanks for document
Thank you for the article.
Thank you for the article.
thank you
thanks for document
my page: www.yuhoha.com
türkçe rap müzik
Rap,Hiphop
rap dinle
free Beat
Linux
thanks for document
Bravo
Thanks for an excellent article on a subject affect many embedded engineers.