• Keine Ergebnisse gefunden

Linker & Loader in .NET

N/A
N/A
Protected

Academic year: 2022

Aktie "Linker & Loader in .NET"

Copied!
17
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Linker & Loader in .NET

August Steinbacher

(2)

Vortragsüberblick

 C++ vs .NET

 Auffinden von Assemblies

 Execution Model

 Runtime Layout

 Methodenadressierung

(3)

Traditioneller Ansatz

Compiler Frontend:

Parsen der High-Level-Syntax

Kompilieren in Zwischencode

Compiler Backend:

Zwischencode -> Native Code

Platzhalter für imports & exports

Linker:

Erzeugen eines executable file

Loader:

Platzieren des Executables im Speicher

App2.cpp Incl.h

Objekt datei

Objekt datei

EXE Datei

Compiler

Linker App1.cpp

(4)

.NET Modell

 Compiler Frontend:

Parsen der High-Level-Syntax

Erzeugen von Zwischencode + Metadaten

• Assemblies

 Compiler Backend (CLR):

Lokalisieren des Assemblies

Erzeugen von Native Code

• Kompilieren

• Linken

• Laden

Source Source

Compiler

Assemblies Compiler

CLR

Processes

Memory

(5)

Ausführen von .NET

 .exe Datei starten

Windows-loader startet die CLR

Applikation läuft innerhalb der CLR

 Applikationsdomäne

Isoliert Applikationen voneinander

• Laden aller Assemblies, Module und Typen

• Methodentabellen der Typen

• Statische Felder und Objekte

Side-by-Side Execution

 Eintrittspunkt

Schlüsselwort .entrypoint in PE-Datei

(6)

3 Levels of Loading

 Laden der PE-Datei von Disk

Einziger Festplattenzugrif

Enthält Metadaten

 Laden des Assemblies

Aufgrund der Metadaten

Sicherheitsmanager prüft Rechte

 Laden der Typen

Classloader

PE-Datei

Assemblies

Object Integer

String

(7)

Lokalisieren von Assemblies

 Assembly Resolver

Name des gesuchten Assemblies

Versionsinformation

Informationen über AppDomain

Konfigurationsdateien

 Öfentliche Assemblies

GAC

Codebase-Hints in Konfigurationsdateien

 Private Assemblies

Im Applikationsverzeichnis

Probing

(8)

Lokalisieren von Assemblies

Assembly.Load(name)

Public Key?

Lade File J

In GAC?

J

Lade File aus GAC J

<CodeBase>

Vorhanden?

N

Passt File?

J

Probing erfolgreich?

N

N

Passt File?

J

N

Lade File von

<CodeBase>

J

Assembly.Load endet mit Fehler N

N

(9)

Probing

 4 Kriterien:

Applikationsverzeichnis

Culture-Attribut

Assembly Name

Relativer Suchpfad

[AppDir] / [Assembly name].dll

[AppDir] / [Assembly name] / [Assembly name].dll

C:/App/code.dll

C:/App/code/code.dll

[AppDir] / [culture] / [Assembly name].dll

[AppDir] / [culture] / [Assembly name] / [Assembly name].dll

C:/App/en-US/code.dll

C:/App/en-US/code/code.dll

[AppDir] / [binpath] / [Assembly name].dll

[AppDir] / [binpath] / [Assembly name] / [Assembly name].dll

C:/App/shared/code.dll

C:/App/shared/code/code.dll

[AppDir] / [binpath] / [culture] / [Assembly name].dll

[AppDir] / [binpath] / [culture] / [Assembly name] / [Assembly name].dll

C:/App/shared/en-US/code.dll

C:/App/shared/en-US/code/code.dll

(10)

Laden eines Typs T

 Durch Classloader

Bestimmung des benötigten Speicherplatzes

Bestimmung des Speicherlayouts

Auflösen von Referenzen auf bereits geladene Typen

Stubs erzeugen für Methoden von T

