diff options
Diffstat (limited to 'lib/ReaderWriter/MachO/MachOLinkingContext.cpp')
-rw-r--r-- | lib/ReaderWriter/MachO/MachOLinkingContext.cpp | 63 |
1 files changed, 24 insertions, 39 deletions
diff --git a/lib/ReaderWriter/MachO/MachOLinkingContext.cpp b/lib/ReaderWriter/MachO/MachOLinkingContext.cpp index 05375f145d341..db4a96823e74e 100644 --- a/lib/ReaderWriter/MachO/MachOLinkingContext.cpp +++ b/lib/ReaderWriter/MachO/MachOLinkingContext.cpp @@ -22,7 +22,7 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/Triple.h" -#include "llvm/Config/config.h" +#include "llvm/Demangle/Demangle.h" #include "llvm/Support/Debug.h" #include "llvm/Support/Errc.h" #include "llvm/Support/Host.h" @@ -30,10 +30,6 @@ #include "llvm/Support/Path.h" #include <algorithm> -#if defined(HAVE_CXXABI_H) -#include <cxxabi.h> -#endif - using lld::mach_o::ArchHandler; using lld::mach_o::MachOFile; using lld::mach_o::MachODylibFile; @@ -734,7 +730,7 @@ uint32_t MachOLinkingContext::dylibCurrentVersion(StringRef installName) const { if (pos != _pathToDylibMap.end()) return pos->second->currentVersion(); else - return 0x1000; // 1.0 + return 0x10000; // 1.0 } uint32_t MachOLinkingContext::dylibCompatVersion(StringRef installName) const { @@ -742,7 +738,7 @@ uint32_t MachOLinkingContext::dylibCompatVersion(StringRef installName) const { if (pos != _pathToDylibMap.end()) return pos->second->compatVersion(); else - return 0x1000; // 1.0 + return 0x10000; // 1.0 } void MachOLinkingContext::createImplicitFiles( @@ -772,7 +768,10 @@ void MachOLinkingContext::createImplicitFiles( void MachOLinkingContext::registerDylib(MachODylibFile *dylib, bool upward) const { std::lock_guard<std::mutex> lock(_dylibsMutex); - _allDylibs.insert(dylib); + + if (std::find(_allDylibs.begin(), + _allDylibs.end(), dylib) == _allDylibs.end()) + _allDylibs.push_back(dylib); _pathToDylibMap[dylib->installName()] = dylib; // If path is different than install name, register path too. if (!dylib->path().equals(dylib->installName())) @@ -873,24 +872,32 @@ std::string MachOLinkingContext::demangle(StringRef symbolName) const { if (!symbolName.startswith("__Z")) return symbolName; -#if defined(HAVE_CXXABI_H) SmallString<256> symBuff; StringRef nullTermSym = Twine(symbolName).toNullTerminatedStringRef(symBuff); // Mach-O has extra leading underscore that needs to be removed. const char *cstr = nullTermSym.data() + 1; int status; - char *demangled = abi::__cxa_demangle(cstr, nullptr, nullptr, &status); + char *demangled = llvm::itaniumDemangle(cstr, nullptr, nullptr, &status); if (demangled) { std::string result(demangled); // __cxa_demangle() always uses a malloc'ed buffer to return the result. free(demangled); return result; } -#endif return symbolName; } +static void addDependencyInfoHelper(llvm::raw_fd_ostream *DepInfo, + char Opcode, StringRef Path) { + if (!DepInfo) + return; + + *DepInfo << Opcode; + *DepInfo << Path; + *DepInfo << '\0'; +} + std::error_code MachOLinkingContext::createDependencyFile(StringRef path) { std::error_code ec; _dependencyInfo = std::unique_ptr<llvm::raw_fd_ostream>(new @@ -900,42 +907,20 @@ std::error_code MachOLinkingContext::createDependencyFile(StringRef path) { return ec; } - char linkerVersionOpcode = 0x00; - *_dependencyInfo << linkerVersionOpcode; - *_dependencyInfo << "lld"; // FIXME - *_dependencyInfo << '\0'; - + addDependencyInfoHelper(_dependencyInfo.get(), 0x00, "lld" /*FIXME*/); return std::error_code(); } void MachOLinkingContext::addInputFileDependency(StringRef path) const { - if (!_dependencyInfo) - return; - - char inputFileOpcode = 0x10; - *_dependencyInfo << inputFileOpcode; - *_dependencyInfo << path; - *_dependencyInfo << '\0'; + addDependencyInfoHelper(_dependencyInfo.get(), 0x10, path); } void MachOLinkingContext::addInputFileNotFound(StringRef path) const { - if (!_dependencyInfo) - return; - - char inputFileOpcode = 0x11; - *_dependencyInfo << inputFileOpcode; - *_dependencyInfo << path; - *_dependencyInfo << '\0'; + addDependencyInfoHelper(_dependencyInfo.get(), 0x11, path); } void MachOLinkingContext::addOutputFileDependency(StringRef path) const { - if (!_dependencyInfo) - return; - - char outputFileOpcode = 0x40; - *_dependencyInfo << outputFileOpcode; - *_dependencyInfo << path; - *_dependencyInfo << '\0'; + addDependencyInfoHelper(_dependencyInfo.get(), 0x40, path); } void MachOLinkingContext::appendOrderedSymbol(StringRef symbol, @@ -1044,7 +1029,7 @@ void MachOLinkingContext::finalizeInputFiles() { llvm::Error MachOLinkingContext::handleLoadedFile(File &file) { auto *machoFile = dyn_cast<MachOFile>(&file); if (!machoFile) - return llvm::Error(); + return llvm::Error::success(); // Check that the arch of the context matches that of the file. // Also set the arch of the context if it didn't have one. @@ -1111,7 +1096,7 @@ llvm::Error MachOLinkingContext::handleLoadedFile(File &file) { return llvm::make_error<GenericError>("different swift versions"); } - return llvm::Error(); + return llvm::Error::success(); } } // end namespace lld |