diff --git a/lld/MachO/ExportTrie.cpp b/lld/MachO/ExportTrie.cpp --- a/lld/MachO/ExportTrie.cpp +++ b/lld/MachO/ExportTrie.cpp @@ -178,7 +178,7 @@ 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 call: // multikeySort(vec.slice(i, j - i), lastPos, pos + 1, node); diff --git a/lld/MachO/InputSection.cpp b/lld/MachO/InputSection.cpp --- a/lld/MachO/InputSection.cpp +++ b/lld/MachO/InputSection.cpp @@ -32,7 +32,7 @@ uint64_t va = 0; if (auto *s = r.target.dyn_cast()) { if (auto *dylibSymbol = dyn_cast(s)) { - va = in.got->addr - ImageBase + dylibSymbol->gotIndex * WordSize; + va = in.got->addr + dylibSymbol->gotIndex * WordSize; } else { va = s->getVA(); } @@ -43,7 +43,7 @@ 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); } } diff --git a/lld/MachO/Symbols.h b/lld/MachO/Symbols.h --- a/lld/MachO/Symbols.h +++ b/lld/MachO/Symbols.h @@ -81,7 +81,7 @@ inline uint64_t Symbol::getVA() const { if (auto *d = dyn_cast(this)) - return d->isec->addr + d->value - ImageBase; + return d->isec->addr + d->value; return 0; } diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp --- a/lld/MachO/Writer.cpp +++ b/lld/MachO/Writer.cpp @@ -162,7 +162,7 @@ auto *c = reinterpret_cast(buf); c->cmd = LC_MAIN; c->cmdsize = getSize(); - c->entryoff = config->entry->getVA(); + c->entryoff = config->entry->getVA() - ImageBase; c->stacksize = 0; } };