Generating Programs and Linking. Professor Rick Han Department of Computer Science University of Colorado at Boulder

Size: px
Start display at page:

Download "Generating Programs and Linking. Professor Rick Han Department of Computer Science University of Colorado at Boulder"

Transcription

1 Generating Programs and Linking Professor Rick Han Department of Computer Science University of Colorado at Boulder

2 CSCI 3753 Announcements Moodle - posted last Thursday s lecture Programming shell assignment 0 due Thursday at 11:55 pm, not 11 am Introduction to Operating Systems Read Chapters 3 and 4 in the textbook

3 Operating System Architecture Posix, Win32, Java, C library API System call API OS Kernel App1 Scheduler App2 App3 System Libraries and Tools (Compilers, Shells, GUIs) VM File System Device Manager CPU Memory Disk Display Mouse I/O

4 What is an Application? A software program consist of a sequence of code instructions and data for now, let a simple app = a program Computer executes the instructions line by line code instructions operate on data Program P1

5 Loading and Executing a Program P1 binary Disk OS Loader P2 binary Main Memory Program P1 binary Fetch and Registers CPU Program Counter (PC) ALU Write

6 Loading and Executing a Program P1 binary Disk OS Loader P2 binary Main Memory Program P1 binary Machine instructions of binary executable shift left by 2 register R1 and put in address A invoke low level system call n to OS: syscall n jump to address B

7 Generating a Program s Binary Executable We program source code in a high-level language like C or Java, and use tools like compilers to create a program s binary executable file P1.c gcc can generate any of these stages Program P1 s Binary Executable Source Compiler P1.s Assembler P1.o Linker technically, there is a preprocessing step before the compiler. gcc -c will generate relocatable object files, and not run linker

8 Linking Multiple Object Files Into an file P1.c Executable foo2.o P1 or P1.exe Source Compiler cc1 P1.s Assembler as P1.o Linker ld foo3.o linker combines multiple.o object files into one binary executable file why split a program into multiple objects and then relink them? breaking up a program into multiple files, and compiling them separately, reduces amount of recompilation if a single file is edited don t have to recompile entire program, just the object file of the changed source file, then relink object files

9 Linking Multiple Object Files Into an file P1.c Executable foo2.o P1 or P1.exe Source Compiler cc1 P1.s Assembler as P1.o Linker ld foo3.o in combining multiple object files, the linker must resolve references to variables and functions defined in other object files - this is called symbol resolution relocate each object s internal addresses so that the executable s combination of objects is consistent in its memory references an object s code and data are compiled in its own private world to start at address zero

10 Linker Resolves Unknown Symbols P1.c extern void f1(...); int globalvar1=0; main(...) { f1(...) } foo2.c extern int globalvar1; void f1(...) { ---- } void f2(...) { ---- globalvar1 = 4; ---- } P1.o the P1.o object file will contain a list of unknown symbols, e.g. f1, in a symbol table foo2.o foo2.o s symbol table lists unknown symbols, e.g. globalvar1

