Linking and Loading. Γ.Κορνάρος Κ. Χαρτερός

Σχετικά έγγραφα
Εργαστήριο Ανάπτυξης Εφαρμογών Βάσεων Δεδομένων. Εξάμηνο 7 ο

Instruction Execution Times

ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 19/5/2007

ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 6/5/2006

ΠΑΝΕΠΙΣΤΗΜΙΟ ΚΥΠΡΟΥ - ΤΜΗΜΑ ΠΛΗΡΟΦΟΡΙΚΗΣ ΕΠΛ 133: ΑΝΤΙΚΕΙΜΕΝΟΣΤΡΕΦΗΣ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΣ ΕΡΓΑΣΤΗΡΙΟ 3 Javadoc Tutorial

2 Composition. Invertible Mappings

ΕΠΛ221: Οργάνωση Υπολογιστών και Συμβολικός Προγραμματισμός. Εργαστήριο Αρ. 2

EE512: Error Control Coding

Phys460.nb Solution for the t-dependent Schrodinger s equation How did we find the solution? (not required)

The Simply Typed Lambda Calculus

Block Ciphers Modes. Ramki Thurimella

DESIGN OF MACHINERY SOLUTION MANUAL h in h 4 0.

ΠΑΝΕΠΙΣΤΗΜΙΟ ΘΕΣΣΑΛΙΑΣ ΤΜΗΜΑ ΠΟΛΙΤΙΚΩΝ ΜΗΧΑΝΙΚΩΝ ΤΟΜΕΑΣ ΥΔΡΑΥΛΙΚΗΣ ΚΑΙ ΠΕΡΙΒΑΛΛΟΝΤΙΚΗΣ ΤΕΧΝΙΚΗΣ. Ειδική διάλεξη 2: Εισαγωγή στον κώδικα της εργασίας

Section 8.3 Trigonometric Equations

ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 24/3/2007

EPL 603 TOPICS IN SOFTWARE ENGINEERING. Lab 5: Component Adaptation Environment (COPE)

VBA ΣΤΟ WORD. 1. Συχνά, όταν ήθελα να δώσω ένα φυλλάδιο εργασίας με ασκήσεις στους μαθητές έκανα το εξής: Version ΗΜΙΤΕΛΗΣ!!!!

Hancock. Ζωγραφάκης Ιωάννης Εξαρχάκος Νικόλαος. ΕΠΛ 428 Προγραμματισμός Συστημάτων

Approximation of distance between locations on earth given by latitude and longitude

derivation of the Laplacian from rectangular to spherical coordinates

HOMEWORK 4 = G. In order to plot the stress versus the stretch we define a normalized stretch:

The challenges of non-stable predicates

ΕΙΣΑΓΩΓΗ ΣΤΟN ΠΡΟΓΡΑΜΜΑΤΙΣΜΟ ΠΑΝΕΠΙΣΤΗΜΙΟ ΠΑΤΡΩΝ ΠΟΛΥΤΕΧΝΙΚΗ ΣΧΟΛΗ ΤΜΗΜΑ ΜΗΧΑΝΙΚΩΝ Η/Υ ΚΑΙ ΠΛΗΡΟΦΟΡΙΚΗΣ

CYTA Cloud Server Set Up Instructions

Test Data Management in Practice

Reminders: linear functions

Every set of first-order formulas is equivalent to an independent set

the total number of electrons passing through the lamp.

(C) 2010 Pearson Education, Inc. All rights reserved.

TMA4115 Matematikk 3

ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 11/3/2006

Homework 3 Solutions

