Presentation is loading. Please wait.

Presentation is loading. Please wait.

Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Object Code.

Similar presentations


Presentation on theme: "Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Object Code."— Presentation transcript:

1 Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Object Code

2 Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Object Code Defined Binary translation of assembler code Format acceptable to the hardware Often also called “binary” or “machine” code

3 Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Symbol Table Variable Name LocationOffset arg1base%ebp+4 arg2base%ebp+8 lvar1stack%esp lvar2stack%esp+4 lvar3stack%esp+8 int myfunc(int arg1,char arg2) { int lvar1; char lvar2; int lvar3=1; … }

4 Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Object Code consists of List of instructions and Data Each instruction is 1 or more bytes long (depends on instruction) Each instruction starts with an Operation Code (opcode) Opcodes are 0x00 – 0xff 0x0f – “extended” 2 byte op-code Arguments: binary code – Format depends on opcode Registers are numbered Offsets expressed as integers in object Addresses expressed in binary Leave the details to the compiler/dis-assembler Reference to data or functions outside of this file remain unresolved! (place-holders)

5 Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Object vs. Assembler Assembler “Man Readable” Labels “Variable Names” Line numbers Comments Object Machine Readable Addresses (or offsets) Addresses [-g exception] ------ [-g exception] ------

6 Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Disassembly Turning object code back into x86 assembler (ASCII) If no debug info is present All local variables expressed as (%esp) All parameter variables expressed as (%ebp) Function calls expressed as absolute address in memory (if loaded) or… Offset from main e.g. call 14 Offset from main to a placeholder for an unresolved reference Function names often kept even without -g

7 Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Link Edit (or Link) Joining multiple object files into a single binary executable file Resolving unresolved references Replace place-holders with real values where possible Note: Absolute addresses still unknown Keep track of locations via offsets rather than absolute locations Note: Not all unresolved references may be resolved Statically linked libraries resolved at link edit time Dynamically linked libraries remain unresolved – but checked Linker reports unresolved references that cannot be resolved dynamically Result: Binary executable file (in Windows,.exe. in Unix, no suffix)

8 Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 myprog.o Making a command myprog.s Assembler myprog.o Linker mycmd objdump staticlib.a myprog.o myprog.s “disassembly”

9 Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Running a command Loading the command: Parsing the command line into argc and argv Loading a binary file into memory Loading required dynamically linked libraries into memory Resolving unresolved references to dynamic libraries Replacing offsets with real addresses if required Push argc and argv on stack Executing the command: call main

10 Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Instruction Processing Cycle Fetch Instruction Decode Fetch Operands Execute Store Results EIP Increments EIP!


Download ppt "Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 Object Code."

Similar presentations


Ads by Google