llvm.org GIT mirror llvm / c2966a3
Remove getRelocationAddress. Originally added in r139314. Back then it didn't actually get the address, it got whatever value the relocation used: address or offset. The values in different object formats are: * MachO: Always an offset. * COFF: Always an address, but when talking about the virtual address of sections it says: "for simplicity, compilers should set this to zero". * ELF: An offset for .o files and and address for .so files. In the case of the .so, the relocation in not linked to any section (sh_info is 0). We can't really compute an offset. Some API mappings would be: * Use getAddress for everything. It would be quite cumbersome. To compute the address elf has to follow sh_info, which can be corrupted and therefore the method has to return an ErrorOr. The address of the section is also the same for every relocation in a section, so we shouldn't have to check the error and fetch the value for every relocation. * Use a getValue and make it up to the user to know what it is getting. * Use a getOffset and: * Assert for dynamic ELF objects. That is a very peculiar case and it is probably fair to ask any tool that wants to support it to use ELF.h. The only tool we have that reads those (llvm-readobj) already does that. The only other use case I can think of is a dynamic linker. * Check that COFF .obj files have sections with zero virtual address spaces. If it turns out that some assembler/compiler produces these, we can change COFFObjectFile::getRelocationOffset to subtract it. Given COFF format, this can be done without the need for ErrorOr. The getRelocationAddress method was never implemented for COFF. It also had exactly one use in a very peculiar case: a shortcut for adding the section value to a pcrel reloc on MachO. Given that, I don't expect that there is any use out there of the C API. If that is not the case, let me know and I will add it back with the implementation inlined and do a proper deprecation. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241450 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 5 years ago
15 changed file(s) with 16 addition(s) and 74 deletion(s). Raw diff Collapse all Expand all
371371 self.expired = False
372372
373373 @CachedProperty
374 def address(self):
375 """The address of this relocation, in long bytes."""
376 if self.expired:
377 raise Exception('Relocation instance has expired.')
378
379 return lib.LLVMGetRelocationAddress(self)
380
381 @CachedProperty
382374 def offset(self):
383375 """The offset of this relocation, in long bytes."""
384376 if self.expired:
497489 library.LLVMGetSymbolSize.argtypes = [Symbol]
498490 library.LLVMGetSymbolSize.restype = c_uint64
499491
500 library.LLVMGetRelocationAddress.argtypes = [c_object_p]
501 library.LLVMGetRelocationAddress.restype = c_uint64
502
503492 library.LLVMGetRelocationOffset.argtypes = [c_object_p]
504493 library.LLVMGetRelocationOffset.restype = c_uint64
505494
670670 relocation_iterator section_rel_end(DataRefImpl Sec) const override;
671671
672672 void moveRelocationNext(DataRefImpl &Rel) const override;
673 ErrorOr getRelocationAddress(DataRefImpl Rel) const override;
674673 uint64_t getRelocationOffset(DataRefImpl Rel) const override;
675674 symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
676675 uint64_t getRelocationType(DataRefImpl Rel) const override;
224224 section_iterator getRelocatedSection(DataRefImpl Sec) const override;
225225
226226 void moveRelocationNext(DataRefImpl &Rel) const override;
227 ErrorOr getRelocationAddress(DataRefImpl Rel) const override;
228227 uint64_t getRelocationOffset(DataRefImpl Rel) const override;
229228 symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
230229 uint64_t getRelocationType(DataRefImpl Rel) const override;
679678 else
680679 SymbolData = toDRI(EF.getDotSymtabSec(), symbolIdx);
681680 return symbol_iterator(SymbolRef(SymbolData, this));
682 }
683
684 template
685 ErrorOr
686 ELFObjectFile::getRelocationAddress(DataRefImpl Rel) const {
687 uint64_t ROffset = getROffset(Rel);
688 const Elf_Ehdr *Header = EF.getHeader();
689
690 if (Header->e_type == ELF::ET_REL) {
691 const Elf_Shdr *RelocationSec = getRelSection(Rel);
692 ErrorOr RelocatedSec =
693 EF.getSection(RelocationSec->sh_info);
694 if (std::error_code EC = RelocatedSec.getError())
695 return EC;
696 return ROffset + (*RelocatedSec)->sh_addr;
697 }
698 return ROffset;
699681 }
700682
701683 template
231231 relocation_iterator section_rel_end(DataRefImpl Sec) const override;
232232
233233 void moveRelocationNext(DataRefImpl &Rel) const override;
234 ErrorOr getRelocationAddress(DataRefImpl Rel) const override;
235234 uint64_t getRelocationOffset(DataRefImpl Rel) const override;
236235 symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
237236 section_iterator getRelocationSection(DataRefImpl Rel) const;
242241
243242 // MachO specific.
244243 std::error_code getLibraryShortNameByIndex(unsigned Index, StringRef &) const;
244
245 section_iterator getRelocationRelocatedSection(relocation_iterator Rel) const;
245246
246247 // TODO: Would be useful to have an iterator based version
247248 // of the load command interface too.
4949
5050 void moveNext();
5151
52 ErrorOr getAddress() const;
5352 uint64_t getOffset() const;
5453 symbol_iterator getSymbol() const;
5554 uint64_t getType() const;
227226 // Same as above for RelocationRef.
228227 friend class RelocationRef;
229228 virtual void moveRelocationNext(DataRefImpl &Rel) const = 0;
230 virtual ErrorOr getRelocationAddress(DataRefImpl Rel) const = 0;
231229 virtual uint64_t getRelocationOffset(DataRefImpl Rel) const = 0;
232230 virtual symbol_iterator getRelocationSymbol(DataRefImpl Rel) const = 0;
233231 virtual uint64_t getRelocationType(DataRefImpl Rel) const = 0;
428426 return OwningObject->moveRelocationNext(RelocationPimpl);
429427 }
430428
431 inline ErrorOr RelocationRef::getAddress() const {
432 return OwningObject->getRelocationAddress(RelocationPimpl);
433 }
434
435429 inline uint64_t RelocationRef::getOffset() const {
436430 return OwningObject->getRelocationOffset(RelocationPimpl);
437431 }
8080 uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI);
8181
8282 // RelocationRef accessors
83 uint64_t LLVMGetRelocationAddress(LLVMRelocationIteratorRef RI);
8483 uint64_t LLVMGetRelocationOffset(LLVMRelocationIteratorRef RI);
8584 LLVMSymbolIteratorRef LLVMGetRelocationSymbol(LLVMRelocationIteratorRef RI);
8685 uint64_t LLVMGetRelocationType(LLVMRelocationIteratorRef RI);
8888 }
8989
9090 void RuntimeDyldMachO::makeValueAddendPCRel(RelocationValueRef &Value,
91 const ObjectFile &BaseTObj,
9291 const relocation_iterator &RI,
9392 unsigned OffsetToNextPC) {
94 const MachOObjectFile &Obj =
95 static_cast(BaseTObj);
96 MachO::any_relocation_info RelInfo =
97 Obj.getRelocation(RI->getRawDataRefImpl());
98
99 bool IsPCRel = Obj.getAnyRelocationPCRel(RelInfo);
100 if (IsPCRel) {
101 ErrorOr RelocAddr = RI->getAddress();
102 Value.Offset += *RelocAddr + OffsetToNextPC;
103 }
93 auto &O = *cast(RI->getObject());
94 section_iterator SecI = O.getRelocationRelocatedSection(RI);
95 Value.Offset += RI->getOffset() + OffsetToNextPC + SecI->getAddress();
10496 }
10597
10698 void RuntimeDyldMachO::dumpRelocationToResolve(const RelocationEntry &RE,
9494
9595 /// Make the RelocationValueRef addend PC-relative.
9696 void makeValueAddendPCRel(RelocationValueRef &Value,
97 const ObjectFile &BaseTObj,
9897 const relocation_iterator &RI,
9998 unsigned OffsetToNextPC);
10099
283283
284284 bool IsExtern = Obj.getPlainRelocationExternal(RelInfo);
285285 if (!IsExtern && RE.IsPCRel)
286 makeValueAddendPCRel(Value, Obj, RelI, 1 << RE.Size);
286 makeValueAddendPCRel(Value, RelI, 1 << RE.Size);
287287
288288 RE.Addend = Value.Offset;
289289
7373 getRelocationValueRef(Obj, RelI, RE, ObjSectionToID));
7474
7575 if (RE.IsPCRel)
76 makeValueAddendPCRel(Value, Obj, RelI, 8);
76 makeValueAddendPCRel(Value, RelI, 8);
7777
7878 if ((RE.RelType & 0xf) == MachO::ARM_RELOC_BR24)
7979 processBranchRelocation(RE, Value, Stubs);
6767 // Value.Addend += RelocAddr + 4;
6868 // }
6969 if (RE.IsPCRel)
70 makeValueAddendPCRel(Value, Obj, RelI, 1 << RE.Size);
70 makeValueAddendPCRel(Value, RelI, 1 << RE.Size);
7171
7272 RE.Addend = Value.Offset;
7373
4949
5050 bool IsExtern = Obj.getPlainRelocationExternal(RelInfo);
5151 if (!IsExtern && RE.IsPCRel)
52 makeValueAddendPCRel(Value, Obj, RelI, 1 << RE.Size);
52 makeValueAddendPCRel(Value, RelI, 1 << RE.Size);
5353
5454 if (RE.RelType == MachO::X86_64_RELOC_GOT ||
5555 RE.RelType == MachO::X86_64_RELOC_GOT_LOAD)
955955 void COFFObjectFile::moveRelocationNext(DataRefImpl &Rel) const {
956956 Rel.p = reinterpret_cast(
957957 reinterpret_cast(Rel.p) + 1);
958 }
959
960 ErrorOr COFFObjectFile::getRelocationAddress(DataRefImpl Rel) const {
961 report_fatal_error("getRelocationAddress not implemented in COFFObjectFile");
962958 }
963959
964960 uint64_t COFFObjectFile::getRelocationOffset(DataRefImpl Rel) const {
587587 ++Rel.d.b;
588588 }
589589
590 ErrorOr MachOObjectFile::getRelocationAddress(DataRefImpl Rel) const {
591 uint64_t Offset = getRelocationOffset(Rel);
592
593 DataRefImpl Sec;
594 Sec.d.a = Rel.d.a;
595 uint64_t SecAddress = getSectionAddress(Sec);
596 return SecAddress + Offset;
597 }
598
599590 uint64_t MachOObjectFile::getRelocationOffset(DataRefImpl Rel) const {
600591 assert(getHeader().filetype == MachO::MH_OBJECT &&
601592 "Only implemented for MH_OBJECT");
924915
925916 Res = LibrariesShortNames[Index];
926917 return std::error_code();
918 }
919
920 section_iterator
921 MachOObjectFile::getRelocationRelocatedSection(relocation_iterator Rel) const {
922 DataRefImpl Sec;
923 Sec.d.a = Rel->getRawDataRefImpl().d.a;
924 return section_iterator(SectionRef(Sec, this));
927925 }
928926
929927 basic_symbol_iterator MachOObjectFile::symbol_begin_impl() const {
190190 }
191191
192192 // RelocationRef accessors
193 uint64_t LLVMGetRelocationAddress(LLVMRelocationIteratorRef RI) {
194 ErrorOr Ret = (*unwrap(RI))->getAddress();
195 if (std::error_code EC = Ret.getError())
196 report_fatal_error(EC.message());
197 return *Ret;
198 }
199
200193 uint64_t LLVMGetRelocationOffset(LLVMRelocationIteratorRef RI) {
201194 return (*unwrap(RI))->getOffset();
202195 }