1 //===- tools/dsymutil/RelocationMap.cpp - Relocation map representation---===//
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
7 //===----------------------------------------------------------------------===//
9 #include "RelocationMap.h"
15 void RelocationMap::print(raw_ostream
&OS
) const {
16 yaml::Output
yout(OS
, /* Ctxt = */ nullptr, /* WrapColumn = */ 0);
17 yout
<< const_cast<RelocationMap
&>(*this);
21 void RelocationMap::dump() const { print(errs()); }
24 void RelocationMap::addRelocationMapEntry(const ValidReloc
&Relocation
) {
25 Relocations
.push_back(Relocation
);
31 StringRef PrependPath
;
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())
46 Ctxt
.PrependPath
= PrependPath
;
48 std::unique_ptr
<RelocationMap
> Result
;
49 yaml::Input
yin((*ErrOrFile
)->getBuffer(), &Ctxt
);
52 if (auto EC
= yin
.error())
54 return std::move(Result
);
57 } // end namespace dsymutil
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
) {
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