SlideShare una empresa de Scribd logo
1 de 39
Linker – AN INTRODUCTION




9/3/2012                          1
Steps in Program execution

              Translator



               Linking



              Relocation



               Loading

9/3/2012                          2
Agenda
•   Linking
•   Linker
•   Historical Perspective
•   Linker vs Loader
•   Linking Process
     – Two pass Linking
• Object Code Libraries
• Relocation and Code modification
• Linking an Example

9/3/2012                             3
Linking

• Binding Abstract Names -> Concrete Names
• Eg:
      – Getline -> Abstract Name
      – 0x00100101 -> Concrete Name


Definition:
 Linking is a process of binding an external
 reference to the correct link time address
9/3/2012                                       4
What is a Linker?

• A System Software that Combines two or more
  separate object programs and supplies the information
  needed to allow references between them




9/3/2012                                              5
Historical Perspective in Address
             Binding

• Linking in Low Level Programming
   – Hand written
   – Problem???
      • Hand Inspection
      • Address bound to the names too early
• Assemblers made it simple…
   – Programmer -> Computers
• After Advent of Operating System
   – Separation of Linkers and Loaders
9/3/2012                                       6
• At the time of Programs became larger than
  available memory
      – Overlays, A technique that let programmers
        arrange for different parts of a program to share
        the same memory, with each overlay loaded on
        demand when another part of the program called
        into it.
      – Popular in 1960 but faded after the advent of
        Virtual Memory on PCs at 1990s

9/3/2012                                                    7
Types of Linking
• Two Types
      – Dynamic Linking
      – Static Linking


• Static Linking:
      – Static linkers takes input a collection of
        relocatable object files and command line
        arguments and generate as output a fully linked
        executable object file that can be loaded and run.
9/3/2012                                                     8
Types…
• Dynamic Linking:
      – The addresses of called procedures aren‟t bound
        until the first call.
      – Programs can bind to libraries as the programs are
        running, loading libraries in the middle of program
        execution.
      – This provides a powerful and high-performance
        way to extend the function of programs
      – MS Windows extensively uses DLL (Dynamic
        Linked Libraries)

9/3/2012                                                  9
Difference b/w Linker and
            Loader
• Linker is a program that takes one or more objects
  generated by a compiler and combines them into a
  single executable program.

• Loader is the part of an operating system that is
  responsible for loading programs from executables
  (i.e., executable files) into memory, preparing them
  for execution and then executing them.
• Linkers are the system softwares that are used to link
  the functions,resources to their respective references.
  EX-
  source code(.c) is compiled and converted into object
  code(.obj) in C.
  After this Linker comes into the act, linker resolve all
  the references in .obj file via linking them to their
  respectives codes and resources.In short linker
  performs the final step to convert .obj into executable
  or machine readable file(.exe).
• eg:
  #include<stdio.h>
  int main()
  {
  printf("ashwin");
  return 0;
  }

  here,compiler first searches the declaration for
  "printf()" function,finds it in "#include<stdio.h>" and
  creates a (.obj) file successfully.
• A symbol table is created in (.obj) file which contains
  all the references to be resolved,linkers resolves them
  by providing respective code or resource,
  here code referred by "printf" also gets executed after
  successful creation of( .exe) file by linker.
• LOADERS:

 Loaders are the programs that are used to load the
 resources like files from secondary or main
 memory,i.e.
 Loader loads the referred resource or file after being
 Linked to referrer via a Linker during the execution
 of program.
LINKING PROCESS

                OBJECT         SHARED
                 FILES        LIBRARIES
COMMANDLINE



                                                NORMAL
     CONTROL                                   LIBRARIES
                           LINKER
      FILES




       DEBUG
       SYMBOL
                         EXECUTAB         LINK/LOAD
        FILE
                          LE FILE            MAP
Object code Libraries
 Object code library:
             set of object files.
• Object File:-
  header information (size, creation date, ...) ,object code
  relocation information (list of places to relocate)
  symbols: global symbols defined and symbols
      imported.
  debugging information (source file, line numbers, local
     symbols, data structures)
 A library is little more than a set of object code files.
   9/3/2012                                                16
