Lecture14-linking-part2

Lecture14-linking-part2 - 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 14 Announcements •P ro jec t 3 due Oct 14 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 2 10/17/2011 CS 3214 Fall 2011 3 Merging Relocatable Object Files into an Executable Object File headers main() 0 system code system data Relocatable Object Files Executable Object File .text .text .data system code 0 main() m.o int *ep = &e a() a.o int e = 7 a() int *ep = &e int e = 7 more system code int x = 15 int y system data int x = 15 .text .data .text .data .bss .symtab .debug .data uninitialized data .bss 0 0 10/17/2011 4 CS 3214 Fall 2011 Packaging Commonly Used Functions • How to package functions commonly used by programmers? – Math, I/O, memory management, string manipulation, etc. • Awkward given the linker framework so far: Awkward, given the linker framework so far: – Option 1: Put all functions in a single source file • Programmers link big object file into their programs • Space and time inefficient – Option 2: Put each function in a separate source file • Programmers explicitly link appropriate binaries into their programs • More efficient, but burdensome on the programmer 10/17/2011 5 CS 3214 Fall 2011 Static libraries (.a archive files) • Concatenate related relocatable object files into a single file with an index (called an archive). • Enhance linker so that it tries to resolve unresolved external references by looking for the symbols in one or more archives. • If an archive member file resolves reference, link member file into executable. 10/17/2011 6 CS 3214 Fall 2011
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 Static Libraries (archives) Translator p1.c p1.o Translator p2.c p2.o libc.a static library (archive) of relocatable object files concatenated into one file. executable object file (only contains code and data for libc functions that are called from p1.c and p2.c) Further improves modularity and efficiency by packaging commonly used functions [e.g., C standard library (libc), math library (libm)] Linker selectively includes only the .o files in the archive that are actually needed by the program. Linker (ld) p 10/17/2011 7 CS 3214 Fall 2011 How to link with static libraries • Suppose have /some/path/to/libfun.a –Two op t ions • Specify library directly gcc /some/path/to/libfun.a • Use –L and –l switch gcc … -L/some/path/to –lfun – Driver adds ‘lib[name].a’ – -L must come before -l •E x amp le : -liberty links in libiberty.a 10/17/2011 CS 3214 Fall 2011 8 Creating Static Libraries
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.

This note was uploaded on 12/31/2011 for the course CS 3214 taught by Professor Staff during the Fall '11 term at Virginia Tech.

Page1 / 5

Lecture14-linking-part2 - 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