2016-12-08 1 views
-1

私はアセンブラのようなnasmを開発していますが、今はCOFF形式のファイルを生成するプロセスをコーディングしています。一般関数記号からCOFFシンボルテーブルの "値"を計算または指定する方法は?

私の問題は非常に具体的で、valueというフィールドがCOFF Symbol Tableにあります。私はそれを計算または指定する方法を見つけることができませんでした。

私はMicrosoft Portable Executable and Common Object File Format Specificationという文書を読んでいます。私が参照されている記事、次のとおりです。 は

// define basic C function, I think it will be the symbol like "_test" in COFF files. 
void test(int value) { return;} 

、私は基本的なCの関数シンボルを定義するためにValueフィールドを指定する方法を知りたいのですが

The Symbol Table described in this section is inherited from the traditional COFF format. 
It is distinct from CodeView® information. A file may contain both a COFF Symbol 
Table and CodeView debug information, and the two are kept separate. Some Microsoft 
tools use the Symbol Table for limited but important purposes, such as communicating 
COMDAT information to the linker. Section names and file names, as well as code and 
data symbols, are listed in the Symbol Table. 
The location of the Symbol Table is indicated in the COFF Header. 
The Symbol Table is an array of records, each 18 bytes long. Each record is either a 
standard or auxiliary symbol-table record. A standard record defines a symbol or name, 
and has the following format: 

|--------| -----|---------------|-------------------------------------------------------------------| 
| Offset | Size | Field   | Description              | 
|--------| -----|---------------|-------------------------------------------------------------------| 
| 0  | 8 | Name (*)  | Name of the symbol, represented by union of three structures.  | 
|  |  |    | An array of eight bytes is used if the name is not more than  | 
|  |  |    | eight bytes long. See Section 5.4.1,        | 
|  |  |    | "Symbol Name Representation, " for more information.    | 
----------------------------------------------------------------------------------------------------| 
| 8  | 4 | Value   | Value associated with the symbol.         | 
|  |  |    | The interpretation of this field depends on Section Number  | 
|  |  |    | and Storage Class. A typical meaning is the relocatable address. | 
----------------------------------------------------------------------------------------------------| 
| 12  | 2 | SectionNumber | Signed integer identifying the section, using a one-based index | 
|  |  |    | into the Section Table. Some values have special meaning defined | 
|  |  |    | in "Section Number Values."          | 
----------------------------------------------------------------------------------------------------| 
| 14  | 2 | Type   | representing type. Microsoft tools set this field to 0x20   | 
|  |  |    | (function) or 0x0 (not a function). See Section 5.4.3,   | 
|  |  |    | "Type Representation," for more information.      | 
----------------------------------------------------------------------------------------------------| 
| 16  | 1 | StorageClass | Enumerated value representing storage class.      | 
|  |  |    | See Section 5.4.4, "Storage Class," for more information.   | 
|  |  |    |                 | 
----------------------------------------------------------------------------------------------------| 
| 17  | 1 | NumberOfAux | Number of auxiliary symbol table entries that follow this record. | 
|  |  | Symbols  |                 | 
----------------------------------------------------------------------------------------------------| 

を例えば_test

この文書では、 Valueフィールドが表すと relocatable address。それを知る方法?

+0

いい悲しみです。私はより具体的な質問を変えることができます。 – hiropon

+0

@πάνταῥεῖねえ、私は質問を更新しました – hiropon

答えて

0

最後に、valueフィールドの意味を理解しました。

このフィールドは、シンボルテーブルの先頭からのオフセットの値を表します。 シンボルと別のシンボルの間にマシンコードがある場合、この値はそれらのバイトサイズを含む必要があります。

関連する問題