Object Code Libraries

 All linkers support object code libraries in one form
  or another, with most also providing support for
  various kinds of shared libraries.

 After the linker processes all of the regular input files,
  if any imported names remain undefined
   it runs through the library/libraries
   links in any of the files in the library that export
      one or more undefined names.

9/3/2012                                                   17
Object code Libraries
       Object A                          Library1
       Calls C D
                                Linker      C

                                            D
           Object B
           Calls C E                        X

                                            Y

                            A

                            B            Library 2

                           C               E
                           D               F
                           E
                                            Z
9/3/2012               EXECUTABLE FILE               18
Contd…

 Shared libraries complicate this task a little by moving
  some of the work from link time to load time.

 The linker identifies the shared libraries that
   resolve the undefined names in a linker run, but rather
than linking anything into the program, the linker notes in
the output file the names of the libraries in which the
symbols were found, so that the shared library can be bound
in when the program is loaded.


 9/3/2012                                                    19
Relocation
• Relocation is the process of assigning load addresses
  to the various parts of the program, adjusting the code
  and data in the program to reflect the assigned
  addresses.

• Relocation, which modifies the object program so
  that it can be loaded at an address different from the
  location originally specified.



9/3/2012                                                   20
Contd…

 The linker relocates these sections by
   associating a memory location with each symbol
    definition
   modifying all of the references to those symbols so
    that they point to this memory location.

 Relocation might happen more than once
  linking several object files into a library
  loading the library
 9/3/2012                                                 21
Relocation and code modification

 The heart of a linker or loader‟s actions is relocation and
  code modification.

 When a compiler or assembler generates an object file,
  it generates the code using the unrelocated addresses of
  code and data defined within the file, and usually zeros
  for code and data defined elsewhere.

 As part of the linking process, the linker modifies the
  object code to reflect the actual addresses assigned.
 9/3/2012                                                   22
Example
Code that moves the contents of variable a to
 variable b using the eax register.
          mov a,%eax
          mov %eax,b

If a is defined in the same file at location 1234
 hex and b is imported from somewhere else, the
 generated object code will be:
            A1 34 12 00 00 mov a,%eax
 9/3/2012
            A3 00 00 00 00 mov %eax,b            23
Contd…
• The linker links this code so that the section in which a is located is
  relocated by hex 10000 bytes, and b turns out to be at hex 9A12.

• The linker modifies the code to be:
      Relocated code
              A1 34 12 01 00 mov a,%eax
              A3 12 9A 00 00 mov %eax,b

• That is, it adds 10000 to the address in the first instruction so now it
  refers to a‟s relocated address which is 11234, and it patches in the
  address for b. These adjustments affect instructions, but any pointers
  in the data part of an object file have to be adjusted as well.

   9/3/2012                                                            24
Relocation and code modification
• Linker modifies code to reflect assigned addresses depends on
  hardware architecture
• On older computers with small address spaces and direct
  addressing there are only one or two address formats that a linker
  has to handle.

• Modern computers(RISC) require considerably more complex code
  modification because it constructs addresses by several
  instructions.
• No single instruction contains enough bits to hold a direct address,
  so the compiler and linker have to use complicated addressing
  tricks to handle data at arbitrary addresses.

  9/3/2012                                                        25
Relocation and code modification

• In some cases, it‟s possible to calculate an address using two or three
  instructions, each of which contains part of the address, and use bit
  manipulation to combine the parts into a full address.
• In this case, the linker has to be prepared to modify each of the
  instructions, inserting some of the bits of the address into each
  instruction.

• In other cases, all of the addresses used by a routine or group of
  routines are placed in an array used as an „„address pool‟‟,
  initialization code sets one of the machine registers to point to that
  array, and code loads pointers out of the address pool as needed using
  that register as a base register.
   9/3/2012                                                          26
Contd…
• The linker may have to create the array from all of the addresses
  used in a program, then modify instructions that so that they refer to
  the respective address pool entry.

• Code might be required to be position independent (PIC)
   – works regardless where library is loaded
   – same library used at different addresses by processes

• Linkers generally have to provide extra tricks to support that,
  separating out the parts of the program that can‟t be made position
  independent, and arranging for the two parts to communicate.


  9/3/2012                                                          27
Linker Command Languages
• Every linker has some sort of command language to
  control the linking process.
