Coverage Report

Created: 2018-10-20 12:32

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