Coverage Report

Created: 2018-01-17 21: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/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
// Implemented in MarkLive.cpp.
40
void markLive(ArrayRef<Chunk *> Chunks);
41
42
// Implemented in ICF.cpp.
43
void doICF(ArrayRef<Chunk *> Chunks);
44
45
class COFFOptTable : public llvm::opt::OptTable {
46
public:
47
  COFFOptTable();
48
};
49
50
class ArgParser {
51
public:
52
  // Concatenate LINK environment variable and given arguments and parse them.
53
  llvm::opt::InputArgList parseLINK(std::vector<const char *> Args);
54
55
  // Tokenizes a given string and then parses as command line options.
56
0
  llvm::opt::InputArgList parse(StringRef S) { return parse(tokenize(S)); }
57
58
  // Tokenizes a given string and then parses as command line options in
59
  // .drectve section. /EXPORT options are returned in second element
60
  // to be processed in fastpath.
61
  std::pair<llvm::opt::InputArgList, std::vector<StringRef>>
62
  parseDirectives(StringRef S);
63
64
private:
65
  // Parses command line options.
66
  llvm::opt::InputArgList parse(llvm::ArrayRef<const char *> Args);
67
68
  std::vector<const char *> tokenize(StringRef S);
69
70
  COFFOptTable Table;
71
};
72
73
class LinkerDriver {
74
public:
75
  void link(llvm::ArrayRef<const char *> Args);
76
77
  // Used by the resolver to parse .drectve section contents.
78
  void parseDirectives(StringRef S);
79
80
  // Used by ArchiveFile to enqueue members.
81
  void enqueueArchiveMember(const Archive::Child &C, StringRef SymName,
82
                            StringRef ParentName);
83
84
  MemoryBufferRef takeBuffer(std::unique_ptr<MemoryBuffer> MB);
85
86
private:
87
  std::unique_ptr<llvm::TarWriter> Tar; // for /linkrepro
88
89
  // Opens a file. Path has to be resolved already.
90
  MemoryBufferRef openFile(StringRef Path);
91
92
  // Searches a file from search paths.
93
  Optional<StringRef> findFile(StringRef Filename);
94
  Optional<StringRef> findLib(StringRef Filename);
95
  StringRef doFindFile(StringRef Filename);
96
  StringRef doFindLib(StringRef Filename);
97
98
  // Parses LIB environment which contains a list of search paths.
99
  void addLibSearchPaths();
100
101
  // Library search path. The first element is always "" (current directory).
102
  std::vector<StringRef> SearchPaths;
103
  std::set<std::string> VisitedFiles;
104
  std::set<std::string> VisitedLibs;
105
106
  Symbol *addUndefined(StringRef Sym);
107
  StringRef mangle(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 invokeMSVC(llvm::opt::InputArgList &Args);
120
121
  void addBuffer(std::unique_ptr<MemoryBuffer> MB, bool WholeArchive);
122
  void addArchiveBuffer(MemoryBufferRef MBRef, StringRef SymName,
123
                        StringRef ParentName);
124
125
  void enqueuePath(StringRef Path, bool WholeArchive);
126
127
  void enqueueTask(std::function<void()> Task);
128
  bool run();
129
130
  std::list<std::function<void()>> TaskQueue;
131
  std::vector<StringRef> FilePaths;
132
  std::vector<MemoryBufferRef> Resources;
133
134
  llvm::StringSet<> DirectivesExports;
135
};
136
137
// Functions below this line are defined in DriverUtils.cpp.
138
139
void printHelp(const char *Argv0);
140
141
// For /machine option.
142
MachineTypes getMachineType(StringRef Arg);
143
StringRef machineToStr(MachineTypes MT);
144
145
// Parses a string in the form of "<integer>[,<integer>]".
146
void parseNumbers(StringRef Arg, uint64_t *Addr, uint64_t *Size = nullptr);
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 "EMBED[,=<integer>]|NO".
162
void parseManifest(StringRef Arg);
163
164
// Parses a string in the form of "level=<string>|uiAccess=<string>"
165
void parseManifestUAC(StringRef Arg);
166
167
// Create a resource file containing a manifest XML.
168
std::unique_ptr<MemoryBuffer> createManifestRes();
169
void createSideBySideManifest();
170
171
// Used for dllexported symbols.
172
Export parseExport(StringRef Arg);
173
void fixupExports();
174
void assignExportOrdinals();
175
176
// Parses a string in the form of "key=value" and check
177
// if value matches previous values for the key.
178
// This feature used in the directive section to reject
179
// incompatible objects.
180
void checkFailIfMismatch(StringRef Arg);
181
182
// Convert Windows resource files (.res files) to a .obj file.
183
MemoryBufferRef convertResToCOFF(ArrayRef<MemoryBufferRef> MBs);
184
185
void runMSVCLinker(std::string Rsp, ArrayRef<StringRef> Objects);
186
187
// Create enum with OPT_xxx values for each option in Options.td
188
enum {
189
  OPT_INVALID = 0,
190
#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11, _12) OPT_##ID,
191
#include "Options.inc"
192
#undef OPTION
193
};
194
195
} // namespace coff
196
} // namespace lld
197
198
#endif