• The linker needs the list of object files and libraries to
  link.
• In linkers that support multiple code and data
  segments, a linker command language can specify the
  order in which segments are to be linked.




9/3/2012                                                   28
• There are common techniques to pass commands to a
  linker,
Command Line:
• It is used to direct the linker to read commands from
  a file.
Embedded in object files:
• Linker commands to be embedded inside object files.
• This permits a compiler to pass any options needed to
  link an object file in the file itself.


9/3/2012                                              29
Contd…
Separate configuration language:
• The linkers have a full fledged configuration
  language to control linking.
• The GNU linker, which can handle an enormous
  range of object file formats, machine architectures,
  and address space conventions




9/3/2012                                                 30
An Example From C Language

• A pair of C language source files, m.c with a main
  program that calls a routine named a, and a.c that
  contains the routine with a call to the library routines
  strlen and printf.
• When the source file compiles at the time the object
  file create.
• Each object file contain atleast one symbol table.




9/3/2012                                                     31
m.c                 a.c

           Compiler         Compiler

                                       Separately compiled
            m.o                 a.o
                                       relocatable object files

                  Linker (ld)

                            Executable object file (contains code and
                       p    data for all functions defined in m.c and a.c)




9/3/2012                                                                32
Source file m.c             Source file a.c

     extern void a(char *);        #include <stdio.h>
     int main(int ac, char **av)   #include <string.h>
     {                             void a(char *s)
     static char string[] =        {
        "Hello, world!n";         printf(“%d”,strlen(s));
     a(string);                    }
     }



9/3/2012                                                     33
Object code for m.o

Idx        Name Size        VMA       LMA   File off   Algn

0.         text 00000010 00000000 00000000 00000020 2**3
1.         data 00000010 00000010 00000010 00000030 2**3

•     00000000 <_main>:
•     0: 55 pushl %ebp
•     1: 89 e5 movl %esp,%ebp
•     3: 68 10 00 00 00 pushl $0x10
•     4: 32 .data
•     8: e8 f3 ff ff ff call 0
•     9: DISP32 _a
•     d: c9 leave
•     e: c3 ret
•     ...

9/3/2012                                                      34
• In that object file "text" segment containing the read
  only program code, and "data" segment containing
  the string.
There are two relocation entries,
• That marks the pushl instruction that puts the address
  of the string on the stack in preparation for the call to
  a.
• one that marks the call instruction that transfers
  control to a.



9/3/2012                                                  35
• The symbol table exports the definition of _main,
  imports _a.
• The object file of the subprogram a.c also contain
  data and text segments.
Two relocation entries,
• mark the calls to strlen and printf, and the symbol
  table exports _a and imports _strlen and _printf.




9/3/2012                                                36
An Example From C Language


                  m.c                 a.c
           int e=7;         extern int e;

           int main() {     int *ep=&e;
             int r = a();   int x=15;
             exit(0);       int y;
           }
                            int a() {
                              return *ep+x+y;
                            }



9/3/2012                                        37
Merging Relocatable Object Files
 into an Executable Object File
  Relocatable Object Files        Executable Object File

           system code    .text   0
                                          headers
           system data    .data
                                        system code
                                           main()          .text
                                             a()
             main()       .text
m.o
             int e = 7    .data       more system code
                                        system data
                                            int e = 7      .data
                a()       .text          int *ep = &e
                                           int x = 15
a.o        int *ep = &e   .data       uninitialized data   .bss
             int x = 15                     .symtab
                int y     .bss
                                             .debug
9/3/2012                                                     38
Linkers

Más contenido relacionado

La actualidad más candente

Assemblers: Ch03
Assemblers: Ch03Assemblers: Ch03
Assemblers: Ch03desta_gebre
 
Introduction to loaders
Introduction to loadersIntroduction to loaders
Introduction to loadersTech_MX
 
Linker and Loader Explained
Linker and Loader  ExplainedLinker and Loader  Explained
Linker and Loader ExplainedAdarsh Kr Sinha
 
Single pass assembler
Single pass assemblerSingle pass assembler
Single pass assemblerBansari Shah
 
System Programing Unit 1
System Programing Unit 1System Programing Unit 1
System Programing Unit 1Manoj Patil
 
