coff.h

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C头文件 代码 · 共 606 行 · 第 1/2 页

H
606
字号
/****************************************************************************
*
*                            Open Watcom Project
*
*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
*  ========================================================================
*
*    This file contains Original Code and/or Modifications of Original
*    Code as defined in and that are subject to the Sybase Open Watcom
*    Public License version 1.0 (the 'License'). You may not use this file
*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
*    provided with the Original Code and Modifications, and is also
*    available at www.sybase.com/developer/opensource.
*
*    The Original Code and all software distributed under the License are
*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
*    NON-INFRINGEMENT. Please see the License for the specific language
*    governing rights and limitations under the License.
*
*  ========================================================================
*
* Description:  WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
*               DESCRIBE IT HERE!
*
****************************************************************************/


#include <watcom.h>
#pragma pack( 1 )

typedef struct {
    uint_16     cpu_type;
    uint_16     num_sections;
    uint_32     time_stamp;
    uint_32     sym_table;
    uint_32     num_symbols;
    uint_16     opt_hdr_size;
    uint_16     flags;
} coff_file_header;

#define COFF_FILE_HEADER_SIZE sizeof(coff_file_header)

#define COFF_SEC_NAME_LEN 8

typedef struct {
    char        name[COFF_SEC_NAME_LEN];
    uint_32     virtsize;
    uint_32     offset;
    uint_32     size;
    uint_32     rawdata_ptr;
    uint_32     reloc_ptr;
    uint_32     lineno_ptr;
    uint_16     num_relocs;
    uint_16     num_lineno;
    uint_32     flags;
} coff_section_header;

#define COFF_SECTION_HEADER_SIZE sizeof(coff_section_header)

typedef struct {
    uint_32     offset;
    uint_32     sym_tab_index;
    uint_16     type;
} coff_reloc;

#define COFF_RELOC_SIZE sizeof(coff_reloc)

#define COFF_SYM_NAME_LEN 8

// typedef struct _IMAGE_SYMBOL in WINNT.H

typedef struct {
    union {
        char            name_string[COFF_SYM_NAME_LEN];
        struct {
            uint_32     zeros;
            uint_32     offset;
        } non_name;
    } name;
    uint_32             value;
    signed_16           sec_num;
    uint_16             type;
    uint_8              storage_class;
    uint_8              num_aux;
} coff_symbol;

#define COFF_SYM_SIZE sizeof(coff_symbol)

#define _CoffSymType( complex, simple )         ( ( (complex) << 4 ) | (simple) )
#define _CoffBaseType( sym_type )               ( (sym_type) & 0xf )
#define _CoffComplexType( sym_type )            ( ( (sym_type) >> 4 ) & 0xf )

typedef struct {
    uint_32     bf;
    uint_32     size;
    uint_32     linenum;
    uint_32     next_func;
    char        unused[3];
} coff_sym_func;

typedef struct {
    char        unused1[4];
    uint_16     linenum;
    char        unused2[6];
    uint_32     next_func;
    char        unused3[2];
} coff_sym_bfef;

typedef struct {
    uint_32     tag_index;
    uint_32     characteristics;
    char        unused1[10];
} coff_sym_weak;

#define COFF_FILE_NAME_LEN 18

typedef struct {
    char        filename[COFF_FILE_NAME_LEN];
} coff_sym_file;

typedef struct {
    uint_32     length;
    uint_16     num_relocs;
    uint_16     num_line_numbers;
    uint_32     checksum;
    uint_16     number;
    uint_8      selection;
    char        unused[3];
} coff_sym_section;

typedef struct {
    union {
        uint_32         symbol_table_index;
        uint_32         RVA;
    };
    uint_16             line_number;
} coff_line_num;

/* from the COFF/PE docs */

// CPU types
enum {
    IMAGE_FILE_MACHINE_UNKNOWN          = 0,
    IMAGE_FILE_MACHINE_I386             = 0x014c, // Intel 386.
    IMAGE_FILE_MACHINE_I860             = 0x014d, // Intel 860.
    IMAGE_FILE_MACHINE_R3000            = 0x0162, // MIPS little-endian, 0x160 big-endian
    IMAGE_FILE_MACHINE_R4000            = 0x0166, // MIPS little-endian
    IMAGE_FILE_MACHINE_R10000           = 0x0168, // MIPS little-endian
    IMAGE_FILE_MACHINE_WCEMIPSV2        = 0x0169, // MIPS little-endian WCE v2
    IMAGE_FILE_MACHINE_ALPHA            = 0x0184, // Alpha_AXP
    IMAGE_FILE_MACHINE_POWERPC          = 0x01F0, // IBM PowerPC Little-Endian
    IMAGE_FILE_MACHINE_SH3              = 0x01a2, // SH3 little-endian
    IMAGE_FILE_MACHINE_SH3E             = 0x01a4, // SH3E little-endian
    IMAGE_FILE_MACHINE_SH4              = 0x01a6, // SH4 little-endian
    IMAGE_FILE_MACHINE_ARM              = 0x01c0, // ARM Little-Endian
    IMAGE_FILE_MACHINE_THUMB            = 0x01c2,
    IMAGE_FILE_MACHINE_IA64             = 0x0200, // Intel 64
    IMAGE_FILE_MACHINE_MIPS16           = 0x0266, // MIPS
    IMAGE_FILE_MACHINE_MIPSFPU          = 0x0366, // MIPS
    IMAGE_FILE_MACHINE_MIPSFPU16        = 0x0466, // MIPS
    IMAGE_FILE_MACHINE_ALPHA64          = 0x0284, // ALPHA64
    IMAGE_FILE_MACHINE_AXP64            = IMAGE_FILE_MACHINE_ALPHA64,
    IMAGE_FILE_MACHINE_AMD64            = 0x8664  // AMD64 / Intel EM64T
};

