diff --git a/lld/MachO/ConcatOutputSection.cpp b/lld/MachO/ConcatOutputSection.cpp --- a/lld/MachO/ConcatOutputSection.cpp +++ b/lld/MachO/ConcatOutputSection.cpp @@ -192,7 +192,6 @@ isecAddr = alignTo(isecAddr, isec->align); isecFileOff = alignTo(isecFileOff, isec->align); isec->outSecOff = isecAddr - addr; - isec->outSecFileOff = isecFileOff - fileOff; isec->isFinal = true; isecAddr += isec->getSize(); isecFileOff += isec->getFileSize(); @@ -323,11 +322,11 @@ while (i < ie || t < te) { while (i < ie && (t == te || inputs[i]->getSize() == 0 || inputs[i]->outSecOff < thunks[t]->outSecOff)) { - inputs[i]->writeTo(buf + inputs[i]->outSecFileOff); + inputs[i]->writeTo(buf + inputs[i]->outSecOff); ++i; } while (t < te && (i == ie || thunks[t]->outSecOff < inputs[i]->outSecOff)) { - thunks[t]->writeTo(buf + thunks[t]->outSecFileOff); + thunks[t]->writeTo(buf + thunks[t]->outSecOff); ++t; } } diff --git a/lld/MachO/InputSection.h b/lld/MachO/InputSection.h --- a/lld/MachO/InputSection.h +++ b/lld/MachO/InputSection.h @@ -40,7 +40,6 @@ // offset from the beginning of its parent OutputSection. virtual uint64_t getOffset(uint64_t off) const = 0; // The offset from the beginning of the file. - virtual uint64_t getFileOffset(uint64_t off) const = 0; uint64_t getVA(uint64_t off) const; // Whether the data at \p off in this InputSection is live. virtual bool isLive(uint64_t off) const = 0; @@ -86,7 +85,6 @@ ArrayRef data, uint32_t align, uint32_t flags) : InputSection(ConcatKind, segname, name, file, data, align, flags) {} - uint64_t getFileOffset(uint64_t off) const override; uint64_t getOffset(uint64_t off) const override { return outSecOff + off; } uint64_t getVA() const { return InputSection::getVA(0); } // ConcatInputSections are entirely live or dead, so the offset is irrelevant. @@ -110,7 +108,6 @@ // How many symbols refer to this InputSection. uint32_t numRefs = 0; uint64_t outSecOff = 0; - uint64_t outSecFileOff = 0; }; // We allocate a lot of these and binary search on them, so they should be as @@ -145,7 +142,6 @@ ArrayRef data, uint32_t align, uint32_t flags) : InputSection(CStringLiteralKind, segname, name, file, data, align, flags) {} - uint64_t getFileOffset(uint64_t off) const override; uint64_t getOffset(uint64_t off) const override; bool isLive(uint64_t off) const override { return getStringPiece(off).live; } void markLive(uint64_t off) override { getStringPiece(off).live = true; } @@ -177,7 +173,6 @@ WordLiteralInputSection(StringRef segname, StringRef name, InputFile *file, ArrayRef data, uint32_t align, uint32_t flags); - uint64_t getFileOffset(uint64_t off) const override; uint64_t getOffset(uint64_t off) const override; bool isLive(uint64_t off) const override { return live[off >> power2LiteralSize]; diff --git a/lld/MachO/InputSection.cpp b/lld/MachO/InputSection.cpp --- a/lld/MachO/InputSection.cpp +++ b/lld/MachO/InputSection.cpp @@ -25,10 +25,6 @@ std::vector macho::inputSections; -uint64_t ConcatInputSection::getFileOffset(uint64_t off) const { - return parent->fileOff + outSecFileOff + off; -} - uint64_t InputSection::getFileSize() const { return isZeroFill(flags) ? 0 : getSize(); } @@ -119,10 +115,6 @@ return const_cast(this)->getStringPiece(off); } -uint64_t CStringInputSection::getFileOffset(uint64_t off) const { - return parent->fileOff + getOffset(off); -} - uint64_t CStringInputSection::getOffset(uint64_t off) const { const StringPiece &piece = getStringPiece(off); uint64_t addend = off - piece.inSecOff; @@ -152,10 +144,6 @@ live.resize(data.size() >> power2LiteralSize, !config->deadStrip); } -uint64_t WordLiteralInputSection::getFileOffset(uint64_t off) const { - return parent->fileOff + getOffset(off); -} - uint64_t WordLiteralInputSection::getOffset(uint64_t off) const { auto *osec = cast(parent); const uint8_t *buf = data.data(); diff --git a/lld/MachO/Symbols.h b/lld/MachO/Symbols.h --- a/lld/MachO/Symbols.h +++ b/lld/MachO/Symbols.h @@ -55,10 +55,6 @@ virtual uint64_t getVA() const { return 0; } - virtual uint64_t getFileOffset() const { - llvm_unreachable("attempt to get an offset from a non-defined symbol"); - } - virtual bool isWeakDef() const { llvm_unreachable("cannot be weak def"); } // Only undefined or dylib symbols can be weak references. A weak reference @@ -140,7 +136,6 @@ bool isAbsolute() const { return isec == nullptr; } uint64_t getVA() const override; - uint64_t getFileOffset() const override; static bool classof(const Symbol *s) { return s->kind() == DefinedKind; } diff --git a/lld/MachO/Symbols.cpp b/lld/MachO/Symbols.cpp --- a/lld/MachO/Symbols.cpp +++ b/lld/MachO/Symbols.cpp @@ -71,15 +71,6 @@ return isec->getVA(value); } -uint64_t Defined::getFileOffset() const { - if (isAbsolute()) { - error("absolute symbol " + toString(*this) + - " does not have a file offset"); - return 0; - } - return isec->getFileOffset(value); -} - uint64_t DylibSymbol::getVA() const { return isInStubs() ? getStubVA() : Symbol::getVA(); } diff --git a/lld/MachO/UnwindInfoSection.cpp b/lld/MachO/UnwindInfoSection.cpp --- a/lld/MachO/UnwindInfoSection.cpp +++ b/lld/MachO/UnwindInfoSection.cpp @@ -218,7 +218,7 @@ assert(isec->parent == compactUnwindSection); uint8_t *buf = - reinterpret_cast(cuVector.data()) + isec->outSecFileOff; + reinterpret_cast(cuVector.data()) + isec->outSecOff; memcpy(buf, isec->data.data(), isec->data.size()); for (const Reloc &r : isec->relocs) { diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp --- a/lld/MachO/Writer.cpp +++ b/lld/MachO/Writer.cpp @@ -240,7 +240,7 @@ c->entryoff = in.stubs->fileOff + config->entry->stubsIndex * target->stubSize; else - c->entryoff = config->entry->getFileOffset(); + c->entryoff = config->entry->getVA() - in.header->addr; c->stacksize = 0; }