// -----------------------------------------------------------------------------
// COFF IMAGE SYMBOL related types and contants
// see:
//
// http://www.delorie.com/djgpp/doc/coff/symtab.html
//
// for detailed information about the meaning of the fields in IMAGE_SYMBOL as
// well as winnt.h
const
// these value can be found in the SymSectionNumber to indicate the meaning
// of the SymValue field
IMAGE_SYM_UNDEFINED = 0; // symbol is undefined or common
IMAGE_SYM_ABSOLUTE = word(-1); // symbol is an absolute value
IMAGE_SYM_DEBUG = word(-2); // symbol is a special debug item
IMAGE_SYM_SECTION_MAX = word($FEFF); // values 0xFF00-0xFFFF are special
IMAGE_SYM_SECTION_MAX_EX = high(int16);
const
// Symbol Types - fundamental types
IMAGE_SYM_TYPE_NULL = $0000; // no type
IMAGE_SYM_TYPE_VOID = $0001; //
IMAGE_SYM_TYPE_CHAR = $0002; // type character
IMAGE_SYM_TYPE_SHORT = $0003; // type short integer
IMAGE_SYM_TYPE_INT = $0004; //
IMAGE_SYM_TYPE_LONG = $0005; //
IMAGE_SYM_TYPE_FLOAT = $0006; //
IMAGE_SYM_TYPE_DOUBLE = $0007; //
IMAGE_SYM_TYPE_STRUCT = $0008; //
IMAGE_SYM_TYPE_UNION = $0009; //
IMAGE_SYM_TYPE_ENUM = $000A; // enumeration
IMAGE_SYM_TYPE_MOE = $000B; // member of enumeration
IMAGE_SYM_TYPE_BYTE = $000C; //
IMAGE_SYM_TYPE_WORD = $000D; //
IMAGE_SYM_TYPE_UINT = $000E; //
IMAGE_SYM_TYPE_DWORD = $000F; //
IMAGE_SYM_TYPE_PCODE = $8000; //
// Symbol types - derived types
IMAGE_SYM_DTYPE_NULL = 0; // no derived type
IMAGE_SYM_DTYPE_POINTER = 1; // pointer
IMAGE_SYM_DTYPE_FUNCTION = 2; // function
IMAGE_SYM_DTYPE_ARRAY = 3; // array
// Type entry
//
// The type field in the symbol table entry contains information about the basic
// and derived type for the symbol. This information is generated by the C
// compilation system only if the -g option is used. Each symbol has exactly one
// basic or fundamental type but can have more than one derived type. The format
// of the 16-bit type entry is:
//
// dx are two bits each, type is one nibble (4 bits)
//
// d6 d5 d4 d3 d2 d1 type
//
//
// Bits 0 through 3, called type, indicate one of the fundamental types given in
// the Fundamental types table below:
//
// Fundamental types
//
// Mnemonic Value Type
//
// T_NULL 0 type not assigned
// 1 function argument T_ARG
// (used only by compiler)
//
// 2 character T_CHAR
// 3 short integer T_SHORT
// 4 integer T_INT
// 5 long integer T_LONG
// 6 floating point T_FLOAT
// 7 double word T_DOUBLE
// 8 structure T_STRUCT
// 9 union T_UNION
// 10 enumeration T_ENUM
// 11 member of enumeration T_MOE
// 12 unsigned character T_UCHAR
// 13 unsigned short T_USHORT
// 14 unsigned integer T_UINT
// 15 unsigned long T_ULONG
//
// Bits 4 through 15 are arranged as six 2-bit fields marked d1 through d6.
// These d fields represent levels of the derived types given in given in the
// Derived types table below:
//
// Derived types
//
// Mnemonic Value Type
//
// DT_NON 0 no derived type
// DT_PTR 1 pointer
// DT_FCN 2 function
// DT_ARY 3 array
//
// The following examples demonstrate the interpretation of the symbol table
// entry representing type:
//
// char *func();
//
// Here func is the name of a function that returns a pointer to a character.
// The fundamental type of func is 2 (character), the d1 field is 2 (function),
// and the d2 field is 1 (pointer).
//
// Therefore, the type word in the symbol table for func contains the
// hexadecimal number 0x62, which is interpreted to mean a function that
// returns a pointer to a character.
//
//
// short *tabptr[10][25][3];
//
// Here tabptr is a three-dimensional array of pointers to short integers. The
// fundamental type of tabptr is 3 (short integer); the d1, d2, and d3 fields
// each contains a 3 (array), and the d4 field is 1 (pointer).
//
// Therefore, the type entry in the symbol table contains the hexadecimal
// number 0x7f3 indicating a three-dimensional array of pointers to short
// integers.
const
// Symbol storage classes
IMAGE_SYM_CLASS_END_OF_FUNCTION = byte(-1);
IMAGE_SYM_CLASS_NULL = $0;
IMAGE_SYM_CLASS_AUTOMATIC = $1;
IMAGE_SYM_CLASS_EXTERNAL = $2;
IMAGE_SYM_CLASS_STATIC = $3;
IMAGE_SYM_CLASS_REGISTER = $4;
IMAGE_SYM_CLASS_EXTERNAL_DEF = $5;
IMAGE_SYM_CLASS_LABEL = $6;
IMAGE_SYM_CLASS_UNDEFINED_LABEL = $7;
IMAGE_SYM_CLASS_MEMBER_OF_STRUCT = $8;
IMAGE_SYM_CLASS_ARGUMENT = $9;
IMAGE_SYM_CLASS_STRUCT_TAG = $A;
IMAGE_SYM_CLASS_MEMBER_OF_UNION = $B;
IMAGE_SYM_CLASS_UNION_TAG = $C;
IMAGE_SYM_CLASS_TYPE_DEFINITION = $D;
IMAGE_SYM_CLASS_UNDEFINED_STATIC = $E;
IMAGE_SYM_CLASS_ENUM_TAG = $F;
IMAGE_SYM_CLASS_MEMBER_OF_ENUM = $10;
IMAGE_SYM_CLASS_REGISTER_PARAM = $11;
IMAGE_SYM_CLASS_BIT_FIELD = $12;
IMAGE_SYM_CLASS_FAR_EXTERNAL = $44;
IMAGE_SYM_CLASS_BLOCK = $64;
IMAGE_SYM_CLASS_FUNCTION = $65;
IMAGE_SYM_CLASS_END_OF_STRUCT = $66;
IMAGE_SYM_CLASS_FILE = $67;
IMAGE_SYM_CLASS_SECTION = $68;
IMAGE_SYM_CLASS_WEAK_EXTERNAL = $69;
IMAGE_SYM_CLASS_CLR_TOKEN = $6B;
type
// if the symbol name is inline and it is exactly 8 characters long then it
// is not null terminated. This buffer type provides a large enough buffer
// where the symbol name can be copied and be null terminated. Note that
// this buffer may also be used to hold a symbol name that is present in the
// string table, for this reason it cannot be made to simply hold 8 characters
// and a null terminator since most strings in the string table are longer
// than that.
TSYM_NAME_BUFFER = array[0..1023] of char;
TSYMBOL_NAME_INFO = packed record
case integer of
0 : (SymName : packed array[0..7] of char);
1 : (
SymNameInline : boolean32; // use SymNameOffset if false
SymNameOffset : DWORD; // offset to name into string table
);
end;
type
// WARNING: this definition depends on how FPC does bitpacking and also how
// it accesses bitpacked fields (this definition is tested and known
// valid only for FPC v3.0.4)
TSYM_TYPE_RANGE = -2..5; // the bitfields 1..6 start at index 0
TSYM_TYPE_DERIVED_RANGE = 0..5;
TSYM_TYPE = bitpacked record
case integer of
0 : (
FundamentalType : T4BITS;
DerivedType1 : T2BITS;
DerivedType2 : T2BITS;
DerivedType3 : T2BITS;
DerivedType4 : T2BITS;
DerivedType5 : T2BITS;
DerivedType6 : T2BITS;
);
1 : (
// tested the array representation with value $7F3 and it _seems_ to
// work as expected.
DerivedType : bitpacked array[TSYM_TYPE_RANGE] of T2BITS;
);
2 : (
TypeWord : word;
);
end;
type
PIMAGE_SYMBOL = ^TIMAGE_SYMBOL; // 18
TIMAGE_SYMBOL = packed record
SymNameInfo : TSYMBOL_NAME_INFO;
SymValue : DWORD;
SymSectionNumber : word; // usually the 1 based section number
// but see IMAGE_SYM... constants
SymType : TSYM_TYPE; // see IMAGE_SYM_TYPE... constants
SymStorageClass : byte; // see IMAGE_SYM_CLASS... constants
SymNumberOfAuxSymbols : byte;
end;