comparison lld/MachO/Symbols.cpp @ 207:2e18cbf3894f

LLVM12
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 08 Jun 2021 06:07:14 +0900
parents 0572611fdcc8
children 5f17cb93ff66
comparison
equal deleted inserted replaced
173:0572611fdcc8 207:2e18cbf3894f
6 // 6 //
7 //===----------------------------------------------------------------------===// 7 //===----------------------------------------------------------------------===//
8 8
9 #include "Symbols.h" 9 #include "Symbols.h"
10 #include "InputFiles.h" 10 #include "InputFiles.h"
11 #include "lld/Common/ErrorHandler.h" 11 #include "SyntheticSections.h"
12 #include "lld/Common/Strings.h"
13 12
14 using namespace llvm; 13 using namespace llvm;
15 using namespace lld; 14 using namespace lld;
16 using namespace lld::macho; 15 using namespace lld::macho;
17 16
18 void LazySymbol::fetchArchiveMember() { file->fetch(sym); } 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 }
19 23
20 // Returns a symbol for an error message. 24 std::string lld::toString(const Symbol &sym) { return demangle(sym.getName()); }
21 std::string lld::toString(const Symbol &sym) { 25
22 if (Optional<std::string> s = demangleItanium(sym.getName())) 26 std::string lld::toMachOString(const object::Archive::Symbol &b) {
23 return *s; 27 return demangle(b.getName());
24 return std::string(sym.getName());
25 } 28 }
29
30 uint64_t Symbol::getStubVA() const { return in.stubs->getVA(stubsIndex); }
31 uint64_t Symbol::getGotVA() const { return in.got->getVA(gotIndex); }
32 uint64_t Symbol::getTlvVA() const { return in.tlvPointers->getVA(gotIndex); }
33
34 bool Symbol::isLive() const {
35 if (isa<DylibSymbol>(this) || isa<Undefined>(this))
36 return used;
37
38 if (auto *d = dyn_cast<Defined>(this)) {
39 // Non-absolute symbols might be alive because their section is
40 // no_dead_strip or live_support. In that case, the section will know
41 // that it's live but `used` might be false. Non-absolute symbols always
42 // have to use the section's `live` bit as source of truth.
43 return d->isAbsolute() ? used : d->isec->live;
44 }
45
46 assert(!isa<CommonSymbol>(this) &&
47 "replaceCommonSymbols() runs before dead code stripping, and isLive() "
48 "should only be called after dead code stripping");
49
50 // Assume any other kind of symbol is live.
51 return true;
52 }
53
54 uint64_t Defined::getVA() const {
55 assert(isLive() && "this should only be called for live symbols");
56
57 if (isAbsolute())
58 return value;
59
60 if (!isec->isFinal) {
61 // A target arch that does not use thunks ought never ask for
62 // the address of a function that has not yet been finalized.
63 assert(target->usesThunks());
64
65 // ConcatOutputSection::finalize() can seek the address of a
66 // function before its address is assigned. The thunking algorithm
67 // knows that unfinalized functions will be out of range, so it is
68 // expedient to return a contrived out-of-range address.
69 return TargetInfo::outOfRangeVA;
70 }
71 return isec->getVA() + value;
72 }
73
74 uint64_t Defined::getFileOffset() const {
75 if (isAbsolute()) {
76 error("absolute symbol " + toString(*this) +
77 " does not have a file offset");
78 return 0;
79 }
80 return isec->getFileOffset() + value;
81 }
82
83 uint64_t DylibSymbol::getVA() const {
84 return isInStubs() ? getStubVA() : Symbol::getVA();
85 }
86
87 void LazySymbol::fetchArchiveMember() { getFile()->fetch(sym); }