| ... | ... | @@ -172,6 +172,8 @@ private: |
| 172 | 172 | SymbolScope &symbolScope); |
| 173 | 173 | void appendSection(SectionInfo *si, NormalizedFile &file); |
| 174 | 174 | uint32_t sectionIndexForAtom(const Atom *atom); |
| 175 | void fixLazyReferenceImm(const DefinedAtom *atom, uint32_t offset, |
| 176 | NormalizedFile &file); |
| 175 | 177 | |
| 176 | 178 | typedef llvm::DenseMap<const Atom*, uint32_t> AtomToIndex; |
| 177 | 179 | struct AtomAndIndex { const Atom *atom; uint32_t index; SymbolScope scope; }; |
| ... | ... | @@ -1423,6 +1425,8 @@ void Util::addRebaseAndBindingInfo(const lld::File &atomFile, |
| 1423 | 1425 | |
| 1424 | 1426 | uint8_t segmentIndex; |
| 1425 | 1427 | uint64_t segmentStartAddr; |
| 1428 | uint32_t offsetInBindInfo = 0; |
| 1429 | |
| 1426 | 1430 | for (SectionInfo *sect : _sectionInfos) { |
| 1427 | 1431 | segIndexForSection(sect, segmentIndex, segmentStartAddr); |
| 1428 | 1432 | for (const AtomInfo &info : sect->atomsAndOffsets) { |
| ... | ... | @@ -1467,6 +1471,59 @@ void Util::addRebaseAndBindingInfo(const lld::File &atomFile, |
| 1467 | 1471 | bind.symbolName = targ->name(); |
| 1468 | 1472 | bind.addend = ref->addend(); |
| 1469 | 1473 | nFile.lazyBindingInfo.push_back(bind); |
| 1474 | |
| 1475 | // Now that we know the segmentOffset and the ordinal attribute, |
| 1476 | // we can fix the helper's code |
| 1477 | |
| 1478 | fixLazyReferenceImm(atom, offsetInBindInfo, nFile); |
| 1479 | |
| 1480 | // 5 bytes for opcodes + variable sizes (target name + \0 and offset |
| 1481 | // encode's size) |
| 1482 | offsetInBindInfo += |
| 1483 | 6 + targ->name().size() + llvm::getULEB128Size(bind.segOffset); |
| 1484 | if (bind.ordinal > BIND_IMMEDIATE_MASK) |
| 1485 | offsetInBindInfo += llvm::getULEB128Size(bind.ordinal); |
| 1486 | } |
| 1487 | } |
| 1488 | } |
| 1489 | } |
| 1490 | } |
| 1491 | |
| 1492 | void Util::fixLazyReferenceImm(const DefinedAtom *atom, uint32_t offset, |
| 1493 | NormalizedFile &file) { |
| 1494 | for (const auto &ref : *atom) { |
| 1495 | const DefinedAtom *da = dyn_cast<DefinedAtom>(ref->target()); |
| 1496 | if (da == nullptr) |
| 1497 | return; |
| 1498 | |
| 1499 | const Reference *helperRef = nullptr; |
| 1500 | for (const Reference *hr : *da) { |
| 1501 | if (hr->kindValue() == _archHandler.lazyImmediateLocationKind()) { |
| 1502 | helperRef = hr; |
| 1503 | break; |
| 1504 | } |
| 1505 | } |
| 1506 | if (helperRef == nullptr) |
| 1507 | continue; |
| 1508 | |
| 1509 | // TODO: maybe get the fixed atom content from _archHandler ? |
| 1510 | for (SectionInfo *sectInfo : _sectionInfos) { |
| 1511 | for (const AtomInfo &atomInfo : sectInfo->atomsAndOffsets) { |
| 1512 | if (atomInfo.atom == helperRef->target()) { |
| 1513 | auto sectionContent = |
| 1514 | file.sections[sectInfo->normalizedSectionIndex].content; |
| 1515 | uint8_t *rawb = |
| 1516 | file.ownedAllocations.Allocate<uint8_t>(sectionContent.size()); |
| 1517 | llvm::MutableArrayRef<uint8_t> newContent{rawb, |
| 1518 | sectionContent.size()}; |
| 1519 | std::copy(sectionContent.begin(), sectionContent.end(), |
| 1520 | newContent.begin()); |
| 1521 | llvm::support::ulittle32_t *loc = |
| 1522 | reinterpret_cast<llvm::support::ulittle32_t *>( |
| 1523 | &newContent[atomInfo.offsetInSection + |
| 1524 | helperRef->offsetInAtom()]); |
| 1525 | *loc = offset; |
| 1526 | file.sections[sectInfo->normalizedSectionIndex].content = newContent; |
| 1470 | 1527 | } |
| 1471 | 1528 | } |
| 1472 | 1529 | } |