diff options
author | Eric Christopher <echristo@apple.com> | 2011-04-03 22:53:19 +0000 |
---|---|---|
committer | Eric Christopher <echristo@apple.com> | 2011-04-03 22:53:19 +0000 |
commit | ee066fc4f309713c215d4b2cda16579155076a22 (patch) | |
tree | 7992a9768272ada363f179d49850752bce6b2d0f /llvm/lib/Support/Path.cpp | |
parent | 9f08a3bbf4ce59690eec684bc46f2e5197d6a9be (diff) | |
download | llvm-ee066fc4f309713c215d4b2cda16579155076a22.zip llvm-ee066fc4f309713c215d4b2cda16579155076a22.tar.gz llvm-ee066fc4f309713c215d4b2cda16579155076a22.tar.bz2 |
Assorted bugfixes in object file handling:
- Adds support for sniffing PE/COFF files on win32 (.exe and .dll)
which are COFF files that have an MS-DOS compatibility stub on
the front of them.
- Fixes a bug in the COFFObjectFile's support for the Microsoft COFF
extension for long symbol names, wherein it was attempting to parse
the leading '/' in an extended symbol name reference as part of the
integer offset.
- Fixes bugs in COFFObjectFile and ELFObjectFile wherein section
and symbol iterators were being returned with uninitialized bytes;
the type DataRefImpl is a union between 2 32-bit words (d.a and d.b)
and a single intptr_t word (p). Only p was being initialized, so in
32-bit builds the result would be iterators with random upper 32-bit
words in their DataRefImpls. This caused random failures when
seeking around in object files.
Patch by Graydon Hoare!
llvm-svn: 128799
Diffstat (limited to 'llvm/lib/Support/Path.cpp')
-rw-r--r-- | llvm/lib/Support/Path.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp index e5e875b..cfe23d8 100644 --- a/llvm/lib/Support/Path.cpp +++ b/llvm/lib/Support/Path.cpp @@ -15,11 +15,15 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Config/config.h" #include "llvm/Support/FileSystem.h" +#include "llvm/Support/Endian.h" #include <cassert> #include <cstring> #include <ostream> using namespace llvm; using namespace sys; +namespace { +using support::ulittle32_t; +} //===----------------------------------------------------------------------===// //=== WARNING: Implementation here must contain only TRULY operating system @@ -129,6 +133,16 @@ sys::IdentifyFileType(const char *magic, unsigned length) { if (magic[1] == 0x02) return COFF_FileType; break; + + case 0x4d: // Possible MS-DOS stub on Windows PE file + if (magic[1] == 0x5a) { + uint32_t off = *reinterpret_cast<const ulittle32_t *>(magic + 0x3c); + // PE/COFF file, either EXE or DLL. + if (off < length && memcmp(magic + off, "PE\0\0",4) == 0) + return COFF_FileType; + } + break; + case 0x64: // x86-64 Windows. if (magic[1] == char(0x86)) return COFF_FileType; |