MSILFileFormatSpec.docx

上传人:b****5 文档编号:8214870 上传时间:2023-01-29 格式:DOCX 页数:37 大小:42.96KB
下载 相关 举报
MSILFileFormatSpec.docx_第1页
第1页 / 共37页
MSILFileFormatSpec.docx_第2页
第2页 / 共37页
MSILFileFormatSpec.docx_第3页
第3页 / 共37页
MSILFileFormatSpec.docx_第4页
第4页 / 共37页
MSILFileFormatSpec.docx_第5页
第5页 / 共37页
点击查看更多>>
下载资源
资源描述

MSILFileFormatSpec.docx

《MSILFileFormatSpec.docx》由会员分享,可在线阅读,更多相关《MSILFileFormatSpec.docx(37页珍藏版)》请在冰豆网上搜索。

MSILFileFormatSpec.docx

MSILFileFormatSpec

CommonLanguageRuntime

FileFormatSpec

Thisdocumentdefinestheextensions,fortheCommonLanguageRuntime(CLR),totheMicrosoftPE(PortableExecutable)fileformatthatdevelopmenttoolsandcompilerswillgenerate,andthattheCLRwillloadandexecute.Thisspecencompassesadescriptionofthefollowing:

headerandtags;metadata;MSILandnativecodestructures;issuesofreorderingandfix-ups.Generally,allformatissuesarecoveredexcepttheactualcodesections.Thereaderisreferredtothefollowingadditionalrelatedruntimespecifications:

ILInstrSet_cor_Intermediate_LanguageandMetadataAPI_cor_COM__Metadata_Emit_Import_Interface_SpecificationforemittingthemetadataportionoftheCLRfile

Thisispreliminarydocumentationandsubjecttochange

Lastupdated:

10October2000

TableOfContents

1Overview4

1.1StructureoftheRuntimeFileFormat4

1.2ProducersandConsumersoftheRuntimeFileFormat5

1.3RequirementsAddressedbytheRuntimeFileFormatDesign5

1.4OSInteractions7

2EmittingAValidCLRImage8

2.1FileHeaders8

2.1.1Signature8

2.1.2COFFHeader8

2.1.2.1MachineType8

2.1.2.2Characteristics8

2.1.3OptionalHeader9

2.1.3.1OptionalHeaderStandardFields9

2.1.3.2OptionalHeaderWindowsNT-SpecificFields10

2.1.3.2.1SubSystemSettings11

2.1.3.2.2StackReserveSize11

2.1.3.3OptionalHeaderDataDirectories12

2.1.4StoringRuntimeDatainSections13

2.1.5RuntimeHeader13

2.1.5.1RuntimeHeaderDefinition14

2.1.5.2RuntimeFlags15

2.1.5.3EntryPointMetaDataToken15

2.1.5.4VTableFixup16

2.1.5.5Resources17

2.1.5.6StrongNameSignature17

2.2SectionHeaders17

2.3ModificationstoExistingPEData17

2.3.1ImportAddressTable(IAT)18

2.3.2ExportSection(.edata)18

2.3.3ThreadLocalStorageTable18

2.3.4Relocations18

3IntermediateLanguage20

3.1LocalVariableLayout20

3.2FileFormatStructureDefinitions20

3.2.1MethodBody20

3.2.1.1MethodHeaderTypeValues21

3.2.1.2TinyFormat21

3.2.1.3FatFormat21

3.2.1.4IMAGE_COR_ILMETHOD22

3.2.1.5IMAGE_COR_ILMETHOD_TINY22

3.2.1.6IMAGE_COR_ILMETHOD_FAT22

3.2.1.6.1FlagsforMethodHeaders23

3.2.2SectionData23

3.2.3IMAGE_COR_ILMETHOD_SECT_EH24

3.2.3.1IMAGE_COR_ILMETHOD_SECT_EH_SMALL24

3.2.3.2CorExceptionFlagValues24

3.2.3.3IMAGE_COR_ILMETHOD_SECT_EH_CLAUSE_SMALL25

