1 //===- Symbols.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 "Symbols.h" 10 #include "InputFiles.h" 11 #include "SyntheticSections.h" 12 13 using namespace llvm; 14 using namespace lld; 15 using namespace lld::macho; 16 17 // Returns a symbol for an error message. 18 static std::string demangle(StringRef symName) { 19 if (config->demangle) 20 return demangleItanium(symName); 21 return std::string(symName); 22 } 23 24 std::string lld::toString(const Symbol &sym) { return demangle(sym.getName()); } 25 26 std::string lld::toMachOString(const object::Archive::Symbol &b) { 27 return demangle(b.getName()); 28 } 29 30 uint64_t Defined::getVA() const { 31 if (isAbsolute()) 32 return value; 33 return isec->getVA() + value; 34 } 35 36 uint64_t Defined::getFileOffset() const { 37 if (isAbsolute()) { 38 error("absolute symbol " + toString(*this) + 39 " does not have a file offset"); 40 return 0; 41 } 42 return isec->getFileOffset() + value; 43 } 44 45 void LazySymbol::fetchArchiveMember() { getFile()->fetch(sym); } 46