Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/MC/XCOFFObjectWriter.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- lib/MC/XCOFFObjectWriter.cpp - XCOFF file writer ------------------===//
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
// This file implements XCOFF object file writer information.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "llvm/MC/MCAssembler.h"
14
#include "llvm/MC/MCObjectWriter.h"
15
#include "llvm/MC/MCValue.h"
16
#include "llvm/MC/MCXCOFFObjectWriter.h"
17
18
using namespace llvm;
19
20
namespace {
21
22
class XCOFFObjectWriter : public MCObjectWriter {
23
  support::endian::Writer W;
24
  std::unique_ptr<MCXCOFFObjectTargetWriter> TargetObjectWriter;
25
26
  void executePostLayoutBinding(MCAssembler &, const MCAsmLayout &) override;
27
28
  void recordRelocation(MCAssembler &, const MCAsmLayout &, const MCFragment *,
29
                        const MCFixup &, MCValue, uint64_t &) override;
30
31
  uint64_t writeObject(MCAssembler &, const MCAsmLayout &) override;
32
33
public:
34
  XCOFFObjectWriter(std::unique_ptr<MCXCOFFObjectTargetWriter> MOTW,
35
                    raw_pwrite_stream &OS);
36
};
37
38
XCOFFObjectWriter::XCOFFObjectWriter(
39
    std::unique_ptr<MCXCOFFObjectTargetWriter> MOTW, raw_pwrite_stream &OS)
40
5
    : W(OS, support::big), TargetObjectWriter(std::move(MOTW)) {}
41
42
void XCOFFObjectWriter::executePostLayoutBinding(MCAssembler &,
43
2
                                                 const MCAsmLayout &) {
44
2
  // TODO Implement once we have sections and symbols to handle.
45
2
}
46
47
void XCOFFObjectWriter::recordRelocation(MCAssembler &, const MCAsmLayout &,
48
                                         const MCFragment *, const MCFixup &,
49
0
                                         MCValue, uint64_t &) {
50
0
  report_fatal_error("XCOFF relocations not supported.");
51
0
}
52
53
2
uint64_t XCOFFObjectWriter::writeObject(MCAssembler &Asm, const MCAsmLayout &) {
54
2
  // We always emit a timestamp of 0 for reproducibility, so ensure incremental
55
2
  // linking is not enabled, in case, like with Windows COFF, such a timestamp
56
2
  // is incompatible with incremental linking of XCOFF.
57
2
  if (Asm.isIncrementalLinkerCompatible())
58
0
    report_fatal_error("Incremental linking not supported for XCOFF.");
59
2
60
2
  if (TargetObjectWriter->is64Bit())
61
1
    report_fatal_error("64-bit XCOFF object files are not supported yet.");
62
1
63
1
  uint64_t StartOffset = W.OS.tell();
64
1
65
1
  // TODO FIXME Assign section numbers/finalize sections.
66
1
67
1
  // TODO FIXME Finalize symbols.
68
1
69
1
  // Magic.
70
1
  W.write<uint16_t>(0x01df);
71
1
  // Number of sections.
72
1
  W.write<uint16_t>(0);
73
1
  // Timestamp field. For reproducible output we write a 0, which represents no
74
1
  // timestamp.
75
1
  W.write<int32_t>(0);
76
1
  // Byte Offset to the start of the symbol table.
77
1
  W.write<uint32_t>(0);
78
1
  // Number of entries in the symbol table.
79
1
  W.write<int32_t>(0);
80
1
  // Size of the optional header.
81
1
  W.write<uint16_t>(0);
82
1
  // Flags.
83
1
  W.write<uint16_t>(0);
84
1
85
1
  return W.OS.tell() - StartOffset;
86
1
}
87
88
} // end anonymous namespace
89
90
std::unique_ptr<MCObjectWriter>
91
llvm::createXCOFFObjectWriter(std::unique_ptr<MCXCOFFObjectTargetWriter> MOTW,
92
5
                              raw_pwrite_stream &OS) {
93
5
  return llvm::make_unique<XCOFFObjectWriter>(std::move(MOTW), OS);
94
5
}