11 Linker Resolves Unknown Symbols ELF relocatable object file contains following sections: ELF header (type, size, size/# sections) code (.text) data (.data,.bss,.rodata).data = initialized global variables.bss = uninitialized global variables (does not actually occupy space on disk, just a placeholder) symbol table (.symtab) relocation info (.rel.text,.rel.data) debug symbol table (.debug only if -g compile flag used) line info (map C &.text line #s only if -g ) string table (for symbol tables) ELF relocatable object file ELF header.text.rodata.data.bss.symtab.rel.text.rel.data.debug.line.strtab Section header table

12 Linker Resolves Unknown Symbols Symbol table contains 3 types of symbols: global symbols - defined in this object global symbols referenced but not defined here local symbols defined and referenced exclusively by this object, e.g. static global variables and functions local symbols are not equivalent to local variables, which get allocated on the stack at run time

13 Linker Resolves Unknown Symbols global symbol referenced here but defined elsewhere global symbols defined here extern float f1(); int globalvar1=0; void f2(...) { local symbol } static int x=-1; The symbol table informs the Linker where symbols referenced or referenceable by each object file can be found: if another file references globalvar1, then look here for info if this file reference f2, then another object file s symbol table will mention f2

14 Linker Resolves Unknown Symbols Each entry in the ELF symbol table looks like: typedef struct { int name; /* string table offset */ int value; /* section offset or VM address */ int size; /* object size in bytes */ char type:4, /* data, func, section or src file name (4 bits) */ binding:4;/* local or global (4 bits) */ char reserved; /* unused */ char section; /* section header index, ABS, UNDEF, */ } ELF_Symbol; here s where we flag the undefined status

15 Linker Resolves Unknown Symbols During linking, the linker goes through each input object file and determines if unknown symbols are defined in other object files P1.o relocatableobject file P2.o P3.o.symtab function f1() in P1.o is referenced but not defined, hence unknown defined in P2?.symtab Linker No defined in P3? Yes.symtab

16 Linker Resolves Unknown Symbols What if two object files use the same name for a global variable? Linker resolves multiply defined global symbols functions and initialized global variables are defined as strong symbols, while uninitialized global variables are weak symbols Rule 1: multiple strong symbols are not allowed Rule 2: choose the strong symbol over the weak symbol Rule 3: given multiple weak symbols, choose any one

17 Linker Resolves Unknown Symbols Linking with static libraries Bundle together many related.o files together into a single file called a library or.a file e.g. the C library libc.a contains printf(), strcpy(), random(), atoi(), etc. library is created using the archive ar tool the library is input to the linker as one file linker can accept multiple libraries linker copies only those object modules in the library that are referenced by the application program Example: gcc main.c /usr/lib/libm.a /usr/lib/libc.a

18 Linker Resolves Unknown Symbols a static library is a collection of relocatable object modules group together related object modules within each object, can further group related functions if an application links to libfoo.a, and only calls a function in foo3.o, then only foo3.o will be linked into the program libfoo.a foo1.o foo2.o foo3.o foo4.o

19 Linker Resolves Unknown Symbols Linker scans object files and libraries sequentially left to right on command line to resolve unknown symbols for each input file on command line, linker updates a list of defined symbols with object s defined symbols tries to resolve the undefined symbols (from object and from list of previously undefined symbols) with the list of previously defined symbols carries over the list of defined and undefined symbols to next input object file so linker looks for undefined symbols only after they re undefined! it doesn t go back over the entire set of input files to resolve the unknown symbol if an unknown symbol becomes referenced after it was defined, then linker won t be able to resolve the symbol! Thus, order on the command line is important - put libraries last!

20 Linker Resolves Unknown Symbols Example: gcc libfoo.a main.c main.c calls a function f1 defined in libfoo.a scanning left to right, when linker hits libfoo.a, there are no unresolved symbols, so no object modules are copied when linker hits main.c, f1 is unresolved and gets added to unresolved list Since there are no more input files, the linker stops and generates a linking error: /tmp/something.o: In function main : /tmp/something.o: undefined reference to f1

21 Linker Resolves Unknown Symbols Example: gcc main.c libfoo.a main.c calls a function f1 defined in libfoo.a scanning left to right, when linker hits main.c, it will add f1 to the list of unresolved references when linker next hits libfoo.a, it will look for f1 in the library s object modules, see that it is found, and add the object module to the linked program No errors are generated. A binary executable is generated. Lesson #1: the order of linking can be important, so put libraries at the end of command lines Lesson #2: an undefined symbol error can also mean that you didn t link in the right libraries, didn t add right library path forgot to define the symbol somewhere in your code

22 Linker Relocates Addresses After resolving symbols, the linker relocates addresses when combining the different object modules merges separate code.text sections into a single.text section merges separate.data sections into a single.data section each section is assigned a memory address then each symbol reference in the code and data sections is reassigned to the correct memory address looks at.relo.text and.relo.data to find relocation entries of references that needed address translation these are virtual memory addresses that are translated at load time into real run-time memory addresses

23 Linked ELF Executable Object File ELF executable object file contains following sections: ELF header (type, size, size/# sections) segment header table.init (program s entry point, i.e. address of first instruction) other sections similar Note the absence of.rel.tex and.rel.data - they ve been relocated! Ready to be loaded into memory and run only sections through.bss are loaded into memory.symtab and below are not loaded into memory code section is read-only.data and.bss are read/write ELF executable object file ELF header segment header table.init.text.rodata.data.bss.symtab.debug.line.strtab Section header table

24 Loading Executable Object Files Run-time memory image Essentially code, data, stack, and heap and data loaded from executable file Stack grows downward, heap grows upward Run-time memory User stack Unallocated Heap Read/write.data,.bss Read-only.init,.text,.rodata

Link 3. Symbols. Young W. Lim Mon. Young W. Lim Link 3. Symbols Mon 1 / 42

Link 3. Symbols. Young W. Lim Mon. Young W. Lim Link 3. Symbols Mon 1 / 42 Link 3. Symbols Young W. Lim 2017-09-11 Mon Young W. Lim Link 3. Symbols 2017-09-11 Mon 1 / 42 Outline 1 Linking - 3. Symbols Based on Symbols Symbol Tables Symbol Table Examples main.o s symbol table

More information

COS 318: Operating Systems

COS 318: Operating Systems COS 318: Operating Systems Overview Kai Li Computer Science Department Princeton University (http://www.cs.princeton.edu/courses/cos318/) Important Times Lectures 9/20 Lecture is here Other lectures in

More information

CSE 2421: Systems I Low-Level Programming and Computer Organization. Linking. Presentation N. Introduction to Linkers

CSE 2421: Systems I Low-Level Programming and Computer Organization. Linking. Presentation N. Introduction to Linkers CSE 2421: Systems I Low-Level Programming and Computer Organization Linking Read/Study: Bryant 7.1 7.10 Gojko Babić 11-15-2017 Introduction to Linkers Linking is the process of collecting and combining

More information

Exercise Session 7 Computer Architecture and Systems Programming

Exercise Session 7 Computer Architecture and Systems Programming Systems Group Department of Computer Science ETH Zürich Exercise Session 7 Computer Architecture and Systems Programming Herbstsemester 2014 Review of last week s excersice structs / arrays in Assembler

More information

COS 318: Operating Systems. Overview. Andy Bavier Computer Science Department Princeton University

COS 318: Operating Systems. Overview. Andy Bavier Computer Science Department Princeton University COS 318: Operating Systems Overview Andy Bavier Computer Science Department Princeton University http://www.cs.princeton.edu/courses/archive/fall10/cos318/ Logistics Precepts: Tue: 7:30pm-8:30pm, 105 CS

More information

CSCI341. Lecture 22, MIPS Programming: Directives, Linkers, Loaders, Memory

CSCI341. Lecture 22, MIPS Programming: Directives, Linkers, Loaders, Memory CSCI341 Lecture 22, MIPS Programming: Directives, Linkers, Loaders, Memory REVIEW Assemblers understand special commands called directives Assemblers understand macro commands Assembly programs become

More information

A Simplistic Program Translation Scheme

A Simplistic Program Translation Scheme A Simplistic Program Translation Scheme m.c ASCII source file Translator p Binary executable object file (memory image on disk) Problems: Efficiency: small change requires complete recompilation Modularity:

More information

9/19/18. COS 318: Operating Systems. Overview. Important Times. Hardware of A Typical Computer. Today CPU. I/O bus. Network

9/19/18. COS 318: Operating Systems. Overview. Important Times. Hardware of A Typical Computer. Today CPU. I/O bus. Network Important Times COS 318: Operating Systems Overview Jaswinder Pal Singh and a Fabulous Course Staff Computer Science Department Princeton University (http://www.cs.princeton.edu/courses/cos318/) u Precepts:

More information

Linking. Explain what ELF format is. Explain what an executable is and how it got that way. With huge thanks to Steve Chong for his notes from CS61.

Linking. Explain what ELF format is. Explain what an executable is and how it got that way. With huge thanks to Steve Chong for his notes from CS61. Linking Topics How do you transform a collection of object files into an executable? How is an executable structured? Why is an executable structured as it is? Learning Objectives: Explain what ELF format

More information

Slide 6-1. Processes. Operating Systems: A Modern Perspective, Chapter 6. Copyright 2004 Pearson Education, Inc.

Slide 6-1. Processes. Operating Systems: A Modern Perspective, Chapter 6. Copyright 2004 Pearson Education, Inc. Slide 6-1 6 es Announcements Slide 6-2 Extension til Friday 11 am for HW #1 Previous lectures online Program Assignment #1 online later today, due 2 weeks from today Homework Set #2 online later today,

More information

(Extract from the slides by Terrance E. Boult

(Extract from the slides by Terrance E. Boult What software engineers need to know about linking and a few things about execution (Extract from the slides by Terrance E. Boult http://vast.uccs.edu/~tboult/) A Simplistic Program Translation Scheme

More information

Computer Systems Organization

Computer Systems Organization Computer Systems Organization 1 Outline 2 A software view User Interface 3 How it works 4 The gcc compilation system 5 The gcc compilation system hello.c (source code) Pre-processor (cpp) hello.i (modified

More information

Link 7.A Static Linking

Link 7.A Static Linking Link 7.A Static Linking Young W. Lim 2019-01-04 Fri Young W. Lim Link 7.A Static Linking 2019-01-04 Fri 1 / 27 Outline 1 Linking - 7.A Static Linking Based on Static Library Examples Linking with Static

More information

LINKING. Jo, Heeseung

LINKING. Jo, Heeseung LINKING Jo, Heeseung PROGRAM TRANSLATION (1) A simplistic program translation scheme m.c ASCII source file Translator p Binary executable object file (memory image on disk) Problems: - Efficiency: small

More information

CSE2421 Systems1 Introduction to Low-Level Programming and Computer Organization

CSE2421 Systems1 Introduction to Low-Level Programming and Computer Organization Spring 2013 CSE2421 Systems1 Introduction to Low-Level Programming and Computer Organization Kitty Reeves TWRF 8:00-8:55am 1 Compiler Drivers = GCC When you invoke GCC, it normally does preprocessing,

More information

Process Environment. Pradipta De

Process Environment. Pradipta De Process Environment Pradipta De pradipta.de@sunykorea.ac.kr Today s Topic Program to process How is a program loaded by the kernel How does kernel set up the process Outline Review of linking and loading

More information

CS2141 Software Development using C/C++ Libraries

CS2141 Software Development using C/C++ Libraries CS2141 Software Development using C/C++ Compilation and linking /* p1.c */ int x; int z; main() { x=0; z=0; printf("f(3)=%d x=%d z=%d\n",f(3),x,z); } Code for int f(int) not available yet, nor printf()

More information

CSci 4061 Introduction to Operating Systems. Programs in C/Unix

CSci 4061 Introduction to Operating Systems. Programs in C/Unix CSci 4061 Introduction to Operating Systems Programs in C/Unix Today Basic C programming Follow on to recitation Structure of a C program A C program consists of a collection of C functions, structs, arrays,

More information

COMPILING OBJECTS AND OTHER LANGUAGE IMPLEMENTATION ISSUES. Credit: Mostly Bryant & O Hallaron

COMPILING OBJECTS AND OTHER LANGUAGE IMPLEMENTATION ISSUES. Credit: Mostly Bryant & O Hallaron COMPILING OBJECTS AND OTHER LANGUAGE IMPLEMENTATION ISSUES Credit: Mostly Bryant & O Hallaron Word-Oriented Memory Organization Addresses Specify Byte Locations Address of first byte in word Addresses

More information

CS 550 Operating Systems Spring Process I

CS 550 Operating Systems Spring Process I CS 550 Operating Systems Spring 2018 Process I 1 Process Informal definition: A process is a program in execution. Process is not the same as a program. Program is a passive entity stored in the disk Process

More information

Executables and Linking. CS449 Spring 2016

Executables and Linking. CS449 Spring 2016 Executables and Linking CS449 Spring 2016 Remember External Linkage Scope? #include int global = 0; void foo(); int main() { foo(); printf( global=%d\n, global); return 0; } extern int

More information

Executables and Linking. CS449 Fall 2017

Executables and Linking. CS449 Fall 2017 Executables and Linking CS449 Fall 2017 Remember External Linkage Scope? #include int global = 0; void foo(); int main() { } foo(); printf( global=%d\n, global); return 0; extern int

More information

Lecture 8: linking CS 140. Dawson Engler Stanford CS department

Lecture 8: linking CS 140. Dawson Engler Stanford CS department Lecture 8: linking CS 140 Dawson Engler Stanford CS department Today s Big Adventure Linking f.c gcc f.s as f.o c.c gcc c.s as c.o ld a.out how to name and refer to things that don t exist yet how to merge

More information

Compiler Drivers = GCC

Compiler Drivers = GCC Compiler Drivers = GCC When you invoke GCC, it normally does preprocessing, compilation, assembly and linking, as needed, on behalf of the user accepts options and file names as operands % gcc O1 -g -o

More information

CIT 595 Spring System Software: Programming Tools. Assembly Process Example: First Pass. Assembly Process Example: Second Pass.

CIT 595 Spring System Software: Programming Tools. Assembly Process Example: First Pass. Assembly Process Example: Second Pass. System Software: Programming Tools Programming tools carry out the mechanics of software creation within the confines of the operating system and hardware environment Linkers & Loaders CIT 595 Spring 2010

More information

COS 318: Operating Systems. Overview. Prof. Margaret Martonosi Computer Science Department Princeton University

COS 318: Operating Systems. Overview. Prof. Margaret Martonosi Computer Science Department Princeton University COS 318: Operating Systems Overview Prof. Margaret Martonosi Computer Science Department Princeton University http://www.cs.princeton.edu/courses/archive/fall11/cos318/ Announcements Precepts: Tue (Tonight)!

More information

High Performance Computing Lecture 1. Matthew Jacob Indian Institute of Science

High Performance Computing Lecture 1. Matthew Jacob Indian Institute of Science High Performance Computing Lecture 1 Matthew Jacob Indian Institute of Science Agenda 1. Program execution: Compilation, Object files, Function call and return, Address space, Data & its representation

More information

Incremental Linking with Gold

Incremental Linking with Gold Incremental Linking with Gold Linux Foundation Collaboration Summit April 5, 2012 Cary Coutant This work is licensed under the Creative Commons Attribution-NoDerivs 3.0 Unported License. To view a copy

More information

Linking Oct. 15, 2002

Linking Oct. 15, 2002 15-213 The course that gives CMU its Zip! Topics Linking Oct. 15, 2002 Static linking Object files Static libraries Loading Dynamic linking of shared libraries class15.ppt Linker Puzzles int x; p1() {}

More information

Stacks and Frames Demystified. CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han

Stacks and Frames Demystified. CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han s and Frames Demystified CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han Announcements Homework Set #2 due Friday at 11 am - extension Program Assignment #1 due Tuesday Feb. 15 at 11 am - note extension

More information

Systems I. Linking II

Systems I. Linking II Systems I Linking II Topics Relocation Static libraries Loading Dynamic linking of shared libraries Relocating Symbols and Resolving External References Symbols are lexical entities that name functions

More information

A software view. Computer Systems. The Compilation system. How it works. 1. Preprocesser. 1. Preprocessor (cpp)

A software view. Computer Systems. The Compilation system. How it works. 1. Preprocesser. 1. Preprocessor (cpp) A software view User Interface Computer Systems MTSU CSCI 3240 Spring 2016 Dr. Hyrum D. Carroll Materials from CMU and Dr. Butler How it works hello.c #include int main() { printf( hello, world\n

More information

Language Translation. Compilation vs. interpretation. Compilation diagram. Step 1: compile. Step 2: run. compiler. Compiled program. program.

Language Translation. Compilation vs. interpretation. Compilation diagram. Step 1: compile. Step 2: run. compiler. Compiled program. program. Language Translation Compilation vs. interpretation Compilation diagram Step 1: compile program compiler Compiled program Step 2: run input Compiled program output Language Translation compilation is translation

More information

ECE 498 Linux Assembly Language Lecture 1

ECE 498 Linux Assembly Language Lecture 1 ECE 498 Linux Assembly Language Lecture 1 Vince Weaver http://www.eece.maine.edu/ vweaver vincent.weaver@maine.edu 13 November 2012 Assembly Language: What s it good for? Understanding at a low-level what

More information

Linking and Loading. ICS312 - Spring 2010 Machine-Level and Systems Programming. Henri Casanova

Linking and Loading. ICS312 - Spring 2010 Machine-Level and Systems Programming. Henri Casanova Linking and Loading ICS312 - Spring 2010 Machine-Level and Systems Programming Henri Casanova (henric@hawaii.edu) The Big Picture High-level code char *tmpfilename; int num_schedulers=0; int num_request_submitters=0;

More information

CS429: Computer Organization and Architecture

CS429: Computer Organization and Architecture CS429: Computer Organization and Architecture Dr. Bill Young Department of Computer Sciences University of Texas at Austin Last updated: January 13, 2017 at 08:55 CS429 Slideset 25: 1 Relocating Symbols

More information

Lec 13: Linking and Memory. Kavita Bala CS 3410, Fall 2008 Computer Science Cornell University. Announcements

Lec 13: Linking and Memory. Kavita Bala CS 3410, Fall 2008 Computer Science Cornell University. Announcements Lec 13: Linking and Memory Kavita Bala CS 3410, Fall 2008 Computer Science Cornell University PA 2 is out Due on Oct 22 nd Announcements Prelim Oct 23 rd, 7:30-9:30/10:00 All content up to Lecture on Oct

More information

M2 Instruction Set Architecture

M2 Instruction Set Architecture M2 Instruction Set Architecture Module Outline Addressing modes. Instruction classes. MIPS-I ISA. Translating and starting a program. High level languages, Assembly languages and object code. Subroutine

More information

Deadlock Detection. Several Instances of a Resource Type. Single Instance of Each Resource Type

Deadlock Detection. Several Instances of a Resource Type. Single Instance of Each Resource Type CS341: Operating System Lect26: 08 th Oct 2014 Dr. A. Sahu Dept of Comp. Sc. & Engg. Indian Institute of Technology Guwahati Deadlock Conditions Mutex, Hold & Wait, No Preemption and Circular wait Deadlock

More information

Computer Organization: A Programmer's Perspective

Computer Organization: A Programmer's Perspective A Programmer's Perspective Linking Gal A. Kaminka galk@cs.biu.ac.il A Simplistic Program Translation Scheme m.c ASCII source file Translator p Binary executable object file (memory image on disk) Problems:

More information

Outline. Unresolved references

Outline. Unresolved references Outline CS 4120 Introduction to Compilers Andrew Myers Cornell University Lecture 36: Linking and Loading 21 Nov 11 Static linking Object files Libraries Shared libraries Relocatable Dynamic linking explicit

More information

Memory and C/C++ modules

Memory and C/C++ modules Memory and C/C++ modules From Reading #5 and mostly #6 More OOP topics (templates; libraries) as time permits later Program building l Have: source code human readable instructions l Need: machine language

More information

Today s Big Adventure

Today s Big Adventure Today s Big Adventure - How to name and refer to things that don t exist yet - How to merge separate name spaces into a cohesive whole Readings - man a.out & elf on a Solaris machine - run nm or objdump

More information

Relocating Symbols and Resolving External References. CS429: Computer Organization and Architecture. m.o Relocation Info

Relocating Symbols and Resolving External References. CS429: Computer Organization and Architecture. m.o Relocation Info Relocating Symbols and Resolving External References CS429: Computer Organization and Architecture Dr. Bill Young Department of Computer Sciences University of Texas at Austin Last updated: January 13,

More information

Today s Big Adventure

Today s Big Adventure 1/34 Today s Big Adventure - How to name and refer to things that don t exist yet - How to merge separate name spaces into a cohesive whole Readings - man a.out & elf on a Solaris machine - run nm or objdump

More information

COS 318: Operating Systems. Overview. Jaswinder Pal Singh Computer Science Department Princeton University

COS 318: Operating Systems. Overview. Jaswinder Pal Singh Computer Science Department Princeton University COS 318: Operating Systems Overview Jaswinder Pal Singh Computer Science Department Princeton University (http://www.cs.princeton.edu/courses/cos318/) Important Times u Precepts: l Mon: 7:30-8:20pm, 105

More information

ECE 598 Advanced Operating Systems Lecture 10

ECE 598 Advanced Operating Systems Lecture 10 ECE 598 Advanced Operating Systems Lecture 10 Vince Weaver http://web.eece.maine.edu/~vweaver vincent.weaver@maine.edu 22 February 2018 Announcements Homework #5 will be posted 1 Blocking vs Nonblocking

More information

Introduction to Computer Systems

Introduction to Computer Systems CS-213 Introduction to Computer Systems Yan Chen Topics: Staff, text, and policies Lecture topics and assignments Lab rationale CS 213 F 06 Teaching staff Instructor TA Prof. Yan Chen (Thu 2-4pm, Tech

More information

C03c: Linkers and Loaders

C03c: Linkers and Loaders CISC 3320 MW3 C03c: Linkers and Loaders Hui Chen Department of Computer & Information Science CUNY Brooklyn College 2/4/2019 CUNY Brooklyn College: CISC 3320 OS 1 Outline Linkers and linking Loaders and

More information

Lectures 5-6: Introduction to C

Lectures 5-6: Introduction to C Lectures 5-6: Introduction to C Motivation: C is both a high and a low-level language Very useful for systems programming Faster than Java This intro assumes knowledge of Java Focus is on differences Most

More information

ECE 471 Embedded Systems Lecture 5

ECE 471 Embedded Systems Lecture 5 ECE 471 Embedded Systems Lecture 5 Vince Weaver http://web.eece.maine.edu/~vweaver vincent.weaver@maine.edu 13 September 2016 HW#2 is due Thursday It is going OK? Announcements 1 Homework #1 Review Characteristics

More information

12: Memory Management

12: Memory Management 12: Memory Management Mark Handley Address Binding Program goes through multiple steps from compilation to execution. At some stage, addresses in the program must be bound to physical memory addresses:

More information

ECE 471 Embedded Systems Lecture 4

ECE 471 Embedded Systems Lecture 4 ECE 471 Embedded Systems Lecture 4 Vince Weaver http://www.eece.maine.edu/ vweaver vincent.weaver@maine.edu 12 September 2013 Announcements HW#1 will be posted later today For next class, at least skim

More information

From Source to Execution:

From Source to Execution: From Source to Execution: Translation and Linking CSE 410, Spring 2009 Computer Systems http://www.cs.washington.edu/410 4/16/2009 cse410-08-link 2006-09 Perkins, DW Johnson and University of Washington

More information

CS399 New Beginnings. Jonathan Walpole

CS399 New Beginnings. Jonathan Walpole CS399 New Beginnings Jonathan Walpole Memory Management Memory Management Memory a linear array of bytes - Holds O.S. and programs (processes) - Each cell (byte) is named by a unique memory address Recall,

More information

Link 7. Static Linking

Link 7. Static Linking Link 7. Static Linking Young W. Lim 2018-12-21 Fri Young W. Lim Link 7. Static Linking 2018-12-21 Fri 1 / 41 Outline 1 Linking - 7. Static Linking Based on Static Library Examples Linking with Static Libraries

More information

Draft. Chapter 1 Program Structure. 1.1 Introduction. 1.2 The 0s and the 1s. 1.3 Bits and Bytes. 1.4 Representation of Numbers in Memory

Draft. Chapter 1 Program Structure. 1.1 Introduction. 1.2 The 0s and the 1s. 1.3 Bits and Bytes. 1.4 Representation of Numbers in Memory Chapter 1 Program Structure In the beginning there were 0s and 1s. GRR 1.1 Introduction In this chapter we will talk about memory: bits, bytes and how data is represented in the computer. We will also

More information

CSC 369 Operating Systems

CSC 369 Operating Systems CSC 369 Operating Systems Lecture 6: Memory management Bogdan Simion Memory hierarchy 1 KB Registers Speed Price 32 128 KB L1 cache 2 8 MB L2 cache 4 16 GB DRAM 1 2 TB Disk 2 But that s not all Sequential

More information

Introduction to Computer Systems

Introduction to Computer Systems Introduction to Computer Systems Today: Welcome to EECS 213 Lecture topics and assignments Next time: Bits & bytes and some Boolean algebra Fabián E. Bustamante, Spring 2010 Welcome to Intro. to Computer

More information

Making Address Spaces Smaller

Making Address Spaces Smaller ICS332 Operating Systems Spring 2018 Smaller Address Spaces Having small address spaces is always a good idea This is good for swapping: don t swap as often (because if address spaces are small, then RAM

More information

Example C program. 11: Linking. Why linkers? Modularity! Static linking. Why linkers? Efficiency! What do linkers do? 10/28/2013

Example C program. 11: Linking. Why linkers? Modularity! Static linking. Why linkers? Efficiency! What do linkers do? 10/28/2013 Example C program 11: Linking Computer Architecture and Systems Programming 252 61, Herbstsemester 213 Timothy Roscoe main.c int buf[2] = 1, 2; swap(); return ; swap.c static int *bufp = &buf[]; void swap()

More information

COSC345 Software Engineering. Linkers Loaders Libraries

COSC345 Software Engineering. Linkers Loaders Libraries COSC345 Software Engineering Linkers Loaders Libraries Sources of error A bunch of statistics Compiling Linking Loading Libraries Static libraries Overlays Shared libraries DLLs Outline Sources of Errors

More information

238P: Operating Systems. Lecture 7: Basic Architecture of a Program. Anton Burtsev January, 2018

238P: Operating Systems. Lecture 7: Basic Architecture of a Program. Anton Burtsev January, 2018 238P: Operating Systems Lecture 7: Basic Architecture of a Program Anton Burtsev January, 2018 What is a program? What parts do we need to run code? Parts needed to run a program Code itself By convention

More information

Programs in memory. The layout of memory is roughly:

Programs in memory. The layout of memory is roughly: Memory 1 Programs in memory 2 The layout of memory is roughly: Virtual memory means that memory is allocated in pages or segments, accessed as if adjacent - the platform looks after this, so your program

More information

Reminder: compiling & linking

Reminder: compiling & linking Reminder: compiling & linking source file 1 object file 1 source file 2 compilation object file 2 library object file 1 linking (relocation + linking) load file source file N object file N library object

More information

CS140 - Summer Handout #8

CS140 - Summer Handout #8 CS1 - Summer 2 - Handout # Today s Big Adventure Linking f.c gcc f.s as c.c gcc c.s as c.o how to name and refer to things that don t exist yet how to merge separate name spaces into a cohesive whole Readings

More information

Linking Oct. 26, 2009"

Linking Oct. 26, 2009 Linking Oct. 26, 2009" Linker Puzzles" int x; p1() {} p1() {} int x; p1() {} int x; p2() {} int x; int y; p1() {} int x=7; int y=5; p1() {} double x; p2() {} double x; p2() {} int x=7; p1() {} int x; p2()

More information

Chapter 2: System Structures

Chapter 2: System Structures Chapter 2: System Structures Chapter 2: System Structures 2.1 Operating-System Services 2.2 User and Operating-System Interface 2.3 System Calls 2.4 Types of System Calls 2.5 System Programs 2.6 Operating-System

More information

Function Calls and Stack Allocation

Function Calls and Stack Allocation Function Calls and Allocation Topics Pushing and Popping Role of in (Automatic) Allocation Parameter Passing Region of memory managed with stack discipline Grows toward lower addresses pointer indicates

More information

CS 390 Chapter 8 Homework Solutions

CS 390 Chapter 8 Homework Solutions CS 390 Chapter 8 Homework Solutions 8.3 Why are page sizes always... Page sizes that are a power of two make it computationally fast for the kernel to determine the page number and offset of a logical

More information

Function Calls and Stack Allocation

Function Calls and Stack Allocation Function Calls and Allocation Topics Pushing and Popping Role of in (Automatic) Allocation Parameter Passing Region of memory managed with stack discipline Grows toward lower addresses pointer indicates

More information

Stack. Stack. Function Calls and Stack Allocation. Stack Popping Popping. Stack Pushing Pushing. Page 1

Stack. Stack. Function Calls and Stack Allocation. Stack Popping Popping. Stack Pushing Pushing. Page 1 Function Calls and Allocation Region of memory managed with stack discipline Grows toward lower addresses pointer indicates lowest stack address Bottom Increasing Addresses Topics Pushing and Popping Role

More information

Linking and Loading. CS61, Lecture 16. Prof. Stephen Chong October 25, 2011

Linking and Loading. CS61, Lecture 16. Prof. Stephen Chong October 25, 2011 Linking and Loading CS61, Lecture 16 Prof. Stephen Chong October 25, 2011 Announcements Midterm exam in class on Thursday 80 minute exam Open book, closed note. No electronic devices allowed Please be

More information

Linkers and Loaders. CS 167 VI 1 Copyright 2008 Thomas W. Doeppner. All rights reserved.

Linkers and Loaders. CS 167 VI 1 Copyright 2008 Thomas W. Doeppner. All rights reserved. Linkers and Loaders CS 167 VI 1 Copyright 2008 Thomas W. Doeppner. All rights reserved. Does Location Matter? int main(int argc, char *[ ]) { return(argc); } main: pushl %ebp ; push frame pointer movl

More information

Objectives. Chapter 2: Operating-System Structures. 2.1 Operating System Services

Objectives. Chapter 2: Operating-System Structures. 2.1 Operating System Services Objectives Chapter 2: Operating-System Structures To describe the services an operating system provides to users, processes, and other systems To discuss the various ways of structuring an operating system

More information

Systems Programming and Computer Architecture ( ) Timothy Roscoe

Systems Programming and Computer Architecture ( ) Timothy Roscoe Systems Group Department of Computer Science ETH Zürich Systems Programming and Computer Architecture (252-0061-00) Timothy Roscoe Herbstsemester 2016 AS 2016 Linking 1 12: Linking Computer Architecture

More information

Operating Systems. 09. Memory Management Part 1. Paul Krzyzanowski. Rutgers University. Spring 2015

Operating Systems. 09. Memory Management Part 1. Paul Krzyzanowski. Rutgers University. Spring 2015 Operating Systems 09. Memory Management Part 1 Paul Krzyzanowski Rutgers University Spring 2015 March 9, 2015 2014-2015 Paul Krzyzanowski 1 CPU Access to Memory The CPU reads instructions and reads/write

More information

Department of Computer Science and Engineering Yonghong Yan

Department of Computer Science and Engineering Yonghong Yan Appendix A and Chapter 2.12: Compiler, Assembler, Linker and Program Execution CSCE 212 Introduction to Computer Architecture, Spring 2019 https://passlab.github.io/csce212/ Department of Computer Science

More information

Midterm. Median: 56, Mean: "midterm.data" using 1:2 1 / 37

Midterm. Median: 56, Mean: midterm.data using 1:2 1 / 37 30 Midterm "midterm.data" using 1:2 25 20 15 10 5 0 0 20 40 60 80 100 Median: 56, Mean: 53.13 1 / 37 Today s Big Adventure f.c gcc f.s as f.o c.c gcc c.s as c.o ld a.out How to name and refer to things

More information

Lecture 10: Program Development versus Execution Environment

Lecture 10: Program Development versus Execution Environment Lecture 10: Program Development versus Execution Environment CSE 30: Computer Organization and Systems Programming Winter 2010 Rajesh Gupta / Ryan Kastner Dept. of Computer Science and Engineering University

More information

Computer Systems A Programmer s Perspective 1 (Beta Draft)

Computer Systems A Programmer s Perspective 1 (Beta Draft) Computer Systems A Programmer s Perspective 1 (Beta Draft) Randal E. Bryant David R. O Hallaron August 1, 2001 1 Copyright c 2001, R. E. Bryant, D. R. O Hallaron. All rights reserved. 2 Contents Preface

More information

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 7

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 7 CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2017 Lecture 7 LAST TIME Dynamic memory allocation and the heap: A run-time facility that satisfies multiple needs: Programs can use widely varying, possibly

More information

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco CS 326 Operating Systems C Programming Greg Benson Department of Computer Science University of San Francisco Why C? Fast (good optimizing compilers) Not too high-level (Java, Python, Lisp) Not too low-level

More information

ECE260: Fundamentals of Computer Engineering

ECE260: Fundamentals of Computer Engineering ECE260: Fundamentals of Computer Engineering Translation of High-Level Languages James Moscola Dept. of Engineering & Computer Science York College of Pennsylvania ECE260: Fundamentals of Computer Engineering

More information

Operating Systems (2INC0) 2017/18

Operating Systems (2INC0) 2017/18 Operating Systems (2INC0) 2017/18 Memory Management (09) Dr. Courtesy of Dr. I. Radovanovic, Dr. R. Mak (figures from Bic & Shaw) System Architecture and Networking Group Agenda Reminder: OS & resources

More information

Linking. Computer Systems Organization (Spring 2017) CSCI-UA 201, Section 3. Instructor: Joanna Klukowska

Linking. Computer Systems Organization (Spring 2017) CSCI-UA 201, Section 3. Instructor: Joanna Klukowska Linking Computer Systems Organization (Spring 2017) CSCI-UA 201, Section 3 Instructor: Joanna Klukowska Slides adapted from Randal E. Bryant and David R. O Hallaron (CMU) Mohamed Zahran (NYU) Example C

More information

CSCI-UA /2. Computer Systems Organization Lecture 19: Dynamic Memory Allocation: Basics

CSCI-UA /2. Computer Systems Organization Lecture 19: Dynamic Memory Allocation: Basics Slides adapted (and slightly modified) from: Clark Barrett Jinyang Li Randy Bryant Dave O Hallaron CSCI-UA.0201-001/2 Computer Systems Organization Lecture 19: Dynamic Memory Allocation: Basics Mohamed

More information

Reviewing gcc, make, gdb, and Linux Editors 1

Reviewing gcc, make, gdb, and Linux Editors 1 Reviewing gcc, make, gdb, and Linux Editors 1 Colin Gordon csgordon@cs.washington.edu University of Washington CSE333 Section 1, 3/31/11 1 Lots of material borrowed from 351/303 slides Colin Gordon (University

More information

Compiler Theory. (GCC the GNU Compiler Collection) Sandro Spina 2009

Compiler Theory. (GCC the GNU Compiler Collection) Sandro Spina 2009 Compiler Theory (GCC the GNU Compiler Collection) Sandro Spina 2009 GCC Probably the most used compiler. Not only a native compiler but it can also cross-compile any program, producing executables for

More information

CSL373: Operating Systems Linking

CSL373: Operating Systems Linking CSL373: Operating Systems Linking Today Linking f.c gcc f.s as c.c gcc c.s as f.o c.o ld a.out e.g., f.o = hello.o (uses printf); c.o = libc.o (implements printf) How to name and refer to things that don

More information

Classifying Information Stored in Memory! Memory Management in a Uniprogrammed System! Segments of a Process! Processing a User Program!

Classifying Information Stored in Memory! Memory Management in a Uniprogrammed System! Segments of a Process! Processing a User Program! Memory Management in a Uniprogrammed System! A! gets a fixed segment of (usually highest )"! One process executes at a time in a single segment"! Process is always loaded at "! Compiler and linker generate

More information

Compiler, Assembler, and Linker

Compiler, Assembler, and Linker Compiler, Assembler, and Linker Minsoo Ryu Department of Computer Science and Engineering Hanyang University msryu@hanyang.ac.kr What is a Compilation? Preprocessor Compiler Assembler Linker Loader Contents

More information

Memory Management. CSCI 315 Operating Systems Design Department of Computer Science

Memory Management. CSCI 315 Operating Systems Design Department of Computer Science Memory Management CSCI 315 Operating Systems Design Department of Computer Science Notice: The slides for this lecture are based on those from Operating Systems Concepts, 9th ed., by Silberschatz, Galvin,

More information

Agenda. CSE P 501 Compilers. Java Implementation Overview. JVM Architecture. JVM Runtime Data Areas (1) JVM Data Types. CSE P 501 Su04 T-1

Agenda. CSE P 501 Compilers. Java Implementation Overview. JVM Architecture. JVM Runtime Data Areas (1) JVM Data Types. CSE P 501 Su04 T-1 Agenda CSE P 501 Compilers Java Implementation JVMs, JITs &c Hal Perkins Summer 2004 Java virtual machine architecture.class files Class loading Execution engines Interpreters & JITs various strategies

More information

CPEG421/621 Tutorial

CPEG421/621 Tutorial CPEG421/621 Tutorial Compiler data representation system call interface calling convention Assembler object file format object code model Linker program initialization exception handling relocation model

More information

Memory and C/C++ modules

Memory and C/C++ modules Memory and C/C++ modules From Reading #6 Will return to OOP topics (templates and library tools) soon Compilation/linking revisited source file 1 object file 1 source file 2 compilation object file 2 library

More information

Operating System Labs. Yuanbin Wu

Operating System Labs. Yuanbin Wu Operating System Labs Yuanbin Wu CS@ECNU Operating System Labs Project 2 Due 21:00, Oct. 24 Project 3 Group of 3 If you can not find a partner, drop us an email You now have 3 late days, but start early!

More information

Memory Management: The process by which memory is shared, allocated, and released. Not applicable to cache memory.

Memory Management: The process by which memory is shared, allocated, and released. Not applicable to cache memory. Memory Management Page 1 Memory Management Wednesday, October 27, 2004 4:54 AM Memory Management: The process by which memory is shared, allocated, and released. Not applicable to cache memory. Two kinds

More information

Example C Program The course that gives CMU its Zip! Linking March 2, Static Linking. Why Linkers? Page # Topics

Example C Program The course that gives CMU its Zip! Linking March 2, Static Linking. Why Linkers? Page # Topics 15-213 The course that gives CMU its Zip! Topics Linking March 2, 24 Static linking Dynamic linking Case study: Library interpositioning Example C Program main.c int buf[2] = 1, 2; int main() swap(); return

More information

Programming Tools. Venkatanatha Sarma Y. Lecture delivered by: Assistant Professor MSRSAS-Bangalore

Programming Tools. Venkatanatha Sarma Y. Lecture delivered by: Assistant Professor MSRSAS-Bangalore Programming Tools Lecture delivered by: Venkatanatha Sarma Y Assistant Professor MSRSAS-Bangalore 1 Session Objectives To understand the process of compilation To be aware of provisions for data structuring

More information