// file flag values
enum {
    IMAGE_FILE_RELOCS_STRIPPED          = 0x0001, // Relocation info stripped from file.
    IMAGE_FILE_EXECUTABLE_IMAGE         = 0x0002, // File is executable  (i.e. no unresolved externel references).
    IMAGE_FILE_LINE_NUMS_STRIPPED       = 0x0004, // Line nunbers stripped from file.
    IMAGE_FILE_LOCAL_SYMS_STRIPPED      = 0x0008, // Local symbols stripped from file.
    IMAGE_FILE_AGGRESIVE_WS_TRIM        = 0x0010, // Agressively trim working set
    IMAGE_FILE_LARGE_ADDRESS_AWARE      = 0x0020, // App can handle >2gb addresses
    IMAGE_FILE_16BIT_MACHINE            = 0x0040,
    IMAGE_FILE_BYTES_REVERSED_LO        = 0x0080, // Bytes of machine word are reversed.
    IMAGE_FILE_32BIT_MACHINE            = 0x0100, // 32 bit word machine.
    IMAGE_FILE_DEBUG_STRIPPED           = 0x0200, // Debugging info stripped from file in .DBG file
    IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP  = 0x0400, // If Image is on removable media, copy and run from the swap file.
    IMAGE_FILE_NET_RUN_FROM_SWAP        = 0x0800, // If Image is on Net, copy and run from the swap file.
    IMAGE_FILE_SYSTEM                   = 0x1000, // System File.
    IMAGE_FILE_DLL                      = 0x2000, // File is a DLL.
    IMAGE_FILE_UP_SYSTEM_ONLY           = 0x4000, // File should only be run on a UP machine
    IMAGE_FILE_BYTES_REVERSED_HI        = 0x8000  // Bytes of machine word are reversed.
};

// section flag values
enum {
//  IMAGE_SCN_TYPE_REG                  = 0x00000000, // Reserved.
//  IMAGE_SCN_TYPE_DSECT                = 0x00000001, // Reserved.
//  IMAGE_SCN_TYPE_NOLOAD               = 0x00000002, // Reserved.
//  IMAGE_SCN_TYPE_GROUP                = 0x00000004, // Reserved.
    IMAGE_SCN_TYPE_NO_PAD               = 0x00000008, // Reserved.
//  IMAGE_SCN_TYPE_COPY                 = 0x00000010, // Reserved.

    IMAGE_SCN_CNT_CODE                  = 0x00000020, // Section contains code.
    IMAGE_SCN_CNT_INITIALIZED_DATA      = 0x00000040, // Section contains initialized data.
    IMAGE_SCN_CNT_UNINITIALIZED_DATA    = 0x00000080, // Section contains uninitialized data.

    IMAGE_SCN_LNK_OTHER                 = 0x00000100, // Reserved.
    IMAGE_SCN_LNK_INFO                  = 0x00000200, // Section contains comments or some other type of information.
//  IMAGE_SCN_TYPE_OVER                 = 0x00000400, // Reserved.
    IMAGE_SCN_LNK_REMOVE                = 0x00000800, // Section contents will not become part of image.
    IMAGE_SCN_LNK_COMDAT                = 0x00001000, // Section contents comdat.
//                                      = 0x00002000, // Reserved.
//  IMAGE_SCN_MEM_PROTECTED - Obsolete  = 0x00004000,
    IMAGE_SCN_NO_DEFER_SPEC_EXC         = 0x00004000, // Reset speculative exceptions handling bits in the TLB entries for this section.
    IMAGE_SCN_GPREL                     = 0x00008000, // Section content can be accessed relative to GP
    IMAGE_SCN_MEM_FARDATA               = 0x00008000,
//  IMAGE_SCN_MEM_SYSHEAP  - Obsolete   = 0x00010000,
    IMAGE_SCN_MEM_PURGEABLE             = 0x00020000,
    IMAGE_SCN_MEM_16BIT                 = 0x00020000,
    IMAGE_SCN_MEM_LOCKED                = 0x00040000,
    IMAGE_SCN_MEM_PRELOAD               = 0x00080000,

