aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-12-28 21:22:49 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-12-28 21:22:49 +0000
commitb2b7c066a48f61ec67332fb797a20bb04901c83d (patch)
treeb3de3914f41bb160a795f7dcd767566c62bdf3e8 /tools
parentfd4675b5a029cce616a1b0ad339344c5df800ea6 (diff)
downloadsrc-b2b7c066a48f61ec67332fb797a20bb04901c83d.tar.gz
src-b2b7c066a48f61ec67332fb797a20bb04901c83d.zip
Vendor import of llvm trunk r321530:vendor/llvm/llvm-trunk-r321530
Notes
Notes: svn path=/vendor/llvm/dist/; revision=327300 svn path=/vendor/llvm/llvm-trunk-r321530/; revision=327301; tag=vendor/llvm/llvm-trunk-r321530
Diffstat (limited to 'tools')
-rw-r--r--tools/dsymutil/CFBundle.cpp88
-rw-r--r--tools/llvm-cov/CodeCoverage.cpp5
-rw-r--r--tools/llvm-objdump/llvm-objdump.cpp2
-rw-r--r--tools/llvm-readobj/COFFDumper.cpp24
-rw-r--r--tools/llvm-readobj/ELFDumper.cpp4
-rw-r--r--tools/yaml2obj/yaml2obj.cpp2
6 files changed, 64 insertions, 61 deletions
diff --git a/tools/dsymutil/CFBundle.cpp b/tools/dsymutil/CFBundle.cpp
index 304838f7ee2c..15ee8011a4a4 100644
--- a/tools/dsymutil/CFBundle.cpp
+++ b/tools/dsymutil/CFBundle.cpp
@@ -11,6 +11,7 @@
#ifdef __APPLE__
#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
#include <CoreFoundation/CoreFoundation.h>
#include <assert.h>
@@ -56,7 +57,7 @@ public:
static const char *UTF8(CFStringRef CFStr, std::string &Str);
};
-/// Static function that puts a copy of the UTF8 contents of CFStringRef into
+/// Static function that puts a copy of the UTF-8 contents of CFStringRef into
/// std::string and returns the C string pointer that is contained in the
/// std::string when successful, nullptr otherwise.
///
@@ -85,13 +86,10 @@ const char *CFString::UTF8(CFStringRef CFStr, std::string &Str) {
/// RAII wrapper around CFBundleRef.
class CFBundle : public CFReleaser<CFBundleRef> {
public:
- CFBundle(const char *Path = nullptr) : CFReleaser<CFBundleRef>() {
- if (Path && Path[0])
- SetFromPath(Path);
- }
+ CFBundle(StringRef Path) : CFReleaser<CFBundleRef>() { SetFromPath(Path); }
- CFBundle(CFURLRef url)
- : CFReleaser<CFBundleRef>(url ? ::CFBundleCreate(nullptr, url)
+ CFBundle(CFURLRef Url)
+ : CFReleaser<CFBundleRef>(Url ? ::CFBundleCreate(nullptr, Url)
: nullptr) {}
/// Return the bundle identifier.
@@ -109,67 +107,49 @@ public:
}
private:
- /// Update this instance with a new bundle created from the given path.
- bool SetFromPath(const char *Path);
+ /// Helper to initialize this instance with a new bundle created from the
+ /// given path. This function will recursively remove components from the
+ /// path in its search for the nearest Info.plist.
+ void SetFromPath(StringRef Path);
};
-bool CFBundle::SetFromPath(const char *InPath) {
- // Release our old bundle and URL.
+void CFBundle::SetFromPath(StringRef Path) {
+ // Start from an empty/invalid CFBundle.
reset();
- if (InPath && InPath[0]) {
- char ResolvedPath[PATH_MAX];
- const char *Path = ::realpath(InPath, ResolvedPath);
- if (Path == nullptr)
- Path = InPath;
+ if (Path.empty() || !sys::fs::exists(Path))
+ return;
+
+ SmallString<256> RealPath;
+ sys::fs::real_path(Path, RealPath, /*expand_tilde*/ true);
- CFAllocatorRef Allocator = kCFAllocatorDefault;
- // Make our Bundle URL.
+ do {
+ // Create a CFURL from the current path and use it to create a CFBundle.
CFReleaser<CFURLRef> BundleURL(::CFURLCreateFromFileSystemRepresentation(
- Allocator, (const UInt8 *)Path, strlen(Path), false));
- if (BundleURL.get()) {
- CFIndex LastLength = LONG_MAX;
-
- while (BundleURL.get() != nullptr) {
- // Check the Path range and make sure we didn't make it to just "/",
- // ".", or "..".
- CFRange rangeIncludingSeparators;
- CFRange range = ::CFURLGetByteRangeForComponent(
- BundleURL.get(), kCFURLComponentPath, &rangeIncludingSeparators);
- if (range.length > LastLength)
- break;
-
- reset(::CFBundleCreate(Allocator, BundleURL.get()));
- if (get() != nullptr) {
- if (GetIdentifier() != nullptr)
- break;
- reset();
- }
- BundleURL.reset(::CFURLCreateCopyDeletingLastPathComponent(
- Allocator, BundleURL.get()));
-
- LastLength = range.length;
- }
+ kCFAllocatorDefault, (const UInt8 *)RealPath.data(), RealPath.size(),
+ false));
+ reset(::CFBundleCreate(kCFAllocatorDefault, BundleURL.get()));
+
+ // If we have a valid bundle and find its identifier we are done.
+ if (get() != nullptr) {
+ if (GetIdentifier() != nullptr)
+ return;
+ reset();
}
- }
- return get() != nullptr;
+ // Remove the last component of the path and try again until there's
+ // nothing left but the root.
+ sys::path::remove_filename(RealPath);
+ } while (RealPath != sys::path::root_name(RealPath));
}
-
#endif
-/// On Darwin, try and find the original executable's Info.plist information
-/// using CoreFoundation calls by creating a URL for the executable and
-/// chopping off the last Path component. The CFBundle can then get the
-/// identifier and grab any needed information from it directly. Return default
-/// CFBundleInfo on other platforms.
+/// On Darwin, try and find the original executable's Info.plist to extract
+/// information about the bundle. Return default values on other platforms.
CFBundleInfo getBundleInfo(StringRef ExePath) {
CFBundleInfo BundleInfo;
#ifdef __APPLE__
- if (ExePath.empty() || !sys::fs::exists(ExePath))
- return BundleInfo;
-
auto PrintError = [&](CFTypeID TypeID) {
CFString TypeIDCFStr(::CFCopyTypeIDDescription(TypeID));
std::string TypeIDStr;
@@ -178,7 +158,7 @@ CFBundleInfo getBundleInfo(StringRef ExePath) {
<< ", but it should be a string in: " << ExePath << ".\n";
};
- CFBundle Bundle(ExePath.data());
+ CFBundle Bundle(ExePath);
if (CFStringRef BundleID = Bundle.GetIdentifier()) {
CFString::UTF8(BundleID, BundleInfo.IDStr);
if (CFTypeRef TypeRef =
diff --git a/tools/llvm-cov/CodeCoverage.cpp b/tools/llvm-cov/CodeCoverage.cpp
index 00258f2a1b33..c5ea50bff273 100644
--- a/tools/llvm-cov/CodeCoverage.cpp
+++ b/tools/llvm-cov/CodeCoverage.cpp
@@ -353,13 +353,14 @@ std::unique_ptr<CoverageMapping> CodeCoverageTool::load() {
auto Coverage = std::move(CoverageOrErr.get());
unsigned Mismatched = Coverage->getMismatchedCount();
if (Mismatched) {
- warning(utostr(Mismatched) + " functions have mismatched data");
+ warning(Twine(Mismatched) + " functions have mismatched data");
if (ViewOpts.Debug) {
for (const auto &HashMismatch : Coverage->getHashMismatches())
errs() << "hash-mismatch: "
<< "No profile record found for '" << HashMismatch.first << "'"
- << " with hash = 0x" << utohexstr(HashMismatch.second) << "\n";
+ << " with hash = 0x" << Twine::utohexstr(HashMismatch.second)
+ << '\n';
for (const auto &CounterMismatch : Coverage->getCounterMismatches())
errs() << "counter-mismatch: "
diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp
index 79204c6e9533..3a9112423cff 100644
--- a/tools/llvm-objdump/llvm-objdump.cpp
+++ b/tools/llvm-objdump/llvm-objdump.cpp
@@ -1643,7 +1643,7 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
outs() << " <" << TargetName;
uint64_t Disp = Target - TargetAddress;
if (Disp)
- outs() << "+0x" << utohexstr(Disp);
+ outs() << "+0x" << Twine::utohexstr(Disp);
outs() << '>';
}
}
diff --git a/tools/llvm-readobj/COFFDumper.cpp b/tools/llvm-readobj/COFFDumper.cpp
index 8ac9f1a51cc5..0e76e75c085d 100644
--- a/tools/llvm-readobj/COFFDumper.cpp
+++ b/tools/llvm-readobj/COFFDumper.cpp
@@ -81,6 +81,9 @@ public:
void printSymbols() override;
void printDynamicSymbols() override;
void printUnwindInfo() override;
+
+ void printNeededLibraries() override;
+
void printCOFFImports() override;
void printCOFFExports() override;
void printCOFFDirectives() override;
@@ -764,7 +767,7 @@ void COFFDumper::printRVATable(uint64_t TableVA, uint64_t Count,
for (uintptr_t I = TableStart; I < TableEnd; I += EntrySize) {
uint32_t RVA = *reinterpret_cast<const ulittle32_t *>(I);
raw_ostream &OS = W.startLine();
- OS << "0x" << utohexstr(Obj->getImageBase() + RVA);
+ OS << "0x" << W.hex(Obj->getImageBase() + RVA);
if (PrintExtra)
PrintExtra(OS, reinterpret_cast<const uint8_t *>(I));
OS << '\n';
@@ -1522,6 +1525,25 @@ void COFFDumper::printUnwindInfo() {
}
}
+void COFFDumper::printNeededLibraries() {
+ ListScope D(W, "NeededLibraries");
+
+ using LibsTy = std::vector<StringRef>;
+ LibsTy Libs;
+
+ for (const ImportDirectoryEntryRef &DirRef : Obj->import_directories()) {
+ StringRef Name;
+ if (!DirRef.getName(Name))
+ Libs.push_back(Name);
+ }
+
+ std::stable_sort(Libs.begin(), Libs.end());
+
+ for (const auto &L : Libs) {
+ outs() << " " << L << "\n";
+ }
+}
+
void COFFDumper::printImportedSymbols(
iterator_range<imported_symbol_iterator> Range) {
for (const ImportedSymbolRef &I : Range) {
diff --git a/tools/llvm-readobj/ELFDumper.cpp b/tools/llvm-readobj/ELFDumper.cpp
index f2b936904393..5605eaea7555 100644
--- a/tools/llvm-readobj/ELFDumper.cpp
+++ b/tools/llvm-readobj/ELFDumper.cpp
@@ -1900,8 +1900,8 @@ template <> void ELFDumper<ELFType<support::little, false>>::printAttributes() {
ArrayRef<uint8_t> Contents = unwrapOrError(Obj->getSectionContents(&Sec));
if (Contents[0] != ARMBuildAttrs::Format_Version) {
- errs() << "unrecognised FormatVersion: 0x" << utohexstr(Contents[0])
- << '\n';
+ errs() << "unrecognised FormatVersion: 0x"
+ << Twine::utohexstr(Contents[0]) << '\n';
continue;
}
diff --git a/tools/yaml2obj/yaml2obj.cpp b/tools/yaml2obj/yaml2obj.cpp
index 3e2a5ca7ae0f..0f21d7a54708 100644
--- a/tools/yaml2obj/yaml2obj.cpp
+++ b/tools/yaml2obj/yaml2obj.cpp
@@ -65,7 +65,7 @@ static int convertYAML(yaml::Input &YIn, raw_ostream &Out) {
}
} while (YIn.nextDocument());
- error("yaml2obj: Cannot find the " + utostr(DocNum) +
+ error("yaml2obj: Cannot find the " + Twine(DocNum) +
llvm::getOrdinalSuffix(DocNum) + " document");
}