• Methodenaufrufe lösen JIT-Kompilierung aus

 Verifikation der Typsicherheit

4 Kategorien

• Ungültig

• Gültig

• Typsicher

• Verifizierbar Gültig

Typsicher Verifizierbar Ungültig

(11)

Execution Model

Source

Code Compiler

csc, jsc,... Assembly

PE File + MSIL + Metadaten

PE Verifikation

GAC AppDir Assembly

Loader Assembly Info

Class List

Native Code

Class Runtime

Assembly

Method Class

Policy Manager

Policy

Erteilte Rechte

(12)

Objektinstanzen

Instance Data

Instance Data

Instance Data

Method Table A

Method

Table B Sync Block

Table Instance of

A Instance of

B Instance of

A

Heap

Private EE Memory

(13)

Instance Data Object

Header

Index Sync Block

Table

MethodTable

EEClass

Runtime Layout

GCDesc

Object Reference

Interface map

Compiled method JMI thunk

Module

Class Loader

Assembly

App

„Hot Data“

„Cold Data“

MethodDesc MethodDesc

Prestub ptr

Prestub Prestub ptr

(14)

Method Table & Interface Map

Interface Map 1

2 3 4 5 GCDesc

MethodTable header Inherited

virtuals

Introduced virtuals

Instance and static methods Method Table

EEClass

(15)

M e th o d Im p le m e n ta tio n s

Methodenadressierung

class C : B { I2.m2() {..}; } A.m1; I1.m1;

A.m2; I1.m2;

B.m3;

I2.m2;

interface I1 { m1(); m2(); } interface I2 { m2(); m3(); }

B.m3;

class B : A, I2 {m3(){..}; }

A.m1;

A.m2;

class A : I1 { m1(){..};

m2(){..}; }

A.m1; I1.m1 A.m2; I1.m2

A.m1; I1.m1;

A.m2; I1.m2;

B.m3;

A.m1; I1.m1;

A.m2; I1.m2; I2.m2

B.m3; I2.m3

(16)

Quellen

Don Box, Chris Sells: Essential .NET, The Common Language Runtime, Addison-Wesley 2003

Dave Stutz, Ted Neward, Geof Shilling: Shared Source CLI Essentials. O'Reilly 2003

W.Beer, D.Birngruber, H.Mössenböck, A.Wöß: Die .NET- Technologie, dpunkt.verlag 2002

http://www.msdn.microsoft.com/netframework/

http://www.dotnetframework.de

http://dotnet.di.unipi.it/

(17)

Ende...

...Fragen?

Referenzen

ÄHNLICHE DOKUMENTE

http://www2.h-net.msu.edu/announce/show.cgi?ID=133351 Title: A Fragile Alliance: Porcelain as Sculpture 1700 to 1900 Deadline: 2003-05-12.. Description: Although porcelain has played

Description: The OUHS Journal was established by the postgraduate community at Oxford as a medium for the publication and. dissemination of original and inter-disciplinary

Users may print, post, or forward all or part of the index, or click on individual items to view and use the entire entry from the events site.. H-Net assumes no liability for

Description: Visual Rhetoric Parlor Press Marguerite Helmers, Series Editor Visual culture studies and visual rhetoric have been increasing areas of emphasis in scholarly

Während CTS die Typen spezifiziert, welche in einem Programm verwendet wer- den können, spezifiziert die CLS wie diese Typen verwendet werden dürfen, um mit anderen Sprachen

Users may print, post, or forward all or part of the index, or click on individual items to view and use the entire entry from the events site. The theme of the conference, planned

http://www2.h-net.msu.edu/announce/show.cgi?ID=135542 Title: The Historical Society of New Mexico will hold its 2004 Annual Meeting and Conference on April 22-24th in Los Alamos,

Description: The Society of Military History will hold its 71st Annual Meeting under the auspices of the Department of History, University of Maryland, College Park, at the