By the time you have completed this lab you should be able to
file
command.strings
, nm
, objdump
and readelf
The first order of business this week is to fill out end-of-term evaluations for your Teaching Assistant(s). Please complete this task before proceeding to Step 1. Thank you!
g++ -g -c lab08.cpp
g++ -o lab08 lab08.o
file
command for the three files:
-bash-4.2$ file lab08* lab08: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, not stripped lab08.cpp: ASCII text lab08.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not strippedELF stands for "Executable and Linking Format" as you learned from the Reader and lecture, LSB means "Linux Standard Base" (a collection of APIs meant to be supported by all Linux systems), and SYSV abbreviates "UNIX System V." What else can you learn from these results? And what do you suppose "not stripped" means?
strings
command can be used to list the strings in a binary file. For
example, the relocatable object file (lab08.o) has two strings:
-bash-4.2$ strings lab08.o element isDid you read the source code? If so, then these strings should look familiar. Meanwhile, the executable file contains many more strings. Try `strings lab08` to see them.
nm
and objdump
The command nm
lists the "names" (symbols) in an object or load module, and
objdump
displays various information about such files. Both commands have
useful options that are worth learning.
-bash-4.2$ nm lab08.o 000000fa t _GLOBAL__sub_I_a 000000ba t _Z41__static_initialization_and_destruction_0ii 00000010 r _ZL1M U _ZNSolsEPFRSoS_E U _ZNSolsEi U _ZNSt8ios_base4InitC1Ev U _ZNSt8ios_base4InitD1Ev U _ZSt4cout U _ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_ 00000028 b _ZStL8__ioinit U _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc 00000028 d _ZZ4mainE1k U __cxa_atexit U __dso_handle 00000000 D a 00000000 B b 00000000 T mainThe values on the left side are addresses in hexadecimal, and you can show these values in decimal with the "-td" option. The next column shows the class of each symbol, where T and t are functions, D and d are data (global variables), r is read-only data, B and b are uninitialized data, and U is undefined.
Using objdump
can reveal more details about object files. At least one
option must be specified.
more
to view one screenful at a time:
objdump -S lab08.o | moreTry it now. According to
man
, the "-S" option will "display source
code intermixed with disassembly, if possible. Implies -d" where "-d" means disassemble the code.man objdump
or read the man page at http://sourceware.org/binutils/docs/binutils/objdump.html#objdump
to learn about more options. You might like the "-l" (ELL) option in particular - use
it along with the "-d" option as follows:
objdump -d -l lab08.o | more
nm
command. Do you remember that purpose? The -j option lets you specify
"just" particular sections. Interesting sections include .text, .data, .rodata, and .ctors,
among others.readelf
Although you could use objdump to inspect this load module, the readelf
tool gives
more information about load modules (so called because they are ready to be loaded
into memory for execution). As with objdump
, at least one option must be specified.
readelf
than it does
for objdump
? It means
"Display the sections' header" for readelf
. Use it now to find out the names
of the sections in lab08:
readelf -S lab08
a
stored?M
stored?k
stored?b
handled differently than other variables?i
is handled differently too. How?
First be sure you know the answers to all of questions a through f listed at the end of Step 4. Then ...
Get your TA's attention to inspect your work, and to record completion of your in-lab work. |
This time you may leave early! But be sure to get checked off first.
Step 5a. ONLY IF YOU RAN OUT OF TIME TO HAVE THE TA INSPECT YOUR WORK
If you must complete this assignment at CSIL, then submit it with the turnin program - but do NOT turn it in if the TA already checked you off.
First create a text file named lab08.txt, and type answers to each of the six questions at the end of Step 4 above. You MUST have both your name and your partner's name in lab08.txt in order to receive credit.
Bring up a terminal window on CSIL, and cd into the original pilot's ~/cs32/lab08 directory. Then type the following to turn in your text file:
turnin lab08@cs32 lab08.txt
Each pair of students must accomplish the following to earn full credit for this lab:
Prepared by Michael Costanzo.