Coverage Report

Created: 2018-06-25 02:00

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/COFF/MinGW.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- MinGW.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 "MinGW.h"
11
#include "SymbolTable.h"
12
#include "lld/Common/ErrorHandler.h"
13
#include "llvm/Object/COFF.h"
14
#include "llvm/Support/Path.h"
15
#include "llvm/Support/raw_ostream.h"
16
17
using namespace lld;
18
using namespace lld::coff;
19
using namespace llvm;
20
using namespace llvm::COFF;
21
22
5
AutoExporter::AutoExporter() {
23
5
  if (Config->Machine == I386) {
24
3
    ExcludeSymbols = {
25
3
        "__NULL_IMPORT_DESCRIPTOR",
26
3
        "__pei386_runtime_relocator",
27
3
        "_do_pseudo_reloc",
28
3
        "_impure_ptr",
29
3
        "__impure_ptr",
30
3
        "__fmode",
31
3
        "_environ",
32
3
        "___dso_handle",
33
3
        // These are the MinGW names that differ from the standard
34
3
        // ones (lacking an extra underscore).
35
3
        "_DllMain@12",
36
3
        "_DllEntryPoint@12",
37
3
        "_DllMainCRTStartup@12",
38
3
    };
39
3
  } else {
40
2
    ExcludeSymbols = {
41
2
        "_NULL_IMPORT_DESCRIPTOR",
42
2
        "_pei386_runtime_relocator",
43
2
        "do_pseudo_reloc",
44
2
        "impure_ptr",
45
2
        "_impure_ptr",
46
2
        "_fmode",
47
2
        "environ",
48
2
        "__dso_handle",
49
2
        // These are the MinGW names that differ from the standard
50
2
        // ones (lacking an extra underscore).
51
2
        "DllMain",
52
2
        "DllEntryPoint",
53
2
        "DllMainCRTStartup",
54
2
    };
55
2
  }
56
5
57
5
  ExcludeLibs = {
58
5
      "libgcc",
59
5
      "libgcc_s",
60
5
      "libstdc++",
61
5
      "libmingw32",
62
5
      "libmingwex",
63
5
      "libg2c",
64
5
      "libsupc++",
65
5
      "libobjc",
66
5
      "libgcj",
67
5
      "libclang_rt.builtins-aarch64",
68
5
      "libclang_rt.builtins-arm",
69
5
      "libclang_rt.builtins-i386",
70
5
      "libclang_rt.builtins-x86_64",
71
5
      "libc++",
72
5
      "libc++abi",
73
5
      "libunwind",
74
5
      "libmsvcrt",
75
5
      "libucrtbase",
76
5
  };
77
5
  ExcludeObjects = {
78
5
      "crt0.o",
79
5
      "crt1.o",
80
5
      "crt1u.o",
81
5
      "crt2.o",
82
5
      "crt2u.o",
83
5
      "dllcrt1.o",
84
5
      "dllcrt2.o",
85
5
      "gcrt0.o",
86
5
      "gcrt1.o",
87
5
      "gcrt2.o",
88
5
      "crtbegin.o",
89
5
      "crtend.o",
90
5
  };
91
5
}
92
93
78
bool AutoExporter::shouldExport(Defined *Sym) const {
94
78
  if (!Sym || 
!Sym->isLive()75
||
!Sym->getChunk()75
)
95
56
    return false;
96
22
97
22
  // Only allow the symbol kinds that make sense to export; in particular,
98
22
  // disallow import symbols.
99
22
  if (!isa<DefinedRegular>(Sym) && 
!isa<DefinedCommon>(Sym)2
)
100
2
    return false;
101
20
  if (ExcludeSymbols.count(Sym->getName()))
102
2
    return false;
103
18
104
18
  // Don't export anything that looks like an import symbol (which also can be
105
18
  // a manually defined data symbol with such a name).
106
18
  if (Sym->getName().startswith("__imp_"))
107
1
    return false;
108
17
109
17
  // If a corresponding __imp_ symbol exists and is defined, don't export it.
110
17
  if (Symtab->find(("__imp_" + Sym->getName()).str()))
111
1
    return false;
112
16
113
16
  // Check that file is non-null before dereferencing it, symbols not
114
16
  // originating in regular object files probably shouldn't be exported.
115
16
  if (!Sym->getFile())
116
0
    return false;
117
16
118
16
  StringRef LibName = sys::path::filename(Sym->getFile()->ParentName);
119
16
120
16
  // Drop the file extension.
121
16
  LibName = LibName.substr(0, LibName.rfind('.'));
122
16
  if (!LibName.empty())
123
1
    return !ExcludeLibs.count(LibName);
124
15
125
15
  StringRef FileName = sys::path::filename(Sym->getFile()->getName());
126
15
  return !ExcludeObjects.count(FileName);
127
15
}
128
129
3
void coff::writeDefFile(StringRef Name) {
130
3
  std::error_code EC;
131
3
  raw_fd_ostream OS(Name, EC, sys::fs::F_None);
132
3
  if (EC)
133
0
    fatal("cannot open " + Name + ": " + EC.message());
134
3
135
3
  OS << "EXPORTS\n";
136
7
  for (Export &E : Config->Exports) {
137
7
    OS << "    " << E.ExportName << " "
138
7
       << "@" << E.Ordinal;
139
7
    if (auto *Def = dyn_cast_or_null<Defined>(E.Sym)) {
140
7
      if (Def && Def->getChunk() &&
141
7
          !(Def->getChunk()->getOutputCharacteristics() & IMAGE_SCN_MEM_EXECUTE))
142
0
        OS << " DATA";
143
7
    }
144
7
    OS << "\n";
145
7
  }
146
3
}