2015-08-14 22:12:54 +08:00
|
|
|
//===- Config.h -------------------------------------------------*- C++ -*-===//
|
2015-05-29 03:09:30 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// 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
|
2015-05-29 03:09:30 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLD_COFF_CONFIG_H
|
|
|
|
#define LLD_COFF_CONFIG_H
|
|
|
|
|
2018-01-27 08:34:46 +08:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
2015-05-29 03:09:30 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2015-05-30 00:06:00 +08:00
|
|
|
#include "llvm/Object/COFF.h"
|
2017-09-08 08:50:50 +08:00
|
|
|
#include "llvm/Support/CachePruning.h"
|
2015-05-29 03:09:30 +08:00
|
|
|
#include <cstdint>
|
2015-06-05 03:21:24 +08:00
|
|
|
#include <map>
|
2015-05-29 03:09:30 +08:00
|
|
|
#include <set>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace lld {
|
|
|
|
namespace coff {
|
|
|
|
|
2015-07-09 02:14:51 +08:00
|
|
|
using llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN;
|
2015-05-30 00:34:31 +08:00
|
|
|
using llvm::COFF::WindowsSubsystem;
|
2015-06-01 03:17:14 +08:00
|
|
|
using llvm::StringRef;
|
2015-07-25 07:51:14 +08:00
|
|
|
class DefinedAbsolute;
|
|
|
|
class DefinedRelative;
|
2016-01-09 09:22:00 +08:00
|
|
|
class StringChunk;
|
2017-11-04 05:21:47 +08:00
|
|
|
class Symbol;
|
2019-03-30 03:58:58 +08:00
|
|
|
class InputFile;
|
2015-05-30 00:34:31 +08:00
|
|
|
|
2015-07-25 08:20:06 +08:00
|
|
|
// Short aliases.
|
|
|
|
static const auto AMD64 = llvm::COFF::IMAGE_FILE_MACHINE_AMD64;
|
2017-07-02 04:29:27 +08:00
|
|
|
static const auto ARM64 = llvm::COFF::IMAGE_FILE_MACHINE_ARM64;
|
2015-07-25 10:25:14 +08:00
|
|
|
static const auto ARMNT = llvm::COFF::IMAGE_FILE_MACHINE_ARMNT;
|
2015-07-25 08:20:06 +08:00
|
|
|
static const auto I386 = llvm::COFF::IMAGE_FILE_MACHINE_I386;
|
|
|
|
|
2015-06-17 08:16:33 +08:00
|
|
|
// Represents an /export option.
|
|
|
|
struct Export {
|
2015-07-29 06:34:24 +08:00
|
|
|
StringRef name; // N in /export:N or /export:E=N
|
|
|
|
StringRef extName; // E in /export:E=N
|
2017-11-04 05:21:47 +08:00
|
|
|
Symbol *sym = nullptr;
|
2015-06-17 08:16:33 +08:00
|
|
|
uint16_t ordinal = 0;
|
|
|
|
bool noname = false;
|
|
|
|
bool data = false;
|
|
|
|
bool isPrivate = false;
|
2017-04-22 02:05:46 +08:00
|
|
|
bool constant = false;
|
2015-07-04 07:23:29 +08:00
|
|
|
|
2016-01-09 09:22:00 +08:00
|
|
|
// If an export is a form of /export:foo=dllname.bar, that means
|
|
|
|
// that foo should be exported as an alias to bar in the DLL.
|
2019-07-16 16:26:38 +08:00
|
|
|
// forwardTo is set to "dllname.bar" part. Usually empty.
|
2016-01-09 09:22:00 +08:00
|
|
|
StringRef forwardTo;
|
|
|
|
StringChunk *forwardChunk = nullptr;
|
|
|
|
|
COFF: Improve dllexported name mangling compatibility.
The rules for dllexported symbols are overly complicated due to
x86 name decoration, fuzzy symbol resolution, and the fact that
one symbol can be resolved by so many different names. The rules
are probably intended to be "intuitive", so that users don't have
to understand the name mangling schemes, but it seems that it can
lead to unintended symbol exports.
To make it clear what I'm trying to do with this patch, let me
write how the export rules are subtle and complicated.
- x86 name decoration: If machine type is i386 and export name
is given by a command line option, like /export:foo, the
real symbol name the linker has to search for is _foo because
all symbols are decorated with "_" prefixes. This doesn't happen
on non-x86 machines. This automatic name decoration happens only
when the name is not C++ mangled.
However, the symbol name exported from DLLs are ones without "_"
on all platforms.
Moreover, if the option is given via .drectve section, no
symbol decoration is done (the reason being that the .drectve
section is created by a compiler and the compiler should always
know the exact name of the symbol, I guess).
- Fuzzy symbol resolution: In addition to x86 name decoration,
the linker has to look for cdecl or C++ mangled symbols
for a given /export. For example, it searches for not only
_foo but also _foo@<number> or ??foo@... for /export:foo.
Previous implementation didn't get it right. I'm trying to make
it as compatible with MSVC linker as possible with this patch
however the rules are. The new code looks a bit messy to me, but
I don't think it can be simpler due to the ad-hoc-ness of the rules.
llvm-svn: 246424
2015-08-31 16:43:21 +08:00
|
|
|
// True if this /export option was in .drectves section.
|
|
|
|
bool directives = false;
|
|
|
|
StringRef symbolName;
|
|
|
|
StringRef exportName; // Name in DLL
|
2019-07-11 13:40:30 +08:00
|
|
|
|
2015-07-04 07:23:29 +08:00
|
|
|
bool operator==(const Export &e) {
|
|
|
|
return (name == e.name && extName == e.extName &&
|
|
|
|
ordinal == e.ordinal && noname == e.noname &&
|
|
|
|
data == e.data && isPrivate == e.isPrivate);
|
|
|
|
}
|
2015-06-17 08:16:33 +08:00
|
|
|
};
|
|
|
|
|
2016-08-09 06:02:44 +08:00
|
|
|
enum class DebugType {
|
|
|
|
None = 0x0,
|
|
|
|
CV = 0x1, /// CodeView
|
|
|
|
PData = 0x2, /// Procedure Data
|
|
|
|
Fixup = 0x4, /// Relocation Table
|
|
|
|
};
|
|
|
|
|
2018-02-14 04:32:53 +08:00
|
|
|
enum class GuardCFLevel {
|
|
|
|
Off,
|
|
|
|
NoLongJmp, // Emit gfids but no longjmp tables
|
|
|
|
Full, // Enable all protections.
|
|
|
|
};
|
|
|
|
|
2015-06-17 08:16:33 +08:00
|
|
|
// Global configuration.
|
|
|
|
struct Configuration {
|
2015-06-18 08:12:42 +08:00
|
|
|
enum ManifestKind { SideBySide, Embed, No };
|
2017-07-02 04:29:27 +08:00
|
|
|
bool is64() { return machine == AMD64 || machine == ARM64; }
|
2019-07-11 13:40:30 +08:00
|
|
|
|
2015-07-26 05:54:50 +08:00
|
|
|
llvm::COFF::MachineTypes machine = IMAGE_FILE_MACHINE_UNKNOWN;
|
2018-10-12 01:45:58 +08:00
|
|
|
size_t wordsize;
|
2015-05-29 03:09:30 +08:00
|
|
|
bool verbose = false;
|
2015-05-31 11:55:46 +08:00
|
|
|
WindowsSubsystem subsystem = llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN;
|
2017-11-04 05:21:47 +08:00
|
|
|
Symbol *entry = nullptr;
|
2015-06-29 03:56:30 +08:00
|
|
|
bool noEntry = false;
|
2015-06-07 08:20:32 +08:00
|
|
|
std::string outputFile;
|
2017-07-19 10:01:27 +08:00
|
|
|
std::string importName;
|
2019-03-12 07:02:18 +08:00
|
|
|
bool demangle = true;
|
2015-06-07 11:17:42 +08:00
|
|
|
bool doGC = true;
|
2015-09-17 00:41:38 +08:00
|
|
|
bool doICF = true;
|
2018-05-12 06:21:36 +08:00
|
|
|
bool tailMerge;
|
2015-06-15 09:23:58 +08:00
|
|
|
bool relocatable = true;
|
2018-09-14 06:05:10 +08:00
|
|
|
bool forceMultiple = false;
|
2019-05-03 05:21:55 +08:00
|
|
|
bool forceMultipleRes = false;
|
2018-09-14 06:05:10 +08:00
|
|
|
bool forceUnresolved = false;
|
2015-07-05 07:37:32 +08:00
|
|
|
bool debug = false;
|
2017-11-21 09:14:14 +08:00
|
|
|
bool debugDwarf = false;
|
2017-12-15 02:07:04 +08:00
|
|
|
bool debugGHashes = false;
|
2018-06-29 14:08:25 +08:00
|
|
|
bool debugSymtab = false;
|
2019-11-13 12:53:15 +08:00
|
|
|
bool driver = false;
|
|
|
|
bool driverUponly = false;
|
|
|
|
bool driverWdm = false;
|
2018-01-18 03:16:26 +08:00
|
|
|
bool showTiming = false;
|
2019-03-15 02:45:08 +08:00
|
|
|
bool showSummary = false;
|
2016-08-09 06:02:44 +08:00
|
|
|
unsigned debugTypes = static_cast<unsigned>(DebugType::None);
|
2018-03-24 03:57:25 +08:00
|
|
|
std::vector<std::string> natvisFiles;
|
2018-04-18 07:28:38 +08:00
|
|
|
llvm::SmallString<128> pdbAltPath;
|
2017-03-22 08:57:14 +08:00
|
|
|
llvm::SmallString<128> pdbPath;
|
2018-07-19 12:56:22 +08:00
|
|
|
llvm::SmallString<128> pdbSourcePath;
|
2017-07-11 05:01:37 +08:00
|
|
|
std::vector<llvm::StringRef> argv;
|
2015-06-04 10:12:16 +08:00
|
|
|
|
|
|
|
// Symbols in this set are considered as live by the garbage collector.
|
2019-07-12 14:12:27 +08:00
|
|
|
std::vector<Symbol *> gcroot;
|
2015-05-30 00:21:11 +08:00
|
|
|
|
2019-06-26 23:40:17 +08:00
|
|
|
std::set<std::string> noDefaultLibs;
|
2015-06-01 03:17:14 +08:00
|
|
|
bool noDefaultLibAll = false;
|
|
|
|
|
2015-06-17 08:16:33 +08:00
|
|
|
// True if we are creating a DLL.
|
|
|
|
bool dll = false;
|
2015-06-19 04:27:09 +08:00
|
|
|
StringRef implib;
|
2015-06-17 08:16:33 +08:00
|
|
|
std::vector<Export> exports;
|
2019-08-20 17:53:06 +08:00
|
|
|
bool hadExplicitExports;
|
2015-07-03 09:40:14 +08:00
|
|
|
std::set<std::string> delayLoads;
|
2015-09-02 15:27:31 +08:00
|
|
|
std::map<std::string, int> dllOrder;
|
2017-11-04 05:21:47 +08:00
|
|
|
Symbol *delayLoadHelper = nullptr;
|
2015-06-17 08:16:33 +08:00
|
|
|
|
2017-02-09 02:36:41 +08:00
|
|
|
bool saveTemps = false;
|
|
|
|
|
2018-02-06 09:58:26 +08:00
|
|
|
// /guard:cf
|
2018-02-14 04:32:53 +08:00
|
|
|
GuardCFLevel guardCF = GuardCFLevel::Off;
|
2018-02-06 09:58:26 +08:00
|
|
|
|
2015-07-25 07:51:14 +08:00
|
|
|
// Used for SafeSEH.
|
[COFF] Implement /safeseh:no and check @feat.00 flags by default
Summary:
Fixes PR41828. Before this, LLD always emitted SafeSEH chunks and
defined __safe_se_handler_table & size. Now, /safeseh:no leaves those
undefined.
Additionally, we were checking for the safeseh @feat.00 flag in two
places: once to emit errors, and once during safeseh table construction.
The error was set up to be off by default, but safeseh is supposed to be
on by default. I combined the two checks, so now LLD emits an error if
an input object lacks @feat.00 and safeseh is enabled. This caused the
majority of 32-bit LLD tests to fail, since many test input object files
lack @feat.00 symbols. I explicitly added -safeseh:no to those tests to
preserve behavior.
Finally, LLD no longer sets IMAGE_DLL_CHARACTERISTICS_NO_SEH if any
input file wasn't compiled for safeseh.
Reviewers: mstorsjo, ruiu, thakis
Reviewed By: ruiu, thakis
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D63570
llvm-svn: 366238
2019-07-17 02:17:33 +08:00
|
|
|
bool safeSEH = false;
|
2017-11-04 05:21:47 +08:00
|
|
|
Symbol *sehTable = nullptr;
|
|
|
|
Symbol *sehCount = nullptr;
|
2015-07-25 07:51:14 +08:00
|
|
|
|
2015-08-14 12:47:07 +08:00
|
|
|
// Used for /opt:lldlto=N
|
2018-05-23 04:20:25 +08:00
|
|
|
unsigned ltoo = 2;
|
2015-08-14 12:47:07 +08:00
|
|
|
|
2015-08-29 06:16:09 +08:00
|
|
|
// Used for /opt:lldltojobs=N
|
2018-05-23 04:20:25 +08:00
|
|
|
unsigned thinLTOJobs = 0;
|
2017-02-03 07:58:14 +08:00
|
|
|
// Used for /opt:lldltopartitions=N
|
|
|
|
unsigned ltoPartitions = 1;
|
2015-08-29 06:16:09 +08:00
|
|
|
|
2017-09-08 08:50:50 +08:00
|
|
|
// Used for /opt:lldltocache=path
|
|
|
|
StringRef ltoCache;
|
|
|
|
// Used for /opt:lldltocachepolicy=policy
|
|
|
|
llvm::CachePruningPolicy ltoCachePolicy;
|
|
|
|
|
2015-07-05 07:37:32 +08:00
|
|
|
// Used for /merge:from=to (e.g. /merge:.rdata=.text)
|
|
|
|
std::map<StringRef, StringRef> merge;
|
|
|
|
|
2016-06-20 11:39:39 +08:00
|
|
|
// Used for /section=.name,{DEKPRSW} to set section attributes.
|
|
|
|
std::map<StringRef, uint32_t> section;
|
|
|
|
|
2015-06-18 08:12:42 +08:00
|
|
|
// Options for manifest files.
|
2017-07-26 02:08:03 +08:00
|
|
|
ManifestKind manifest = No;
|
2015-06-18 08:12:42 +08:00
|
|
|
int manifestID = 1;
|
|
|
|
StringRef manifestDependency;
|
|
|
|
bool manifestUAC = true;
|
2016-04-19 09:21:58 +08:00
|
|
|
std::vector<std::string> manifestInput;
|
2015-06-18 08:12:42 +08:00
|
|
|
StringRef manifestLevel = "'asInvoker'";
|
|
|
|
StringRef manifestUIAccess = "'false'";
|
|
|
|
StringRef manifestFile;
|
|
|
|
|
2017-08-15 03:07:27 +08:00
|
|
|
// Used for /aligncomm.
|
|
|
|
std::map<std::string, int> alignComm;
|
|
|
|
|
2015-06-19 03:09:30 +08:00
|
|
|
// Used for /failifmismatch.
|
2019-03-30 03:58:58 +08:00
|
|
|
std::map<StringRef, std::pair<StringRef, InputFile *>> mustMatch;
|
2015-06-05 03:21:24 +08:00
|
|
|
|
2015-06-19 03:09:30 +08:00
|
|
|
// Used for /alternatename.
|
2015-06-19 07:04:26 +08:00
|
|
|
std::map<StringRef, StringRef> alternateNames;
|
2015-06-19 03:09:30 +08:00
|
|
|
|
2018-01-27 08:34:46 +08:00
|
|
|
// Used for /order.
|
|
|
|
llvm::StringMap<int> order;
|
|
|
|
|
2017-01-14 11:14:46 +08:00
|
|
|
// Used for /lldmap.
|
2020-03-24 05:06:48 +08:00
|
|
|
std::string lldmapFile;
|
|
|
|
|
|
|
|
// Used for /map.
|
2017-01-14 11:14:46 +08:00
|
|
|
std::string mapFile;
|
2019-07-11 13:40:30 +08:00
|
|
|
|
[lld-link] implement -thinlto-index-only
Summary:
This implements -thinlto-index-only, -thinlto-index-only:,
and -thinlto-emit-imports-files options in lld-link. They are
analogous to their counterparts in ld.lld: -thinlto-index-only
causes us to perform ThinLTO's thin link and write index files,
but not perform code generation. -thinlto-index-only: does the
same, but also writes a text file listing the native object
files expected to be generated. -thinlto-emit-imports-files
creates a text file next to each index file, listing the files
to import from.
Reviewers: ruiu, tejohnson, pcc, rnk
Subscribers: mehdi_amini, steven_wu, dexonsmith, arphaman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D64461
llvm-svn: 365800
2019-07-12 02:03:14 +08:00
|
|
|
// Used for /thinlto-index-only:
|
|
|
|
llvm::StringRef thinLTOIndexOnlyArg;
|
|
|
|
|
2019-07-12 02:48:58 +08:00
|
|
|
// Used for /thinlto-object-prefix-replace:
|
|
|
|
std::pair<llvm::StringRef, llvm::StringRef> thinLTOPrefixReplace;
|
|
|
|
|
|
|
|
// Used for /thinlto-object-suffix-replace:
|
|
|
|
std::pair<llvm::StringRef, llvm::StringRef> thinLTOObjectSuffixReplace;
|
|
|
|
|
2019-08-22 02:24:59 +08:00
|
|
|
// Used for /lto-obj-path:
|
|
|
|
llvm::StringRef ltoObjPath;
|
|
|
|
|
2019-08-07 18:16:21 +08:00
|
|
|
uint64_t align = 4096;
|
2015-07-26 05:42:33 +08:00
|
|
|
uint64_t imageBase = -1;
|
2019-05-24 20:42:36 +08:00
|
|
|
uint64_t fileAlign = 512;
|
2015-05-30 00:21:11 +08:00
|
|
|
uint64_t stackReserve = 1024 * 1024;
|
|
|
|
uint64_t stackCommit = 4096;
|
2015-05-30 00:23:40 +08:00
|
|
|
uint64_t heapReserve = 1024 * 1024;
|
|
|
|
uint64_t heapCommit = 4096;
|
2015-05-30 00:28:29 +08:00
|
|
|
uint32_t majorImageVersion = 0;
|
|
|
|
uint32_t minorImageVersion = 0;
|
2015-05-30 00:34:31 +08:00
|
|
|
uint32_t majorOSVersion = 6;
|
|
|
|
uint32_t minorOSVersion = 0;
|
2018-05-17 23:11:01 +08:00
|
|
|
uint32_t timestamp = 0;
|
2019-02-23 09:46:18 +08:00
|
|
|
uint32_t functionPadMin = 0;
|
2015-06-17 07:13:00 +08:00
|
|
|
bool dynamicBase = true;
|
2017-09-16 06:49:13 +08:00
|
|
|
bool allowBind = true;
|
2020-03-13 18:41:18 +08:00
|
|
|
bool cetCompat = false;
|
2015-06-17 07:13:00 +08:00
|
|
|
bool nxCompat = true;
|
|
|
|
bool allowIsolation = true;
|
|
|
|
bool terminalServerAware = true;
|
2015-07-28 11:12:00 +08:00
|
|
|
bool largeAddressAware = false;
|
2015-07-28 11:15:57 +08:00
|
|
|
bool highEntropyVA = false;
|
2017-04-07 07:07:53 +08:00
|
|
|
bool appContainer = false;
|
2017-09-14 03:29:39 +08:00
|
|
|
bool mingw = false;
|
2018-03-09 20:41:04 +08:00
|
|
|
bool warnMissingOrderSymbol = true;
|
2017-12-28 15:02:13 +08:00
|
|
|
bool warnLocallyDefinedImported = true;
|
2019-01-12 03:10:01 +08:00
|
|
|
bool warnDebugInfoUnusable = true;
|
2019-10-30 06:57:40 +08:00
|
|
|
bool warnLongSectionNames = true;
|
2018-02-01 07:44:00 +08:00
|
|
|
bool incremental = true;
|
2018-05-31 21:43:02 +08:00
|
|
|
bool integrityCheck = false;
|
2018-03-15 04:17:16 +08:00
|
|
|
bool killAt = false;
|
2018-05-17 23:11:01 +08:00
|
|
|
bool repro = false;
|
2019-04-25 22:02:26 +08:00
|
|
|
bool swaprunCD = false;
|
|
|
|
bool swaprunNet = false;
|
[lld-link] implement -thinlto-index-only
Summary:
This implements -thinlto-index-only, -thinlto-index-only:,
and -thinlto-emit-imports-files options in lld-link. They are
analogous to their counterparts in ld.lld: -thinlto-index-only
causes us to perform ThinLTO's thin link and write index files,
but not perform code generation. -thinlto-index-only: does the
same, but also writes a text file listing the native object
files expected to be generated. -thinlto-emit-imports-files
creates a text file next to each index file, listing the files
to import from.
Reviewers: ruiu, tejohnson, pcc, rnk
Subscribers: mehdi_amini, steven_wu, dexonsmith, arphaman, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D64461
llvm-svn: 365800
2019-07-12 02:03:14 +08:00
|
|
|
bool thinLTOEmitImportsFiles;
|
|
|
|
bool thinLTOIndexOnly;
|
2015-05-29 03:09:30 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
extern Configuration *config;
|
|
|
|
|
|
|
|
} // namespace coff
|
|
|
|
} // namespace lld
|
|
|
|
|
|
|
|
#endif
|