3.2.3.4IMAGE_COR_ILMETHOD_SECT_EH_FAT25

3.2.4IMAGE_COR_ILMETHOD_SECT_EH_CLAUSE_FAT26

4CodeTransitions27

4.1CallTransitions27

4.1.1TransitionTypes27

EffectsonLikePiecesofCode28

AffectsonILCode28

AffectsonNativeCode28

4.2RuntimeHeaderSupportforTransitions28

4.2.1VTableFixups28

4.2.2ExportAddressTableFix-ups29

5EntryPoints31

5.1RuntimeAPI’s31

5.1.1_CorExeMain31

5.1.2_CorDllMain31

5.1.3EntryPointsforWindowsCE31

5.2ShutDownRequirements31

5.3EntryPointStubs31

5.3.1RuntimeAwareOSLoader31

5.3.2NonRuntimeAwareOSLoader32

5.3.3Samplex86Stubs32

1Overview

ThisdocumentspecifiesafileformatforCommonLanguageRuntime(CLR)componentsthatisbasedon,andisastrictextensionof,thecurrentMicrosoftWindowsPortableExecutable(PE)andCommonObjectFileFormat(COFF).ThisextendedPE/COFFformatenablestheWindowsoperatingsystemtorecognizeruntimeimages,accommodatescodeemittedasruntimeMicrosoftintermediatelanguage(MSIL)ornativecode,andaccommodatesruntimemetadataasanintegralpartoftheemittedcode.

Thissectionprovidesabriefoverviewofandmotivationforthedesignapproach,includingasummaryofrequirementsandconstraints.SubsequentsectionspresentthetechnicalspecificationsasadeltafromthecurrentWindowsPE/COFFfileformat,insufficientdetailthatatoolorcompilercanusethespecificationstoemitvalidruntimeimages.

TheentiredocumentassumesfamiliaritywiththecurrentPE/COFFstructureandterminology.Formoreinformation,refertothe“MicrosoftPortableExecutableandCommonObjectFileFormatSpecification”

StructureoftheRuntimeFileFormat

Thefigurebelowprovidesahigh-levelviewoftheCLRfileformat.Allruntimeimagescontainthefollowing:

∙StandardPE/COFFheaders,withspecificguidelinesonhowfieldvaluesshouldbesetinaruntimefile

∙Aruntimeheaderthatcontainsalloftheruntimespecificdataentries.Currently,theruntimeheaderisread-onlyandmaybeplacedinanyread-onlysection

∙AnyofthedataonecurrentlyfindsinavalidPE/COFFimage,includingimports/exports,data,andcode.Thisspeccallsoutspecificareaswhereweusethisdataintheruntime.

PE/COFFHeaders

CLRHeader

CLRData:

metadata,ILmethodbodies,fix-ups

NativeImageSections:

.rdata,.rsrc,.data,.text,...

TheimageisafullPE/COFFfileimage.ThenormalPE/COFFheadersapply.TheruntimeheaderisfoundusingdirectoryentryIMAGE_DIRECTORY_COR_DESCRIPTORinthePEheader.Theruntimeheaderinturncontainstheaddressandlocationsoftheruntimedataintherestoftheimage.NotethattheruntimedatacanbemergedintootherareasofthePEformatwiththeotherdatabasedontheattributesofthesections(suchasreadonlyversusexecute,etc.).

Whilethebulkofthefileformatisgeneratedbytoolsdirectly,themetadataportionisemittedthroughanAPIthatabstractsthetoolsfromtheunderlyingdatastructures.Thisisinpartbecausethedatastructuresaremanyandcomplex,havingbeentunedforperformanceandsize,andbecausewewanttobeabletodoadditionaltuningofthestructureswithoutimpactingthetoolsthatareemittingthem.And,itisinpartbecausetheruntimemetadataengineeventodaysupportsanumberofdifferentformatsexposedinauniformwaythroughthesameAPI.Forexample,forCOMInterop,aconsumerofruntimemetadatacanimportatypelibasthoughitwereaperfectlyvalidruntimemetadatafile.RefertotheMetadataInterfaces_cor_COM__Metadata_Emit_Import_Interface_Specificationspecfordetailsonemittingandconsumingthemetadataportionofaruntimeimage.

