X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FSupport%2FPath.cpp;h=a7a991950bca89c0febf4598c9e6fce2d488003b;hb=de15d01f9d48701b6b6830670b858d366172f096;hp=259000b4e47c14737a0650dda79aece507a0b313;hpb=9be4884731b20e540b13b47737f0b4acb7c66e86;p=oota-llvm.git diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp index 259000b4e47..a7a991950bc 100644 --- a/lib/Support/Path.cpp +++ b/lib/Support/Path.cpp @@ -11,9 +11,10 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Support/COFF.h" +#include "llvm/Support/Endian.h" #include "llvm/Support/Errc.h" #include "llvm/Support/Path.h" -#include "llvm/Support/Endian.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Process.h" @@ -210,13 +211,13 @@ retry_random_path: } case FS_Name: { - bool Exists; - std::error_code EC = sys::fs::exists(ResultPath.begin(), Exists); + std::error_code EC = + sys::fs::access(ResultPath.begin(), sys::fs::AccessMode::Exist); + if (EC == errc::no_such_file_or_directory) + return std::error_code(); if (EC) return EC; - if (Exists) - goto retry_random_path; - return std::error_code(); + goto retry_random_path; } case FS_Dir: { @@ -359,7 +360,7 @@ bool reverse_iterator::operator==(const reverse_iterator &RHS) const { Position == RHS.Position; } -const StringRef root_path(StringRef path) { +StringRef root_path(StringRef path) { const_iterator b = begin(path), pos = b, e = end(path); @@ -391,7 +392,7 @@ const StringRef root_path(StringRef path) { return StringRef(); } -const StringRef root_name(StringRef path) { +StringRef root_name(StringRef path) { const_iterator b = begin(path), e = end(path); if (b != e) { @@ -413,7 +414,7 @@ const StringRef root_name(StringRef path) { return StringRef(); } -const StringRef root_directory(StringRef path) { +StringRef root_directory(StringRef path) { const_iterator b = begin(path), pos = b, e = end(path); @@ -442,7 +443,7 @@ const StringRef root_directory(StringRef path) { return StringRef(); } -const StringRef relative_path(StringRef path) { +StringRef relative_path(StringRef path) { StringRef root = root_path(path); return path.substr(root.size()); } @@ -494,7 +495,7 @@ void append(SmallVectorImpl &path, path::append(path, *begin); } -const StringRef parent_path(StringRef path) { +StringRef parent_path(StringRef path) { size_t end_pos = parent_path_end(path); if (end_pos == StringRef::npos) return StringRef(); @@ -552,11 +553,11 @@ void native(SmallVectorImpl &Path) { #endif } -const StringRef filename(StringRef path) { +StringRef filename(StringRef path) { return *rbegin(path); } -const StringRef stem(StringRef path) { +StringRef stem(StringRef path) { StringRef fname = filename(path); size_t pos = fname.find_last_of('.'); if (pos == StringRef::npos) @@ -569,7 +570,7 @@ const StringRef stem(StringRef path) { return fname.substr(0, pos); } -const StringRef extension(StringRef path) { +StringRef extension(StringRef path) { StringRef fname = filename(path); size_t pos = fname.find_last_of('.'); if (pos == StringRef::npos) @@ -594,7 +595,7 @@ bool is_separator(char value) { static const char preferred_separator_string[] = { preferred_separator, '\0' }; -const StringRef get_separator() { +StringRef get_separator() { return preferred_separator_string; } @@ -901,10 +902,23 @@ file_magic identify_magic(StringRef Magic) { return file_magic::unknown; switch ((unsigned char)Magic[0]) { case 0x00: { - // COFF short import library file + // COFF bigobj or short import library file if (Magic[1] == (char)0x00 && Magic[2] == (char)0xff && - Magic[3] == (char)0xff) - return file_magic::coff_import_library; + Magic[3] == (char)0xff) { + size_t MinSize = offsetof(COFF::BigObjHeader, UUID) + sizeof(COFF::BigObjMagic); + if (Magic.size() < MinSize) + return file_magic::coff_import_library; + + int BigObjVersion = *reinterpret_cast( + Magic.data() + offsetof(COFF::BigObjHeader, Version)); + if (BigObjVersion < COFF::BigObjHeader::MinBigObjectVersion) + return file_magic::coff_import_library; + + const char *Start = Magic.data() + offsetof(COFF::BigObjHeader, UUID); + if (memcmp(Start, COFF::BigObjMagic, sizeof(COFF::BigObjMagic)) != 0) + return file_magic::coff_import_library; + return file_magic::coff_object; + } // Windows resource file const char Expected[] = { 0, 0, 0, 0, '\x20', 0, 0, 0, '\xff' }; if (Magic.size() >= sizeof(Expected) && @@ -944,6 +958,9 @@ file_magic identify_magic(StringRef Magic) { case 3: return file_magic::elf_shared_object; case 4: return file_magic::elf_core; } + else + // It's still some type of ELF file. + return file_magic::elf; } break; @@ -985,7 +1002,7 @@ file_magic identify_magic(StringRef Magic) { case 6: return file_magic::macho_dynamically_linked_shared_lib; case 7: return file_magic::macho_dynamic_linker; case 8: return file_magic::macho_bundle; - case 9: return file_magic::macho_dynamic_linker; + case 9: return file_magic::macho_dynamically_linked_shared_lib_stub; case 10: return file_magic::macho_dsym_companion; } break; @@ -1006,12 +1023,13 @@ file_magic identify_magic(StringRef Magic) { return file_magic::coff_object; break; - case 0x4d: // Possible MS-DOS stub on Windows PE file - if (Magic[1] == 0x5a) { + case 'M': // Possible MS-DOS stub on Windows PE file + if (Magic[1] == 'Z') { uint32_t off = *reinterpret_cast(Magic.data() + 0x3c); // PE/COFF file, either EXE or DLL. - if (off < Magic.size() && memcmp(Magic.data() + off, "PE\0\0",4) == 0) + if (off < Magic.size() && + memcmp(Magic.data()+off, COFF::PEMagic, sizeof(COFF::PEMagic)) == 0) return file_magic::pecoff_executable; } break;