    IMAGE_SCN_ALIGN_1BYTES              = 0x00100000, //
    IMAGE_SCN_ALIGN_2BYTES              = 0x00200000, //
    IMAGE_SCN_ALIGN_4BYTES              = 0x00300000, //
    IMAGE_SCN_ALIGN_8BYTES              = 0x00400000, //
    IMAGE_SCN_ALIGN_16BYTES             = 0x00500000, // Default alignment if no others are specified.
    IMAGE_SCN_ALIGN_32BYTES             = 0x00600000, //
    IMAGE_SCN_ALIGN_64BYTES             = 0x00700000, //
    IMAGE_SCN_ALIGN_128BYTES            = 0x00800000, //
    IMAGE_SCN_ALIGN_256BYTES            = 0x00900000, //
    IMAGE_SCN_ALIGN_512BYTES            = 0x00A00000, //
    IMAGE_SCN_ALIGN_1024BYTES           = 0x00B00000, //
    IMAGE_SCN_ALIGN_2048BYTES           = 0x00C00000, //
    IMAGE_SCN_ALIGN_4096BYTES           = 0x00D00000, //
    IMAGE_SCN_ALIGN_8192BYTES           = 0x00E00000, //
// Unused                               = 0x00F00000,
    IMAGE_SCN_ALIGN_MASK                = 0x00F00000,

    IMAGE_SCN_LNK_NRELOC_OVFL           = 0x01000000, // Section contains extended relocations.
    IMAGE_SCN_MEM_DISCARDABLE           = 0x02000000, // Section can be discarded.
    IMAGE_SCN_MEM_NOT_CACHED            = 0x04000000, // Section is not cachable.
    IMAGE_SCN_MEM_NOT_PAGED             = 0x08000000, // Section is not pageable.
    IMAGE_SCN_MEM_SHARED                = 0x10000000, // Section is shareable.
    IMAGE_SCN_MEM_EXECUTE               = 0x20000000, // Section is executable.
    IMAGE_SCN_MEM_READ                  = 0x40000000, // Section is readable.
    IMAGE_SCN_MEM_WRITE                 = 0x80000000, // Section is writeable.

//  COFF_SEC_FLAG_ALIGN_MASK            = 0x00700000, // replaced by IMAGE_SCN_ALIGN_MASK
    COFF_SEC_FLAG_ALIGN_SHIFT           = 20
};

//
// Section values.
//
// Symbols have a section number of the section in which they are
// defined. Otherwise, section numbers have the following meanings:
//
enum {
    IMAGE_SYM_UNDEFINED         = (signed_16)0,  // Symbol is undefined or is common.
    IMAGE_SYM_ABSOLUTE          = (signed_16)-1, // Symbol is an absolute value.
    IMAGE_SYM_DEBUG             = (signed_16)-2  // Symbol is a special debug item.
};

//
// Type (fundamental) values.
//
enum {
    IMAGE_SYM_TYPE_NULL         = 0x0000, // no type.
    IMAGE_SYM_TYPE_VOID         = 0x0001, //
    IMAGE_SYM_TYPE_CHAR         = 0x0002, // type character.
    IMAGE_SYM_TYPE_SHORT        = 0x0003, // type short integer.
    IMAGE_SYM_TYPE_INT          = 0x0004, //
    IMAGE_SYM_TYPE_LONG         = 0x0005, //
    IMAGE_SYM_TYPE_FLOAT        = 0x0006, //
    IMAGE_SYM_TYPE_DOUBLE       = 0x0007, //
    IMAGE_SYM_TYPE_STRUCT       = 0x0008, //
    IMAGE_SYM_TYPE_UNION        = 0x0009, //
    IMAGE_SYM_TYPE_ENUM         = 0x000A, // enumeration.
    IMAGE_SYM_TYPE_MOE          = 0x000B, // member of enumeration.
    IMAGE_SYM_TYPE_BYTE         = 0x000C, //
    IMAGE_SYM_TYPE_WORD         = 0x000D, //
    IMAGE_SYM_TYPE_UINT         = 0x000E, //
    IMAGE_SYM_TYPE_DWORD        = 0x000F, //
    IMAGE_SYM_TYPE_PCODE        = 0x8000  //
};

//
// Type (derived) values.
//
enum {
    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.
};

//
// Storage classes.
//
typedef enum {
    IMAGE_SYM_CLASS_END_OF_FUNCTION     = -1,
    IMAGE_SYM_CLASS_NULL                = 0x0000,
    IMAGE_SYM_CLASS_AUTOMATIC           = 0x0001,
    IMAGE_SYM_CLASS_EXTERNAL            = 0x0002,
    IMAGE_SYM_CLASS_STATIC              = 0x0003,

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?