Principle source of optimazation
Principle source of optimazationPrinciple source of optimazation
Principle source of optimazationSiva Sathya
 
ADVANCED COMPUTER ARCHITECTURE AND PARALLEL PROCESSING
ADVANCED COMPUTER ARCHITECTUREAND PARALLEL PROCESSINGADVANCED COMPUTER ARCHITECTUREAND PARALLEL PROCESSING
ADVANCED COMPUTER ARCHITECTURE AND PARALLEL PROCESSING Zena Abo-Altaheen
 
File Management in Operating System
File Management in Operating SystemFile Management in Operating System
File Management in Operating SystemJanki Shah
 
Basic blocks and control flow graphs
Basic blocks and control flow graphsBasic blocks and control flow graphs
Basic blocks and control flow graphsTilakpoudel2
 
Basic Computer Organization and Design
Basic Computer Organization and DesignBasic Computer Organization and Design
Basic Computer Organization and Designmekind
 

La actualidad más candente (20)

Macro Processor
Macro ProcessorMacro Processor
Macro Processor
 
Assemblers: Ch03
Assemblers: Ch03Assemblers: Ch03
Assemblers: Ch03
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
 
Introduction to loaders
Introduction to loadersIntroduction to loaders
Introduction to loaders
 
Linker and Loader Explained
Linker and Loader  ExplainedLinker and Loader  Explained
Linker and Loader Explained
 
Memory Hierarchy
Memory HierarchyMemory Hierarchy
Memory Hierarchy
 
Unit 3
Unit 3Unit 3
Unit 3
 
Single pass assembler
Single pass assemblerSingle pass assembler
Single pass assembler
 
System Programing Unit 1
System Programing Unit 1System Programing Unit 1
System Programing Unit 1
 
Unit 4 sp macro
Unit 4 sp macroUnit 4 sp macro
Unit 4 sp macro
 
Lex
LexLex
Lex
 
Code generation
Code generationCode generation
Code generation
 
Principle source of optimazation
Principle source of optimazationPrinciple source of optimazation
Principle source of optimazation
 
ADVANCED COMPUTER ARCHITECTURE AND PARALLEL PROCESSING
ADVANCED COMPUTER ARCHITECTUREAND PARALLEL PROCESSINGADVANCED COMPUTER ARCHITECTUREAND PARALLEL PROCESSING
ADVANCED COMPUTER ARCHITECTURE AND PARALLEL PROCESSING
 
File Management in Operating System
File Management in Operating SystemFile Management in Operating System
File Management in Operating System
 
Specification-of-tokens
Specification-of-tokensSpecification-of-tokens
Specification-of-tokens
 
Basic blocks and control flow graphs
Basic blocks and control flow graphsBasic blocks and control flow graphs
Basic blocks and control flow graphs
 
Loaders
LoadersLoaders
Loaders
 
Basic Computer Organization and Design
Basic Computer Organization and DesignBasic Computer Organization and Design
Basic Computer Organization and Design
 
Assembler
AssemblerAssembler
Assembler
 

Similar a Linkers

C++ shared libraries and loading
C++ shared libraries and loadingC++ shared libraries and loading
C++ shared libraries and loadingRahul Jamwal
 
Loaders and Linkers
Loaders and LinkersLoaders and Linkers
Loaders and Linkerskunj desai
 
How to write shared libraries!
How to write shared libraries!How to write shared libraries!
How to write shared libraries!Stanley Ho
 
Dbms & prog lang
Dbms & prog langDbms & prog lang
Dbms & prog langTech_MX
 
COMPILATION PROCESS IN C.pptx
COMPILATION PROCESS IN C.pptxCOMPILATION PROCESS IN C.pptx
COMPILATION PROCESS IN C.pptxLECO9
 
COMPILATION PROCESS IN C.pptx
COMPILATION PROCESS IN C.pptxCOMPILATION PROCESS IN C.pptx
COMPILATION PROCESS IN C.pptxSKUP1
 
.net Based Component Technologies
.net Based Component Technologies.net Based Component Technologies
.net Based Component Technologiesprakashk453625
 
Address Binding Scheme
Address Binding SchemeAddress Binding Scheme
Address Binding SchemeRajesh Piryani
 
Loaders complete
Loaders completeLoaders complete
Loaders completeFaisal Shah
 
