如何从使用/GL编译的.obj文件中确定主要的编译器版本? [英] How to determine the major compiler version from .obj files compiled with /GL?
问题描述
我正试图通过使用链接时间代码生成选项生成的.obj
文件来确定Visual Studio版本(2002/2003、2005、2008、2010、2012、2013、2015).
I'm trying to determine Visual Studio version (2002/2003, 2005, 2008, 2010, 2012, 2013, 2015) from the .obj
file generated with the link time code generation option.
我使用MSVC2012生成的文件具有以下COFF标头内容:
The file I have, generated with MSVC2012, has following COFF header contents:
File Header
+0 00 00 Machine - Unknown Machine
+2 FF FF NumberOfSections
+4 01 00 4C 01 TimeDateStamp
+8 70 94 F9 55 PointerToSymbolTable
+12 38 FE B3 0C NumberOfSymbols
+16 A5 D9 SizeOfOptionalHeader
+18 AB 4D Characteristics
Optional Header
+20 AC 9B Magic
+22 D6 B6 Linker Version Major/Minor
似乎最初的4个字节为00,00,FF,FF将其标记为LTCG对象,其后是专有的.通常的文件头成员都没有感觉"(也许时间戳没问题,我没有检查).
It seems that the initial 4 bytes being 00,00,FF,FF mark it as a LTCG object, and what follows is proprietary. None of the usual file header members make "sense" (maybe the timestamp is OK, I didn't check).
有人知道此标头的任何部分是否特定于编译器吗?我需要确定的是用于编译对象的MSVC主版本...
Does anyone know offhand if any part of this header is compiler-specific? All I need to determine is the MSVC major version used to compile the object...
似乎在标题之后不久存储了一个编码为<MAJOR:16:LE> 0x80 <MINOR:16:LE>
的版本.例如:
It appears that there is a version, coded as <MAJOR:16:LE> 0x80 <MINOR:16:LE>
, stored shortly after the header. E.g.:
17.00.61030 -> 0x11.0xEE66 -> 11 00 80 66 EE
19.00.23026 -> 0x13.0x59F2 -> 13 00 80 F2 59
需要的是找出如何通过与先前数据的偏移量可靠地获取它.
What's needed is to figure out how to get to it reliably by offsets from preceding data.
这是一个相关问题,没有解决方法...
This is a related question, with no resolution...
推荐答案
TL,DR:
我想您无法获得具有此文件格式的编译器版本...
TL,DR :
You can't get the compiler version with this file format, I guess ...
完整答案:
它看起来像匿名文件格式"的某种变体,在"winnth.h"中由各种ANON_OBJECT_HEADER_XXX
结构描述(用V2
或BIGOBJ
替换XXX
).
这是在winnt.h中找到的ANON_OBJECT_HEADER_BIGOBJ
的副本:
It looks like some variation of the "anonymous file format", described in the "winnth.h" by various ANON_OBJECT_HEADER_XXX
structures (replace XXX
by V2
or BIGOBJ
).
Here is a copy of the ANON_OBJECT_HEADER_BIGOBJ
found in winnt.h :
typedef struct ANON_OBJECT_HEADER_BIGOBJ {
/* same as ANON_OBJECT_HEADER_V2 */
WORD Sig1; // Must be IMAGE_FILE_MACHINE_UNKNOWN
WORD Sig2; // Must be 0xffff
WORD Version; // >= 2 (implies the Flags field is present)
WORD Machine; // Actual machine - IMAGE_FILE_MACHINE_xxx
DWORD TimeDateStamp;
CLSID ClassID; // CLSID is a 16 bytes struct (not original comment)
DWORD SizeOfData; // Size of data that follows the header
DWORD Flags; // 0x1 -> contains metadata
DWORD MetaDataSize; // Size of CLR metadata
DWORD MetaDataOffset; // Offset of CLR metadata
/* bigobj specifics */
DWORD NumberOfSections; // extended from WORD
DWORD PointerToSymbolTable;
DWORD NumberOfSymbols;
} ANON_OBJECT_HEADER_BIGOBJ;</code>
说明匹配项:
Sig1 : 00 00
Sig2 : FF FF
Version : >=2
Machine : 0x14c`
其他标头结构(即ANON_OBJECT_HEADER
和ANON_OBJECT_HEADER_V2
)基本相同,但字段较少.
对于Version
字段,我在这里找到了一些信息:
http://www.geoffchappell.com/studies/msvc/link/dump/infiles/obj.htm
The other header structures (i.e, ANON_OBJECT_HEADER
and ANON_OBJECT_HEADER_V2
) are basically the same, but with less fields.
For the Version
field, I found some information here :
http://www.geoffchappell.com/studies/msvc/link/dump/infiles/obj.htm
对于匿名文件,看起来Version
字段为"1",并且似乎匿名文件和所谓的导入文件"具有相同的特征,只是对于导入文件格式,这是Version = 0
(我确实真的不知道这是什么).
Looks like the Version
field is "1" for anonymous files, and it seems like the anonymous files and the so called "import files" shared the same characteristics, only that Version = 0
for import file format (I do not really know what it is admittedly).
但是,是的,仅通过查看标头,似乎我们没有使用哪个编译器版本的信息.即使这样,当查看通过/GL开关生成的.obj文件时,它们也不完全遵循这种格式,因此我也没有找到太多有关它们的信息.我很高兴有人证明我错了.
But yeah, by just looking at the header, it seems that we have no information on what compiler version was used. And even then, when looking at .obj files generated with the /GL switch, they do not exactly follow this format and I didn't find much information about them. I'll be glad that someone prove me wrong.
这篇关于如何从使用/GL编译的.obj文件中确定主要的编译器版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!