Assalamu `alaikum wr. wb.

Partial Trace and Partial Transpose

Εγκατάσταση λογισμικού και αναβάθμιση συσκευής Device software installation and software upgrade

Εργαστήριο Ανάπτυξης Εφαρμογών Βάσεων Δεδομένων. Εξάμηνο 7 ο

PARTIAL NOTES for 6.1 Trigonometric Identities

Special edition of the Technical Chamber of Greece on Video Conference Services on the Internet, 2000 NUTWBCAM

Dynamic types, Lambda calculus machines Section and Practice Problems Apr 21 22, 2016

Fractional Colorings and Zykov Products of graphs

Galatia SIL Keyboard Information

ω ω ω ω ω ω+2 ω ω+2 + ω ω ω ω+2 + ω ω+1 ω ω+2 2 ω ω ω ω ω ω ω ω+1 ω ω2 ω ω2 + ω ω ω2 + ω ω ω ω2 + ω ω+1 ω ω2 + ω ω+1 + ω ω ω ω2 + ω

C.S. 430 Assignment 6, Sample Solutions

Advanced Subsidiary Unit 1: Understanding and Written Response

ΑΚΑ ΗΜΙΑ ΕΜΠΟΡΙΚΟΥ ΝΑΥΤΙΚΟΥ ΜΑΚΕ ΟΝΙΑΣ ΣΧΟΛΗ ΜΗΧΑΝΙΚΩΝ ΠΤΥΧΙΑΚΗ ΕΡΓΑΣΙΑ

Code Breaker. TEACHER s NOTES

Writing kernels for fun and profit

Démographie spatiale/spatial Demography

Lecture 2: Dirac notation and a review of linear algebra Read Sakurai chapter 1, Baym chatper 3

ΛΕΙΤΟΥΡΓΙΚΑ ΣΥΣΤΗΜΑΤΑ ΔΙΕΡΓΑΣΙΕΣ

HY150a Φροντιστήριο 3 24/11/2017

department listing department name αχχουντσ ϕανε βαλικτ δδσϕηασδδη σδηφγ ασκϕηλκ τεχηνιχαλ αλαν ϕουν διξ τεχηνιχαλ ϕοην µαριανι

Συντακτικές λειτουργίες

MathCity.org Merging man and maths

Πρόβλημα 1: Αναζήτηση Ελάχιστης/Μέγιστης Τιμής

Physical DB Design. B-Trees Index files can become quite large for large main files Indices on index files are possible.

Section 1: Listening and responding. Presenter: Niki Farfara MGTAV VCE Seminar 7 August 2016

Finite Field Problems: Solutions

Fourier Series. MATH 211, Calculus II. J. Robert Buchanan. Spring Department of Mathematics

Mean bond enthalpy Standard enthalpy of formation Bond N H N N N N H O O O

ΠΑΝΕΠΙΣΤΗΜΙΟ ΠΕΙΡΑΙΑ ΤΜΗΜΑ ΝΑΥΤΙΛΙΑΚΩΝ ΣΠΟΥΔΩΝ ΠΡΟΓΡΑΜΜΑ ΜΕΤΑΠΤΥΧΙΑΚΩΝ ΣΠΟΥΔΩΝ ΣΤΗΝ ΝΑΥΤΙΛΙΑ

ΕΙΣΑΓΩΓΗ ΣΤΗ ΣΤΑΤΙΣΤΙΚΗ ΑΝΑΛΥΣΗ

Numerical Analysis FMN011

Business English. Ενότητα # 9: Financial Planning. Ευαγγελία Κουτσογιάννη Τμήμα Διοίκησης Επιχειρήσεων

Συστήματα Διαχείρισης Βάσεων Δεδομένων

Example Sheet 3 Solutions

Στο εστιατόριο «ToDokimasesPrinToBgaleisStonKosmo?» έξω από τους δακτυλίους του Κρόνου, οι παραγγελίες γίνονται ηλεκτρονικά.

ΠΑΝΕΠΙΣΤΗΜΙΟ ΠΑΤΡΩΝ ΠΟΛΥΤΕΧΝΙΚΗ ΣΧΟΛΗ ΤΜΗΜΑ ΜΗΧΑΝΙΚΩΝ Η/Υ & ΠΛΗΡΟΦΟΡΙΚΗΣ. του Γεράσιμου Τουλιάτου ΑΜ: 697

Προσομοίωση BP με το Bizagi Modeler

(1) Describe the process by which mercury atoms become excited in a fluorescent tube (3)

Econ 2110: Fall 2008 Suggested Solutions to Problem Set 8 questions or comments to Dan Fetter 1

ΑΝΙΧΝΕΥΣΗ ΓΕΓΟΝΟΤΩΝ ΒΗΜΑΤΙΣΜΟΥ ΜΕ ΧΡΗΣΗ ΕΠΙΤΑΧΥΝΣΙΟΜΕΤΡΩΝ ΔΙΠΛΩΜΑΤΙΚΗ ΕΡΓΑΣΙΑ

Εισαγωγή στη Βιοπληροφορική

Main source: "Discrete-time systems and computer control" by Α. ΣΚΟΔΡΑΣ ΨΗΦΙΑΚΟΣ ΕΛΕΓΧΟΣ ΔΙΑΛΕΞΗ 4 ΔΙΑΦΑΝΕΙΑ 1

Δημιουργία Λογαριασμού Διαχείρισης Business Telephony Create a Management Account for Business Telephony

Other Test Constructions: Likelihood Ratio & Bayes Tests

Μηχανική Μάθηση Hypothesis Testing

ΓΡΑΜΜΙΚΟΣ & ΔΙΚΤΥΑΚΟΣ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΣ

Modbus basic setup notes for IO-Link AL1xxx Master Block

SOAP API. Table of Contents

Πώς μπορεί κανείς να έχει έναν διερμηνέα κατά την επίσκεψή του στον Οικογενειακό του Γιατρό στο Ίσλινγκτον Getting an interpreter when you visit your

Chapter 6: Systems of Linear Differential. be continuous functions on the interval

Ordinal Arithmetic: Addition, Multiplication, Exponentiation and Limit

Οδηγίες χρήσης. Registered. Οδηγίες ένταξης σήματος D-U-N-S Registered στην ιστοσελίδα σας και χρήσης του στην ηλεκτρονική σας επικοινωνία

Partial Differential Equations in Biology The boundary element method. March 26, 2013

ΤΕΧΝΟΛΟΓΙΚΟ ΠΑΝΕΠΙΣΤΗΜΙΟ ΚΥΠΡΟΥ ΤΜΗΜΑ ΝΟΣΗΛΕΥΤΙΚΗΣ

Capacitors - Capacitance, Charge and Potential Difference

About these lecture notes. Simply Typed λ-calculus. Types

ΑΥΤΟΜΑΤΟΠΟΙΗΣΗ ΜΟΝΑΔΑΣ ΘΡΑΥΣΤΗΡΑ ΜΕ ΧΡΗΣΗ P.L.C. AUTOMATION OF A CRUSHER MODULE USING P.L.C.

How to register an account with the Hellenic Community of Sheffield.

3.4 SUM AND DIFFERENCE FORMULAS. NOTE: cos(α+β) cos α + cos β cos(α-β) cos α -cos β

Οδηγίες Αγοράς Ηλεκτρονικού Βιβλίου Instructions for Buying an ebook

AME SAMPLE REPORT James R. Cole, Ph.D. Neuropsychology

Calculating the propagation delay of coaxial cable

Οδηγίες χρήσης υλικού D U N S Registered

Section 9.2 Polar Equations and Graphs

Εργαστήριο Ανάπτυξης Εφαρμογών Βάσεων Δεδομένων. Εξάμηνο 7 ο

Solutions to the Schrodinger equation atomic orbitals. Ψ 1 s Ψ 2 s Ψ 2 px Ψ 2 py Ψ 2 pz

ΚΥΠΡΙΑΚΟΣ ΣΥΝΔΕΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY 21 ος ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ Δεύτερος Γύρος - 30 Μαρτίου 2011

Transcript:

Linking and Loading Γ.Κορνάρος Κ. Χαρτερός

Περίληψη Linking Τι συμβαίνει κατά το linking? Διαφορετικά είδη linking Loading ELF file format 2

Linker Οι compilers και οι assemblers γεννούν relocatable object files References to external symbols are not resolved Compilers generate object files in which code starts at address 0 Cannot execute a compiler produced object file Τα εκτελέσιμα αρχεία δημιουργούνται από το καθένα object file και τις βιβλιοθήκες με την διαδικασία του linking 3

Linker (2) Ο Linker εκτελεί δύο εργασίες : Symbol resolution: Object files define and reference symbols, linker tries to resolve each symbol reference with one symbol definition Relocation: Linker tries to relocate code and data from different object files so that different sections start at different addresses and all the references are updated 4

Παράδειγμα: Compiling main.c and square.c 5

Παράδειγμα: After Linking main.o and square.o 6

Συναρτήσεις Βιβλιοθήκης Τι συμβαίνει όταν τα αρχεία source χρησιμοποιούν συναρτήσεις βιβλιοθήκης όπως printf, scanf, etc.? Compiler produces a symbol (in the same way as the square function in the previous example) in the object file Linker Attempts to resolve these references by matching them to definitions found in other object files If the symbol is not resolved, the linker searches for the symbol definition in library files What are library files? Collection of object files that provide related functionality Example: The standard C library libc.a is a collection of object files printf.o, scanf.o, fprintf.o, fscanf.o 7

Συναρτήσεις Βιβλιοθήκης (2) Πως γνωρίζει ο linker που να βρει την βιβλιοθήκη? User defined libraries can be specified as a command line argument, or in the CodeWarrior IDE (when you Add Files to a project) The environment variable ARMLIB holds the path (Example C:\Program Files\ARM\ADSv1_2\Lib) for the default ARM standard library 8

Συναρτήσεις Βιβλιοθήκης (3) Linker does a search to see whether the symbol is defined in the specified libraries The order in which this search is performed is determined by the order in which the libraries are specified If the symbol is defined in more than 1 library, the first library in the path is selected Linker then extracts the specific.o file that defines the symbol in the library and processes this.o file with all the other object files If the symbol is not defined in any of the library, linker throws an error 9

Είδη Αρχείων Object Three main types of object files Re-locatable file: Code and data suitable for linking with other object files to create an executable or a shared object file Executable file: Program suitable for execution Shared object file (also called Dynamically linked library : Special type of relocatable object file that can be loaded into memory and linked dynamically First, the linker may process it with other re-locatable and shared object files to create another object file Second, the dynamic linker combines it with an executable file and other shared objects to create a process image Compilers and assemblers generate re-locatable object files Linkers generate executable object files 10

Είδη Μοντέλων Linking Different kinds of linking models Static: Set of object files, system libraries and library archives are statically bound, references are resolved, and a self-contained executable file is created Problem: If multiple programs are running on the processor simultaneously, and they require some common library module (say, printf.o), multiple copies of this common module are included in the executable file and loaded into memory (waste of memory!) Dynamic: Set of object files, libraries, system shared resources and other shared libraries are linked together to create an executable file When this executable is loaded, other shared resources and dynamic libraries must be made available in the system for the program to run successfully If multiple programs running on a processor need the same object module, only one copy of the module needs to be loaded in the memory 11

Δυναμικό Linking Dynamically linked executable or shared object undergoes final linking when Loaded into memory by a program loader An executable or shared object to be linked dynamically might List one or more shared objects (shared libraries) with which it should be linked Other advantages of dynamic linking Updating of libraries The size on disk of an executable that uses dynamically linked modules may be less than its size in memory (during run-time) Why? 12

Executable and Linking Format (ELF) Τα Object files πρέπει να είναι σε ένα συγκεκριμένο φορματ για να διευκολυνθεί το linking και το loading Το Executable and Linking Format (ELF) είναι ένα δημοφιλές φορμάτ για ένα object file Supported by many vendors and tools Diverse processors, multiple data encodings and multiple classes of machines ELF specifies the layout of the object files and not the contents of code or data 13

Executable and Linking Format (ELF) Ένα ELF object αρχείο αποτελείται από : ELF Header Beginning of ELF file Holds a road map of file s organization How to interpret the file, independent of the processor Program header table Tells the system how to create a process image Files used to build a process image (execute a program) must have a program header table Re-locatable files do not need one Sections Object file information for the linking view Instructions, data, symbol table, relocation information, etc. 14

Linking & Execution Views 15

ELF Execution View 16

ELF Header Όλα τα ELF αρχεία περιέχουν μία επικεφαλίδα στην αρχή του αρχείου Determines whether the file is an ELF file, whether it is in big/little endian format, the target processor, offsets to the program header table and/or section header table Format of the ELF header #define EI_NIDENT 16 typedeμf struct { unsigned char e_ident[ei_nident]; // file info (object file or not) Elf32_Half e_type; // type of file (relocatable, executable, etc.) Elf32_Half e_machine; // target processor (Intel x86, ARM, SPARC etc.) Elf32_Word e_version; / version # (to allow for future versions of ELF) Elf32_Addr e_entry; // program entry point (0 if no entry point) Elf32_Off e_phoff; // offset of program header (in bytes) Elf32_Off e_shoff; // offset of section header table Elf32_Word e_flags; // processor-specific flags Elf32_Half e_ehsize; // ELF header s size Elf32_Half e_phentsize; // entry size in pgm header tbl Elf32_Half e_phnum; // # of entries in pgm header Elf32_Half e_shentsize; // entry size in sec header tbl Elf32_Half e_shnum; // # of entries in sec header tbl Elf32_Half e_shstrndx; // sec header tbl index of str tbl } Elf32_Ehdr; 17

ELF Sections Relocatable files must have a section header table Locations and size of sections are described by the section header table 18

Περιγραφή των διαφόρων Τμημάτων.text: program instructions and literal data.rodata: Read-only data such as the format strings in printf statements.data: initialized global data.bss: un-initialized global data (set to zero when program image is created) This section does not occupy any space in the object file.symtab: this section holds the symbol table information All global variables and functions that are defined and referenced in the program.rel.text: list of locations in the.text section that will need to be modified when linker combines this object files with others.rel.data: relocation information for any global variables that are referenced or defined in a module.debug: debugging information (present only if code is compiled to produce debug information).line: mapping between line numbers in C program and machine code instructions (present only if code is compiled to produce debug information).strtab: string table for symbols defined in.symtab and.debug sections 19

Executable Object Files 20

ELF Program Header Executable ELF files must have a program header table The program header table is used to load the program (called creating program image ) Each segment has its own entry in the program header table o e_phnum in ELF Header holds the number of program header entries All program header entries have the same size (e_phentsize in ELF header) Program header entry for each segment What happens if p_memsz > p_filesz? The remaining bytes (p_memsz-p_filesz) are initialized with 0 typedef struct { Elf32_Word p_type; Elf32_Off p_offset; Elf32_Addr p_vaddr; Elf32_Addr p_paddr; Elf32_Word p_filesz; Elf32_Word p_memsz; Elf32_Word p_flags; Elf32_Word p_align; } Elf32_Phdr; // type of segment loadable, dll,... // offset in bytes from the start of file // virtual address in memory of segment // physical address in memory of segment // number of bytes in the file of the segment // number of bytes in memory of the process // image of the segment // indicates whether segment is executable // alignment information 21