Directory services by SAJID
Directory services by SAJIDDirectory services by SAJID
Directory services by SAJIDSajid khan
 
RethinkDB - the open-source database for the realtime web
RethinkDB - the open-source database for the realtime webRethinkDB - the open-source database for the realtime web
RethinkDB - the open-source database for the realtime webAlex Ivanov
 

Similar a Linkers (20)

Linkers in compiler
Linkers in compilerLinkers in compiler
Linkers in compiler
 
C++ shared libraries and loading
C++ shared libraries and loadingC++ shared libraries and loading
C++ shared libraries and loading
 
Microsoft data access components
Microsoft data access componentsMicrosoft data access components
Microsoft data access components
 
Linkers
LinkersLinkers
Linkers
 
Dsohowto
DsohowtoDsohowto
Dsohowto
 
Loaders and Linkers
Loaders and LinkersLoaders and Linkers
Loaders and Linkers
 
Linking in MS-Dos System
Linking in MS-Dos SystemLinking in MS-Dos System
Linking in MS-Dos System
 
How to write shared libraries!
How to write shared libraries!How to write shared libraries!
How to write shared libraries!
 
Metadata lecture 5 part 2
Metadata lecture 5 part 2Metadata lecture 5 part 2
Metadata lecture 5 part 2
 
Dbms & prog lang
Dbms & prog langDbms & prog lang
Dbms & prog lang
 
COMPILATION PROCESS IN C.pptx
COMPILATION PROCESS IN C.pptxCOMPILATION PROCESS IN C.pptx
COMPILATION PROCESS IN C.pptx
 
COMPILATION PROCESS IN C.pptx
COMPILATION PROCESS IN C.pptxCOMPILATION PROCESS IN C.pptx
COMPILATION PROCESS IN C.pptx
 
.net Based Component Technologies
.net Based Component Technologies.net Based Component Technologies
.net Based Component Technologies
 
wk 4 -- linking.ppt
wk 4 -- linking.pptwk 4 -- linking.ppt
wk 4 -- linking.ppt
 
Linkers
LinkersLinkers
Linkers
 
Address Binding Scheme
Address Binding SchemeAddress Binding Scheme
Address Binding Scheme
 
Loaders complete
Loaders completeLoaders complete
Loaders complete
 
LOD2 Webinar Series: SILK
LOD2 Webinar Series: SILKLOD2 Webinar Series: SILK
LOD2 Webinar Series: SILK
 
Directory services by SAJID
Directory services by SAJIDDirectory services by SAJID
Directory services by SAJID
 
RethinkDB - the open-source database for the realtime web
RethinkDB - the open-source database for the realtime webRethinkDB - the open-source database for the realtime web
RethinkDB - the open-source database for the realtime web
 

Más de Tech_MX

Virtual base class
Virtual base classVirtual base class
Virtual base classTech_MX
 
Theory of estimation
Theory of estimationTheory of estimation
Theory of estimationTech_MX
 
Templates in C++
Templates in C++Templates in C++
Templates in C++Tech_MX
 
String & its application
String & its applicationString & its application
String & its applicationTech_MX
 
Statistical quality__control_2
Statistical  quality__control_2Statistical  quality__control_2
Statistical quality__control_2Tech_MX
 
Stack data structure
Stack data structureStack data structure
Stack data structureTech_MX
 
Stack Data Structure & It's Application
Stack Data Structure & It's Application Stack Data Structure & It's Application
Stack Data Structure & It's Application Tech_MX
 
Spanning trees & applications
Spanning trees & applicationsSpanning trees & applications
Spanning trees & applicationsTech_MX
 
Set data structure 2
Set data structure 2Set data structure 2
Set data structure 2Tech_MX
 
Set data structure
Set data structure Set data structure
Set data structure Tech_MX
 
Real time Operating System
Real time Operating SystemReal time Operating System
Real time Operating SystemTech_MX
 
Mouse interrupts (Assembly Language & C)
Mouse interrupts (Assembly Language & C)Mouse interrupts (Assembly Language & C)
Mouse interrupts (Assembly Language & C)Tech_MX
 
Motherboard of a pc
Motherboard of a pcMotherboard of a pc
Motherboard of a pcTech_MX
 
