Currently, getVA() returns a virtual address with the assumption that
the ImageBase is zero. As I understand, this is what lld-ELF is doing.
However, under our current design, it seems like an awkward setup --
I'm finding that I have to add and subtract ImageBase in several places
to make things work out.
As such, I think it's simpler to have getVA() return a non-relative VA,
but I'm not sure if I'm missing something. Would love to hear more from
folks familiar with lld-ELF.
Differential Revision: https://reviews.llvm.org/D78168
if (isTerminal) {
assert(j - i == 1); // no duplicate symbols
- node->info = {pivotSymbol->getVA() + ImageBase};
+ node->info = {pivotSymbol->getVA()};
} else {
// This is the tail-call-optimized version of the following:
// sortAndBuild(vec.slice(i, j - i), node, lastPos, pos + 1);
uint64_t va = 0;
if (auto *s = r.target.dyn_cast<Symbol *>()) {
if (auto *dylibSymbol = dyn_cast<DylibSymbol>(s)) {
- va = in.got->addr - ImageBase + dylibSymbol->gotIndex * WordSize;
+ va = in.got->addr + dylibSymbol->gotIndex * WordSize;
} else {
va = s->getVA();
}
uint64_t val = va + r.addend;
if (1) // TODO: handle non-pcrel relocations
- val -= addr - ImageBase + r.offset;
+ val -= addr + r.offset;
target->relocateOne(buf + r.offset, r.type, val);
}
}
inline uint64_t Symbol::getVA() const {
if (auto *d = dyn_cast<Defined>(this))
- return d->isec->addr + d->value - ImageBase;
+ return d->isec->addr + d->value;
return 0;
}
auto *c = reinterpret_cast<entry_point_command *>(buf);
c->cmd = LC_MAIN;
c->cmdsize = getSize();
- c->entryoff = config->entry->getVA();
+ c->entryoff = config->entry->getVA() - ImageBase;
c->stacksize = 0;
}
};