From 91de80a5350b801b10323e65a6f3ee0f7dfb54f5 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 10 Jun 2013 14:56:16 +0000 Subject: Update for current naming conventions. I will change identifyFileType to use a StringRef in the next patch. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183664 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/Path.cpp | 61 ++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 30 deletions(-) (limited to 'lib/Support/Path.cpp') diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp index d0703754e0..5b34c5eab6 100644 --- a/lib/Support/Path.cpp +++ b/lib/Support/Path.cpp @@ -38,32 +38,32 @@ bool Path::operator<(const Path& that) const { } LLVMFileType -sys::IdentifyFileType(const char *magic, unsigned length) { - assert(magic && "Invalid magic number string"); - assert(length >=4 && "Invalid magic number length"); - switch ((unsigned char)magic[0]) { +sys::identifyFileType(const char *Magic, unsigned Length) { + assert(Magic && "Invalid magic number string"); + assert(Length >=4 && "Invalid magic number length"); + switch ((unsigned char)Magic[0]) { case 0xDE: // 0x0B17C0DE = BC wraper - if (magic[1] == (char)0xC0 && magic[2] == (char)0x17 && - magic[3] == (char)0x0B) + if (Magic[1] == (char)0xC0 && Magic[2] == (char)0x17 && + Magic[3] == (char)0x0B) return Bitcode_FileType; break; case 'B': - if (magic[1] == 'C' && magic[2] == (char)0xC0 && magic[3] == (char)0xDE) + if (Magic[1] == 'C' && Magic[2] == (char)0xC0 && Magic[3] == (char)0xDE) return Bitcode_FileType; break; case '!': - if (length >= 8) - if (memcmp(magic,"!\n",8) == 0) + if (Length >= 8) + if (memcmp(Magic,"!\n",8) == 0) return Archive_FileType; break; case '\177': - if (magic[1] == 'E' && magic[2] == 'L' && magic[3] == 'F') { - bool Data2MSB = magic[5] == 2; + if (Magic[1] == 'E' && Magic[2] == 'L' && Magic[3] == 'F') { + bool Data2MSB = Magic[5] == 2; unsigned high = Data2MSB ? 16 : 17; unsigned low = Data2MSB ? 17 : 16; - if (length >= 18 && magic[high] == 0) - switch (magic[low]) { + if (Length >= 18 && Magic[high] == 0) + switch (Magic[low]) { default: break; case 1: return ELF_Relocatable_FileType; case 2: return ELF_Executable_FileType; @@ -74,11 +74,11 @@ sys::IdentifyFileType(const char *magic, unsigned length) { break; case 0xCA: - if (magic[1] == char(0xFE) && magic[2] == char(0xBA) && - magic[3] == char(0xBE)) { + if (Magic[1] == char(0xFE) && Magic[2] == char(0xBA) && + Magic[3] == char(0xBE)) { // This is complicated by an overlap with Java class files. // See the Mach-O section in /usr/share/file/magic for details. - if (length >= 8 && magic[7] < 43) + if (Length >= 8 && Magic[7] < 43) // FIXME: Universal Binary of any type. return Mach_O_DynamicallyLinkedSharedLib_FileType; } @@ -91,16 +91,16 @@ sys::IdentifyFileType(const char *magic, unsigned length) { case 0xCE: case 0xCF: { uint16_t type = 0; - if (magic[0] == char(0xFE) && magic[1] == char(0xED) && - magic[2] == char(0xFA) && - (magic[3] == char(0xCE) || magic[3] == char(0xCF))) { + if (Magic[0] == char(0xFE) && Magic[1] == char(0xED) && + Magic[2] == char(0xFA) && + (Magic[3] == char(0xCE) || Magic[3] == char(0xCF))) { /* Native endian */ - if (length >= 16) type = magic[14] << 8 | magic[15]; - } else if ((magic[0] == char(0xCE) || magic[0] == char(0xCF)) && - magic[1] == char(0xFA) && magic[2] == char(0xED) && - magic[3] == char(0xFE)) { + if (Length >= 16) type = Magic[14] << 8 | Magic[15]; + } else if ((Magic[0] == char(0xCE) || Magic[0] == char(0xCF)) && + Magic[1] == char(0xFA) && Magic[2] == char(0xED) && + Magic[3] == char(0xFE)) { /* Reverse endian */ - if (length >= 14) type = magic[13] << 8 | magic[12]; + if (Length >= 14) type = Magic[13] << 8 | Magic[12]; } switch (type) { default: break; @@ -123,26 +123,27 @@ sys::IdentifyFileType(const char *magic, unsigned length) { case 0x66: // MPS R4000 Windows case 0x50: // mc68K case 0x4c: // 80386 Windows - if (magic[1] == 0x01) + if (Magic[1] == 0x01) return COFF_FileType; case 0x90: // PA-RISC Windows case 0x68: // mc68K Windows - if (magic[1] == 0x02) + 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(magic + 0x3c); + if (Magic[1] == 0x5a) { + uint32_t off = + *reinterpret_cast(Magic + 0x3c); // PE/COFF file, either EXE or DLL. - if (off < length && memcmp(magic + off, "PE\0\0",4) == 0) + 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)) + if (Magic[1] == char(0x86)) return COFF_FileType; break; -- cgit v1.2.3 From b972457783f6f992d8ee2fe392609fd4b0c5cf00 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 10 Jun 2013 15:22:18 +0000 Subject: Fix an out of bounds array access. We were looking at Magic[5] without checking Length. Since this path would not return unless Length >= 18 anyway, just move the >= 18 check up. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183666 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/Path.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib/Support/Path.cpp') diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp index 5b34c5eab6..b6eeb1484c 100644 --- a/lib/Support/Path.cpp +++ b/lib/Support/Path.cpp @@ -58,11 +58,12 @@ sys::identifyFileType(const char *Magic, unsigned Length) { break; case '\177': - if (Magic[1] == 'E' && Magic[2] == 'L' && Magic[3] == 'F') { + if (Length >= 18 && Magic[1] == 'E' && Magic[2] == 'L' && + Magic[3] == 'F') { bool Data2MSB = Magic[5] == 2; unsigned high = Data2MSB ? 16 : 17; unsigned low = Data2MSB ? 17 : 16; - if (Length >= 18 && Magic[high] == 0) + if (Magic[high] == 0) switch (Magic[low]) { default: break; case 1: return ELF_Relocatable_FileType; -- cgit v1.2.3 From f12745f7a7e68c05c89ebd515b9b4faedce37dd0 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 10 Jun 2013 15:27:39 +0000 Subject: Pass a StringRef to sys::identifyFileType. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183669 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/Path.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lib/Support/Path.cpp') diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp index b6eeb1484c..bf1ae44e0d 100644 --- a/lib/Support/Path.cpp +++ b/lib/Support/Path.cpp @@ -38,9 +38,9 @@ bool Path::operator<(const Path& that) const { } LLVMFileType -sys::identifyFileType(const char *Magic, unsigned Length) { - assert(Magic && "Invalid magic number string"); - assert(Length >=4 && "Invalid magic number length"); +sys::identifyFileType(StringRef Magic) { + unsigned Length = Magic.size(); + assert(Length >= 4 && "Invalid magic number length"); switch ((unsigned char)Magic[0]) { case 0xDE: // 0x0B17C0DE = BC wraper if (Magic[1] == (char)0xC0 && Magic[2] == (char)0x17 && @@ -53,7 +53,7 @@ sys::identifyFileType(const char *Magic, unsigned Length) { break; case '!': if (Length >= 8) - if (memcmp(Magic,"!\n",8) == 0) + if (memcmp(Magic.data(),"!\n",8) == 0) return Archive_FileType; break; @@ -136,9 +136,9 @@ sys::identifyFileType(const char *Magic, unsigned Length) { case 0x4d: // Possible MS-DOS stub on Windows PE file if (Magic[1] == 0x5a) { uint32_t off = - *reinterpret_cast(Magic + 0x3c); + *reinterpret_cast(Magic.data() + 0x3c); // PE/COFF file, either EXE or DLL. - if (off < Length && memcmp(Magic + off, "PE\0\0",4) == 0) + if (off < Length && memcmp(Magic.data() + off, "PE\0\0",4) == 0) return COFF_FileType; } break; -- cgit v1.2.3 From af2c42e3d2ee918c4195ce5f32e732c43d93cea8 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 11 Jun 2013 18:18:02 +0000 Subject: Remove sys::identifyFileType. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183763 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/Path.cpp | 117 --------------------------------------------------- 1 file changed, 117 deletions(-) (limited to 'lib/Support/Path.cpp') diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp index bf1ae44e0d..e53abe8f59 100644 --- a/lib/Support/Path.cpp +++ b/lib/Support/Path.cpp @@ -37,123 +37,6 @@ bool Path::operator<(const Path& that) const { return path < that.path; } -LLVMFileType -sys::identifyFileType(StringRef Magic) { - unsigned Length = Magic.size(); - assert(Length >= 4 && "Invalid magic number length"); - switch ((unsigned char)Magic[0]) { - case 0xDE: // 0x0B17C0DE = BC wraper - if (Magic[1] == (char)0xC0 && Magic[2] == (char)0x17 && - Magic[3] == (char)0x0B) - return Bitcode_FileType; - break; - case 'B': - if (Magic[1] == 'C' && Magic[2] == (char)0xC0 && Magic[3] == (char)0xDE) - return Bitcode_FileType; - break; - case '!': - if (Length >= 8) - if (memcmp(Magic.data(),"!\n",8) == 0) - return Archive_FileType; - break; - - case '\177': - if (Length >= 18 && Magic[1] == 'E' && Magic[2] == 'L' && - Magic[3] == 'F') { - bool Data2MSB = Magic[5] == 2; - unsigned high = Data2MSB ? 16 : 17; - unsigned low = Data2MSB ? 17 : 16; - if (Magic[high] == 0) - switch (Magic[low]) { - default: break; - case 1: return ELF_Relocatable_FileType; - case 2: return ELF_Executable_FileType; - case 3: return ELF_SharedObject_FileType; - case 4: return ELF_Core_FileType; - } - } - break; - - case 0xCA: - if (Magic[1] == char(0xFE) && Magic[2] == char(0xBA) && - Magic[3] == char(0xBE)) { - // This is complicated by an overlap with Java class files. - // See the Mach-O section in /usr/share/file/magic for details. - if (Length >= 8 && Magic[7] < 43) - // FIXME: Universal Binary of any type. - return Mach_O_DynamicallyLinkedSharedLib_FileType; - } - break; - - // The two magic numbers for mach-o are: - // 0xfeedface - 32-bit mach-o - // 0xfeedfacf - 64-bit mach-o - case 0xFE: - case 0xCE: - case 0xCF: { - uint16_t type = 0; - if (Magic[0] == char(0xFE) && Magic[1] == char(0xED) && - Magic[2] == char(0xFA) && - (Magic[3] == char(0xCE) || Magic[3] == char(0xCF))) { - /* Native endian */ - if (Length >= 16) type = Magic[14] << 8 | Magic[15]; - } else if ((Magic[0] == char(0xCE) || Magic[0] == char(0xCF)) && - Magic[1] == char(0xFA) && Magic[2] == char(0xED) && - Magic[3] == char(0xFE)) { - /* Reverse endian */ - if (Length >= 14) type = Magic[13] << 8 | Magic[12]; - } - switch (type) { - default: break; - case 1: return Mach_O_Object_FileType; - case 2: return Mach_O_Executable_FileType; - case 3: return Mach_O_FixedVirtualMemorySharedLib_FileType; - case 4: return Mach_O_Core_FileType; - case 5: return Mach_O_PreloadExecutable_FileType; - case 6: return Mach_O_DynamicallyLinkedSharedLib_FileType; - case 7: return Mach_O_DynamicLinker_FileType; - case 8: return Mach_O_Bundle_FileType; - case 9: return Mach_O_DynamicallyLinkedSharedLibStub_FileType; - case 10: return Mach_O_DSYMCompanion_FileType; - } - break; - } - case 0xF0: // PowerPC Windows - case 0x83: // Alpha 32-bit - case 0x84: // Alpha 64-bit - case 0x66: // MPS R4000 Windows - case 0x50: // mc68K - case 0x4c: // 80386 Windows - if (Magic[1] == 0x01) - return COFF_FileType; - - case 0x90: // PA-RISC Windows - case 0x68: // mc68K Windows - 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(Magic.data() + 0x3c); - // PE/COFF file, either EXE or DLL. - if (off < Length && memcmp(Magic.data() + off, "PE\0\0",4) == 0) - return COFF_FileType; - } - break; - - case 0x64: // x86-64 Windows. - if (Magic[1] == char(0x86)) - return COFF_FileType; - break; - - default: - break; - } - return Unknown_FileType; -} - bool Path::isArchive() const { fs::file_magic type; -- cgit v1.2.3 From 9a82d21512da4a8129ef32d6749b9ae3997de517 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 11 Jun 2013 18:41:07 +0000 Subject: Remove unused FindLibrary function. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183764 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/Path.cpp | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'lib/Support/Path.cpp') diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp index e53abe8f59..5c2b1f7dce 100644 --- a/lib/Support/Path.cpp +++ b/lib/Support/Path.cpp @@ -68,23 +68,6 @@ Path::isObjectFile() const { return true; } -Path -Path::FindLibrary(std::string& name) { - std::vector LibPaths; - GetSystemLibraryPaths(LibPaths); - for (unsigned i = 0; i < LibPaths.size(); ++i) { - sys::Path FullPath(LibPaths[i]); - FullPath.appendComponent("lib" + name + LTDL_SHLIB_EXT); - if (FullPath.isDynamicLibrary()) - return FullPath; - FullPath.eraseSuffix(); - FullPath.appendSuffix("a"); - if (FullPath.isArchive()) - return FullPath; - } - return sys::Path(); -} - StringRef Path::GetDLLSuffix() { return &(LTDL_SHLIB_EXT[1]); } -- cgit v1.2.3 From 40de55a5569bd175cee6abab2070fa0edfbd8658 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 11 Jun 2013 18:58:47 +0000 Subject: Remove GetSystemLibraryPaths. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183770 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/Path.cpp | 19 ------------------- 1 file changed, 19 deletions(-) (limited to 'lib/Support/Path.cpp') diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp index 5c2b1f7dce..09d2eadd51 100644 --- a/lib/Support/Path.cpp +++ b/lib/Support/Path.cpp @@ -95,25 +95,6 @@ bool Path::hasMagicNumber(StringRef Magic) const { return false; } -static void getPathList(const char*path, std::vector& Paths) { - const char* at = path; - const char* delim = strchr(at, PathSeparator); - Path tmpPath; - while (delim != 0) { - std::string tmp(at, size_t(delim-at)); - if (tmpPath.set(tmp)) - if (tmpPath.canRead()) - Paths.push_back(tmpPath); - at = delim + 1; - delim = strchr(at, PathSeparator); - } - - if (*at != 0) - if (tmpPath.set(std::string(at))) - if (tmpPath.canRead()) - Paths.push_back(tmpPath); -} - static StringRef getDirnameCharSep(StringRef path, const char *Sep) { assert(Sep[0] != '\0' && Sep[1] == '\0' && "Sep must be a 1-character string literal."); -- cgit v1.2.3 From 189c27e871763efac38c65a9786127af8d5b92b8 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 11 Jun 2013 19:18:05 +0000 Subject: Remove GetDLLSuffix. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183777 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/Path.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'lib/Support/Path.cpp') diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp index 09d2eadd51..2e8223b6a1 100644 --- a/lib/Support/Path.cpp +++ b/lib/Support/Path.cpp @@ -68,10 +68,6 @@ Path::isObjectFile() const { return true; } -StringRef Path::GetDLLSuffix() { - return &(LTDL_SHLIB_EXT[1]); -} - void Path::appendSuffix(StringRef suffix) { if (!suffix.empty()) { -- cgit v1.2.3 From 715a1be51fe25a09fcc5318cd787893a8fbfc9e1 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 11 Jun 2013 19:32:57 +0000 Subject: Remove Path::getDirname. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183780 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/Path.cpp | 40 ---------------------------------------- 1 file changed, 40 deletions(-) (limited to 'lib/Support/Path.cpp') diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp index 2e8223b6a1..b873b9ab4a 100644 --- a/lib/Support/Path.cpp +++ b/lib/Support/Path.cpp @@ -91,46 +91,6 @@ bool Path::hasMagicNumber(StringRef Magic) const { return false; } -static StringRef getDirnameCharSep(StringRef path, const char *Sep) { - assert(Sep[0] != '\0' && Sep[1] == '\0' && - "Sep must be a 1-character string literal."); - if (path.empty()) - return "."; - - // If the path is all slashes, return a single slash. - // Otherwise, remove all trailing slashes. - - signed pos = static_cast(path.size()) - 1; - - while (pos >= 0 && path[pos] == Sep[0]) - --pos; - - if (pos < 0) - return path[0] == Sep[0] ? Sep : "."; - - // Any slashes left? - signed i = 0; - - while (i < pos && path[i] != Sep[0]) - ++i; - - if (i == pos) // No slashes? Return "." - return "."; - - // There is at least one slash left. Remove all trailing non-slashes. - while (pos >= 0 && path[pos] != Sep[0]) - --pos; - - // Remove any trailing slashes. - while (pos >= 0 && path[pos] == Sep[0]) - --pos; - - if (pos < 0) - return path[0] == Sep[0] ? Sep : "."; - - return path.substr(0, pos+1); -} - // Include the truly platform-specific parts of this class. #if defined(LLVM_ON_UNIX) #include "Unix/Path.inc" -- cgit v1.2.3 From f3e397eb17327423b3f8fff5eac8547c85efddb1 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 11 Jun 2013 20:00:56 +0000 Subject: Include PathV1.h in files that use it. This is preparation for replacing Path.h with PathV2.h. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183782 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/Path.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/Support/Path.cpp') diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp index b873b9ab4a..1bae78137b 100644 --- a/lib/Support/Path.cpp +++ b/lib/Support/Path.cpp @@ -15,6 +15,7 @@ #include "llvm/Config/config.h" #include "llvm/Support/Endian.h" #include "llvm/Support/FileSystem.h" +#include "llvm/Support/PathV1.h" #include #include #include -- cgit v1.2.3 From 26ace5720d471dcff6ab6495f5898597cda54496 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 12 Jun 2013 15:04:59 +0000 Subject: Remove Path::hasMagicNumber. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183838 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/Path.cpp | 7 ------- 1 file changed, 7 deletions(-) (limited to 'lib/Support/Path.cpp') diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp index 1bae78137b..d47d23f57b 100644 --- a/lib/Support/Path.cpp +++ b/lib/Support/Path.cpp @@ -85,13 +85,6 @@ Path::isBitcodeFile() const { return type == fs::file_magic::bitcode; } -bool Path::hasMagicNumber(StringRef Magic) const { - std::string actualMagic; - if (getMagicNumber(actualMagic, static_cast(Magic.size()))) - return Magic == actualMagic; - return false; -} - // Include the truly platform-specific parts of this class. #if defined(LLVM_ON_UNIX) #include "Unix/Path.inc" -- cgit v1.2.3 From c3907f387f0b2ec20913c6f869131c5ffd9f08df Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 12 Jun 2013 15:13:57 +0000 Subject: Inline Path::isBitcodeFile into only use and remove it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183840 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/Path.cpp | 8 -------- 1 file changed, 8 deletions(-) (limited to 'lib/Support/Path.cpp') diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp index d47d23f57b..7ddaf1e89e 100644 --- a/lib/Support/Path.cpp +++ b/lib/Support/Path.cpp @@ -77,14 +77,6 @@ Path::appendSuffix(StringRef suffix) { } } -bool -Path::isBitcodeFile() const { - fs::file_magic type; - if (fs::identify_magic(str(), type)) - return false; - return type == fs::file_magic::bitcode; -} - // Include the truly platform-specific parts of this class. #if defined(LLVM_ON_UNIX) #include "Unix/Path.inc" -- cgit v1.2.3