Lecture13-linking-part1

Lecture13-linking-part1 - Announcements Project 3 due Oct...

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

View Full Document Right Arrow Icon
1 CS 3214 Computer Systems Godmar Back Lecture 13 Announcements •P ro jec t 3 due Oct 14 • Exercise 5 coming out today CS 3214 Fall 2011 2 10/17/2011 Some of the following slides are taken with permission from Complete Powerpoint Lecture Notes for Computer Systems: A Programmer's Perspective (CS:APP) Randal E. Bryant and David R. O'Hallaron http://csapp.cs.cmu.edu/public/lectures.html LINKING AND LOADING Part 1 10/17/2011 CS 3214 Fall 2011 3 Topics • Static linking • Object files • Static libraries • Loading •Dynamic linking of shared libraries • Linking is a mundane topic – Full of quirks and seemingly arbitrary rules – But worth learning, IMO – Essential skill for any practicing C programmer – Necessary skill for productive practice in mixed-language and inter-language environments 10/17/2011 CS 3214 Fall 2011 4 Compiling and Linking Compiler driver coordinates all steps in the translation and linking process. – Typically included with each compilation system (e.g., gcc ) – Invokes preprocessor ( cpp ), compiler ( cc1 ), assembler ( as ), and linker ( ld ). – Passes command line arguments to appropriate phases Example: create executable p from m.c and a.c : bass> gcc -O2 -v -o p m.c a.c cpp [args] m.c /tmp/cca07630.i cc1 /tmp/cca07630.i m.c -O2 [args] -o /tmp/cca07630.s as [args] -o /tmp/cca076301.o /tmp/cca07630.s <similar process for a.c> ld -o p [system obj files] /tmp/cca076301.o /tmp/cca076302.o bass> cpp has been integrated into cc1 10/17/2011 5 CS 3214 Fall 2011 The Big Picture Program Code .c/.cc Source File 1 Assembly Code .s File 1 Program Code .c/.cc Source File 2 Assembly Code .s File 2 .h Header File 1 .h Header File 2 .h Header File 3 Preprocessor Compiler Compile Time 10/17/2011 CS 3214 Fall 2011 6 Object Code .o File 1 Object Code .o File 2 Executable Program1 Process1 Physical RAM (physically addressed) Assembler Linker Loader MMU Run Time Load Time Link Time Executable Program2 Process2 Process3
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 From High To Low Level: Resolving Symbolic Names • Compiler, Assembler, Linker all resolve symbolic names • Compiler: (function-)local variables, field names control flow statements names, control flow statements • Assembler: resolves labels • Linker resolves references to (file-)local (“static”) and global variables and function 10/17/2011 CS 3214 Fall 2011 7 Linker Puzzles int x; p1() {} int x; p2() {} int x int x; p1() {} p1() {} Question for each example: Will it link? If so, will it run? If so, what will happen? code1.c code2.c int x; int y; p1() {} double x; p2() {} int x=7; int y=5; p1() {} double x; p2() {} int x=7; p1() {} int x; p2() {} 10/17/2011 8 CS 3214 Fall 2011 What Does a Linker Do? Merges object files – Merges multiple relocatable (. o ) object files into a single executable object file that can loaded and executed by the loader. Resolves external references – As part of the merging process, resolves external references. External reference : reference to a symbol defined in another object file : reference to a symbol defined in another object file.
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 / 5

Lecture13-linking-part1 - Announcements Project 3 due Oct...

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