summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Pfeiffer <cpfeiffer@live.de>2017-12-19 17:43:08 (GMT)
committerKitware Robot <kwrobot@kitware.com>2017-12-19 17:43:22 (GMT)
commit7bf21414301cde129d7d76f4f9980128deb6849e (patch)
tree726f7e0015bf312879ab897361f0e754457e0725
parent1eac7c6ee58e73302d2049376ff3f114a8e6826e (diff)
parent1f3933d3825e6e99cc60065a8666c5e22bb1e7c2 (diff)
downloadCMake-7bf21414301cde129d7d76f4f9980128deb6849e.zip
CMake-7bf21414301cde129d7d76f4f9980128deb6849e.tar.gz
CMake-7bf21414301cde129d7d76f4f9980128deb6849e.tar.bz2
Merge topic 'winarm64'
1f3933d3 Address code review feedback 14ebad53 Use IMAGE_FILE_HEADER and add missing Arm 32bit images support 8950183b Add Arm64 support to COFF symbol export feature Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !1603
-rw-r--r--Source/bindexplib.cxx75
1 files changed, 46 insertions, 29 deletions
diff --git a/Source/bindexplib.cxx b/Source/bindexplib.cxx
index 2eb47f3..9ec9624 100644
--- a/Source/bindexplib.cxx
+++ b/Source/bindexplib.cxx
@@ -31,7 +31,7 @@
* Extension (Axel 2006-03-15)
* As soon as an object file contains an /EXPORT directive (which
* is generated by the compiler when a symbol is declared as
- * declspec(dllexport)) no to-be-exported symbols are printed,
+ * __declspec(dllexport) no to-be-exported symbols are printed,
* as the linker will see these directives, and if those directives
* are present we only export selectively (i.e. we trust the
* programmer).
@@ -50,12 +50,12 @@
*
* It created a wrong EXPORTS for the global pointers and constants.
* The Section Header has been involved to discover the missing information
-* Now the pointers are correctly supplied supplied with "DATA" descriptor
+* Now the pointers are correctly supplied with "DATA" descriptor
* the constants with no extra descriptor.
*
* Corrections (Valery Fine 16/09/96):
*
-* It didn't work for C++ code with global variables and class definitons
+* It didn't work for C++ code with global variables and class definitions
* The DumpExternalObject function has been introduced to generate .DEF file
*
* Author: Valery Fine 16/09/96 (E-mail: fine@vxcern.cern.ch)
@@ -68,8 +68,20 @@
#include <iostream>
#include <windows.h>
+#ifndef IMAGE_FILE_MACHINE_ARM
+#define IMAGE_FILE_MACHINE_ARM 0x01c0 // ARM Little-Endian
+#endif
+
+#ifndef IMAGE_FILE_MACHINE_THUMB
+#define IMAGE_FILE_MACHINE_THUMB 0x01c2 // ARM Thumb/Thumb-2 Little-Endian
+#endif
+
#ifndef IMAGE_FILE_MACHINE_ARMNT
-#define IMAGE_FILE_MACHINE_ARMNT 0x01c4
+#define IMAGE_FILE_MACHINE_ARMNT 0x01c4 // ARM Thumb-2 Little-Endian
+#endif
+
+#ifndef IMAGE_FILE_MACHINE_ARM64
+#define IMAGE_FILE_MACHINE_ARM64 0xaa64 // ARM64 Little-Endian
#endif
typedef struct cmANON_OBJECT_HEADER_BIGOBJ
@@ -294,7 +306,6 @@ bool DumpFile(const char* filename, std::set<std::string>& symbols,
HANDLE hFile;
HANDLE hFileMapping;
LPVOID lpFileBase;
- PIMAGE_DOS_HEADER dosHeader;
hFile = CreateFileW(cmsys::Encoding::ToWide(filename).c_str(), GENERIC_READ,
FILE_SHARE_READ, NULL, OPEN_EXISTING,
@@ -320,36 +331,42 @@ bool DumpFile(const char* filename, std::set<std::string>& symbols,
return false;
}
- dosHeader = (PIMAGE_DOS_HEADER)lpFileBase;
+ const PIMAGE_DOS_HEADER dosHeader = (PIMAGE_DOS_HEADER)lpFileBase;
if (dosHeader->e_magic == IMAGE_DOS_SIGNATURE) {
fprintf(stderr, "File is an executable. I don't dump those.\n");
return false;
- }
- /* Does it look like a COFF OBJ file??? */
- else if (((dosHeader->e_magic == IMAGE_FILE_MACHINE_I386) ||
- (dosHeader->e_magic == IMAGE_FILE_MACHINE_AMD64) ||
- (dosHeader->e_magic == IMAGE_FILE_MACHINE_ARMNT)) &&
- (dosHeader->e_sp == 0)) {
- /*
- * The two tests above aren't what they look like. They're
- * really checking for IMAGE_FILE_HEADER.Machine == i386 (0x14C)
- * and IMAGE_FILE_HEADER.SizeOfOptionalHeader == 0;
- */
- DumpSymbols<IMAGE_FILE_HEADER, IMAGE_SYMBOL> symbolDumper(
- (PIMAGE_FILE_HEADER)lpFileBase, symbols, dataSymbols,
- (dosHeader->e_magic == IMAGE_FILE_MACHINE_I386));
- symbolDumper.DumpObjFile();
} else {
- // check for /bigobj format
- cmANON_OBJECT_HEADER_BIGOBJ* h = (cmANON_OBJECT_HEADER_BIGOBJ*)lpFileBase;
- if (h->Sig1 == 0x0 && h->Sig2 == 0xffff) {
- DumpSymbols<cmANON_OBJECT_HEADER_BIGOBJ, cmIMAGE_SYMBOL_EX> symbolDumper(
- (cmANON_OBJECT_HEADER_BIGOBJ*)lpFileBase, symbols, dataSymbols,
- (h->Machine == IMAGE_FILE_MACHINE_I386));
+ const PIMAGE_FILE_HEADER imageHeader = (PIMAGE_FILE_HEADER)lpFileBase;
+ /* Does it look like a COFF OBJ file??? */
+ if (((imageHeader->Machine == IMAGE_FILE_MACHINE_I386) ||
+ (imageHeader->Machine == IMAGE_FILE_MACHINE_AMD64) ||
+ (imageHeader->Machine == IMAGE_FILE_MACHINE_ARM) ||
+ (imageHeader->Machine == IMAGE_FILE_MACHINE_ARMNT) ||
+ (imageHeader->Machine == IMAGE_FILE_MACHINE_ARM64)) &&
+ (imageHeader->Characteristics == 0)) {
+ /*
+ * The tests above are checking for IMAGE_FILE_HEADER.Machine
+ * if it contains supported machine formats (currently ARM and x86)
+ * and IMAGE_FILE_HEADER.Characteristics == 0 indicating that
+ * this is not linked COFF OBJ file;
+ */
+ DumpSymbols<IMAGE_FILE_HEADER, IMAGE_SYMBOL> symbolDumper(
+ (PIMAGE_FILE_HEADER)lpFileBase, symbols, dataSymbols,
+ (imageHeader->Machine == IMAGE_FILE_MACHINE_I386));
symbolDumper.DumpObjFile();
} else {
- printf("unrecognized file format in '%s'\n", filename);
- return false;
+ // check for /bigobj format
+ cmANON_OBJECT_HEADER_BIGOBJ* h =
+ (cmANON_OBJECT_HEADER_BIGOBJ*)lpFileBase;
+ if (h->Sig1 == 0x0 && h->Sig2 == 0xffff) {
+ DumpSymbols<cmANON_OBJECT_HEADER_BIGOBJ, cmIMAGE_SYMBOL_EX>
+ symbolDumper((cmANON_OBJECT_HEADER_BIGOBJ*)lpFileBase, symbols,
+ dataSymbols, (h->Machine == IMAGE_FILE_MACHINE_I386));
+ symbolDumper.DumpObjFile();
+ } else {
+ printf("unrecognized file format in '%s'\n", filename);
+ return false;
+ }
}
}
UnmapViewOfFile(lpFileBase);