1

I'm writing a linker for Windows binaries, and currently working on implementing COMDAT. I think I understand most of the specification, except that of the three records for a COMDAT section (the section header, section symbols and auxiliary symbol), the specification doesn't seem to mention the common name being stored in any of them.

In other words, when I run dumpbin on such an object, it gives output like:

SECTION HEADER #8
.text$mn name
       0 physical address
       0 virtual address
       5 size of raw data
    2358 file pointer to raw data (00002358 to 0000235C)
    235D file pointer to relocation table
       0 file pointer to line numbers
       1 number of relocations
       0 number of line numbers
60301020 flags
         Code
         COMDAT; sym= cosl

Where does that last item sym= cosl come from? Or if it's just a regular symbol that points to the section, what happens if there are several different such symbols pointing to it?

4

1 回答 1

2

根据Microsoft PE 和 COFF 规范,第 4.5.6 节(如果您正在编写链接器,我相信您已经仔细阅读过), sym= 值是COMDAT 符号,链接器与选择值来确定在最终图像中保留 COMDAT 部分的哪个副本。每个 COMDAT 部分的符号表中有两个条目。第一个具有部分名称和带有选择信息的辅助记录。COMDAT 符号值来自 COMDAT 部分的符号表中的第二个条目。它要么是符号的 ShortName 值,要么是它指向的字符串表条目的值。

对于要链接的各种目标文件中相同 COMDAT 的所有副本,COMDAT 符号值应该相同。如果我正确理解规范,则任何一个目标文件中的特定 COMDAT 部分都应该只有两个符号表条目具有匹配的 SectionNumber。您不应将具有不同值的多个 COMDAT 符号字符串视为单个 COMDAT 的符号表条目。

于 2014-03-13T20:07:56.577 回答