2008SpCS61C-L19-ddg-runprogII-6up

2008SpCS61C-L19-ddg-runprogII-6up - UCB CS61C : Machine...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 19 – Running a Program II (Compiling, Assembling, Linking, Loading) 2008-03-06 I’m sure you’ve known that the number of people graduating with CS degrees has been dipping since its peak in 2000 due to (false?) perceptions of outsourcing, that CS is “just programming”, and other reasons. We may be on our way to turning that around; for the first time in 8 years the numbers of new CS majors has actually increased! It’s certainly a start! Lecturer SOE Dan Garcia developers.slashdot.org/developers/08/03/05/2113234.shtml 0 5000 10000 15000 20000 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 CS61C L19 Running a Program I (6) Garcia, Spring 2008 © UCB Where Are We Now? CS61C L19 Running a Program I (7) Garcia, Spring 2008 © UCB Input: Object Code files, information tables (e.g., foo.o,libc.o for MIPS) Output: Executable Code (e.g., a.out for MIPS) Combines several object ( .o ) files into a single executable (“linking ”) Enable Separate Compilation of files Changes to one file do not require recompilation of whole program Windows NT source was > 40 M lines of code! Old name “Link Editor” from editing the “links” in jump and link instructions Linker (1/3) CS61C L19 Running a Program I (8) Garcia, Spring 2008 © UCB .o file 1 text 1 data 1 info 1 .o file 2 text 2 data 2 info 2 Linker a.out Relocated text 1 Relocated text 2 Relocated data 1 Relocated data 2 Linker (2/3) CS61C L19 Running a Program I (9) Garcia, Spring 2008 © UCB Linker (3/3) Step 1: Take text segment from each .o file and put them together. Step 2: Take data segment from each .o file, put them together, and concatenate this onto end of text segments. Step 3: Resolve References Go through Relocation Table; handle each entry That is, fill in all absolute addresses CS61C L19 Running a Program I (10) Garcia, Spring 2008 © UCB PC-Relative Addressing ( beq , bne ) never relocate Absolute Address ( j , jal ) always relocate External Reference (usually jal ) always relocate Data Reference (often lui and ori ) always relocate Four Types of Addresses we’ll discuss
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS61C L19 Running a Program I (1 ) Garcia, Spring 2008 © UCB Absolute Addresses in MIPS Which instructions need relocation editing? J-format: jump, jump and link Loads and stores to variables in static area, relative to global pointer What about conditional branches? PC-relative addressing preserved even if code moves j/jal xxxxx lw/sw $gp $x address beq/bne $rs $rt address CS61C L19 Running a Program I (12) Garcia, Spring 2008 © UCB Resolving References (1/2) Linker assumes first word of first text segment is at address 0x00000000. (More later when we study “virtual memory”)
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6

2008SpCS61C-L19-ddg-runprogII-6up - UCB CS61C : Machine...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online