// they can't easily fix them.
llvm::StringSet<> ignoreAutoLinkOptions;
PlatformInfo platformInfo;
- llvm::Optional<PlatformInfo> secondaryPlatformInfo;
+ std::optional<PlatformInfo> secondaryPlatformInfo;
NamespaceKind namespaceKind = NamespaceKind::twolevel;
UndefinedSymbolTreatment undefinedSymbolTreatment =
UndefinedSymbolTreatment::error;
}
static DenseMap<CachedHashStringRef, StringRef> resolvedLibraries;
-static Optional<StringRef> findLibrary(StringRef name) {
+static std::optional<StringRef> findLibrary(StringRef name) {
CachedHashStringRef key(name);
auto entry = resolvedLibraries.find(key);
if (entry != resolvedLibraries.end())
auto doFind = [&] {
if (config->searchDylibsFirst) {
- if (Optional<StringRef> path = findPathCombination(
+ if (std::optional<StringRef> path = findPathCombination(
"lib" + name, config->librarySearchPaths, {".tbd", ".dylib"}))
return path;
return findPathCombination("lib" + name, config->librarySearchPaths,
{".tbd", ".dylib", ".a"});
};
- Optional<StringRef> path = doFind();
+ std::optional<StringRef> path = doFind();
if (path)
resolvedLibraries[key] = *path;
}
static DenseMap<CachedHashStringRef, StringRef> resolvedFrameworks;
-static Optional<StringRef> findFramework(StringRef name) {
+static std::optional<StringRef> findFramework(StringRef name) {
CachedHashStringRef key(name);
auto entry = resolvedFrameworks.find(key);
if (entry != resolvedFrameworks.end())
// Suffix lookup failed, fall through to the no-suffix case.
}
- if (Optional<StringRef> path = resolveDylibPath(symlink.str()))
+ if (std::optional<StringRef> path = resolveDylibPath(symlink.str()))
return resolvedFrameworks[key] = *path;
}
return {};
bool isLazy = false, bool isExplicit = true,
bool isBundleLoader = false,
bool isForceHidden = false) {
- Optional<MemoryBufferRef> buffer = readFile(path);
+ std::optional<MemoryBufferRef> buffer = readFile(path);
if (!buffer)
return nullptr;
MemoryBufferRef mbref = *buffer;
path::filename(path).startswith("libswift");
if ((isCommandLineLoad && config->allLoad) ||
loadType == LoadType::CommandLineForce || isLCLinkerForceLoad) {
- if (Optional<MemoryBufferRef> buffer = readFile(path)) {
+ if (std::optional<MemoryBufferRef> buffer = readFile(path)) {
Error e = Error::success();
for (const object::Archive::Child &c : file->getArchive().children(e)) {
StringRef reason;
// TODO: no need to look for ObjC sections for a given archive member if
// we already found that it contains an ObjC symbol.
- if (Optional<MemoryBufferRef> buffer = readFile(path)) {
+ if (std::optional<MemoryBufferRef> buffer = readFile(path)) {
Error e = Error::success();
for (const object::Archive::Child &c : file->getArchive().children(e)) {
Expected<MemoryBufferRef> mb = c.getMemoryBufferRef();
static void addLibrary(StringRef name, bool isNeeded, bool isWeak,
bool isReexport, bool isHidden, bool isExplicit,
LoadType loadType) {
- if (Optional<StringRef> path = findLibrary(name)) {
+ if (std::optional<StringRef> path = findLibrary(name)) {
if (auto *dylibFile = dyn_cast_or_null<DylibFile>(
addFile(*path, loadType, /*isLazy=*/false, isExplicit,
/*isBundleLoader=*/false, isHidden))) {
static DenseSet<StringRef> loadedObjectFrameworks;
static void addFramework(StringRef name, bool isNeeded, bool isWeak,
bool isReexport, bool isExplicit, LoadType loadType) {
- if (Optional<StringRef> path = findFramework(name)) {
+ if (std::optional<StringRef> path = findFramework(name)) {
if (loadedObjectFrameworks.contains(*path))
return;
}
static void addFileList(StringRef path, bool isLazy) {
- Optional<MemoryBufferRef> buffer = readFile(path);
+ std::optional<MemoryBufferRef> buffer = readFile(path);
if (!buffer)
return;
MemoryBufferRef mbref = *buffer;
static void parseSymbolPatternsFile(const Arg *arg,
SymbolPatterns &symbolPatterns) {
StringRef path = arg->getValue();
- Optional<MemoryBufferRef> buffer = readFile(path);
+ std::optional<MemoryBufferRef> buffer = readFile(path);
if (!buffer) {
error("Could not read symbol file: " + path);
return;
StringRef segName = arg->getValue(0);
StringRef sectName = arg->getValue(1);
StringRef fileName = arg->getValue(2);
- Optional<MemoryBufferRef> buffer = readFile(fileName);
+ std::optional<MemoryBufferRef> buffer = readFile(fileName);
if (buffer)
inputFiles.insert(make<OpaqueFile>(*buffer, segName, sectName));
}
#define LLD_MACHO_DRIVER_H
#include "lld/Common/LLVM.h"
-#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/BinaryFormat/MachO.h"
#include "llvm/Option/OptTable.h"
#include "llvm/Support/MemoryBuffer.h"
+#include <optional>
#include <set>
#include <type_traits>
std::string createResponseFile(const llvm::opt::InputArgList &args);
// Check for both libfoo.dylib and libfoo.tbd (in that order).
-llvm::Optional<StringRef> resolveDylibPath(llvm::StringRef path);
+std::optional<StringRef> resolveDylibPath(llvm::StringRef path);
DylibFile *loadDylib(llvm::MemoryBufferRef mbref, DylibFile *umbrella = nullptr,
bool isBundleLoader = false,
// Search for all possible combinations of `{root}/{name}.{extension}`.
// If \p extensions are not specified, then just search for `{root}/{name}`.
-llvm::Optional<llvm::StringRef>
+std::optional<llvm::StringRef>
findPathCombination(const llvm::Twine &name,
const std::vector<llvm::StringRef> &roots,
ArrayRef<llvm::StringRef> extensions = {""});
os << "-o " << quote(path::filename(arg->getValue())) << "\n";
break;
case OPT_filelist:
- if (Optional<MemoryBufferRef> buffer = readFile(arg->getValue()))
+ if (std::optional<MemoryBufferRef> buffer = readFile(arg->getValue()))
for (StringRef path : args::getLines(*buffer))
os << quote(rewriteInputPath(path)) << "\n";
break;
depTracker->logFileNotFound(path);
}
-Optional<StringRef> macho::resolveDylibPath(StringRef dylibPath) {
+std::optional<StringRef> macho::resolveDylibPath(StringRef dylibPath) {
// TODO: if a tbd and dylib are both present, we should check to make sure
// they are consistent.
SmallString<261> tbdPath = dylibPath;
void macho::resetLoadedDylibs() { loadedDylibs.clear(); }
-Optional<StringRef>
+std::optional<StringRef>
macho::findPathCombination(const Twine &name,
const std::vector<StringRef> &roots,
ArrayRef<StringRef> extensions) {
if (!path::is_absolute(path, path::Style::posix) || path.endswith(".o"))
return path;
- if (Optional<StringRef> rerootedPath =
+ if (std::optional<StringRef> rerootedPath =
findPathCombination(path, config->systemLibraryRoots))
return *rerootedPath;
* 1. Length of the entry (4 or 12 bytes)
* 2. CIE offset (4 bytes pcrel offset that points backwards to this FDE's CIE)
* 3. Function address (pointer-sized pcrel offset)
- * 4. (Optional) Augmentation data length
- * 5. (Optional) LSDA address (pointer-sized pcrel offset)
+ * 4. (std::optional) Augmentation data length
+ * 5. (std::optional) LSDA address (pointer-sized pcrel offset)
* 6. DWARF instructions (ignored by LLD)
*/
namespace lld::macho {
#include "lld/Common/ErrorHandler.h"
#include "lld/Common/Memory.h"
-#include "llvm/ADT/Optional.h"
#include "llvm/BinaryFormat/MachO.h"
#include "llvm/Support/LEB128.h"
#include <optional>
// would require altering many callers to track the state.
DenseMap<CachedHashStringRef, MemoryBufferRef> macho::cachedReads;
// Open a given file path and return it as a memory-mapped file.
-Optional<MemoryBufferRef> macho::readFile(StringRef path) {
+std::optional<MemoryBufferRef> macho::readFile(StringRef path) {
CachedHashStringRef key(path);
auto entry = cachedReads.find(key);
if (entry != cachedReads.end())
}
// The path can point to either a dylib or a .tbd file.
static DylibFile *loadDylib(StringRef path, DylibFile *umbrella) {
- Optional<MemoryBufferRef> mbref = readFile(path);
+ std::optional<MemoryBufferRef> mbref = readFile(path);
if (!mbref) {
error("could not read dylib file at " + path);
return nullptr;
for (StringRef dir : config->frameworkSearchPaths) {
SmallString<128> candidate = dir;
path::append(candidate, frameworkName);
- if (Optional<StringRef> dylibPath = resolveDylibPath(candidate.str()))
+ if (std::optional<StringRef> dylibPath =
+ resolveDylibPath(candidate.str()))
return loadDylib(*dylibPath, umbrella);
}
- } else if (Optional<StringRef> dylibPath = findPathCombination(
+ } else if (std::optional<StringRef> dylibPath = findPathCombination(
stem, config->librarySearchPaths, {".tbd", ".dylib"}))
return loadDylib(*dylibPath, umbrella);
}
// 2. As absolute path.
if (path::is_absolute(path, path::Style::posix))
for (StringRef root : config->systemLibraryRoots)
- if (Optional<StringRef> dylibPath = resolveDylibPath((root + path).str()))
+ if (std::optional<StringRef> dylibPath =
+ resolveDylibPath((root + path).str()))
return loadDylib(*dylibPath, umbrella);
// 3. As relative path.
path::remove_filename(newPath);
}
path::append(newPath, rpath, path.drop_front(strlen("@rpath/")));
- if (Optional<StringRef> dylibPath = resolveDylibPath(newPath.str()))
+ if (std::optional<StringRef> dylibPath = resolveDylibPath(newPath.str()))
return loadDylib(*dylibPath, umbrella);
}
}
}
}
- if (Optional<StringRef> dylibPath = resolveDylibPath(path))
+ if (std::optional<StringRef> dylibPath = resolveDylibPath(path))
return loadDylib(*dylibPath, umbrella);
return nullptr;
extern llvm::SetVector<InputFile *> inputFiles;
extern llvm::DenseMap<llvm::CachedHashStringRef, MemoryBufferRef> cachedReads;
-llvm::Optional<MemoryBufferRef> readFile(StringRef path);
+std::optional<MemoryBufferRef> readFile(StringRef path);
void extract(InputFile &file, StringRef reason);
// If `originalPath` exists, hardlinks `path` to `originalPath`. If that fails,
// or `originalPath` is not set, saves `buffer` to `path`.
static void saveOrHardlinkBuffer(StringRef buffer, const Twine &path,
- Optional<StringRef> originalPath) {
+ std::optional<StringRef> originalPath) {
if (originalPath) {
auto err = fs::create_hard_link(*originalPath, path);
if (!err)
// not use the cached MemoryBuffer directly to ensure dsymutil does not
// race with the cache pruner.
StringRef objBuf;
- Optional<StringRef> cachePath = llvm::None;
+ std::optional<StringRef> cachePath = llvm::None;
if (files[i]) {
objBuf = files[i]->getBuffer();
cachePath = files[i]->getBufferIdentifier();
#include "lld/Common/ErrorHandler.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/MapVector.h"
-#include "llvm/ADT/Optional.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/TimeProfiler.h"
#include "llvm/Support/raw_ostream.h"
return orderMap;
}
-Optional<size_t> macho::PriorityBuilder::getSymbolPriority(const Defined *sym) {
+std::optional<size_t>
+macho::PriorityBuilder::getSymbolPriority(const Defined *sym) {
if (sym->isAbsolute())
return None;
void macho::PriorityBuilder::parseOrderFile(StringRef path) {
assert(callGraphProfile.empty() &&
"Order file must be parsed before call graph profile is processed");
- Optional<MemoryBufferRef> buffer = readFile(path);
+ std::optional<MemoryBufferRef> buffer = readFile(path);
if (!buffer) {
error("Could not read order file at " + path);
return;
return sectionPriorities;
auto addSym = [&](const Defined *sym) {
- Optional<size_t> symbolPriority = getSymbolPriority(sym);
+ std::optional<size_t> symbolPriority = getSymbolPriority(sym);
if (!symbolPriority)
return;
size_t &priority = sectionPriorities[sym->isec];
llvm::DenseMap<llvm::StringRef, size_t> objectFiles;
};
- llvm::Optional<size_t> getSymbolPriority(const Defined *sym);
+ std::optional<size_t> getSymbolPriority(const Defined *sym);
llvm::DenseMap<llvm::StringRef, SymbolPriorityEntry> priorities;
llvm::MapVector<SectionPair, uint64_t> callGraphProfile;
};