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 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=0xb14ebdd36dce7b3974347ca50361c550f4985dae, not stripped lab08.cpp: C source, ASCII text lab08.o: ELF 64-bit LSB relocatable, x86-64, 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 0000000000000000 D a 0000000000000000 B b U __cxa_atexit U __dso_handle 00000000000000e6 t _GLOBAL__sub_I_a 0000000000000000 T main 00000000000000a9 t _Z41__static_initialization_and_destruction_0ii 0000000000000010 r _ZL1M U _ZNSolsEi U _ZNSolsEPFRSoS_E U _ZNSt8ios_base4InitC1Ev U _ZNSt8ios_base4InitD1Ev U _ZSt4cout U _ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_ 0000000000000028 b _ZStL8__ioinit U _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc 0000000000000028 d _ZZ4mainE1kThe 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. |
Now look around the lab to find out if there are other students who might need your help. If yes, first ask them if they would like you to help, and if they say "Yes" then do help guide them through their remaining lab steps - without just giving them the exact solution. When all students are either successful or are being helped by someone else, then you may leave early! But make sure that you were 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:
Full credit is 100 points for this lab work, as there is no associated homework.
Prepared by Michael Costanzo.