Coverage Report

Created: 2018-01-17 17:22

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