2020-04-03 02:54:05 +08:00
|
|
|
//===- Config.h -------------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLD_MACHO_CONFIG_H
|
|
|
|
#define LLD_MACHO_CONFIG_H
|
|
|
|
|
2021-03-04 04:15:09 +08:00
|
|
|
#include "llvm/ADT/CachedHashString.h"
|
2020-05-06 07:37:34 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2021-03-04 04:15:09 +08:00
|
|
|
#include "llvm/ADT/DenseSet.h"
|
2020-04-03 02:54:05 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2020-04-29 07:58:22 +08:00
|
|
|
#include "llvm/BinaryFormat/MachO.h"
|
2021-03-04 04:15:09 +08:00
|
|
|
#include "llvm/Support/GlobPattern.h"
|
2020-08-11 09:47:16 +08:00
|
|
|
#include "llvm/Support/VersionTuple.h"
|
2021-04-06 00:59:50 +08:00
|
|
|
#include "llvm/TextAPI/Architecture.h"
|
|
|
|
#include "llvm/TextAPI/Platform.h"
|
|
|
|
#include "llvm/TextAPI/Target.h"
|
2020-04-03 02:54:05 +08:00
|
|
|
|
2020-04-22 04:37:57 +08:00
|
|
|
#include <vector>
|
|
|
|
|
2020-04-03 02:54:05 +08:00
|
|
|
namespace lld {
|
|
|
|
namespace macho {
|
|
|
|
|
|
|
|
class Symbol;
|
2020-05-06 07:37:34 +08:00
|
|
|
struct SymbolPriorityEntry;
|
2020-04-03 02:54:05 +08:00
|
|
|
|
2021-02-27 07:36:49 +08:00
|
|
|
using NamePair = std::pair<llvm::StringRef, llvm::StringRef>;
|
|
|
|
using SectionRenameMap = llvm::DenseMap<NamePair, NamePair>;
|
|
|
|
using SegmentRenameMap = llvm::DenseMap<llvm::StringRef, llvm::StringRef>;
|
|
|
|
|
2020-08-11 09:47:16 +08:00
|
|
|
struct PlatformInfo {
|
2021-04-21 20:41:14 +08:00
|
|
|
llvm::MachO::Target target;
|
2020-08-11 09:47:16 +08:00
|
|
|
llvm::VersionTuple minimum;
|
|
|
|
llvm::VersionTuple sdk;
|
|
|
|
};
|
|
|
|
|
2021-02-18 21:48:07 +08:00
|
|
|
enum class NamespaceKind {
|
|
|
|
twolevel,
|
|
|
|
flat,
|
|
|
|
};
|
|
|
|
|
2020-12-14 11:31:33 +08:00
|
|
|
enum class UndefinedSymbolTreatment {
|
|
|
|
unknown,
|
|
|
|
error,
|
|
|
|
warning,
|
|
|
|
suppress,
|
|
|
|
dynamic_lookup,
|
|
|
|
};
|
|
|
|
|
2021-05-11 23:43:48 +08:00
|
|
|
struct SectionAlign {
|
|
|
|
llvm::StringRef segName;
|
|
|
|
llvm::StringRef sectName;
|
|
|
|
uint32_t align;
|
|
|
|
};
|
|
|
|
|
2021-03-30 02:08:12 +08:00
|
|
|
struct SegmentProtection {
|
|
|
|
llvm::StringRef name;
|
|
|
|
uint32_t maxProt;
|
|
|
|
uint32_t initProt;
|
|
|
|
};
|
|
|
|
|
2021-03-04 04:15:09 +08:00
|
|
|
class SymbolPatterns {
|
2021-03-11 08:45:18 +08:00
|
|
|
public:
|
2021-03-04 04:15:09 +08:00
|
|
|
// GlobPattern can also match literals,
|
|
|
|
// but we prefer the O(1) lookup of DenseSet.
|
|
|
|
llvm::DenseSet<llvm::CachedHashStringRef> literals;
|
|
|
|
std::vector<llvm::GlobPattern> globs;
|
|
|
|
|
|
|
|
bool empty() const { return literals.empty() && globs.empty(); }
|
|
|
|
void clear();
|
|
|
|
void insert(llvm::StringRef symbolName);
|
|
|
|
bool matchLiteral(llvm::StringRef symbolName) const;
|
|
|
|
bool matchGlob(llvm::StringRef symbolName) const;
|
|
|
|
bool match(llvm::StringRef symbolName) const;
|
|
|
|
};
|
|
|
|
|
2020-04-03 02:54:05 +08:00
|
|
|
struct Configuration {
|
2021-05-10 08:05:45 +08:00
|
|
|
Symbol *entry = nullptr;
|
2020-04-24 11:16:49 +08:00
|
|
|
bool hasReexports = false;
|
2020-08-26 11:00:42 +08:00
|
|
|
bool allLoad = false;
|
2020-08-19 05:37:04 +08:00
|
|
|
bool forceLoadObjC = false;
|
2020-09-22 04:21:45 +08:00
|
|
|
bool staticLink = false;
|
2020-12-10 07:08:05 +08:00
|
|
|
bool implicitDylibs = false;
|
2020-09-06 01:55:33 +08:00
|
|
|
bool isPic = false;
|
2020-09-22 02:04:13 +08:00
|
|
|
bool headerPadMaxInstallNames = false;
|
2021-01-13 03:41:56 +08:00
|
|
|
bool ltoNewPassManager = LLVM_ENABLE_NEW_PASS_MANAGER;
|
2021-03-09 23:17:01 +08:00
|
|
|
bool markDeadStrippableDylib = false;
|
2020-12-03 07:57:30 +08:00
|
|
|
bool printEachFile = false;
|
2020-12-03 07:59:00 +08:00
|
|
|
bool printWhyLoad = false;
|
2020-09-20 23:37:20 +08:00
|
|
|
bool searchDylibsFirst = false;
|
2020-10-27 10:18:29 +08:00
|
|
|
bool saveTemps = false;
|
2021-03-05 22:07:58 +08:00
|
|
|
bool adhocCodesign = false;
|
2021-03-23 05:38:52 +08:00
|
|
|
bool emitFunctionStarts = false;
|
2021-04-17 04:46:45 +08:00
|
|
|
bool emitBitcodeBundle = false;
|
2021-04-22 01:35:12 +08:00
|
|
|
bool emitEncryptionInfo = false;
|
2021-03-11 22:04:27 +08:00
|
|
|
bool timeTraceEnabled = false;
|
2021-04-26 07:00:24 +08:00
|
|
|
bool dataConst = false;
|
2020-07-31 05:28:45 +08:00
|
|
|
uint32_t headerPad;
|
2020-12-15 07:24:50 +08:00
|
|
|
uint32_t dylibCompatibilityVersion = 0;
|
|
|
|
uint32_t dylibCurrentVersion = 0;
|
2021-03-25 09:05:26 +08:00
|
|
|
uint32_t timeTraceGranularity = 500;
|
2021-03-11 22:04:27 +08:00
|
|
|
std::string progName;
|
2020-04-29 07:58:22 +08:00
|
|
|
llvm::StringRef installName;
|
2021-03-18 22:38:30 +08:00
|
|
|
llvm::StringRef mapFile;
|
2020-04-29 07:58:22 +08:00
|
|
|
llvm::StringRef outputFile;
|
2020-12-03 12:34:17 +08:00
|
|
|
llvm::StringRef ltoObjPath;
|
2021-04-09 00:14:47 +08:00
|
|
|
llvm::StringRef thinLTOJobs;
|
clang+lld: Improve clang+ld.darwinnew.lld interaction, pass -demangle
This patch:
- adds an ld64.lld.darwinnew symlink for lld, to go with f2710d4b576,
so that `clang -fuse-ld=lld.darwinnew` can be used to test new
Mach-O lld while it's in bring-up. (The expectation is that we'll
remove this again once new Mach-O lld is the defauld and only Mach-O
lld.)
- lets the clang driver know if the linker is lld (currently
only triggered if `-fuse-ld=lld` or `-fuse-ld=lld.darwinnew` is
passed). Currently only used for the next point, but could be used
to implement other features that need close coordination between
compiler and linker, e.g. having a diag for calling `clang++` instead
of `clang` when link errors are caused by a missing C++ stdlib.
- lets the clang driver pass `-demangle` to Mach-O lld (both old and
new), in addition to ld64
- implements -demangle for new Mach-O lld
- changes demangleItanium() to accept _Z, __Z, ___Z, ____Z prefixes
(and updates one test added in D68014). Mach-O has an extra
underscore for symbols, and the three (or, on Mach-O, four)
underscores are used for block names.
Differential Revision: https://reviews.llvm.org/D91884
2020-11-21 02:57:44 +08:00
|
|
|
bool demangle = false;
|
2021-03-05 03:36:47 +08:00
|
|
|
PlatformInfo platformInfo;
|
2021-02-18 21:48:07 +08:00
|
|
|
NamespaceKind namespaceKind = NamespaceKind::twolevel;
|
2020-12-14 11:31:33 +08:00
|
|
|
UndefinedSymbolTreatment undefinedSymbolTreatment =
|
|
|
|
UndefinedSymbolTreatment::error;
|
2020-04-24 11:16:49 +08:00
|
|
|
llvm::MachO::HeaderFileType outputType;
|
2020-08-14 04:48:47 +08:00
|
|
|
std::vector<llvm::StringRef> systemLibraryRoots;
|
2020-06-18 10:59:27 +08:00
|
|
|
std::vector<llvm::StringRef> librarySearchPaths;
|
|
|
|
std::vector<llvm::StringRef> frameworkSearchPaths;
|
2020-08-13 10:50:28 +08:00
|
|
|
std::vector<llvm::StringRef> runtimePaths;
|
2021-04-09 02:12:20 +08:00
|
|
|
std::vector<std::string> astPaths;
|
2021-02-09 21:18:23 +08:00
|
|
|
std::vector<Symbol *> explicitUndefineds;
|
2021-05-11 23:43:48 +08:00
|
|
|
// There are typically few custom sectionAlignments or segmentProtections,
|
|
|
|
// so use a vector instead of a map.
|
|
|
|
std::vector<SectionAlign> sectionAlignments;
|
2021-03-30 02:08:12 +08:00
|
|
|
std::vector<SegmentProtection> segmentProtections;
|
2021-03-04 04:15:09 +08:00
|
|
|
|
2020-05-06 07:37:34 +08:00
|
|
|
llvm::DenseMap<llvm::StringRef, SymbolPriorityEntry> priorities;
|
2021-02-27 07:36:49 +08:00
|
|
|
SectionRenameMap sectionRenameMap;
|
|
|
|
SegmentRenameMap segmentRenameMap;
|
2021-03-04 04:15:09 +08:00
|
|
|
|
|
|
|
SymbolPatterns exportedSymbols;
|
|
|
|
SymbolPatterns unexportedSymbols;
|
2021-04-22 03:43:38 +08:00
|
|
|
|
|
|
|
llvm::MachO::Architecture arch() const { return platformInfo.target.Arch; }
|
|
|
|
|
|
|
|
llvm::MachO::PlatformKind platform() const {
|
|
|
|
return platformInfo.target.Platform;
|
|
|
|
}
|
2020-05-06 07:37:34 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// The symbol with the highest priority should be ordered first in the output
|
|
|
|
// section (modulo input section contiguity constraints). Using priority
|
|
|
|
// (highest first) instead of order (lowest first) has the convenient property
|
|
|
|
// that the default-constructed zero priority -- for symbols/sections without a
|
|
|
|
// user-defined order -- naturally ends up putting them at the end of the
|
|
|
|
// output.
|
|
|
|
struct SymbolPriorityEntry {
|
|
|
|
// The priority given to a matching symbol, regardless of which object file
|
|
|
|
// it originated from.
|
|
|
|
size_t anyObjectFile = 0;
|
|
|
|
// The priority given to a matching symbol from a particular object file.
|
|
|
|
llvm::DenseMap<llvm::StringRef, size_t> objectFiles;
|
2020-04-03 02:54:05 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
extern Configuration *config;
|
|
|
|
|
|
|
|
} // namespace macho
|
|
|
|
} // namespace lld
|
|
|
|
|
|
|
|
#endif
|