Text Section

Text Section

The .text section of a PE file is a read-only section. In a managed PE file, it contains metadata tables, IL code, an Import Address table, a common language runtime header, and an unmanaged runtime startup stub. The image files generated by the ILAsm compiler additionally contain managed resources, the strong name signature hash, and unmanaged export stubs.

The ILAsm compiler emits data to the .text section in a particular order. When the PE file generator is initialized during the ILAsm compiler startup, space is allocated in the .text section for the Import Address table—which carries one lonely entry, for the startup routine of the runtime DLL—and for the runtime header.

The IL code and the managed structured exception handling tables for each method defined in the module are emitted to the .text section during the parsing of the source code, as soon as parsing and compilation of the next method are completed.

After all the source files representing the module have been parsed and all IL code and structured exception handling tables have been emitted, the ILAsm compiler, if so directed, allocates sufficient space in the .text section for the strong name signature. The signature itself is emitted later, as the last step of the file generation.

Then the ILAsm compiler analyzes and rearranges the metadata defined during the parsing of the source files and emits the metadata tables to the .text section. By this time, all the managed resources to be embedded in the image file are analyzed and accounted for, and their respective offsets within the managed resource directory are recorded as part of the metadata describing these resources. At this time, all the necessary fixups are made in the already emitted IL code. These fixups primarily deal with the metadata tokens, which were unknown before the metadata analysis and rearrangement or were changed during that process. Other fixups deal with references to global data constants placed in the .sdata section that will be discussed later in this chapter.

After all metadata has been emitted, any managed resources to be embedded in the image file are read from the respective files and emitted to the .text section. (For a discussion of embedding managed and unmanaged resources, see “Resources” later in this chapter.)

The next set of data to be emitted to the .text section consists of the export stubs for each managed method that will be exposed as an unmanaged export, to be consumed by the external unmanaged executables. (For detailed information on managed and unmanaged code interoperation, see Chapter 15.)

The last item emitted to the .text section is the unmanaged runtime startup stub, whose RVA is assigned to the AddressOfEntryPoint field of the PE header.

Figure 3-3 summarizes the general structure of the .text section of an image file generated by the ILAsm compiler.

Figure 3-3 Structure of a .text section emitted by the ILAsm compiler.



Inside Microsoft. NET IL Assembler
Inside Microsoft .NET IL Assembler
ISBN: 0735615470
EAN: 2147483647
Year: 2005
Pages: 147
Authors: SERGE LIDIN

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net