Lines Matching full:atom
48 const DefinedAtom *atom; member
115 void processAtomAttributes(const DefinedAtom *atom);
116 void assignAtomToSection(const DefinedAtom *atom);
150 typedef llvm::DenseMap<const Atom*, uint64_t> AtomToAddress;
158 void appendAtom(SectionInfo *sect, const DefinedAtom *atom);
163 uint16_t descBits(const DefinedAtom* atom);
167 const Atom *targetOfLazyPointer(const DefinedAtom *lpAtom);
168 const Atom *targetOfStub(const DefinedAtom *stubAtom);
169 llvm::Error getSymbolTableRegion(const DefinedAtom* atom,
173 uint32_t sectionIndexForAtom(const Atom *atom);
174 void fixLazyReferenceImm(const DefinedAtom *atom, uint32_t offset,
177 typedef llvm::DenseMap<const Atom*, uint32_t> AtomToIndex;
178 struct AtomAndIndex { const Atom *atom; uint32_t index; SymbolScope scope; }; member
202 std::vector<const Atom *> _machHeaderAliasAtoms;
343 SectionInfo *Util::sectionForAtom(const DefinedAtom *atom) { in sectionForAtom() argument
344 if (atom->sectionChoice() == DefinedAtom::sectionBasedOnContent) { in sectionForAtom()
345 // Section for this atom is derived from content type. in sectionForAtom()
346 DefinedAtom::ContentType type = atom->contentType(); in sectionForAtom()
353 // This atom needs to be in a custom section. in sectionForAtom()
354 StringRef customName = atom->customSectionName(); in sectionForAtom()
357 const DefinedAtom *firstAtom = sect->atomsAndOffsets.front().atom; in sectionForAtom()
376 void Util::appendAtom(SectionInfo *sect, const DefinedAtom *atom) { in appendAtom() argument
377 // Figure out offset for atom in this section given alignment constraints. in appendAtom()
379 DefinedAtom::Alignment atomAlign = atom->alignment(); in appendAtom()
389 // Record max alignment of any atom in this section. in appendAtom()
392 // Assign atom to this section with this offset. in appendAtom()
393 AtomInfo ai = {atom, offset}; in appendAtom()
395 // Update section size to include this atom. in appendAtom()
396 sect->size = offset + atom->size(); in appendAtom()
400 for (const DefinedAtom *atom : atomFile.defined()) { in processDefinedAtoms() local
401 processAtomAttributes(atom); in processDefinedAtoms()
402 assignAtomToSection(atom); in processDefinedAtoms()
406 void Util::processAtomAttributes(const DefinedAtom *atom) { in processAtomAttributes() argument
407 if (auto *machoFile = dyn_cast<mach_o::MachOFile>(&atom->file())) { in processAtomAttributes()
428 void Util::assignAtomToSection(const DefinedAtom *atom) { in assignAtomToSection() argument
429 if (atom->contentType() == DefinedAtom::typeMachHeader) { in assignAtomToSection()
430 _machHeaderAliasAtoms.push_back(atom); in assignAtomToSection()
431 // Assign atom to this section with this offset. in assignAtomToSection()
432 AtomInfo ai = {atom, 0}; in assignAtomToSection()
433 sectionForAtom(atom)->atomsAndOffsets.push_back(ai); in assignAtomToSection()
434 } else if (atom->contentType() == DefinedAtom::typeDSOHandle) in assignAtomToSection()
435 _machHeaderAliasAtoms.push_back(atom); in assignAtomToSection()
437 appendAtom(sectionForAtom(atom), atom); in assignAtomToSection()
656 // Utility function for ArchHandler to find address of atom in output file. in copySectionContent()
657 auto addrForAtom = [&] (const Atom &atom) -> uint64_t { in copySectionContent() argument
658 auto pos = _atomToAddress.find(&atom); in copySectionContent()
663 auto sectionAddrForAtom = [&] (const Atom &atom) -> uint64_t { in copySectionContent() argument
666 if (atomInfo.atom == &atom) in copySectionContent()
668 llvm_unreachable("atom not assigned to section"); in copySectionContent()
686 if (!ai.atom->size()) { in copySectionContent()
687 assert(ai.atom->begin() == ai.atom->end() && in copySectionContent()
692 ai.atom->size()); in copySectionContent()
693 _archHandler.generateAtomContent(*ai.atom, r, addrForAtom, in copySectionContent()
740 << "assign atom addresses:\n"); in buildAtomToAddressMap()
744 _atomToAddress[info.atom] = sect->address + info.offsetInSection; in buildAtomToAddressMap()
745 if (lookForEntry && (info.atom->contentType() == DefinedAtom::typeCode) && in buildAtomToAddressMap()
746 (info.atom->size() != 0) && in buildAtomToAddressMap()
747 info.atom->name() == _ctx.entrySymbolName()) { in buildAtomToAddressMap()
748 _entryAtom = info.atom; in buildAtomToAddressMap()
752 << llvm::format("0x%016X", _atomToAddress[info.atom]) in buildAtomToAddressMap()
753 << llvm::format(" 0x%09lX", info.atom) in buildAtomToAddressMap()
755 << info.atom->file().ordinal() in buildAtomToAddressMap()
756 << ", atom=#" in buildAtomToAddressMap()
757 << info.atom->ordinal() in buildAtomToAddressMap()
759 << info.atom->name() in buildAtomToAddressMap()
761 << info.atom->contentType() in buildAtomToAddressMap()
766 << "assign header alias atom addresses:\n"); in buildAtomToAddressMap()
767 for (const Atom *atom : _machHeaderAliasAtoms) { in buildAtomToAddressMap() local
768 _atomToAddress[atom] = _ctx.baseAddress(); in buildAtomToAddressMap()
770 if (auto *definedAtom = dyn_cast<DefinedAtom>(atom)) { in buildAtomToAddressMap()
773 << llvm::format("0x%016X", _atomToAddress[atom]) in buildAtomToAddressMap()
774 << llvm::format(" 0x%09lX", atom) in buildAtomToAddressMap()
777 << ", atom=#" in buildAtomToAddressMap()
787 << llvm::format("0x%016X", _atomToAddress[atom]) in buildAtomToAddressMap()
788 << " atom=" << atom in buildAtomToAddressMap()
789 << " name=" << atom->name() << "\n"); in buildAtomToAddressMap()
808 if (const DefinedAtom *atom = dyn_cast<DefinedAtom>(info.atom)) { in synthesizeDebugNotes() local
814 if (atom->contentType() == DefinedAtom::typeCFI || in synthesizeDebugNotes()
815 atom->contentType() == DefinedAtom::typeCString) in synthesizeDebugNotes()
819 if (&info.atom->file() != objFile) { in synthesizeDebugNotes()
822 dyn_cast<mach_o::MachOFile>(&info.atom->file())) { in synthesizeDebugNotes()
832 // If this atom is from a file that needs dwarf, add it to the list. in synthesizeDebugNotes()
834 atomsNeedingDebugNotes.push_back(info.atom); in synthesizeDebugNotes()
839 // Sort atoms needing debug notes by file ordinal, then atom ordinal. in synthesizeDebugNotes()
855 for (const DefinedAtom *atom : atomsNeedingDebugNotes) { in synthesizeDebugNotes() local
856 const auto &atomFile = cast<mach_o::MachOFile>(atom->file()); in synthesizeDebugNotes()
858 && "file for atom needing debug notes does not contain dwarf"); in synthesizeDebugNotes()
912 if (atom->contentType() == DefinedAtom::typeCode) { in synthesizeDebugNotes()
914 _stabs.push_back(mach_o::Stab(atom, N_BNSYM, 1, 0, 0, "")); in synthesizeDebugNotes()
915 _stabs.push_back(mach_o::Stab(atom, N_FUN, 1, 0, 0, atom->name())); in synthesizeDebugNotes()
919 atom->rawContent().size(), "")); in synthesizeDebugNotes()
921 atom->rawContent().size(), "")); in synthesizeDebugNotes()
923 if (atom->scope() == Atom::scopeTranslationUnit) in synthesizeDebugNotes()
924 _stabs.push_back(mach_o::Stab(atom, N_STSYM, 1, 0, 0, atom->name())); in synthesizeDebugNotes()
926 _stabs.push_back(mach_o::Stab(nullptr, N_GSYM, 1, 0, 0, atom->name())); in synthesizeDebugNotes()
947 uint16_t Util::descBits(const DefinedAtom* atom) { in descBits() argument
949 switch (atom->merge()) { in descBits()
963 if (atom->contentType() == lld::DefinedAtom::typeResolver) in descBits()
965 if (atom->contentType() == lld::DefinedAtom::typeMachHeader) in descBits()
967 if (_archHandler.isThumbFunction(*atom)) in descBits()
969 if (atom->deadStrip() == DefinedAtom::deadStripNever && in descBits()
971 if ((atom->contentType() != DefinedAtom::typeInitializerPtr) in descBits()
972 && (atom->contentType() != DefinedAtom::typeTerminatorPtr)) in descBits()
980 return (left.atom->name().compare(right.atom->name()) < 0); in operator ()()
983 llvm::Error Util::getSymbolTableRegion(const DefinedAtom* atom, in getSymbolTableRegion() argument
987 switch (atom->scope()) { in getSymbolTableRegion()
988 case Atom::scopeTranslationUnit: in getSymbolTableRegion()
992 case Atom::scopeLinkageUnit: in getSymbolTableRegion()
994 _ctx.exportSymbolNamed(atom->name())) { in getSymbolTableRegion()
996 Twine("cannot export hidden symbol ") + atom->name()); in getSymbolTableRegion()
1010 case Atom::scopeGlobal: in getSymbolTableRegion()
1012 if (_ctx.exportSymbolNamed(atom->name())) { in getSymbolTableRegion()
1028 llvm_unreachable("atom->scope() unknown enum value"); in getSymbolTableRegion()
1045 if (stab.atom) in addSymbols()
1046 sym.value = _atomToAddress[stab.atom]; in addSymbols()
1058 const DefinedAtom *atom = info.atom; in addSymbols() local
1059 if (!atom->name().empty()) { in addSymbols()
1062 if (auto ec = getSymbolTableRegion(atom, inGlobalsRegion, symbolScope)){ in addSymbols()
1066 AtomAndIndex ai = { atom, sect->finalSectionIndex, symbolScope }; in addSymbols()
1070 sym.name = atom->name(); in addSymbols()
1074 sym.desc = descBits(atom); in addSymbols()
1075 sym.value = _atomToAddress[atom]; in addSymbols()
1076 _atomToSymbolIndex[atom] = file.localSymbols.size(); in addSymbols()
1079 } else if (rMode && _archHandler.needsLocalSymbolInRelocatableFile(atom)){ in addSymbols()
1091 sym.value = _atomToAddress[atom]; in addSymbols()
1092 _atomToSymbolIndex[atom] = file.localSymbols.size(); in addSymbols()
1103 sym.name = ai.atom->name(); in addSymbols()
1107 sym.desc = descBits(static_cast<const DefinedAtom*>(ai.atom)); in addSymbols()
1108 sym.value = _atomToAddress[ai.atom]; in addSymbols()
1109 _atomToSymbolIndex[ai.atom] = globalStartIndex + file.globalSymbols.size(); in addSymbols()
1116 for (const UndefinedAtom *atom : atomFile.undefined()) { in addSymbols() local
1117 AtomAndIndex ai = { atom, 0, N_EXT }; in addSymbols()
1120 for (const SharedLibraryAtom *atom : atomFile.sharedLibrary()) { in addSymbols() local
1121 AtomAndIndex ai = { atom, 0, N_EXT }; in addSymbols()
1132 ordinal = dylibOrdinal(dyn_cast<SharedLibraryAtom>(ai.atom)); in addSymbols()
1135 sym.name = ai.atom->name(); in addSymbols()
1141 _atomToSymbolIndex[ai.atom] = file.undefinedSymbols.size() + start; in addSymbols()
1148 const Atom *Util::targetOfLazyPointer(const DefinedAtom *lpAtom) { in targetOfLazyPointer()
1157 const Atom *Util::targetOfStub(const DefinedAtom *stubAtom) { in targetOfStub()
1159 if (const Atom *ta = ref->target()) { in targetOfStub()
1161 const Atom *target = targetOfLazyPointer(lpAtom); in targetOfStub()
1177 for (const Reference *ref : *info.atom) { in addIndirectSymbols()
1178 const Atom *target = ref->target(); in addIndirectSymbols()
1198 const Atom *target = targetOfLazyPointer(info.atom); in addIndirectSymbols()
1207 const Atom *target = targetOfStub(info.atom); in addIndirectSymbols()
1230 // If we're in -flat_namespace mode (or this atom came from the flat in addDependentDylibs()
1241 // Unless this was a flat_namespace atom, record the source dylib. in addDependentDylibs()
1283 uint32_t Util::sectionIndexForAtom(const Atom *atom) { in sectionIndexForAtom() argument
1284 uint64_t address = _atomToAddress[atom]; in sectionIndexForAtom()
1289 llvm_unreachable("atom not in any section"); in sectionIndexForAtom()
1296 // Utility function for ArchHandler to find symbol index for an atom. in addSectionRelocs()
1297 auto symIndexForAtom = [&] (const Atom &atom) -> uint32_t { in addSectionRelocs() argument
1298 auto pos = _atomToSymbolIndex.find(&atom); in addSectionRelocs()
1303 // Utility function for ArchHandler to find section index for an atom. in addSectionRelocs()
1304 auto sectIndexForAtom = [&] (const Atom &atom) -> uint32_t { in addSectionRelocs() argument
1305 return sectionIndexForAtom(&atom); in addSectionRelocs()
1308 // Utility function for ArchHandler to find address of atom in output file. in addSectionRelocs()
1309 auto addressForAtom = [&] (const Atom &atom) -> uint64_t { in addSectionRelocs() argument
1310 auto pos = _atomToAddress.find(&atom); in addSectionRelocs()
1318 const DefinedAtom *atom = info.atom; in addSectionRelocs() local
1319 for (const Reference *ref : *atom) { in addSectionRelocs()
1325 _archHandler.appendSectionRelocations(*atom, info.offsetInSection, *ref, in addSectionRelocs()
1344 auto type = info.atom->contentType(); in addFunctionStarts()
1346 addr = _atomToAddress[info.atom]; in addFunctionStarts()
1354 if (!info.atom->size()) in addFunctionStarts()
1356 uint64_t nextAddr = _atomToAddress[info.atom]; in addFunctionStarts()
1357 if (_archHandler.isThumbFunction(*info.atom)) in addFunctionStarts()
1390 for (const Reference *ref : *info.atom) { in buildDataInCodeArray()
1413 entry.length = info.atom->size() - startOffset; in buildDataInCodeArray()
1433 const DefinedAtom *atom = info.atom; in addRebaseAndBindingInfo() local
1434 for (const Reference *ref : *atom) { in addRebaseAndBindingInfo()
1435 uint64_t segmentOffset = _atomToAddress[atom] + ref->offsetInAtom() in addRebaseAndBindingInfo()
1437 const Atom* targ = ref->target(); in addRebaseAndBindingInfo()
1478 fixLazyReferenceImm(atom, offsetInBindInfo, nFile); in addRebaseAndBindingInfo()
1492 void Util::fixLazyReferenceImm(const DefinedAtom *atom, uint32_t offset, in fixLazyReferenceImm() argument
1494 for (const Reference *ref : *atom) { in fixLazyReferenceImm()
1509 // TODO: maybe get the fixed atom content from _archHandler ? in fixLazyReferenceImm()
1512 if (atomInfo.atom == helperRef->target()) { in fixLazyReferenceImm()
1539 const DefinedAtom *atom = info.atom; in addExportInfo() local
1540 if (atom->scope() != Atom::scopeGlobal) in addExportInfo()
1543 if (!_ctx.exportSymbolNamed(atom->name())) in addExportInfo()
1547 exprt.name = atom->name(); in addExportInfo()
1548 exprt.offset = _atomToAddress[atom] - _ctx.baseAddress(); in addExportInfo()
1550 if (atom->merge() == DefinedAtom::mergeAsWeak) in addExportInfo()