xref: /freebsd/contrib/llvm-project/lld/MachO/Symbols.cpp (revision 0d8fe2373503aeac48492f28073049a8bfa4feb5)
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) {
25   return demangle(sym.getName());
26 }
27 
28 std::string lld::toMachOString(const object::Archive::Symbol &b) {
29   return demangle(b.getName());
30 }
31 
32 uint64_t Defined::getVA() const {
33   if (isAbsolute())
34     return value;
35   return isec->getVA() + value;
36 }
37 
38 uint64_t Defined::getFileOffset() const {
39   if (isAbsolute()) {
40     error("absolute symbol " + toString(*this) +
41           " does not have a file offset");
42     return 0;
43   }
44   return isec->getFileOffset() + value;
45 }
46 
47 void LazySymbol::fetchArchiveMember() { file->fetch(sym); }
48 
49 uint64_t DSOHandle::getVA() const { return header->addr; }
50 
51 uint64_t DSOHandle::getFileOffset() const { return header->fileOff; }
52 
53 constexpr StringRef DSOHandle::name;
54