Linkers Linkers

Total Page:16

File Type:pdf, Size:1020Kb

Linkers Linkers 75-08 Sistemas Operativos Lic. Ing. Osvaldo Clúa Lic. Adrián Muccio Facultad de Ingeniería Universidad de Buenos Aires LinkersLinkers Uso del Linker (a) Traducción Programa Fuente 1 Programa Objeto 1 Traductor Programa Fuente 2 Programa Objeto 2 Traductor Programa Fuente 3 Programa Objeto 3 75-08 Sistemas Operativos 2 FIUBA Prof. Lic. Ing. Osvaldo Clúa Lic. Adrián Muccio Traducción - ensamblado ● Si el lenguaje es un assembler, la traducción es un ensamblado (assembly) hecho por un programa ensamblador (assembler). – Convierte código de lenguaje ensamblador memotécnico a códigos de operación. – Resuelve identificadores a posiciones de memoria. – Algunos proveen abstracciones de programación avanzadas. – Existe un assembler distinto para cada arquitectura, incluso hay assemblers generales 75-08 Sistemas Operativos 3 FIUBA Prof. Lic. Ing. Osvaldo Clúa Lic. Adrián Muccio Traducción - Compilación ● Si se trata de un lenguaje de alto o mediano nivel, la traducción es una compilación. ● Un Libro online sobre compiladores del curso de Leonidas Fegaras. 75-08 Sistemas Operativos 4 FIUBA Prof. Lic. Ing. Osvaldo Clúa Lic. Adrián Muccio Link-Editor Mezcla las direcciones de cada módulo Programa Objeto 1 en un único espacio de direcciones. Programa Objeto 2 Linker Programa Ejecutable Además de ejecutable la salida puede ser: ● Programa Objeto 3 Otro programa objeto ● Una biblioteca La entrada puede ser también ● Un ejecutable ● Una biblioteca 75-08 Sistemas Operativos 5 FIUBA Prof. Lic. Ing. Osvaldo Clúa Lic. Adrián Muccio Loader Memoria Programa Ejecutable Loader Ejecutable Se llama binding al proceso de resolver El binding Bibliotecas las llamadas a puede hacerse en Bibliotecas funciones de biblioteca ejecución Bibliotecas En algunos sistemas, el compilador llama ya cargadas al linker (gcc llama a ld) 75-08 Sistemas Operativos 6 FIUBA Prof. Lic. Ing. Osvaldo Clúa Lic. Adrián Muccio Compilando Paso 1 TXT Paso 2 00 Start a .... 00 Start a Procedure a() 20 LR 1,addr(j) .... integer j; 24 ADD, 1,=10 20 LR 1,04 begin 28 ST 1,addr(j) 24 ADD, 1,08 .... ... 28 ST 1,04 j=j+10; 60 CALL B ... ... ... 60 CALL B b() 96 END ... end; DATA Relocation Dictionary RLD 00 Data a El código objeto 04 DS (j) Loc Symbol Pos contiene, entre otras 08 DC 10 #=10 23 j 04 ... cosas, TXT, DATA, 76 End Data a 27 =10 08 RLD 31 j 04 63 B ? 75-08 Sistemas Operativos 7 FIUBA Prof. Lic. Ing. Osvaldo Clúa Lic. Adrián Muccio Compilando (2) TXT 00 Start b Relocation Dictionary .... RLD Procedure b() 36 LR 1,08 integer j; Loc Symbol Pos begin 40 ST 1,04 .... ... 39 =34 08 j=34; 43 j 04 ... end; Exports Table ExT DATA Loc Symbol El espacio de direcciones de 00 Data b 00 b b( ) es distinto del de a( ) 04 DS (j) 08 DC 34 (=34) ... La ExT es otro componente del objeto 75-08 Sistemas Operativos 8 FIUBA Prof. Lic. Ing. Osvaldo Clúa Lic. Adrián Muccio 00 Start a .... Linkeando 20 LR 1,04 00 Start b 24 ADD, 1,08 .... 28 ST 1,04... 36 LR 1,08 60 CALL B 40 ST 1,04 ... ... 96 END 00 Data b 00 Data a 04 DS (j) 04 DS (j) 08 DC 34 (=34) 08 DC 10 #=10 Link-editor ... ... 76 End Data a Loc Symbol Pos 39 =34 08 Loc Symbol Pos 43 j 04 23 j 04 Loc Symbol 27 =10 08 00 b 31 j 04 en el próximo 63 B ? slide .... Loc Symbol 00 a 75-08 Sistemas Operativos 9 FIUBA Prof. Lic. Ing. Osvaldo Clúa Lic. Adrián Muccio Linkeando (2) TXT DATA RLD 00 Data a Loc Symbol Pos 00 Start a 04 DS (j) 23 j 04 .... 08 DC 10 #=10 27 =10 08 20 LR 1,04 ... 31 j 04 24 ADD, 1,08 76 End Data a 63 B 100 28 ST 1,04... Se 60 CALL 100 80 Data b 139 =34 88 puede ... 84 DS (j) 143 j 84 resolver 96 END 88 DC 34 (=34) el ... llamado ExT 100 Start b El linker mezcló los a B() .... espacios de Loc Symbol 136 LR 1,88 00 a 140 ST 1,84 direcciones de los ... dos procedimientos 100 b en uno solo (relocación) 75-08 Sistemas Operativos 10 FIUBA Prof. Lic. Ing. Osvaldo Clúa Lic. Adrián Muccio Object file formats (OFF) ● Es clave para la performance del sistema. ● Algunos preveen su interacción con el paginado. ● Se suele utilizar el mismo formato para: – Ejecutables – Objetos – Bibliotecas ● Que dos Sistemas Operativos tengan el mismo OFF no significa que los programas de uno puedan correr en el otro. 75-08 Sistemas Operativos 11 FIUBA Prof. Lic. Ing. Osvaldo Clúa Lic. Adrián Muccio DOS com ● Son los que tienen extensión .com. Microsoft los llama bin o binary file ● Se hacen con exe2bin. ● Se cargan en una dirección fija de memoria (0x100). ● Datos y código estan en el mismo segmento. ● Su tamaño máximo es de 65,280 (0xFF00) bytes ● Se puede decir que es un “null file format” 75-08 Sistemas Operativos 12 FIUBA Prof. Lic. Ing. Osvaldo Clúa Lic. Adrián Muccio DOS exe File Header ● Aparece en DOS 2.0. RLD ● Su primer byte o (Magic number) es Imagen binaria del TXT “MZ”, iniciales de Mark Zbikowski. ● Tiene previsión para relocación en memoria.. 75-08 Sistemas Operativos 13 FIUBA Prof. Lic. Ing. Osvaldo Clúa Lic. Adrián Muccio Header del DOS .exe char signature[2] = "MZ"; // magic number short lastsize; // # bytes used in last block short nblocks; // number of 512 byte blocks short nreloc; // number of relocation entries short hdrsize; // size of file header in 16 byte paragraphs short minalloc; // minimum extra memory to allocate short maxalloc; // maximum extra memory to allocate void far *sp; // initial stack pointer short checksum; // ones complement of file sum void far *ip; // initial instruction pointer short relocpos; // location of relocation fixup table short noverlay; // Overlay number, 0 for program char extra[]; // extra material for overlays, etc. void far *relocs[]; // relocation entries, starts at relocpos 75-08 Sistemas Operativos 14 FIUBA Prof. Lic. Ing. Osvaldo Clúa Lic. Adrián Muccio Common Object File Format COFF ● Aparece en Unix pero se usa en otros ambientes. ● Se compone de varias secciones separadas por headers (con limitación de longitud). ● Se usa para bibliotecas. – Aunque no de enlace dinámico. AIX usa XCOFF ● Soporta debug (pero solo de C). ● nm(1) lo puede inspeccionar. 75-08 Sistemas Operativos 15 FIUBA Prof. Lic. Ing. Osvaldo Clúa Lic. Adrián Muccio Windows Portable Executable (PE ) ● Es una adaptación del COFF. El Windows hace un wrapping del COFF. ● Se usa en Intel, ARM y SuperH (Windows CE). ● Además Intel lo adoptó para EFI. ● Microsoft también lo usa en .net para la máquina virtual Common Language Runtime . ● Mono lo debió adoptar (quiere ser compatible a nivel binario con .net). 75-08 Sistemas Operativos 16 FIUBA Prof. Lic. Ing. Osvaldo Clúa Lic. Adrián Muccio PE de Microsoft ● Su magic es “PE” pero comienza con un “MZ” por “compatibilidad”. ● Tiene definido espacio para resources. ● Tiene definido tablas para el uso de bibliotecas compartidas. ● Hay herramientas de análisis. ● En 64 bits se lo conoce como PE+ o PE32+ 75-08 Sistemas Operativos 17 FIUBA Prof. Lic. Ing. Osvaldo Clúa Lic. Adrián Muccio PE de Microsoft ● No tiene PIC (Position-Independent Code) ● Todas las direcciones se fijan en referencia a una dirección base. ● Si esa dirección ya lo uso “otro” se deben recalcular todas las direcciones. ● Las DLLs de Microsoft tiene una dirección base predefinida para que no colisionen entre sí. 75-08 Sistemas Operativos 18 FIUBA Prof. Lic. Ing. Osvaldo Clúa Lic. Adrián Muccio Executable and Linkable Format (ELF) ● Sirve para ejecutables y bibliotecas. ● Un directorio permite agregar nuevas secciones. ● Tiene previsiones para emulación – Linux, Solaris, IRIX, Referencias: La especificación FreeBSD, NetBSD, y man elf(5). OpenBSD, PlayStation 75-08 Sistemas Operativos 19 FIUBA Prof. Lic. Ing. Osvaldo Clúa Lic. Adrián Muccio Binarios Universales ● Mac usa la idea en 2005 para facilitar el pase de PPC a Mactel. – Ya la había usado al pasar de 68k a PPC. ● Se basa en el concepto de fat binary. El formato es Mach-O. – Puede usar un emulador: Rosetta – Puede tener código ppc-32,ppc-64 y x86-64 EM64T 75-08 Sistemas Operativos 20 FIUBA Prof. Lic. Ing. Osvaldo Clúa Lic. Adrián Muccio.
Recommended publications
  • The “Stabs” Debug Format
    The \stabs" debug format Julia Menapace, Jim Kingdon, David MacKenzie Cygnus Support Cygnus Support Revision TEXinfo 2017-08-23.19 Copyright c 1992{2021 Free Software Foundation, Inc. Contributed by Cygnus Support. Written by Julia Menapace, Jim Kingdon, and David MacKenzie. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled \GNU Free Documentation License". i Table of Contents 1 Overview of Stabs ::::::::::::::::::::::::::::::: 1 1.1 Overview of Debugging Information Flow ::::::::::::::::::::::: 1 1.2 Overview of Stab Format ::::::::::::::::::::::::::::::::::::::: 1 1.3 The String Field :::::::::::::::::::::::::::::::::::::::::::::::: 2 1.4 A Simple Example in C Source ::::::::::::::::::::::::::::::::: 3 1.5 The Simple Example at the Assembly Level ::::::::::::::::::::: 4 2 Encoding the Structure of the Program ::::::: 7 2.1 Main Program :::::::::::::::::::::::::::::::::::::::::::::::::: 7 2.2 Paths and Names of the Source Files :::::::::::::::::::::::::::: 7 2.3 Names of Include Files:::::::::::::::::::::::::::::::::::::::::: 8 2.4 Line Numbers :::::::::::::::::::::::::::::::::::::::::::::::::: 9 2.5 Procedures ::::::::::::::::::::::::::::::::::::::::::::::::::::: 9 2.6 Nested Procedures::::::::::::::::::::::::::::::::::::::::::::: 11 2.7 Block Structure
    [Show full text]
  • The IAR XLINK Linker™ and IAR XLIB Librarian™ Reference Guide
    IAR Linker and Library To o l s Reference Guide Version 4.60 XLINK-460G COPYRIGHT NOTICE © Copyright 1987–2007 IAR Systems. All rights reserved. No part of this document may be reproduced without the prior written consent of IAR Systems. The software described in this document is furnished under a license and may only be used or copied in accordance with the terms of such a license. DISCLAIMER The information in this document is subject to change without notice and does not represent a commitment on any part of IAR Systems. While the information contained herein is assumed to be accurate, IAR Systems assumes no responsibility for any errors or omissions. In no event shall IAR Systems, its employees, its contractors, or the authors of this document be liable for special, direct, indirect, or consequential damage, losses, costs, charges, claims, demands, claim for lost profits, fees, or expenses of any nature or kind. TRADEMARKS IAR, IAR Systems, IAR Embedded Workbench, IAR MakeApp, C-SPY, visualSTATE, From Idea To Target, IAR KickStart Kit and IAR PowerPac are trademarks or registered trademarks owned by IAR Systems AB. All other product names are trademarks or registered trademarks of their respective owners. EDITION NOTICE April 2007 Part number: XLINK-460G The IAR Linker and Library Tools Reference Guide replaces all versions of the IAR XLINK Linker™ and IAR XLIB Librarian™ Reference Guide. XLINK-460G Contents Tables .....................................................................................................................
    [Show full text]
  • Packet Structure Definition
    xx Tektronix Logic Analyzer Online Help ZZZ PrintedHelpDocument *P077003206* 077-0032-06 Tektronix Logic Analyzer Online Help ZZZ PrintedHelpDocument www.tektronix.com 077-0032-06 Copyright © Tektronix. All rights reserved. Licensed software products are owned by Tektronix or its subsidiaries or suppliers, and are protected by national copyright laws and international treaty provisions. Tektronix products are covered by U.S. and foreign patents, issued and pending. Information in this publication supersedes that in all previously published material. Specifications and price change privileges reserved. TEKTRONIX and TEK are registered trademarks of Tektronix, Inc. D-Max, MagniVu, iView, iVerify, iCapture, iLink, PowerFlex, and TekLink are trademarks of Tektronix, Inc. 076-0113-06 077-0032-06 April 27, 2012 Contacting Tektronix Tektronix, Inc. 14150 SWKarlBraunDrive P.O. Box 500 Beaverton, OR 97077 USA For product information, sales, service, and technical support: In North America, call 1-800-833-9200. Worldwide, visit www.tektronix.com to find contacts in your area. Warranty Tektronix warrants that this product will be free from defects in materials and workmanship for a period of one (1) year from the date of shipment. If any such product proves defective during this warranty period, Tektronix, at its option, either will repair the defective product without charge for parts and labor, or will provide a replacement in exchange for the defective product. Parts, modules and replacement products used by Tektronix for warranty work may be new or reconditioned to like new performance. All replaced parts, modules and products become the property of Tektronix. In order to obtain service under this warranty, Customer must notify Tektronix of the defect before the expiration of the warranty period and make suitable arrangements for the performance of service.
    [Show full text]
  • IAR Linker and Library Tools Reference Guide
    IAR Linker and Library Tools Reference Guide XLINK-540 XLINK-540 COPYRIGHT NOTICE © 1987–2012 IAR Systems AB. No part of this document may be reproduced without the prior written consent of IAR Systems AB. The software described in this document is furnished under a license and may only be used or copied in accordance with the terms of such a license. DISCLAIMER The information in this document is subject to change without notice and does not represent a commitment on any part of IAR Systems. While the information contained herein is assumed to be accurate, IAR Systems assumes no responsibility for any errors or omissions. In no event shall IAR Systems, its employees, its contractors, or the authors of this document be liable for special, direct, indirect, or consequential damage, losses, costs, charges, claims, demands, claim for lost profits, fees, or expenses of any nature or kind. TRADEMARKS IAR Systems, IAR Embedded Workbench, C-SPY, visualSTATE, The Code to Success, IAR KickStart Kit, I-jet, IAR, and the logotype of IAR Systems are trademarks or registered trademarks owned by IAR Systems AB. Microsoft and Windows are registered trademarks of Microsoft Corporation. Adobe and Acrobat Reader are registered trademarks of Adobe Systems Incorporated. All other product names are trademarks or registered trademarks of their respective owners. EDITION NOTICE June 2012 Part number: XLINK-540 The IAR Linker and Library Tools Reference Guide replaces all versions of the IAR XLINK Linker™ and IAR XLIB Librarian™ Reference Guide. XLINK-540 Contents Tables ........................................................................................................................ 7 Preface ...................................................................................................................... 9 Who should read this guide ................................................................. 9 How to use this guide ............................................................................
    [Show full text]
  • Using Ld the GNU Linker
    Using ld The GNU linker ld version 2 January 1994 Steve Chamberlain Cygnus Support Cygnus Support [email protected], [email protected] Using LD, the GNU linker Edited by Jeffrey Osier (jeff[email protected]) Copyright c 1991, 92, 93, 94, 95, 96, 97, 1998 Free Software Foundation, Inc. Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies. Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided also that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. Permission is granted to copy and distribute translations of this manual into another lan- guage, under the above conditions for modified versions. Chapter 1: Overview 1 1 Overview ld combines a number of object and archive files, relocates their data and ties up symbol references. Usually the last step in compiling a program is to run ld. ld accepts Linker Command Language files written in a superset of AT&T’s Link Editor Command Language syntax, to provide explicit and total control over the linking process. This version of ld uses the general purpose BFD libraries to operate on object files. This allows ld to read, combine, and write object files in many different formats—for example, COFF or a.out. Different formats may be linked together to produce any available kind of object file. See Chapter 5 [BFD], page 47, for more information. Aside from its flexibility, the gnu linker is more helpful than other linkers in providing diagnostic information.
    [Show full text]
  • Linker Script Guide Emprog
    Linker Script Guide Emprog Emprog ThunderBench™ Linker Script Guide Version 1.2 ©May 2013 Page | 1 Linker Script Guide Emprog 1 - Linker Script guide 2 -Arm Specific Options Page | 2 Linker Script Guide Emprog 1 The Linker Scripts Every link is controlled by a linker script. This script is written in the linker command language. The main purpose of the linker script is to describe how the sections in the input files should be mapped into the output file, and to control the memory layout of the output file. Most linker scripts do nothing more than this. However, when necessary, the linker script can also direct the linker to perform many other operations, using the commands described below. The linker always uses a linker script. If you do not supply one yourself, the linker will use a default script that is compiled into the linker executable. You can use the ‘--verbose’ command line option to display the default linker script. Certain command line options, such as ‘-r’ or ‘-N’, will affect the default linker script. You may supply your own linker script by using the ‘-T’ command line option. When you do this, your linker script will replace the default linker script. You may also use linker scripts implicitly by naming them as input files to the linker, as though they were files to be linked. 1.1 Basic Linker Script Concepts We need to define some basic concepts and vocabulary in order to describe the linker script language. The linker combines input files into a single output file. The output file and each input file are in a special data format known as an object file format.
    [Show full text]
  • Linkers and Loaders Do?
    Linkers & Loaders by John R. Levine Table of Contents 1 Table of Contents Chapter 0: Front Matter ........................................................ 1 Dedication .............................................................................................. 1 Introduction ............................................................................................ 1 Who is this book for? ......................................................................... 2 Chapter summaries ............................................................................. 3 The project ......................................................................................... 4 Acknowledgements ............................................................................ 5 Contact us ........................................................................................... 6 Chapter 1: Linking and Loading ........................................... 7 What do linkers and loaders do? ............................................................ 7 Address binding: a historical perspective .............................................. 7 Linking vs. loading .............................................................................. 10 Tw o-pass linking .............................................................................. 12 Object code libraries ........................................................................ 15 Relocation and code modification .................................................... 17 Compiler Drivers .................................................................................
    [Show full text]
  • Interaktívny Disassembler Prohlášení
    VYSOKÉ UČENÍ TECHNICKÉ V BRNĚ BRNO UNIVERSITY OF TECHNOLOGY FAKULTA INFORMAČNÍCH TECHNOLOGIÍ ÚSTAV INFORMAČNÝCH SYSTÉMŮ FACULTY OF INFORMATION TECHNOLOGY DEPARTMENT OF INFORMATION SYSTEMS INTERAKTÍVNY DISASSEMBLER BAKALÁŘSKÁ PRÁCE BACHELOR'S THESIS AUTOR PRÁCE Milan Mrva AUTHOR BRNO 2011 VYSOKÉ UČENÍ TECHNICKÉ V BRNĚ BRNO UNIVERSITY OF TECHNOLOGY FAKULTA INFORMAČNÍCH TECHNOLOGIÍ ÚSTAV INFORMAČNÝCH SYSTÉMŮ FACULTY OF INFORMATION TECHNOLOGY DEPARTMENT OF INFORMATION SYSTEMS INTERAKTIVNÍ ZPĚTNÝ ASSEMBLER INTERACTIVE DISASSEMBLER BAKALÁŘSKÁ PRÁCE BACHELOR'S THESIS AUTOR PRÁCE Milan Mrva AUTHOR VEDOUCÍ PRÁCE Ing. Jakub Křoustek SUPERVISOR BRNO 2011 Abstrakt V práci jsou popsané postupy a nástroje zpětného inženýrství v rámci softwaru. Uvedené jsou techniky ochrany před rozkladem či zkoumáním obsahu spustitelného souboru. Představené jsou příklady programů zabývajících se zpětným překladem. Dále se práce zaobírá architekturou procesoru s důrazem na mikroprocesory Intel a Motorola. Jsou ukázané rozdílné formáty spustitelných souborů. Byl implementovaný generický modulovatelný zpětný assembler.V tomto textu je představená jak jeho struktura, tak zásuvné moduly, které prezentují tři různé techniky disassemblovaní. Jeden z modulů používa vícevláknový parser, který je vlastním návrhem autora. Tyto přístupy jsou v závěru porovnané a je nastíněn další vývoj. Abstract This thesis describes procedures and tools of reverse engineering in terms of software development. There are introduces different techniques of protection against decomposition of executables. The work also mentions some programs used for decomposition analysis. Furthermore it contains information about architecture of processing units, with emphasis on microprocessors Intel and Motorola. Variety of executable formats is shown. Generic retargetable disassembler was implemented. There is a description of its structure and plugins. These plugins represents three algorithms used for disassembling a program.
    [Show full text]
  • Developing and Porting C and C++ Applications on AIX
    IBM Front cover Developing and Porting C and C++ Applications on AIX Detailed explanations about 32- and 64-bit process models Effective management of shared objects and libraries Exploring parallel programming using OpenMP Keigo Matsubara Edison Kwok Inge Rodriguez Murali Paramasivam ibm.com/redbooks International Technical Support Organization Developing and Porting C and C++ Applications on AIX June 2003 SG24-5674-01 Note: Before using this information and the product it supports, read the information in “Notices” on page xvii. Second Edition (June 2003) This edition applies to C for AIX (program number 5765-F57) and VisualAge C++ for AIX Version 6.0 (product number 5765-F56) installed on AIX 5L Version 5.2 (product number 5765-E62). © Copyright International Business Machines Corporation 2000, 2003. All rights reserved. Note to U.S. Government Users Restricted Rights -- Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents Figures . xiii Tables . xv Notices . xvii Trademarks . xviii Preface . xix The team that wrote this redbook. xix Become a published author . xx Comments welcome. xxi Summary of changes . xxiii June 2003, Second Edition . xxiii September 2000, First Edition . xxiv Chapter 1. C and C++ compilers . 1 1.1 C for AIX Version 6.0. 2 1.1.1 New or improved optimization features. 2 1.1.2 ISO C Standard conformance . 4 1.1.3 GNU C compatibility . 10 1.1.4 Enhanced language level support. 15 1.2 VisualAge C++ for AIX Version 6.0 . 16 1.2.1 New or improved optimization features. 16 1.2.2 OpenMP support .
    [Show full text]
  • Exe Fájlformátum Loader Linker Kód Visszafejtés
    | Linker és Loader COFF PE/COFF Exe fájlformátum loader linker Kód visszafejtés. Izsó Tamás 2016. december 1. Izsó Tamás Exe fájlformátum loader linker/ 1 | Linker és Loader COFF PE/COFF Section 1 Linker és Loader Izsó Tamás Exe fájlformátum loader linker/ 2 | Linker és Loader COFF PE/COFF Több modulból álló C program fordítása calc.c test.c cl -c calc.c cl -c test.c fordítás calc.obj test.obj link test.obj calc.obj /out:test.exe linkelés test.exe Izsó Tamás Exe fájlformátum loader linker/ 3 | Linker és Loader COFF PE/COFF Több modulból álló C program fordítás 1 // Inclusion guard 2 #ifndef _CALC_H_ 3 #define _CALC_H_ 4 5 6 int Add( int a, intb); 7 void Function( void ); 8 9 // End the inclusion guard 10 #endif calc.h header file Izsó Tamás Exe fájlformátum loader linker/ 4 | Linker és Loader COFF PE/COFF Több modulból álló C program fordítás 1 #include <stdio.h> 2 // Define 2 functions 3 4 // Add will return the sum of two numbers 5 int Add( int a, intb) 6 { 7 return a + b; 8 } 9 10 // Function will print out a text string 11 void Function( void ) 12 { 13 printf("Function called!\n"); 14 } calc.c rutinokat tartalmazó forrásfájl Izsó Tamás Exe fájlformátum loader linker/ 5 | Linker és Loader COFF PE/COFF Több modulból álló C program fordítás 1 #include <stdio.h> 2 #include"calc.h" 3 4 int main() 5 { 6 printf("65+44=%d\n", Add(65, 44) ); 7 Function(); 8 return(1); 9 } test.c foprogram˝ forrásfájl Izsó Tamás Exe fájlformátum loader linker/ 6 | Linker és Loader COFF PE/COFF Statikus linkelés *.lib lefordított tárgykódok (obj) gyüjteménye (archive, library); linkelésnél a futtatható program részévé válik .lib egy része; egyszer˝ua programot telepíteni; sok memóriát használ, mivel minden egyes futtatható fájl- ban azonos kódrészek találhatók; a javítás újralinkelést igényel (nehéz az sw.
    [Show full text]
  • Why Does My Program Not Link Or Not Execute Global Constructors
    Ns-3 Application Note Why Don’t Those #@(%!~& Libraries Work? Craig Dowell [email protected] Background Consider the following program int main(int argc, char **argv) { myprintf("Hello World\n"); } When you compile this program, the compiler determines that there is no function called myprintf in the compilation unit (the source file) and marks the function as an unresolved reference. When the executable is linked, the linker looks through its list of libraries looking for an implementation of the function myprintf. The linker handles providing an implementation in one of two ways depending on the kind of file providing the implementation. • If the implementation is found in a static library (e.g., libcore.a), the linker copies the implementation of myprintf into the executable. The linker must then recursively search for further unresolved references in the myprintf function and resolve them by (possibly) looking in other libraries. This continues until the executable contains all of the code required to execute myprintf (there are no unresolved references). • If the implementation of myprintf is found in a dynamic library (e.g., libcore.so), the linker adds a note to itself that the unresolved reference can be resolved by loading the dynamic library. The linker recursively searches for further unresolved references and continues until all references are resolved. What happens when you run the resulting program depends on the kind of library to which you linked. • If you linked to static libraries, your program is self-contained. It will be loaded into memory and executed, starting at a system-dependent entry point.
    [Show full text]
  • Gdb Internals a Guide to the Internals of the GNU Debugger
    gdb Internals A guide to the internals of the GNU debugger John Gilmore Cygnus Solutions Second Edition: Stan Shebs Cygnus Solutions Cygnus Solutions Revision TEXinfo 2007-09-03.05 Copyright c 1990-2013 Free Software Foundation, Inc. Contributed by Cygnus Solutions. Written by John Gilmore. Second Edition by Stan Shebs. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled \GNU Free Documentation License". i Table of Contents Scope of this Document :::::::::::::::::::::::::::: 1 1 Summary :::::::::::::::::::::::::::::::::::::::: 1 1.1 Requirements :::::::::::::::::::::::::::::::::::::::::::::::::: 1 1.2 Contributors ::::::::::::::::::::::::::::::::::::::::::::::::::: 1 2 Overall Structure ::::::::::::::::::::::::::::::: 2 2.1 The Symbol Side ::::::::::::::::::::::::::::::::::::::::::::::: 2 2.2 The Target Side :::::::::::::::::::::::::::::::::::::::::::::::: 2 2.3 Configurations ::::::::::::::::::::::::::::::::::::::::::::::::: 2 2.4 Source Tree Structure :::::::::::::::::::::::::::::::::::::::::: 3 3 Algorithms :::::::::::::::::::::::::::::::::::::: 4 3.1 Prologue Analysis :::::::::::::::::::::::::::::::::::::::::::::: 4 3.2 Breakpoint Handling ::::::::::::::::::::::::::::::::::::::::::: 6 3.3 Single Stepping ::::::::::::::::::::::::::::::::::::::::::::::::
    [Show full text]