1 //===- Relocations.cpp ----------------------------------------------------===//
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 "Relocations.h"
11 #include "SyntheticSections.h"
14 #include "lld/Common/ErrorHandler.h"
18 using namespace lld::macho
;
20 bool macho::validateSymbolRelocation(const Symbol
*sym
,
21 const InputSection
*isec
, const Reloc
&r
) {
22 const RelocAttrs
&relocAttrs
= target
->getRelocAttrs(r
.type
);
24 auto message
= [relocAttrs
, sym
, isec
, &valid
](const Twine
&diagnostic
) {
26 return (relocAttrs
.name
+ " relocation " + diagnostic
+ " for `" +
27 sym
->getName() + "' in " + toString(isec
))
31 if (relocAttrs
.hasAttr(RelocAttrBits::TLV
) != sym
->isTlv())
32 error(message(Twine("requires that variable ") +
33 (sym
->isTlv() ? "not " : "") + "be thread-local"));
38 void macho::reportRangeError(const Reloc
&r
, const Twine
&v
, uint8_t bits
,
39 int64_t min
, uint64_t max
) {
41 if (auto *sym
= r
.referent
.dyn_cast
<Symbol
*>())
42 hint
= "; references " + toString(*sym
);
43 // TODO: get location of reloc using something like LLD-ELF's getErrorPlace()
44 error("relocation " + target
->getRelocAttrs(r
.type
).name
+
45 " is out of range: " + v
+ " is not in [" + Twine(min
) + ", " +
46 Twine(max
) + "]" + hint
);
49 void macho::reportRangeError(SymbolDiagnostic d
, const Twine
&v
, uint8_t bits
,
50 int64_t min
, uint64_t max
) {
53 hint
= "; references " + toString(*d
.symbol
);
54 error(d
.reason
+ " is out of range: " + v
+ " is not in [" + Twine(min
) +
55 ", " + Twine(max
) + "]" + hint
);
58 const RelocAttrs
macho::invalidRelocAttrs
{"INVALID", RelocAttrBits::_0
};