Coverage Report

Created: 2019-02-23 12:57

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/Object/COFFImportFile.h
Line
Count
Source (jump to first uncovered line)
1
//===- COFFImportFile.h - COFF short import file implementation -*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// COFF short import file is a special kind of file which contains
10
// only symbol names for DLL-exported symbols. This class implements
11
// exporting of Symbols to create libraries and a SymbolicFile
12
// interface for the file type.
13
//
14
//===----------------------------------------------------------------------===//
15
16
#ifndef LLVM_OBJECT_COFF_IMPORT_FILE_H
17
#define LLVM_OBJECT_COFF_IMPORT_FILE_H
18
19
#include "llvm/ADT/ArrayRef.h"
20
#include "llvm/Object/COFF.h"
21
#include "llvm/Object/IRObjectFile.h"
22
#include "llvm/Object/ObjectFile.h"
23
#include "llvm/Object/SymbolicFile.h"
24
#include "llvm/Support/MemoryBuffer.h"
25
#include "llvm/Support/raw_ostream.h"
26
27
namespace llvm {
28
namespace object {
29
30
class COFFImportFile : public SymbolicFile {
31
public:
32
  COFFImportFile(MemoryBufferRef Source)
33
298
      : SymbolicFile(ID_COFFImportFile, Source) {}
34
35
  static bool classof(Binary const *V) { return V->isCOFFImportFile(); }
36
37
571
  void moveSymbolNext(DataRefImpl &Symb) const override { ++Symb.p; }
38
39
  std::error_code printSymbolName(raw_ostream &OS,
40
571
                                  DataRefImpl Symb) const override {
41
571
    if (Symb.p == 0)
42
295
      OS << "__imp_";
43
571
    OS << StringRef(Data.getBufferStart() + sizeof(coff_import_header));
44
571
    return std::error_code();
45
571
  }
46
47
526
  uint32_t getSymbolFlags(DataRefImpl Symb) const override {
48
526
    return SymbolRef::SF_Global;
49
526
  }
50
51
295
  basic_symbol_iterator symbol_begin() const override {
52
295
    return BasicSymbolRef(DataRefImpl(), this);
53
295
  }
54
55
295
  basic_symbol_iterator symbol_end() const override {
56
295
    DataRefImpl Symb;
57
295
    Symb.p = isData() ? 
119
:
2276
;
58
295
    return BasicSymbolRef(Symb, this);
59
295
  }
60
61
383
  const coff_import_header *getCOFFImportHeader() const {
62
383
    return reinterpret_cast<const object::coff_import_header *>(
63
383
        Data.getBufferStart());
64
383
  }
65
66
private:
67
295
  bool isData() const {
68
295
    return getCOFFImportHeader()->getType() == COFF::IMPORT_DATA;
69
295
  }
70
};
71
72
struct COFFShortExport {
73
  std::string Name;
74
  std::string ExtName;
75
  std::string SymbolName;
76
  std::string AliasTarget;
77
78
  uint16_t Ordinal = 0;
79
  bool Noname = false;
80
  bool Data = false;
81
  bool Private = false;
82
  bool Constant = false;
83
84
0
  friend bool operator==(const COFFShortExport &L, const COFFShortExport &R) {
85
0
    return L.Name == R.Name && L.ExtName == R.ExtName &&
86
0
            L.Ordinal == R.Ordinal && L.Noname == R.Noname &&
87
0
            L.Data == R.Data && L.Private == R.Private;
88
0
  }
89
90
0
  friend bool operator!=(const COFFShortExport &L, const COFFShortExport &R) {
91
0
    return !(L == R);
92
0
  }
93
};
94
95
Error writeImportLibrary(StringRef ImportName, StringRef Path,
96
                         ArrayRef<COFFShortExport> Exports,
97
                         COFF::MachineTypes Machine, bool MinGW);
98
99
} // namespace object
100
} // namespace llvm
101
102
#endif