comparison lld/MachO/Symbols.cpp @ 223:5f17cb93ff66 llvm-original

LLVM13 (2021/7/18)
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 18 Jul 2021 22:43:00 +0900
parents 79ff65ed7e25
children c4bab56944e8
comparison
equal deleted inserted replaced
222:81f6424ef0e3 223:5f17cb93ff66
38 if (auto *d = dyn_cast<Defined>(this)) { 38 if (auto *d = dyn_cast<Defined>(this)) {
39 // Non-absolute symbols might be alive because their section is 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 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 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. 42 // have to use the section's `live` bit as source of truth.
43 return d->isAbsolute() ? used : d->isec->live; 43 if (d->isAbsolute())
44 return used;
45 return d->isec->canonical()->isLive(d->value);
44 } 46 }
45 47
46 assert(!isa<CommonSymbol>(this) && 48 assert(!isa<CommonSymbol>(this) &&
47 "replaceCommonSymbols() runs before dead code stripping, and isLive() " 49 "replaceCommonSymbols() runs before dead code stripping, and isLive() "
48 "should only be called after dead code stripping"); 50 "should only be called after dead code stripping");
55 assert(isLive() && "this should only be called for live symbols"); 57 assert(isLive() && "this should only be called for live symbols");
56 58
57 if (isAbsolute()) 59 if (isAbsolute())
58 return value; 60 return value;
59 61
60 if (!isec->isFinal) { 62 if (!isec->canonical()->isFinal) {
61 // A target arch that does not use thunks ought never ask for 63 // A target arch that does not use thunks ought never ask for
62 // the address of a function that has not yet been finalized. 64 // the address of a function that has not yet been finalized.
63 assert(target->usesThunks()); 65 assert(target->usesThunks());
64 66
65 // ConcatOutputSection::finalize() can seek the address of a 67 // ConcatOutputSection::finalize() can seek the address of a
66 // function before its address is assigned. The thunking algorithm 68 // function before its address is assigned. The thunking algorithm
67 // knows that unfinalized functions will be out of range, so it is 69 // knows that unfinalized functions will be out of range, so it is
68 // expedient to return a contrived out-of-range address. 70 // expedient to return a contrived out-of-range address.
69 return TargetInfo::outOfRangeVA; 71 return TargetInfo::outOfRangeVA;
70 } 72 }
71 return isec->getVA() + value; 73 return isec->canonical()->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 } 74 }
82 75
83 uint64_t DylibSymbol::getVA() const { 76 uint64_t DylibSymbol::getVA() const {
84 return isInStubs() ? getStubVA() : Symbol::getVA(); 77 return isInStubs() ? getStubVA() : Symbol::getVA();
85 } 78 }