Fix test failures introduced by PR #113697 (#116941)
[llvm-project.git] / llvm / tools / dsymutil / RelocationMap.cpp
blob5921e7c9c249521454d2efacc80c8592d50bb557
1 //===- tools/dsymutil/RelocationMap.cpp - Relocation map representation---===//
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 //===----------------------------------------------------------------------===//
9 #include "RelocationMap.h"
11 namespace llvm {
13 namespace dsymutil {
15 void RelocationMap::print(raw_ostream &OS) const {
16 yaml::Output yout(OS, /* Ctxt = */ nullptr, /* WrapColumn = */ 0);
17 yout << const_cast<RelocationMap &>(*this);
20 #ifndef NDEBUG
21 void RelocationMap::dump() const { print(errs()); }
22 #endif
24 void RelocationMap::addRelocationMapEntry(const ValidReloc &Relocation) {
25 Relocations.push_back(Relocation);
28 namespace {
30 struct YAMLContext {
31 StringRef PrependPath;
32 Triple BinaryTriple;
35 } // end anonymous namespace
37 ErrorOr<std::unique_ptr<RelocationMap>>
38 RelocationMap::parseYAMLRelocationMap(StringRef InputFile,
39 StringRef PrependPath) {
40 auto ErrOrFile = MemoryBuffer::getFileOrSTDIN(InputFile);
41 if (auto Err = ErrOrFile.getError())
42 return Err;
44 YAMLContext Ctxt;
46 Ctxt.PrependPath = PrependPath;
48 std::unique_ptr<RelocationMap> Result;
49 yaml::Input yin((*ErrOrFile)->getBuffer(), &Ctxt);
50 yin >> Result;
52 if (auto EC = yin.error())
53 return EC;
54 return std::move(Result);
57 } // end namespace dsymutil
59 namespace yaml {
61 void MappingTraits<dsymutil::ValidReloc>::mapping(IO &io,
62 dsymutil::ValidReloc &VR) {
63 io.mapRequired("offset", VR.Offset);
64 io.mapRequired("size", VR.Size);
65 io.mapRequired("addend", VR.Addend);
66 io.mapRequired("symName", VR.SymbolName);
67 io.mapOptional("symObjAddr", VR.SymbolMapping.ObjectAddress);
68 io.mapRequired("symBinAddr", VR.SymbolMapping.BinaryAddress);
69 io.mapRequired("symSize", VR.SymbolMapping.Size);
72 void MappingTraits<dsymutil::RelocationMap>::mapping(
73 IO &io, dsymutil::RelocationMap &RM) {
74 io.mapRequired("triple", RM.BinaryTriple);
75 io.mapRequired("binary-path", RM.BinaryPath);
76 if (void *Ctxt = io.getContext())
77 reinterpret_cast<YAMLContext *>(Ctxt)->BinaryTriple = RM.BinaryTriple;
78 io.mapRequired("relocations", RM.Relocations);
81 void MappingTraits<std::unique_ptr<dsymutil::RelocationMap>>::mapping(
82 IO &io, std::unique_ptr<dsymutil::RelocationMap> &RM) {
83 if (!RM)
84 RM.reset(new RelocationMap());
85 io.mapRequired("triple", RM->BinaryTriple);
86 io.mapRequired("binary-path", RM->BinaryPath);
87 if (void *Ctxt = io.getContext())
88 reinterpret_cast<YAMLContext *>(Ctxt)->BinaryTriple = RM->BinaryTriple;
89 io.mapRequired("relocations", RM->Relocations);
91 } // end namespace yaml
92 } // end namespace llvm