1 //===- Target.cpp ---------------------------------------------------------===// 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 #include "Target.h" 10 #include "InputSection.h" 11 #include "Symbols.h" 12 #include "SyntheticSections.h" 13 14 #include "lld/Common/ErrorHandler.h" 15 16 using namespace llvm; 17 using namespace lld; 18 using namespace lld::macho; 19 20 const TargetInfo::RelocAttrs TargetInfo::invalidRelocAttrs{"INVALID", 21 RelocAttrBits::_0}; 22 23 bool TargetInfo::validateSymbolRelocation(const Symbol *sym, 24 const InputSection *isec, 25 const Reloc &r) { 26 const RelocAttrs &relocAttrs = getRelocAttrs(r.type); 27 bool valid = true; 28 auto message = [relocAttrs, sym, isec, &valid](const Twine &diagnostic) { 29 valid = false; 30 return (relocAttrs.name + " relocation " + diagnostic + " for `" + 31 sym->getName() + "' in " + toString(isec)) 32 .str(); 33 }; 34 35 if ((relocAttrs.hasAttr(RelocAttrBits::TLV) && 36 !relocAttrs.hasAttr(RelocAttrBits::BYTE8)) != sym->isTlv()) 37 error(message(Twine("requires that variable ") + 38 (sym->isTlv() ? "not " : "") + "be thread-local")); 39 if (relocAttrs.hasAttr(RelocAttrBits::DYSYM8) && isa<DylibSymbol>(sym) && 40 r.length != 3) 41 error(message("has width " + std::to_string(1 << r.length) + 42 " bytes, but must be 8 bytes")); 43 44 return valid; 45 } 46 47 TargetInfo *macho::target = nullptr; 48