ProducersandConsumersoftheRuntimeFileFormat

Developmenttoolsandcompilerswillemitruntimeimagesthatcanbepackagedanddeployedacrossarangeofruntime-enabledplatforms.DevelopmenttoolswillrangefromRADtools(includingscriptinglanguages)tohigh-levellanguagecompilers.Thefirstcategoryoftoolswillcompileandemitfilesinasinglepassfromthedevelopmentenvironment.Scriptingtoolsmaynotevenhaveaneedtopersisttheresultingfile,butsimplyregeneratethecodeeverytimeit’sexecuted.Thesecondcategoryoftoolshasanincrementalapproach,firstemittingintermediatecompilationunitsandthenlinkingthemtogetherwithresourcesintoaloadableruntimeimage.

Thefileformatneedstoaccommodatenotonlywhattheruntimewillrequireinordertoloadandexecutethesefiles,butitneedstomakeitreasonablystraightforwardforthisrangeofdifferenttoolswithdifferentinternaldatastructuresandcompilationmodelstoemitmetadataandcodeefficiently(alongwithimports/exports,fix-ups,debugginginformation,etc.).

Consumersoftheruntimefileformatincludetheruntimeitselfaswellasdevelopmenttoolsandadministrativetools.TheruntimeconsumesmetadataandILinordertoJIT-compileILtonativecode.Theloaderconsumesmetadatatoloadclassesandtrackmanageddatastructures.Developmenttoolswillimportmetadatatoenablereferencestoruntimetypesandmembers.Administrativetoolswillconsumemetadatatobrowseclassesandconfigureservices.

RequirementsAddressedbytheRuntimeFileFormatDesign

Initialexplorationofalternativedesignapproachesrangedfromintroducinganentirelynewfileformatfortheruntimethatwouldco-existside-by-sidewithtoday’sPEfileformat,toensuringthattheruntimeformatwasanaturalextensionoftoday’sWindowsPEfile.Inhavingchosenthelatterapproach,itmaybeinstructivetoreviewtherequirementsthatdrovethedesignandspecwork.

AnOptionofILorNativeCode

Adeveloperwhowantstotargetarangeofruntimeplatformsmaywanttobuildacomponentorassemblyofcomponentsonceandcompiletonativewhenneededforaparticularplatform.Optionsfor“whenneeded”rangefromdeploymenttimetoinstalltimetoexecutiontime.Inthisscenario,thecodeisemittedasIL,plusthemetadatathattheruntimeJITcompiler(s)usetocompiletheILtonative.

Adeveloperbuildingaruntimecomponentorapplicationinhisorherfavoritelanguagemayhavereasontocompilecodedirectlytonative.Forexample,ifthecodeisknowntotargetonlyaspecificplatform,theremaybenoperceivedbenefitfromgoingthroughanintermediatelanguage.Thisdoesnotmeanthatthedeveloperneedforegothebenefitsoftheruntimemanagedservices.Inthedesignpresentedinthisdocument,thetargetfileformatistoday’sPEfile,either.exeor.dll.

Tobemorespecific,theruntimerecognizesmanagednativecodeandunmanagednativecode.BotharecompiledinanylanguagetothenativeinstructionsetofaCPU.Unlikeunmanagednativecode,managednativecodehasadditionalmetadataandcodingconventionsusedbytheruntimetoenablegarbagecollection,exceptionsandotherruntimefeatures.Thecurrentfileformatspecificationdoesnotdescribethesemetadataandfileformatextensions.Unmanagednativecodeisfullysupported,emittedusingallofthestructuresoftoday’sPE/COFF.

ACombinationofILandNativeCode

TheruntimewillacceptafilecontainingamixtureofILandnativecode.Theruntimefileformataccommodateseitheroneorbothnaturallyinasingleformat,withoutrequiringcompilerstoemit,andOSloaderstorecognize,arangeofdifferentformatsforspecializedpurposes.

Self

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 工学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1