mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-23 22:00:10 +00:00
[lld/mac] Let OutputSegment store its start address
segment$start$/segment$end$ symbols allow creating segments without sections, so getting the segment address off the first section won't work there. Storing the address on the segment is arguably a bit simpler too. No behavior change, part of PR50760. Differential Revision: https://reviews.llvm.org/D106665
This commit is contained in:
parent
73a9d6d0e2
commit
9482aa98e5
@ -14,5 +14,5 @@ using namespace lld;
|
||||
using namespace lld::macho;
|
||||
|
||||
uint64_t OutputSection::getSegmentOffset() const {
|
||||
return addr - parent->firstSection()->addr;
|
||||
return addr - parent->addr;
|
||||
}
|
||||
|
@ -39,9 +39,6 @@ class InputSection;
|
||||
|
||||
class OutputSegment {
|
||||
public:
|
||||
const OutputSection *firstSection() const { return sections.front(); }
|
||||
const OutputSection *lastSection() const { return sections.back(); }
|
||||
|
||||
void addOutputSection(OutputSection *os);
|
||||
void sortOutputSections();
|
||||
|
||||
@ -50,6 +47,7 @@ public:
|
||||
|
||||
uint64_t fileOff = 0;
|
||||
uint64_t fileSize = 0;
|
||||
uint64_t addr = 0;
|
||||
uint64_t vmSize = 0;
|
||||
int inputOrder = UnspecifiedInputOrder;
|
||||
StringRef name;
|
||||
|
@ -693,7 +693,7 @@ uint32_t LazyBindingSection::encode(const DylibSymbol &sym) {
|
||||
OutputSegment *dataSeg = in.lazyPointers->parent;
|
||||
os << static_cast<uint8_t>(BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB |
|
||||
dataSeg->index);
|
||||
uint64_t offset = in.lazyPointers->addr - dataSeg->firstSection()->addr +
|
||||
uint64_t offset = in.lazyPointers->addr - dataSeg->addr +
|
||||
sym.stubsIndex * target->wordSize;
|
||||
encodeULEB128(offset, os);
|
||||
encodeDylibOrdinal(ordinalForDylibSymbol(sym), os);
|
||||
|
@ -239,10 +239,7 @@ public:
|
||||
c->maxprot = seg->maxProt;
|
||||
c->initprot = seg->initProt;
|
||||
|
||||
if (seg->getSections().empty())
|
||||
return;
|
||||
|
||||
c->vmaddr = seg->firstSection()->addr;
|
||||
c->vmaddr = seg->addr;
|
||||
c->vmsize = seg->vmSize;
|
||||
c->filesize = seg->fileSize;
|
||||
c->nsects = seg->numNonHiddenSections();
|
||||
@ -980,6 +977,7 @@ void Writer::finalizeAddresses() {
|
||||
for (OutputSegment *seg : outputSegments) {
|
||||
if (seg == linkEditSegment)
|
||||
continue;
|
||||
seg->addr = addr;
|
||||
assignAddresses(seg);
|
||||
// codesign / libstuff checks for segment ordering by verifying that
|
||||
// `fileOff + fileSize == next segment fileOff`. So we call alignTo() before
|
||||
@ -987,7 +985,7 @@ void Writer::finalizeAddresses() {
|
||||
// contiguous. We handle addr / vmSize similarly for the same reason.
|
||||
fileOff = alignTo(fileOff, pageSize);
|
||||
addr = alignTo(addr, pageSize);
|
||||
seg->vmSize = addr - seg->firstSection()->addr;
|
||||
seg->vmSize = addr - seg->addr;
|
||||
seg->fileSize = fileOff - seg->fileOff;
|
||||
}
|
||||
}
|
||||
@ -1013,9 +1011,10 @@ void Writer::finalizeLinkEditSegment() {
|
||||
|
||||
// Now that __LINKEDIT is filled out, do a proper calculation of its
|
||||
// addresses and offsets.
|
||||
linkEditSegment->addr = addr;
|
||||
assignAddresses(linkEditSegment);
|
||||
// No need to page-align fileOff / addr here since this is the last segment.
|
||||
linkEditSegment->vmSize = addr - linkEditSegment->firstSection()->addr;
|
||||
linkEditSegment->vmSize = addr - linkEditSegment->addr;
|
||||
linkEditSegment->fileSize = fileOff - linkEditSegment->fileOff;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user