Coverage Report

Created: 2019-05-19 14:56

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/COFF/Driver.h
Line
Count
Source (jump to first uncovered line)
1
//===- Driver.h -------------------------------------------------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#ifndef LLD_COFF_DRIVER_H
10
#define LLD_COFF_DRIVER_H
11
12
#include "Config.h"
13
#include "SymbolTable.h"
14
#include "lld/Common/LLVM.h"
15
#include "lld/Common/Reproduce.h"
16
#include "llvm/ADT/Optional.h"
17
#include "llvm/ADT/StringRef.h"
18
#include "llvm/ADT/StringSet.h"
19
#include "llvm/Object/Archive.h"
20
#include "llvm/Object/COFF.h"
21
#include "llvm/Option/Arg.h"
22
#include "llvm/Option/ArgList.h"
23
#include "llvm/Support/FileSystem.h"
24
#include "llvm/Support/TarWriter.h"
25
#include <memory>
26
#include <set>
27
#include <vector>
28
29
namespace lld {
30
namespace coff {
31
32
class LinkerDriver;
33
extern LinkerDriver *Driver;
34
35
using llvm::COFF::MachineTypes;
36
using llvm::COFF::WindowsSubsystem;
37
using llvm::Optional;
38
39
class COFFOptTable : public llvm::opt::OptTable {
40
public:
41
  COFFOptTable();
42
};
43
44
class ArgParser {
45
public:
46
  // Concatenate LINK environment variable and given arguments and parse them.
47
  llvm::opt::InputArgList parseLINK(std::vector<const char *> Args);
48
49
  // Tokenizes a given string and then parses as command line options.
50
0
  llvm::opt::InputArgList parse(StringRef S) { return parse(tokenize(S)); }
51
52
  // Tokenizes a given string and then parses as command line options in
53
  // .drectve section. /EXPORT options are returned in second element
54
  // to be processed in fastpath.
55
  std::pair<llvm::opt::InputArgList, std::vector<StringRef>>
56
  parseDirectives(StringRef S);
57
58
private:
59
  // Parses command line options.
60
  llvm::opt::InputArgList parse(llvm::ArrayRef<const char *> Args);
61
62
  std::vector<const char *> tokenize(StringRef S);
63
64
  COFFOptTable Table;
65
};
66
67
class LinkerDriver {
68
public:
69
  void link(llvm::ArrayRef<const char *> Args);
70
71
  // Used by the resolver to parse .drectve section contents.
72
  void parseDirectives(InputFile *File);
73
74
  // Used by ArchiveFile to enqueue members.
75
  void enqueueArchiveMember(const Archive::Child &C, StringRef SymName,
76
                            StringRef ParentName);
77
78
  MemoryBufferRef takeBuffer(std::unique_ptr<MemoryBuffer> MB);
79
80
private:
81
  std::unique_ptr<llvm::TarWriter> Tar; // for /linkrepro
82
83
  // Opens a file. Path has to be resolved already.
84
  MemoryBufferRef openFile(StringRef Path);
85
86
  // Searches a file from search paths.
87
  Optional<StringRef> findFile(StringRef Filename);
88
  Optional<StringRef> findLib(StringRef Filename);
89
  StringRef doFindFile(StringRef Filename);
90
  StringRef doFindLib(StringRef Filename);
91
  StringRef doFindLibMinGW(StringRef Filename);
92
93
  // Parses LIB environment which contains a list of search paths.
94
  void addLibSearchPaths();
95
96
  // Library search path. The first element is always "" (current directory).
97
  std::vector<StringRef> SearchPaths;
98
99
  void maybeExportMinGWSymbols(const llvm::opt::InputArgList &Args);
100
101
  // We don't want to add the same file more than once.
102
  // Files are uniquified by their filesystem and file number.
103
  std::set<llvm::sys::fs::UniqueID> VisitedFiles;
104
105
  std::set<std::string> VisitedLibs;
106
107
  Symbol *addUndefined(StringRef Sym);
108
109
  // Windows specific -- "main" is not the only main function in Windows.
110
  // You can choose one from these four -- {w,}{WinMain,main}.
111
  // There are four different entry point functions for them,
112
  // {w,}{WinMain,main}CRTStartup, respectively. The linker needs to
113
  // choose the right one depending on which "main" function is defined.
114
  // This function looks up the symbol table and resolve corresponding
115
  // entry point name.
116
  StringRef findDefaultEntry();
117
  WindowsSubsystem inferSubsystem();
118
119
  void addBuffer(std::unique_ptr<MemoryBuffer> MB, bool WholeArchive);
120
  void addArchiveBuffer(MemoryBufferRef MBRef, StringRef SymName,
121
                        StringRef ParentName, uint64_t OffsetInArchive);
122
123
  void enqueuePath(StringRef Path, bool WholeArchive);
124
125
  void enqueueTask(std::function<void()> Task);
126
  bool run();
127
128
  std::list<std::function<void()>> TaskQueue;
129
  std::vector<StringRef> FilePaths;
130
  std::vector<MemoryBufferRef> Resources;
131
132
  llvm::StringSet<> DirectivesExports;
133
};
134
135
// Functions below this line are defined in DriverUtils.cpp.
136
137
void printHelp(const char *Argv0);
138
139
// For /machine option.
140
MachineTypes getMachineType(StringRef Arg);
141
StringRef machineToStr(MachineTypes MT);
142
143
// Parses a string in the form of "<integer>[,<integer>]".
144
void parseNumbers(StringRef Arg, uint64_t *Addr, uint64_t *Size = nullptr);
145
146
void parseGuard(StringRef Arg);
147
148
// Parses a string in the form of "<integer>[.<integer>]".
149
// Minor's default value is 0.
150
void parseVersion(StringRef Arg, uint32_t *Major, uint32_t *Minor);
151
152
// Parses a string in the form of "<subsystem>[,<integer>[.<integer>]]".
153
void parseSubsystem(StringRef Arg, WindowsSubsystem *Sys, uint32_t *Major,
154
                    uint32_t *Minor);
155
156
void parseAlternateName(StringRef);
157
void parseMerge(StringRef);
158
void parseSection(StringRef);
159
void parseAligncomm(StringRef);
160
161
// Parses a string in the form of "[:<integer>]"
162
void parseFunctionPadMin(llvm::opt::Arg *A, llvm::COFF::MachineTypes Machine);
163
164
// Parses a string in the form of "EMBED[,=<integer>]|NO".
165
void parseManifest(StringRef Arg);
166
167
// Parses a string in the form of "level=<string>|uiAccess=<string>"
168
void parseManifestUAC(StringRef Arg);
169
170
// Parses a string in the form of "cd|net[,(cd|net)]*"
171
void parseSwaprun(StringRef Arg);
172
173
// Create a resource file containing a manifest XML.
174
std::unique_ptr<MemoryBuffer> createManifestRes();
175
void createSideBySideManifest();
176
177
// Used for dllexported symbols.
178
Export parseExport(StringRef Arg);
179
void fixupExports();
180
void assignExportOrdinals();
181
182
// Parses a string in the form of "key=value" and check
183
// if value matches previous values for the key.
184
// This feature used in the directive section to reject
185
// incompatible objects.
186
void checkFailIfMismatch(StringRef Arg, InputFile *Source);
187
188
// Convert Windows resource files (.res files) to a .obj file.
189
MemoryBufferRef convertResToCOFF(ArrayRef<MemoryBufferRef> MBs);
190
191
void runMSVCLinker(std::string Rsp, ArrayRef<StringRef> Objects);
192
193
// Create enum with OPT_xxx values for each option in Options.td
194
enum {
195
  OPT_INVALID = 0,
196
#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11, _12) OPT_##ID,
197
#include "Options.inc"
198
#undef OPTION
199
};
200
201
} // namespace coff
202
} // namespace lld
203
204
#endif