llvm.org GIT mirror llvm / 776f864
Make getRelocationSection MachO only. There are 3 types of relocations on MachO * Scattered * Section based * Symbol based On ELF and COFF relocations are symbol based. We were in the strange situation that we abstracted over two of them. This makes section based relocations MachO only. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240149 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 4 years ago
7 changed file(s) with 9 addition(s) and 39 deletion(s). Raw diff Collapse all Expand all
640640 std::error_code getRelocationOffset(DataRefImpl Rel,
641641 uint64_t &Res) const override;
642642 symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
643 section_iterator getRelocationSection(DataRefImpl Rel) const override;
644643 std::error_code getRelocationType(DataRefImpl Rel,
645644 uint64_t &Res) const override;
646645 std::error_code
111111 std::error_code getRelocationOffset(DataRefImpl Rel,
112112 uint64_t &Res) const override;
113113 symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
114 section_iterator getRelocationSection(DataRefImpl Rel) const override;
115114 std::error_code getRelocationType(DataRefImpl Rel,
116115 uint64_t &Res) const override;
117116 std::error_code
581580 }
582581
583582 return symbol_iterator(SymbolRef(SymbolData, this));
584 }
585
586 // ELF relocations can target sections, by targetting a symbol of type
587 // STT_SECTION
588 template
589 section_iterator
590 ELFObjectFile::getRelocationSection(DataRefImpl Rel) const {
591 symbol_iterator Sym = getRelocationSymbol(Rel);
592 if (Sym == symbol_end())
593 return section_end();
594 const Elf_Sym *ESym = getSymbol(Sym->getRawDataRefImpl());
595 if (ESym->getType() != ELF::STT_SECTION)
596 return section_end();
597 return getSymbolSection(ESym);
598583 }
599584
600585 template
235235 std::error_code getRelocationOffset(DataRefImpl Rel,
236236 uint64_t &Res) const override;
237237 symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
238 section_iterator getRelocationSection(DataRefImpl Rel) const override;
238 section_iterator getRelocationSection(DataRefImpl Rel) const;
239239 std::error_code getRelocationType(DataRefImpl Rel,
240240 uint64_t &Res) const override;
241241 std::error_code
5252 std::error_code getAddress(uint64_t &Result) const;
5353 std::error_code getOffset(uint64_t &Result) const;
5454 symbol_iterator getSymbol() const;
55 section_iterator getSection() const;
5655 std::error_code getType(uint64_t &Result) const;
5756
5857 /// @brief Indicates whether this relocation should hidden when listing
240239 virtual std::error_code getRelocationOffset(DataRefImpl Rel,
241240 uint64_t &Res) const = 0;
242241 virtual symbol_iterator getRelocationSymbol(DataRefImpl Rel) const = 0;
243 virtual section_iterator getRelocationSection(DataRefImpl Rel) const = 0;
244242 virtual std::error_code getRelocationType(DataRefImpl Rel,
245243 uint64_t &Res) const = 0;
246244 virtual std::error_code
458456 return OwningObject->getRelocationSymbol(RelocationPimpl);
459457 }
460458
461 inline section_iterator RelocationRef::getSection() const {
462 return OwningObject->getRelocationSection(RelocationPimpl);
463 }
464
465459 inline std::error_code RelocationRef::getType(uint64_t &Result) const {
466460 return OwningObject->getRelocationType(RelocationPimpl, Result);
467461 }
673673 uint64_t SymAddr = 0;
674674 uint64_t SectionLoadAddress = 0;
675675 object::symbol_iterator Sym = Reloc.getSymbol();
676 object::section_iterator RSec = Reloc.getSection();
676 object::section_iterator RSec = Obj.section_end();
677677
678678 // First calculate the address of the symbol or section as it appears
679679 // in the objct file
681681 Sym->getAddress(SymAddr);
682682 // Also remember what section this symbol is in for later
683683 Sym->getSection(RSec);
684 } else if (RSec != Obj.section_end())
684 } else if (auto *MObj = dyn_cast(&Obj)) {
685 // MachO also has relocations that point to sections and
686 // scattered relocations.
687 // FIXME: We are not handling scattered relocations, do we have to?
688 RSec = MObj->getRelocationSection(Reloc.getRawDataRefImpl());
685689 SymAddr = RSec->getAddress();
690 }
686691
687692 // If we are given load addresses for the sections, we need to adjust:
688693 // SymAddr = (Address of Symbol Or Section in File) -
988988 else
989989 llvm_unreachable("no symbol table pointer!");
990990 return symbol_iterator(SymbolRef(Ref, this));
991 }
992
993 section_iterator COFFObjectFile::getRelocationSection(DataRefImpl Rel) const {
994 symbol_iterator Sym = getRelocationSymbol(Rel);
995 if (Sym == symbol_end())
996 return section_end();
997 COFFSymbolRef Symb = getCOFFSymbol(*Sym);
998 if (!Symb.isSection())
999 return section_end();
1000 section_iterator Res(section_end());
1001 if (getSymbolSection(Sym->getRawDataRefImpl(),Res))
1002 return section_end();
1003 return Res;
1004991 }
1005992
1006993 std::error_code COFFObjectFile::getRelocationType(DataRefImpl Rel,
478478 return;
479479 }
480480 } else if (!IsScattered) {
481 section_iterator SecI = Reloc.getSection();
481 section_iterator SecI = Obj->getRelocationSection(DR);
482482 if (SecI != Obj->section_end()) {
483483 if (error(SecI->getName(TargetName)))
484484 return;