1,885
edits
Changes
→Resources
[[Category:SPO600 Labs]]{{Admon/lab|Purpose of this Lab|In this lab, you will investigate the relationship between basic C source code and the output of the C compiler.}}{{Admon/tip|Host System|You can choose to perform this lab on any of the [[SPO600 Servers]]. Alternately, you may use your own system if it has been set up with development tools and libraries, '''plus''' the static version of the glibc library.}}{{Admon/important|Winter 2020|In Winter 2020, this lab is not a required lab and will instead be used as an in-class Demo.}}
== Lab / Demo == 1. Write a basic C program which prints a message on the screen, [http://enwww.wikipediaroesler-ac.orgde/wikiwolfram/Hello_world_program hello.htm Hello World!]-style -- something like this:
#include <stdio.h>
}
2. Compile the program using the GCC compiler. Include each of these compiler options (refer to the gcc manpage for details):
-g # enable debugging information
--source # (implies -d) show source code, if available, along with disassembly
Using objdump, find the answers to these questions:(i) Which section contains the code you wrote?(ii) Which section contains the string to be printed? {{Admon/tip|objdump ''vs'' readelf|The way that <code>objdump</code> formats strings is not well suited for some uses. The <code>readelf -p</code> command may be a better tool for viewing some strings.}} 4. Try to gain a basic understanding of what the compiled code is doing. '''Focus on the section marked <main> but also take a look at the other sectionsand the overall file size.'''
5. Recompile the code with these changes:
6. Blog about your results. Important! -- explain what you're doing so that a reader coming across your blog post understands the context (in other words, don't just jump into a discussion of optimization results -- give your post some context).
{{Admon/important|Include Seven Variants|Blog about all seven compilations -- the original and the six variants listed in step (5) -- not the just variant your group examined in class.}}
{{Admon/tip|Make|Learn how to use [[Make and Makefiles|make]] -- your life as a programmer will be much easier, and you'll get back years of your life!}}
== External Resources ==
* For a general overview of ELF, see the Wikipedia article on [http://en.wikipedia.org/wiki/Executable_and_Linkable_Format Executable and Linkable Format]