More on Lex
More on LexMore on Lex
More on LexTech_MX
 
MultiMedia dbms
MultiMedia dbmsMultiMedia dbms
MultiMedia dbmsTech_MX
 
Merging files (Data Structure)
Merging files (Data Structure)Merging files (Data Structure)
Merging files (Data Structure)Tech_MX
 
Memory dbms
Memory dbmsMemory dbms
Memory dbmsTech_MX
 

Más de Tech_MX (20)

Virtual base class
Virtual base classVirtual base class
Virtual base class
 
Uid
UidUid
Uid
 
Theory of estimation
Theory of estimationTheory of estimation
Theory of estimation
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
 
String & its application
String & its applicationString & its application
String & its application
 
Statistical quality__control_2
Statistical  quality__control_2Statistical  quality__control_2
Statistical quality__control_2
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
Stack Data Structure & It's Application
Stack Data Structure & It's Application Stack Data Structure & It's Application
Stack Data Structure & It's Application
 
Spss
SpssSpss
Spss
 
Spanning trees & applications
Spanning trees & applicationsSpanning trees & applications
Spanning trees & applications
 
Set data structure 2
Set data structure 2Set data structure 2
Set data structure 2
 
Set data structure
Set data structure Set data structure
Set data structure
 
Real time Operating System
Real time Operating SystemReal time Operating System
Real time Operating System
 
Parsing
ParsingParsing
Parsing
 
Mouse interrupts (Assembly Language & C)
Mouse interrupts (Assembly Language & C)Mouse interrupts (Assembly Language & C)
Mouse interrupts (Assembly Language & C)
 
Motherboard of a pc
Motherboard of a pcMotherboard of a pc
Motherboard of a pc
 
More on Lex
More on LexMore on Lex
More on Lex
 
MultiMedia dbms
MultiMedia dbmsMultiMedia dbms
MultiMedia dbms
 
Merging files (Data Structure)
Merging files (Data Structure)Merging files (Data Structure)
Merging files (Data Structure)
 
Memory dbms
Memory dbmsMemory dbms
Memory dbms
 

Último

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 

Último (20)

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 

