Coverage Report

Created: 2019-01-18 03:29

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/COFF/SymbolTable.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- SymbolTable.cpp ----------------------------------------------------===//
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
#include "SymbolTable.h"
11
#include "Config.h"
12
#include "Driver.h"
13
#include "LTO.h"
14
#include "PDB.h"
15
#include "Symbols.h"
16
#include "lld/Common/ErrorHandler.h"
17
#include "lld/Common/Memory.h"
18
#include "lld/Common/Timer.h"
19
#include "llvm/IR/LLVMContext.h"
20
#include "llvm/Support/Debug.h"
21
#include "llvm/Support/raw_ostream.h"
22
#include <utility>
23
24
using namespace llvm;
25
26
namespace lld {
27
namespace coff {
28
29
static Timer LTOTimer("LTO", Timer::root());
30
31
SymbolTable *Symtab;
32
33
864
void SymbolTable::addFile(InputFile *File) {
34
864
  log("Reading " + toString(File));
35
864
  File->parse();
36
864
37
864
  MachineTypes MT = File->getMachineType();
38
864
  if (Config->Machine == IMAGE_FILE_MACHINE_UNKNOWN) {
39
522
    Config->Machine = MT;
40
522
  } else 
if (342
MT != IMAGE_FILE_MACHINE_UNKNOWN342
&&
Config->Machine != MT163
) {
41
2
    error(toString(File) + ": machine type " + machineToStr(MT) +
42
2
          " conflicts with " + machineToStr(Config->Machine));
43
2
    return;
44
2
  }
45
862
46
862
  if (auto *F = dyn_cast<ObjFile>(File)) {
47
623
    ObjFile::Instances.push_back(F);
48
623
  } else 
if (auto *239
F239
= dyn_cast<BitcodeFile>(File)) {
49
56
    BitcodeFile::Instances.push_back(F);
50
183
  } else if (auto *F = dyn_cast<ImportFile>(File)) {
51
99
    ImportFile::Instances.push_back(F);
52
99
  }
53
862
54
862
  StringRef S = File->getDirectives();
55
862
  if (S.empty())
56
696
    return;
57
166
58
166
  log("Directives: " + toString(File) + ": " + S);
59
166
  Driver->parseDirectives(S);
60
166
}
61
62
40
static void errorOrWarn(const Twine &S) {
63
40
  if (Config->ForceUnresolved)
64
2
    warn(S);
65
38
  else
66
38
    error(S);
67
40
}
68
69
// Returns the symbol in SC whose value is <= Addr that is closest to Addr.
70
// This is generally the global variable or function whose definition contains
71
// Addr.
72
24
static Symbol *getSymbol(SectionChunk *SC, uint32_t Addr) {
73
24
  DefinedRegular *Candidate = nullptr;
74
24
75
360
  for (Symbol *S : SC->File->getSymbols()) {
76
360
    auto *D = dyn_cast_or_null<DefinedRegular>(S);
77
360
    if (!D || 
D->getChunk() != SC170
||
D->getValue() > Addr55
||
78
360
        
(49
Candidate49
&&
D->getValue() < Candidate->getValue()25
))
79
311
      continue;
80
49
81
49
    Candidate = D;
82
49
  }
83
24
84
24
  return Candidate;
85
24
}
86
87
21
std::string getSymbolLocations(ObjFile *File, uint32_t SymIndex) {
88
21
  struct Location {
89
21
    Symbol *Sym;
90
21
    std::pair<StringRef, uint32_t> FileLine;
91
21
  };
92
21
  std::vector<Location> Locations;
93
21
94
64
  for (Chunk *C : File->getChunks()) {
95
64
    auto *SC = dyn_cast<SectionChunk>(C);
96
64
    if (!SC)
97
0
      continue;
98
68
    
for (const coff_relocation &R : SC->Relocs)64
{
99
68
      if (R.SymbolTableIndex != SymIndex)
100
44
        continue;
101
24
      std::pair<StringRef, uint32_t> FileLine =
102
24
          getFileLine(SC, R.VirtualAddress);
103
24
      Symbol *Sym = getSymbol(SC, R.VirtualAddress);
104
24
      if (!FileLine.first.empty() || 
Sym18
)
105
24
        Locations.push_back({Sym, FileLine});
106
24
    }
107
64
  }
108
21
109
21
  if (Locations.empty())
110
2
    return "\n>>> referenced by " + toString(File);
111
19
112
19
  std::string Out;
113
19
  llvm::raw_string_ostream OS(Out);
114
24
  for (Location Loc : Locations) {
115
24
    OS << "\n>>> referenced by ";
116
24
    if (!Loc.FileLine.first.empty())
117
6
      OS << Loc.FileLine.first << ":" << Loc.FileLine.second
118
6
         << "\n>>>               ";
119
24
    OS << toString(File);
120
24
    if (Loc.Sym)
121
24
      OS << ":(" << toString(*Loc.Sym) << ')';
122
24
  }
123
19
  return OS.str();
124
19
}
125
126
40
void SymbolTable::loadMinGWAutomaticImports() {
127
717
  for (auto &I : SymMap) {
128
717
    Symbol *Sym = I.second;
129
717
    auto *Undef = dyn_cast<Undefined>(Sym);
130
717
    if (!Undef)
131
707
      continue;
132
10
    if (!Sym->IsUsedInRegularObj)
133
0
      continue;
134
10
135
10
    StringRef Name = Undef->getName();
136
10
137
10
    if (Name.startswith("__imp_"))
138
0
      continue;
139
10
    // If we have an undefined symbol, but we have a Lazy representing a
140
10
    // symbol we could load from file, make sure to load that.
141
10
    Lazy *L = dyn_cast_or_null<Lazy>(find(("__imp_" + Name).str()));
142
10
    if (!L || 
L->PendingArchiveLoad7
)
143
3
      continue;
144
7
145
7
    log("Loading lazy " + L->getName() + " from " + L->File->getName() +
146
7
        " for automatic import");
147
7
    L->PendingArchiveLoad = true;
148
7
    L->File->addMember(&L->Sym);
149
7
  }
150
40
}
151
152
8
bool SymbolTable::handleMinGWAutomaticImport(Symbol *Sym, StringRef Name) {
153
8
  if (Name.startswith("__imp_"))
154
0
    return false;
155
8
  Defined *Imp = dyn_cast_or_null<Defined>(find(("__imp_" + Name).str()));
156
8
  if (!Imp)
157
1
    return false;
158
7
159
7
  // Replace the reference directly to a variable with a reference
160
7
  // to the import address table instead. This obviously isn't right,
161
7
  // but we mark the symbol as IsRuntimePseudoReloc, and a later pass
162
7
  // will add runtime pseudo relocations for every relocation against
163
7
  // this Symbol. The runtime pseudo relocation framework expects the
164
7
  // reference itself to point at the IAT entry.
165
7
  size_t ImpSize = 0;
166
7
  if (isa<DefinedImportData>(Imp)) {
167
6
    log("Automatically importing " + Name + " from " +
168
6
        cast<DefinedImportData>(Imp)->getDLLName());
169
6
    ImpSize = sizeof(DefinedImportData);
170
6
  } else 
if (1
isa<DefinedRegular>(Imp)1
) {
171
1
    log("Automatically importing " + Name + " from " +
172
1
        toString(cast<DefinedRegular>(Imp)->File));
173
1
    ImpSize = sizeof(DefinedRegular);
174
1
  } else {
175
0
    warn("unable to automatically import " + Name + " from " + Imp->getName() +
176
0
         " from " + toString(cast<DefinedRegular>(Imp)->File) +
177
0
         "; unexpected symbol type");
178
0
    return false;
179
0
  }
180
7
  Sym->replaceKeepingName(Imp, ImpSize);
181
7
  Sym->IsRuntimePseudoReloc = true;
182
7
183
7
  // There may exist symbols named .refptr.<name> which only consist
184
7
  // of a single pointer to <name>. If it turns out <name> is
185
7
  // automatically imported, we don't need to keep the .refptr.<name>
186
7
  // pointer at all, but redirect all accesses to it to the IAT entry
187
7
  // for __imp_<name> instead, and drop the whole .refptr.<name> chunk.
188
7
  DefinedRegular *Refptr =
189
7
      dyn_cast_or_null<DefinedRegular>(find((".refptr." + Name).str()));
190
7
  if (Refptr && 
Refptr->getChunk()->getSize() == Config->Wordsize1
) {
191
1
    SectionChunk *SC = dyn_cast_or_null<SectionChunk>(Refptr->getChunk());
192
1
    if (SC && SC->Relocs.size() == 1 && *SC->symbols().begin() == Sym) {
193
1
      log("Replacing .refptr." + Name + " with " + Imp->getName());
194
1
      Refptr->getChunk()->Live = false;
195
1
      Refptr->replaceKeepingName(Imp, ImpSize);
196
1
    }
197
1
  }
198
7
  return true;
199
7
}
200
201
521
void SymbolTable::reportRemainingUndefines() {
202
521
  SmallPtrSet<Symbol *, 8> Undefs;
203
521
  DenseMap<Symbol *, Symbol *> LocalImports;
204
521
205
6.75k
  for (auto &I : SymMap) {
206
6.75k
    Symbol *Sym = I.second;
207
6.75k
    auto *Undef = dyn_cast<Undefined>(Sym);
208
6.75k
    if (!Undef)
209
6.64k
      continue;
210
110
    if (!Sym->IsUsedInRegularObj)
211
21
      continue;
212
89
213
89
    StringRef Name = Undef->getName();
214
89
215
89
    // A weak alias may have been resolved, so check for that.
216
89
    if (Defined *D = Undef->getWeakAlias()) {
217
33
      // We want to replace Sym with D. However, we can't just blindly
218
33
      // copy sizeof(SymbolUnion) bytes from D to Sym because D may be an
219
33
      // internal symbol, and internal symbols are stored as "unparented"
220
33
      // Symbols. For that reason we need to check which type of symbol we
221
33
      // are dealing with and copy the correct number of bytes.
222
33
      if (isa<DefinedRegular>(D))
223
31
        memcpy(Sym, D, sizeof(DefinedRegular));
224
2
      else if (isa<DefinedAbsolute>(D))
225
0
        memcpy(Sym, D, sizeof(DefinedAbsolute));
226
2
      else
227
2
        memcpy(Sym, D, sizeof(SymbolUnion));
228
33
      continue;
229
33
    }
230
56
231
56
    // If we can resolve a symbol by removing __imp_ prefix, do that.
232
56
    // This odd rule is for compatibility with MSVC linker.
233
56
    if (Name.startswith("__imp_")) {
234
10
      Symbol *Imp = find(Name.substr(strlen("__imp_")));
235
10
      if (Imp && 
isa<Defined>(Imp)9
) {
236
9
        auto *D = cast<Defined>(Imp);
237
9
        replaceSymbol<DefinedLocalImport>(Sym, Name, D);
238
9
        LocalImportChunks.push_back(cast<DefinedLocalImport>(Sym)->getChunk());
239
9
        LocalImports[Sym] = D;
240
9
        continue;
241
9
      }
242
47
    }
243
47
244
47
    // We don't want to report missing Microsoft precompiled headers symbols.
245
47
    // A proper message will be emitted instead in PDBLinker::aquirePrecompObj
246
47
    if (Name.contains("_PchSym_"))
247
0
      continue;
248
47
249
47
    if (Config->MinGW && 
handleMinGWAutomaticImport(Sym, Name)8
)
250
7
      continue;
251
40
252
40
    // Remaining undefined symbols are not fatal if /force is specified.
253
40
    // They are replaced with dummy defined symbols.
254
40
    if (Config->ForceUnresolved)
255
2
      replaceSymbol<DefinedAbsolute>(Sym, Name, 0);
256
40
    Undefs.insert(Sym);
257
40
  }
258
521
259
521
  if (Undefs.empty() && 
LocalImports.empty()493
)
260
484
    return;
261
37
262
38
  
for (Symbol *B : Config->GCRoot)37
{
263
38
    if (Undefs.count(B))
264
22
      errorOrWarn("<root>: undefined symbol: " + toString(*B));
265
38
    if (Config->WarnLocallyDefinedImported)
266
36
      if (Symbol *Imp = LocalImports.lookup(B))
267
0
        warn("<root>: locally defined symbol imported: " + toString(*Imp) +
268
0
             " (defined in " + toString(Imp->getFile()) + ") [LNK4217]");
269
38
  }
270
37
271
42
  for (ObjFile *File : ObjFile::Instances) {
272
42
    size_t SymIndex = (size_t)-1;
273
270
    for (Symbol *Sym : File->getSymbols()) {
274
270
      ++SymIndex;
275
270
      if (!Sym)
276
96
        continue;
277
174
      if (Undefs.count(Sym))
278
18
        errorOrWarn("undefined symbol: " + toString(*Sym) +
279
18
                    getSymbolLocations(File, SymIndex));
280
174
      if (Config->WarnLocallyDefinedImported)
281
163
        if (Symbol *Imp = LocalImports.lookup(Sym))
282
8
          warn(toString(File) +
283
8
               ": locally defined symbol imported: " + toString(*Imp) +
284
8
               " (defined in " + toString(Imp->getFile()) + ") [LNK4217]");
285
174
    }
286
42
  }
287
37
}
288
289
8.14k
std::pair<Symbol *, bool> SymbolTable::insert(StringRef Name) {
290
8.14k
  bool Inserted = false;
291
8.14k
  Symbol *&Sym = SymMap[CachedHashStringRef(Name)];
292
8.14k
  if (!Sym) {
293
6.80k
    Sym = reinterpret_cast<Symbol *>(make<SymbolUnion>());
294
6.80k
    Sym->IsUsedInRegularObj = false;
295
6.80k
    Sym->PendingArchiveLoad = false;
296
6.80k
    Inserted = true;
297
6.80k
  }
298
8.14k
  return {Sym, Inserted};
299
8.14k
}
300
301
7.69k
std::pair<Symbol *, bool> SymbolTable::insert(StringRef Name, InputFile *File) {
302
7.69k
  std::pair<Symbol *, bool> Result = insert(Name);
303
7.69k
  if (!File || 
!isa<BitcodeFile>(File)1.67k
)
304
7.58k
    Result.first->IsUsedInRegularObj = true;
305
7.69k
  return Result;
306
7.69k
}
307
308
Symbol *SymbolTable::addUndefined(StringRef Name, InputFile *F,
309
1.09k
                                  bool IsWeakAlias) {
310
1.09k
  Symbol *S;
311
1.09k
  bool WasInserted;
312
1.09k
  std::tie(S, WasInserted) = insert(Name, F);
313
1.09k
  if (WasInserted || 
(729
isa<Lazy>(S)729
&&
IsWeakAlias27
)) {
314
368
    replaceSymbol<Undefined>(S, Name);
315
368
    return S;
316
368
  }
317
729
  if (auto *L = dyn_cast<Lazy>(S)) {
318
27
    if (!S->PendingArchiveLoad) {
319
27
      S->PendingArchiveLoad = true;
320
27
      L->File->addMember(&L->Sym);
321
27
    }
322
27
  }
323
729
  return S;
324
729
}
325
326
452
void SymbolTable::addLazy(ArchiveFile *F, const Archive::Symbol Sym) {
327
452
  StringRef Name = Sym.getName();
328
452
  Symbol *S;
329
452
  bool WasInserted;
330
452
  std::tie(S, WasInserted) = insert(Name);
331
452
  if (WasInserted) {
332
332
    replaceSymbol<Lazy>(S, F, Sym);
333
332
    return;
334
332
  }
335
120
  auto *U = dyn_cast<Undefined>(S);
336
120
  if (!U || 
U->WeakAlias105
||
S->PendingArchiveLoad105
)
337
15
    return;
338
105
  S->PendingArchiveLoad = true;
339
105
  F->addMember(&Sym);
340
105
}
341
342
8
void SymbolTable::reportDuplicate(Symbol *Existing, InputFile *NewFile) {
343
8
  std::string Msg = "duplicate symbol: " + toString(*Existing) + " in " +
344
8
                    toString(Existing->getFile()) + " and in " +
345
8
                    toString(NewFile);
346
8
347
8
  if (Config->ForceMultiple)
348
2
    warn(Msg);
349
6
  else
350
6
    error(Msg);
351
8
}
352
353
17
Symbol *SymbolTable::addAbsolute(StringRef N, COFFSymbolRef Sym) {
354
17
  Symbol *S;
355
17
  bool WasInserted;
356
17
  std::tie(S, WasInserted) = insert(N, nullptr);
357
17
  S->IsUsedInRegularObj = true;
358
17
  if (WasInserted || 
isa<Undefined>(S)3
||
isa<Lazy>(S)0
)
359
17
    replaceSymbol<DefinedAbsolute>(S, N, Sym);
360
0
  else if (!isa<DefinedCOFF>(S))
361
0
    reportDuplicate(S, nullptr);
362
17
  return S;
363
17
}
364
365
4.52k
Symbol *SymbolTable::addAbsolute(StringRef N, uint64_t VA) {
366
4.52k
  Symbol *S;
367
4.52k
  bool WasInserted;
368
4.52k
  std::tie(S, WasInserted) = insert(N, nullptr);
369
4.52k
  S->IsUsedInRegularObj = true;
370
4.52k
  if (WasInserted || 
isa<Undefined>(S)71
||
isa<Lazy>(S)0
)
371
4.52k
    replaceSymbol<DefinedAbsolute>(S, N, VA);
372
0
  else if (!isa<DefinedCOFF>(S))
373
0
    reportDuplicate(S, nullptr);
374
4.52k
  return S;
375
4.52k
}
376
377
523
Symbol *SymbolTable::addSynthetic(StringRef N, Chunk *C) {
378
523
  Symbol *S;
379
523
  bool WasInserted;
380
523
  std::tie(S, WasInserted) = insert(N, nullptr);
381
523
  S->IsUsedInRegularObj = true;
382
523
  if (WasInserted || 
isa<Undefined>(S)26
||
isa<Lazy>(S)0
)
383
523
    replaceSymbol<DefinedSynthetic>(S, N, C);
384
0
  else if (!isa<DefinedCOFF>(S))
385
0
    reportDuplicate(S, nullptr);
386
523
  return S;
387
523
}
388
389
Symbol *SymbolTable::addRegular(InputFile *F, StringRef N,
390
                                const coff_symbol_generic *Sym,
391
1.02k
                                SectionChunk *C) {
392
1.02k
  Symbol *S;
393
1.02k
  bool WasInserted;
394
1.02k
  std::tie(S, WasInserted) = insert(N, F);
395
1.02k
  if (WasInserted || 
!isa<DefinedRegular>(S)102
)
396
1.02k
    replaceSymbol<DefinedRegular>(S, F, N, /*IsCOMDAT*/ false,
397
1.02k
                                  /*IsExternal*/ true, Sym, C);
398
5
  else
399
5
    reportDuplicate(S, F);
400
1.02k
  return S;
401
1.02k
}
402
403
std::pair<Symbol *, bool>
404
SymbolTable::addComdat(InputFile *F, StringRef N,
405
312
                       const coff_symbol_generic *Sym) {
406
312
  Symbol *S;
407
312
  bool WasInserted;
408
312
  std::tie(S, WasInserted) = insert(N, F);
409
312
  if (WasInserted || 
!isa<DefinedRegular>(S)107
) {
410
287
    replaceSymbol<DefinedRegular>(S, F, N, /*IsCOMDAT*/ true,
411
287
                                  /*IsExternal*/ true, Sym, nullptr);
412
287
    return {S, true};
413
287
  }
414
25
  if (!cast<DefinedRegular>(S)->isCOMDAT())
415
0
    reportDuplicate(S, F);
416
25
  return {S, false};
417
25
}
418
419
Symbol *SymbolTable::addCommon(InputFile *F, StringRef N, uint64_t Size,
420
12
                               const coff_symbol_generic *Sym, CommonChunk *C) {
421
12
  Symbol *S;
422
12
  bool WasInserted;
423
12
  std::tie(S, WasInserted) = insert(N, F);
424
12
  if (WasInserted || 
!isa<DefinedCOFF>(S)0
)
425
12
    replaceSymbol<DefinedCommon>(S, F, N, Size, Sym, C);
426
0
  else if (auto *DC = dyn_cast<DefinedCommon>(S))
427
0
    if (Size > DC->getSize())
428
0
      replaceSymbol<DefinedCommon>(S, F, N, Size, Sym, C);
429
12
  return S;
430
12
}
431
432
100
Symbol *SymbolTable::addImportData(StringRef N, ImportFile *F) {
433
100
  Symbol *S;
434
100
  bool WasInserted;
435
100
  std::tie(S, WasInserted) = insert(N, nullptr);
436
100
  S->IsUsedInRegularObj = true;
437
100
  if (WasInserted || isa<Undefined>(S) || 
isa<Lazy>(S)93
) {
438
98
    replaceSymbol<DefinedImportData>(S, N, F);
439
98
    return S;
440
98
  }
441
2
442
2
  reportDuplicate(S, F);
443
2
  return nullptr;
444
2
}
445
446
Symbol *SymbolTable::addImportThunk(StringRef Name, DefinedImportData *ID,
447
89
                                    uint16_t Machine) {
448
89
  Symbol *S;
449
89
  bool WasInserted;
450
89
  std::tie(S, WasInserted) = insert(Name, nullptr);
451
89
  S->IsUsedInRegularObj = true;
452
89
  if (WasInserted || isa<Undefined>(S) || 
isa<Lazy>(S)14
) {
453
88
    replaceSymbol<DefinedImportThunk>(S, Name, ID, Machine);
454
88
    return S;
455
88
  }
456
1
457
1
  reportDuplicate(S, ID->File);
458
1
  return nullptr;
459
1
}
460
461
1.27k
std::vector<Chunk *> SymbolTable::getChunks() {
462
1.27k
  std::vector<Chunk *> Res;
463
1.64k
  for (ObjFile *File : ObjFile::Instances) {
464
1.64k
    ArrayRef<Chunk *> V = File->getChunks();
465
1.64k
    Res.insert(Res.end(), V.begin(), V.end());
466
1.64k
  }
467
1.27k
  return Res;
468
1.27k
}
469
470
3.00k
Symbol *SymbolTable::find(StringRef Name) {
471
3.00k
  return SymMap.lookup(CachedHashStringRef(Name));
472
3.00k
}
473
474
1.72k
Symbol *SymbolTable::findUnderscore(StringRef Name) {
475
1.72k
  if (Config->Machine == I386)
476
309
    return find(("_" + Name).str());
477
1.41k
  return find(Name);
478
1.41k
}
479
480
1.09k
StringRef SymbolTable::findByPrefix(StringRef Prefix) {
481
3.67k
  for (auto Pair : SymMap) {
482
3.67k
    StringRef Name = Pair.first.val();
483
3.67k
    if (Name.startswith(Prefix))
484
25
      return Name;
485
3.67k
  }
486
1.09k
  
return ""1.07k
;
487
1.09k
}
488
489
965
StringRef SymbolTable::findMangle(StringRef Name) {
490
965
  if (Symbol *Sym = find(Name))
491
274
    if (!isa<Undefined>(Sym))
492
230
      return Name;
493
735
  if (Config->Machine != I386)
494
600
    return findByPrefix(("?" + Name + "@@Y").str());
495
135
  if (!Name.startswith("_"))
496
0
    return "";
497
135
  // Search for x86 stdcall function.
498
135
  StringRef S = findByPrefix((Name + "@").str());
499
135
  if (!S.empty())
500
13
    return S;
501
122
  // Search for x86 fastcall function.
502
122
  S = findByPrefix(("@" + Name.substr(1) + "@").str());
503
122
  if (!S.empty())
504
1
    return S;
505
121
  // Search for x86 vectorcall function.
506
121
  S = findByPrefix((Name.substr(1) + "@@").str());
507
121
  if (!S.empty())
508
1
    return S;
509
120
  // Search for x86 C++ non-member function.
510
120
  return findByPrefix(("?" + Name.substr(1) + "@@Y").str());
511
120
}
512
513
588
void SymbolTable::mangleMaybe(Symbol *B) {
514
588
  auto *U = dyn_cast<Undefined>(B);
515
588
  if (!U || 
U->WeakAlias49
)
516
544
    return;
517
44
  StringRef Alias = findMangle(U->getName());
518
44
  if (!Alias.empty()) {
519
19
    log(U->getName() + " aliased to " + Alias);
520
19
    U->WeakAlias = addUndefined(Alias);
521
19
  }
522
44
}
523
524
775
Symbol *SymbolTable::addUndefined(StringRef Name) {
525
775
  return addUndefined(Name, nullptr, false);
526
775
}
527
528
41
std::vector<StringRef> SymbolTable::compileBitcodeFiles() {
529
41
  LTO.reset(new BitcodeCompiler);
530
41
  for (BitcodeFile *F : BitcodeFile::Instances)
531
54
    LTO->add(*F);
532
41
  return LTO->compile();
533
41
}
534
535
521
void SymbolTable::addCombinedLTOObjects() {
536
521
  if (BitcodeFile::Instances.empty())
537
480
    return;
538
41
539
41
  ScopedTimer T(LTOTimer);
540
51
  for (StringRef Object : compileBitcodeFiles()) {
541
51
    auto *Obj = make<ObjFile>(MemoryBufferRef(Object, "lto.tmp"));
542
51
    Obj->parse();
543
51
    ObjFile::Instances.push_back(Obj);
544
51
  }
545
41
}
546
547
} // namespace coff
548
} // namespace lld