Linking.

Slides:



Advertisements
Similar presentations
Hand-Held Devices and Embedded Systems Course Student: Tomás Sánchez López Student ID:
Advertisements

Copyright 2013 – Noah Mendelsohn Compiling C Programs Noah Mendelsohn Tufts University Web:
Fabián E. Bustamante, Spring 2007 Linking Today Static linking Object files Static & dynamically linked libraries Next time Exceptional control flows.
CSE 303 Lecture 16 Multi-file (larger) programs
Program Development Tools The GNU (GNU’s Not Unix) Toolchain The GNU toolchain has played a vital role in the development of the Linux kernel, BSD, and.
Linking & Loading CS-502 Operating Systems
Chapter 3 Loaders and Linkers
Linker and Loader. Program building into four stages (C Program) Preprocessing (Preprocessor) It processes include files, conditional compilation instructions.
Linkers and Loaders 1 Linkers & Loaders – A Programmers Perspective.
1 Starting a Program The 4 stages that take a C++ program (or any high-level programming language) and execute it in internal memory are: Compiler - C++
Generating Programs and Linking Professor Rick Han Department of Computer Science University of Colorado at Boulder.
Functions Definition: Instruction block called by name Good design: Each function should perform one task and do it well Functions are the basic building.
CS 330 What software engineers need to know about linking and a few things about execution.
C and Data Structures Baojian Hua
Guide To UNIX Using Linux Third Edition
Linking Topics Static linking Object files Static libraries Loading Dynamic linking of shared libraries CS213.
Computer Science 210 Computer Organization Introduction to C.
Adv. UNIX: large/131 Advanced UNIX v Objectives of these slides: –learn how to write/manage large programs consisting of multiple files, which.
Linking and Loading Linker collects procedures and links them together object modules into one executable program. Why isn't everything written as just.
UNIT 13 Separate Compilation.
CS 367 Linking Topics Static linking Object files Static libraries
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Linking February 20, 2001 Topics static linking object files static libraries loading dynamic linking of shared libraries class16.ppt “The course.
Linking Topics Static linking Object files Static libraries Loading.
1 CHAPTER 3 MODULAR PROGRAMMING. 2 Introduction  A library in C is a collection of general purpose and related functions.  2 types of libraries: Standard.
C++ Programming Lecture 11 Functions – Part III By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Linking Ⅱ.
CSE 251 Dr. Charles B. Owen Programming in C1 Compilation and Makefiles.
Processes and Threads-I Static and dynamic linking, Loading, Anatomy of a Process.
Linking October 5, 2002 Topics static linking object files static libraries loading dynamic linking of shared libraries Reading: Chapter 7 Problems: 7.8.
CS412/413 Introduction to Compilers and Translators April 14, 1999 Lecture 29: Linking and loading.
1 CS503: Operating Systems Spring 2014 Part 0: Program Structure Dongyan Xu Department of Computer Science Purdue University.
Chapter 13 : Symbol Management in Linking
Week 4 - Friday.  What did we talk about last time?  Some extra systems programming stuff  Scope.
CSc 453 Linking and Loading
CS252: Systems Programming Ninghui Li Based on Slides by Gustavo Rodriguez-Rivera Topic 2: Program Structure and Using GDB.
Linking I Topics Assembly and symbol resolution Static linking Systems I.
Program Translation and Execution I: Linking Sept. 29, 1998 Topics object files linkers class11.ppt Introduction to Computer Systems.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
Hello world !!! ASCII representation of hello.c.
Binding & Dynamic Linking Presented by: Raunak Sulekh(1013) Pooja Kapoor(1008)
Program Execution in Linux David Ferry, Chris Gill CSE 522S - Advanced Operating Systems Washington University in St. Louis St. Louis, MO
1 CS 192 Lecture 4 Winter 2003 December 8-9, 2003 Dr. Shafay Shamail.
Name Spaces: ALL versus OOL
Slides adapted from Bryant and O’Hallaron
Computer Science 210 Computer Organization
Executable program (p1)
CS 367 Linking Topics Static linking Make Utility Object files
Overview of today’s lecture
Linking Topics Static linking Object files Static libraries Loading
Linking & Loading.
Separate Assembly allows a program to be built from modules rather than a single source file assembler linker source file.
Program Execution in Linux
CS-3013 Operating Systems C-term 2008
CS1010 Programming Methodology
The Preprocessor Based on Chapter 1 in C++ for Java Programmers by Weiss When a C compiler is invoked, the first thing that happens is that the code is.
CS1010 Programming Methodology
Computer Science 210 Computer Organization
Generating Programs and Linking
“The course that gives CMU its Zip!”
Memory Allocation CS 217.
“The course that gives CMU its Zip!”
Linking & Loading CS-502 Operating Systems
Program Execution in Linux
Appendix F C Programming Environment on UNIX Systems
10/6: Lecture Topics C Brainteaser More on Procedure Call
Linking & Loading CS-502 Operating Systems
Instructors: Majd Sakr and Khaled Harras
Executable program (p1)
“The course that gives CMU its Zip!”
Presentation transcript:

Linking

Outline Symbol Resolution Relocation Suggested reading: 7.6~7.7

Symbol Resolution void foo(void) int main() { foo() ; return 0 ; } Unix> gcc –Wall –O2 –o linkerror linkerror.c /tmp/ccSz5uti.o: In function ‘main’: /tmp/ccSz5uti.o (.text+0x7): undefined reference to ‘foo’ collect2: ld return 1 exit status

Multiply Defined Global Symbols Strong: Functions and initialized global variables Weak: Uninitialized global variables Rules: Multiple strong symbols are not allowed Given a strong symbol and multiple weak symbols, choose the strong symbol Given multiple weak symbols, choose any of the weak symbol

Multiply Defined Global Symbols /*bar1.c*/ int main() { return 0; } /*foo2.c*/ int x=15213; /*bar2.c*/ void f() /*foo1.c*/

Multiply Defined Global Symbols /*foo3.c*/ #include <stdio.h> void f(); int x=15213; int main() { f(); printf(“x=%d\n”,x) return 0; } /*bar3.c*/ int x ; void f() { x = 15212 ; }

Multiply Defined Global Symbols /*foo4.c*/ #include <stdio.h> void f(); int x=15213; int main() { x=15213 f(); printf(“x=%d\n”,x) return 0; } /*bar4.c*/ int x ; void f() { x = 15212 ; }

Multiply Defined Global Symbols /*foo5.c*/ #include <stdio.h> void f(); int x=15213; int y=15212; int main() { f(); printf(“x=0x%x y=0x%x \n”, x, y) ; return 0; } /*bar5.c*/ double x ; void f() { x = -0.0 ; }

Packaging commonly used functions How to package functions commonly used by programmers? math, I/O, memory management, string manipulation, etc.

Packaging commonly used functions 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

Packaging commonly used functions Solution: 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 into executable