Linkers

  • 1. Linker – AN INTRODUCTION 9/3/2012 1
  • 2. Steps in Program execution Translator Linking Relocation Loading 9/3/2012 2
  • 3. Agenda • Linking • Linker • Historical Perspective • Linker vs Loader • Linking Process – Two pass Linking • Object Code Libraries • Relocation and Code modification • Linking an Example 9/3/2012 3
  • 4. Linking • Binding Abstract Names -> Concrete Names • Eg: – Getline -> Abstract Name – 0x00100101 -> Concrete Name Definition: Linking is a process of binding an external reference to the correct link time address 9/3/2012 4
  • 5. What is a Linker? • A System Software that Combines two or more separate object programs and supplies the information needed to allow references between them 9/3/2012 5
  • 6. Historical Perspective in Address Binding • Linking in Low Level Programming – Hand written – Problem??? • Hand Inspection • Address bound to the names too early • Assemblers made it simple… – Programmer -> Computers • After Advent of Operating System – Separation of Linkers and Loaders 9/3/2012 6
  • 7. • At the time of Programs became larger than available memory – Overlays, A technique that let programmers arrange for different parts of a program to share the same memory, with each overlay loaded on demand when another part of the program called into it. – Popular in 1960 but faded after the advent of Virtual Memory on PCs at 1990s 9/3/2012 7
  • 8. Types of Linking • Two Types – Dynamic Linking – Static Linking • Static Linking: – Static linkers takes input a collection of relocatable object files and command line arguments and generate as output a fully linked executable object file that can be loaded and run. 9/3/2012 8
  • 9. Types… • Dynamic Linking: – The addresses of called procedures aren‟t bound until the first call. – Programs can bind to libraries as the programs are running, loading libraries in the middle of program execution. – This provides a powerful and high-performance way to extend the function of programs – MS Windows extensively uses DLL (Dynamic Linked Libraries) 9/3/2012 9
  • 10. Difference b/w Linker and Loader • Linker is a program that takes one or more objects generated by a compiler and combines them into a single executable program. • Loader is the part of an operating system that is responsible for loading programs from executables (i.e., executable files) into memory, preparing them for execution and then executing them.
  • 11. • Linkers are the system softwares that are used to link the functions,resources to their respective references. EX- source code(.c) is compiled and converted into object code(.obj) in C. After this Linker comes into the act, linker resolve all the references in .obj file via linking them to their respectives codes and resources.In short linker performs the final step to convert .obj into executable or machine readable file(.exe).
  • 12. • eg: #include<stdio.h> int main() { printf("ashwin"); return 0; } here,compiler first searches the declaration for "printf()" function,finds it in "#include<stdio.h>" and creates a (.obj) file successfully.
  • 13. • A symbol table is created in (.obj) file which contains all the references to be resolved,linkers resolves them by providing respective code or resource, here code referred by "printf" also gets executed after successful creation of( .exe) file by linker.
  • 14. • LOADERS: Loaders are the programs that are used to load the resources like files from secondary or main memory,i.e. Loader loads the referred resource or file after being Linked to referrer via a Linker during the execution of program.
  • 15. LINKING PROCESS OBJECT SHARED FILES LIBRARIES COMMANDLINE NORMAL CONTROL LIBRARIES LINKER FILES DEBUG SYMBOL EXECUTAB LINK/LOAD FILE LE FILE MAP
  • 16. Object code Libraries  Object code library: set of object files. • Object File:- header information (size, creation date, ...) ,object code relocation information (list of places to relocate) symbols: global symbols defined and symbols imported. debugging information (source file, line numbers, local symbols, data structures)  A library is little more than a set of object code files. 9/3/2012 16
  • 17. Object Code Libraries  All linkers support object code libraries in one form or another, with most also providing support for various kinds of shared libraries.  After the linker processes all of the regular input files, if any imported names remain undefined it runs through the library/libraries links in any of the files in the library that export one or more undefined names. 9/3/2012 17
  • 18. Object code Libraries Object A Library1 Calls C D Linker C D Object B Calls C E X Y A B Library 2 C E D F E Z 9/3/2012 EXECUTABLE FILE 18
  • 19. Contd…  Shared libraries complicate this task a little by moving some of the work from link time to load time.  The linker identifies the shared libraries that resolve the undefined names in a linker run, but rather than linking anything into the program, the linker notes in the output file the names of the libraries in which the symbols were found, so that the shared library can be bound in when the program is loaded. 9/3/2012 19
  • 20. Relocation • Relocation is the process of assigning load addresses to the various parts of the program, adjusting the code and data in the program to reflect the assigned addresses. • Relocation, which modifies the object program so that it can be loaded at an address different from the location originally specified. 9/3/2012 20
  • 21. Contd…  The linker relocates these sections by associating a memory location with each symbol definition modifying all of the references to those symbols so that they point to this memory location.  Relocation might happen more than once linking several object files into a library loading the library 9/3/2012 21
  • 22. Relocation and code modification  The heart of a linker or loader‟s actions is relocation and code modification.  When a compiler or assembler generates an object file, it generates the code using the unrelocated addresses of code and data defined within the file, and usually zeros for code and data defined elsewhere.  As part of the linking process, the linker modifies the object code to reflect the actual addresses assigned. 9/3/2012 22
  • 23. Example Code that moves the contents of variable a to variable b using the eax register. mov a,%eax mov %eax,b If a is defined in the same file at location 1234 hex and b is imported from somewhere else, the generated object code will be: A1 34 12 00 00 mov a,%eax 9/3/2012 A3 00 00 00 00 mov %eax,b 23
  • 24. Contd… • The linker links this code so that the section in which a is located is relocated by hex 10000 bytes, and b turns out to be at hex 9A12. • The linker modifies the code to be: Relocated code A1 34 12 01 00 mov a,%eax A3 12 9A 00 00 mov %eax,b • That is, it adds 10000 to the address in the first instruction so now it refers to a‟s relocated address which is 11234, and it patches in the address for b. These adjustments affect instructions, but any pointers in the data part of an object file have to be adjusted as well. 9/3/2012 24
  • 25. Relocation and code modification • Linker modifies code to reflect assigned addresses depends on hardware architecture • On older computers with small address spaces and direct addressing there are only one or two address formats that a linker has to handle. • Modern computers(RISC) require considerably more complex code modification because it constructs addresses by several instructions. • No single instruction contains enough bits to hold a direct address, so the compiler and linker have to use complicated addressing tricks to handle data at arbitrary addresses. 9/3/2012 25
  • 26. Relocation and code modification • In some cases, it‟s possible to calculate an address using two or three instructions, each of which contains part of the address, and use bit manipulation to combine the parts into a full address. • In this case, the linker has to be prepared to modify each of the instructions, inserting some of the bits of the address into each instruction. • In other cases, all of the addresses used by a routine or group of routines are placed in an array used as an „„address pool‟‟, initialization code sets one of the machine registers to point to that array, and code loads pointers out of the address pool as needed using that register as a base register. 9/3/2012 26
  • 27. Contd… • The linker may have to create the array from all of the addresses used in a program, then modify instructions that so that they refer to the respective address pool entry. • Code might be required to be position independent (PIC) – works regardless where library is loaded – same library used at different addresses by processes • Linkers generally have to provide extra tricks to support that, separating out the parts of the program that can‟t be made position independent, and arranging for the two parts to communicate. 9/3/2012 27
  • 28. Linker Command Languages • Every linker has some sort of command language to control the linking process. • The linker needs the list of object files and libraries to link. • In linkers that support multiple code and data segments, a linker command language can specify the order in which segments are to be linked. 9/3/2012 28
  • 29. • There are common techniques to pass commands to a linker, Command Line: • It is used to direct the linker to read commands from a file. Embedded in object files: • Linker commands to be embedded inside object files. • This permits a compiler to pass any options needed to link an object file in the file itself. 9/3/2012 29
  • 30. Contd… Separate configuration language: • The linkers have a full fledged configuration language to control linking. • The GNU linker, which can handle an enormous range of object file formats, machine architectures, and address space conventions 9/3/2012 30
  • 31. An Example From C Language • A pair of C language source files, m.c with a main program that calls a routine named a, and a.c that contains the routine with a call to the library routines strlen and printf. • When the source file compiles at the time the object file create. • Each object file contain atleast one symbol table. 9/3/2012 31
  • 32. m.c a.c Compiler Compiler Separately compiled m.o a.o relocatable object files Linker (ld) Executable object file (contains code and p data for all functions defined in m.c and a.c) 9/3/2012 32
  • 33. Source file m.c Source file a.c extern void a(char *); #include <stdio.h> int main(int ac, char **av) #include <string.h> { void a(char *s) static char string[] = { "Hello, world!n"; printf(“%d”,strlen(s)); a(string); } } 9/3/2012 33
  • 34. Object code for m.o Idx Name Size VMA LMA File off Algn 0. text 00000010 00000000 00000000 00000020 2**3 1. data 00000010 00000010 00000010 00000030 2**3 • 00000000 <_main>: • 0: 55 pushl %ebp • 1: 89 e5 movl %esp,%ebp • 3: 68 10 00 00 00 pushl $0x10 • 4: 32 .data • 8: e8 f3 ff ff ff call 0 • 9: DISP32 _a • d: c9 leave • e: c3 ret • ... 9/3/2012 34
  • 35. • In that object file "text" segment containing the read only program code, and "data" segment containing the string. There are two relocation entries, • That marks the pushl instruction that puts the address of the string on the stack in preparation for the call to a. • one that marks the call instruction that transfers control to a. 9/3/2012 35
  • 36. • The symbol table exports the definition of _main, imports _a. • The object file of the subprogram a.c also contain data and text segments. Two relocation entries, • mark the calls to strlen and printf, and the symbol table exports _a and imports _strlen and _printf. 9/3/2012 36
  • 37. An Example From C Language m.c a.c int e=7; extern int e; int main() { int *ep=&e; int r = a(); int x=15; exit(0); int y; } int a() { return *ep+x+y; } 9/3/2012 37
  • 38. Merging Relocatable Object Files into an Executable Object File Relocatable Object Files Executable Object File system code .text 0 headers system data .data system code main() .text a() main() .text m.o int e = 7 .data more system code system data int e = 7 .data a() .text int *ep = &e int x = 15 a.o int *ep = &e .data uninitialized data .bss int x = 15 .symtab int y .bss .debug 9/3/2012 38