csc374And407_lect2 - CSC 374/407 Computer Systems II...

Info icon This preview shows pages 1–15. Sign up to view the full content.

View Full Document Right Arrow Icon
CSC 374/407: Computer Systems II Lecture 2 Joseph Phillips De Paul University 2016 April 21 Copyright © 2011-2016 Joseph Phillips All rights reserved
Image of page 1

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

View Full Document Right Arrow Icon
Reading Bryant & O'Hallaron “ Computer Systems, 3 rd Ed. Chapter 7: Linking Hoover “ System Programming Program Management 6 Libraries 8.1-8.3, 8.6, 8.7
Image of page 2
Topics Linkers ELF Dynamic Linking
Image of page 3

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

View Full Document Right Arrow Icon
Today's topic (in time) Linking object files into executable files
Image of page 4
Today's topic (in space) Parts of the program the compiler actually has to create
Image of page 5

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

View Full Document Right Arrow Icon
How would you write a compiler? The direct approach: One program to compile everything : Everything includes your code (naturally!) Everything includes standard library code too ( hmm? )
Image of page 6
What?!? Re-compiling library code again and again?!? Sounds like a bad idea because 1. It's a waste of time : mostly it doesn't change. 2. So much for hiding implementation : When given easy-access to the source code some folks just can't stop themselves from trying to “optimize” their own code after seeing how the standard library code actually works. Even worse they can start to muck with it . . . So, let's give them the library code in a post-compiled but pre-integrated into a program . . .
Image of page 7

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

View Full Document Right Arrow Icon
Enter the linker! Compile standard code into libraries. Distribute libraries to user-programmers Programmers compile their own code to object files Linkers combine object files + libraries into executable files
Image of page 8
Linkers give you . . . Modularity You can write your program as small files can compile them individually You can use the libraries of others or build your own Efficiency Time : No need to re-compile everything if change one small file Space : Can incorporate from libraries only code that's actually used
Image of page 9

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

View Full Document Right Arrow Icon
There's a linker under the hood? You But all I have to say is gcc main.c Prof Joe Yes, 'cuz it does a number of things behind your back :” cpp : the C preprocessor The C/C++ compiler proper as : the assembler ld : the linker
Image of page 10
Let's try! You can tell gcc and g++ to stop along the way: gcc -E test.c # stop after preprocessing Output is post-processed C code to stdout gcc -S test.c # stop after compiling Output is assembly code in test.s gcc -c test.c # stop after assembling Output is object file test.o gcc test.c    # Go  all the way  baby! Output is executable file a.out
Image of page 11

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

View Full Document Right Arrow Icon
How do Linkers Spend Their Time? To merge object files they must: Resolve “external references:” extern int externallyDefinedVar ; extern int externallyDefinedFunc(int) ; int        locallyDefinedGlobalVar; int main () {   externallyDefinedVar=externallyDefinedFnc(5); } “Symbol” means either named code or data Move all symbols from several object files to distinct places in executable Update symbol locations extern tells the compiler “ Don’t freak-out if you do not see a definition for this symbol, the linker will handle it!
Image of page 12
Executable and Link Format (ELF) Assembler, Linker and Program Loader all need one format to describe object files and executables ELF derived from AT&T Unix System V and BSD Unifies description of: Relocatable object files (.o) Executables Shared object files (.so)
Image of page 13

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

View Full Document Right Arrow Icon
What's in an ELF?
Image of page 14
Image of page 15
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern