Coverage Report

Created: 2017-09-19 22:28

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