The Assembly Language Level Part C – Linking and Loading.

Slides:



Advertisements
Similar presentations
Programs in Memory Bryce Boe 2012/08/29 CS32, Summer 2012 B.
Advertisements

Assembly Code Example Selection Sort.
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.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 3 Memory Management Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
The Assembly Language Level
Assembler/Linker/Loader Mooly Sagiv html:// Chapter 4.3 J. Levine: Linkers & Loaders
Chapter 3 Loaders and Linkers
Loaders and Linkers CS 230 이준원. 2 Overview assembler –generates an object code in a predefined format »COFF (common object file format) »ELF (executable.
Lecture 10: Linking and loading. Lecture 10 / Page 2AE4B33OSS 2011 Contents Linker vs. loader Linking the executable Libraries Loading executable ELF.
Machine Independent Assembler Features
The Functions and Purposes of Translators Code Generation (Intermediate Code, Optimisation, Final Code), Linkers & Loaders.
CS 31003: Compilers ANIRUDDHA GUPTA 11CS10004 G2 CLASS DATE : 24/07/2013.
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++
Assembly Process. Machine Code Generation Assembling a program entails translating the assembly language into binary machine code This requires more than.
Chapter 8: Programming the Microprocessor. Copyright ©2009 by Pearson Education, Inc. Upper Saddle River, New Jersey All rights reserved. The Intel.
Assembler/Linker/Loader Mooly Sagiv html:// Chapter 4.3.
COSC 120 Computer Programming
Loader- Machine Independent Loader Features
An introduction to systems programming
Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved The Operating System Machine.
The Assembly Language Level
Software Development Process Compiler Linker C File Asm. File Binary File Exec. File Assemble r Library Implementation Phase Debugger Profiler Verification.
Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved The Assembly Language Level.
Software Development and Software Loading in Embedded Systems.
Chapter 2 Software Tools and Assembly Language Syntax.
1/2002JNM Edit, Assemble, Link & Debug. 1/2002JNM Files Created.
Enabling the ARM Learning in INDIA ARM DEVELOPMENT TOOL SETUP.
MIPS coding. SPIM Some links can be found such as:
The Assembly Language Level Part B – The Assembly Process.
Programming With C.
Linking and Loading Linker collects procedures and links them together object modules into one executable program. Why isn't everything written as just.
CIS250 OPERATING SYSTEMS Memory Management Since we share memory, we need to manage it Memory manager only sees the address A program counter value indicates.
Computer Science 101 How the Assembler Works. Assembly Language Programming.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
The LC-3 – Chapter 7 COMP 2620 Dr. James Money COMP
Topic 2d High-Level languages and Systems Software
5-1 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles.
CSE451 Linking and Loading Autumn 2002 Gary Kimura Lecture #21 December 9, 2002.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Computer Science 210 Computer Organization More on Assembler.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /29/2013 Lecture 13: Compile-Link-Load Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE.
2 : Assembler 1 Chapter II: Assembler Chapter goal: r Introduce the fundamental functions that any assembler must perform. m Assign machine address m Translate.
CS412/413 Introduction to Compilers and Translators April 14, 1999 Lecture 29: Linking and loading.
The Assembly Process Computer Organization and Assembly Language: Module 10.
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
CSc 453 Linking and Loading
Loaders and Linkers T 李俊葦. 1. Loader Accepts the object programs , prepares these programs for execution by the computer , and indicates the execution.
Computer Software 1.
Binding & Dynamic Linking Presented by: Raunak Sulekh(1013) Pooja Kapoor(1008)
1 CE 454 Computer Architecture Lecture 11 Ahmed Ezzat The Assembly Language Level, Ch-(7.1 – 7.4)
Compiling examples in MIPS
Lecture 3 Translation.
Topic 2: Hardware and Software
Assemblers, linkers, loaders
Computer Science 210 Computer Organization
System Programming and administration
Naming and Binding A computer system is merely a bunch of resources that are glued together with names Thus, much of system design is merely making choices.
The University of Adelaide, School of Computer Science
Linking & Loading.
Separate Assembly allows a program to be built from modules rather than a single source file assembler linker source file.
CS-3013 Operating Systems C-term 2008
Computer Science 210 Computer Organization
The Assembly Language Level
Loaders and Linkers: Features
The Operating System Machine Level
The Assembly Language Level
Linking & Loading CS-502 Operating Systems
10/6: Lecture Topics C Brainteaser More on Procedure Call
An introduction to systems programming
Program Assembly.
Presentation transcript:

The Assembly Language Level Part C – Linking and Loading

Linking and loading Note that we didn’t have to write System.out.println() or Math.sin() (Java) or printf() or sin() (C/C++) yet we were able to use it! Where is the code for these function? – Is it source code or binary? By what mechanism are we able to call them?

Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved Linking and Loading Generation of an executable binary program from a collection of independently translated source procedures requires using a linker. Note: Translator causes a level change but linker does not.

Purpose of linker To collect separately translated functions and data and link them to run as a unit (executable binary program). – ILC (Instruction Location Counter) starts at 0 when assembling each module. – But 2 or more modules can’t all start at 0 in the executable! – Linker’s job is to resolve this via relocation.

Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved Tasks Performed by the Linker (1) Each module has its own address space, starting at 0. external reference to B

Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved Tasks Performed by the Linker (1) Each module has its own address space, starting at 0!

Relocation problem Each object module represents a separate address space. But we need a single, linear address space.

Linker steps: 1.Construct a table of all the object modules and their lengths. 2.Assign a starting address to each object module. 3.For all instructions that reference memory, add a relocation constant equal to the starting address of the module. 4.For all instructions that reference other procedures, insert the address of these procedures in place.

Linker steps: 1.Construct a table of all the object modules and their lengths. 2.Assign a starting address to each object module. 3.For all instructions that reference memory, add a relocation constant equal to the starting address of the module. modulelengthstarting address A B C D

Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved Tasks Performed by the Linker (5) The object modules after being positioned in the binary image but before being relocated and linked. X Note: Exe’s are often linked to start above address 0 to catch bad pointers and for other special purposes.

Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved Tasks Performed by the Linker (5) The branching structure we want appears above.

Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved Tasks Performed by the Linker (5) Unfortunately, the branching structure that we have appears below!

Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved Tasks Performed by the Linker (5) Note that the references to data are bollixed up as well! (From webster.com: to throw into disorder; also: bungle — usually used with up.)

Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved Tasks Performed by the Linker (6) The same object modules after linking and after relocation (of code and data) has been performed. Together they form an executable binary program, ready to run.

Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved Structure of an Object Module The internal structure of an object module produced by a translator.

Parts of an object module 1.module name, date, lengths 2.list of public symbols and values in module 3.list of extern(al) symbols used by module – includes list of location of instructions that refer to these symbols 4.code and constants – this is the only part that is actually loaded and executed 5.relocation dictionary – list of memory addresses that require the addition of a relocation constant 6.end-of-module mark, checksum

Linker passes Pass 1: – read all object modules – build table of module names and lengths – build global symbol table of entry points and external references Pass 2: – read all object modules (again) – relocate their contents – write all of them out to one file (executable file)

Linking with MASM \masm32\bin\ml /c /coff /Cp /nologo /Zd /Zi /Fl /Fm /FR /DDebug test.asm – creates test.obj from test.asm \masm32\bin\ml /c /coff /Cp /nologo /Zd /Zi /Fl /Fm /FR /DDebug utilities.asm – creates utilities.obj from utilities.asm \masm32\bin\ link /nologo /map /debug /subsystem:console test.obj utilities.obj – creates test.exe from test.obj and utilities.obj

THE END skip and 7.4.4

Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved Binding Time and Dynamic Relocation The relocated binary program of Fig. 7-15(b) moved up 300 addresses. Many instructions now refer to an incorrect memory address.

Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved Dynamic Linking in MULTICS (1) Before EARTH is called.

Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved Dynamic Linking in MULTICS (2) After EARTH has been called and linked.

Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved Dynamic Linking in Windows Use of a DLL file by two processes.