llvm.org GIT mirror llvm / 7426771
Convert getFileOffset to getOffset and move it to its only user. We normally don't drop functions from the C API's, but in this case I think we can: * The old implementation of getFileOffset was fairly broken * The introduction of LLVMGetSymbolFileOffset was itself a C api breaking change as it removed LLVMGetSymbolOffset. * It is an incredibly specialized use case. The only reason MCJIT needs it is because of its odd position of being a dynamic linker of .o files. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206750 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 5 years ago
6 changed file(s) with 34 addition(s) and 69 deletion(s). Raw diff Collapse all Expand all
310310 return lib.LLVMGetSymbolAddress(self)
311311
312312 @CachedProperty
313 def file_offset(self):
314 """The offset of this symbol in the file, in long bytes."""
315 if self.expired:
316 raise Exception('Symbol instance has expired.')
317
318 return lib.LLVMGetSymbolFileOffset(self)
319
320 @CachedProperty
321313 def size(self):
322314 """The size of the symbol, in long bytes."""
323315 if self.expired:
344336 """Cache all cacheable properties."""
345337 getattr(self, 'name')
346338 getattr(self, 'address')
347 getattr(self, 'file_offset')
348339 getattr(self, 'size')
349340
350341 def expire(self):
494485 library.LLVMGetSymbolAddress.argtypes = [Symbol]
495486 library.LLVMGetSymbolAddress.restype = c_uint64
496487
497 library.LLVMGetSymbolFileOffset.argtypes = [Symbol]
498 library.LLVMGetSymbolFileOffset.restype = c_uint64
499
500488 library.LLVMGetSymbolSize.argtypes = [Symbol]
501489 library.LLVMGetSymbolSize.restype = c_uint64
502490
144144 /// Returns the symbol virtual address (i.e. address at which it will be
145145 /// mapped).
146146 error_code getAddress(uint64_t &Result) const;
147 error_code getFileOffset(uint64_t &Result) const;
148147 /// @brief Get the alignment of this symbol as the actual value (not log 2).
149148 error_code getAlignment(uint32_t &Result) const;
150149 error_code getSize(uint64_t &Result) const;
347346 return getObject()->getSymbolAddress(getRawDataRefImpl(), Result);
348347 }
349348
350 inline error_code SymbolRef::getFileOffset(uint64_t &Result) const {
351 uint64_t Address;
352 if (error_code EC = getAddress(Address))
353 return EC;
354 if (Address == UnknownAddressOrSize) {
355 Result = UnknownAddressOrSize;
356 return object_error::success;
357 }
358
359 const ObjectFile *Obj = getObject();
360 section_iterator SecI(Obj->section_begin());
361 if (error_code EC = getSection(SecI))
362 return EC;
363
364 if (SecI == Obj->section_end()) {
365 Result = UnknownAddressOrSize;
366 return object_error::success;
367 }
368
369 uint64_t SectionAddress;
370 if (error_code EC = SecI->getAddress(SectionAddress))
371 return EC;
372
373 uint64_t OffsetInSection = Address - SectionAddress;
374
375 StringRef SecContents;
376 if (error_code EC = SecI->getContents(SecContents))
377 return EC;
378
379 // FIXME: this is a hack.
380 uint64_t SectionOffset = (uint64_t)SecContents.data() - (uint64_t)Obj->base();
381
382 Result = SectionOffset + OffsetInSection;
383 return object_error::success;
384 }
385
386349 inline error_code SymbolRef::getAlignment(uint32_t &Result) const {
387350 return getObject()->getSymbolAlignment(getRawDataRefImpl(), Result);
388351 }
7777 // SymbolRef accessors
7878 const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI);
7979 uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI);
80 uint64_t LLVMGetSymbolFileOffset(LLVMSymbolIteratorRef SI);
8180 uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI);
8281
8382 // RelocationRef accessors
6969 }
7070 }
7171 llvm_unreachable("Attempting to remap address of unknown section!");
72 }
73
74 static error_code getOffset(const SymbolRef &Sym, uint64_t &Result) {
75 uint64_t Address;
76 if (error_code EC = Sym.getAddress(Address))
77 return EC;
78
79 if (Address == UnknownAddressOrSize) {
80 Result = UnknownAddressOrSize;
81 return object_error::success;
82 }
83
84 const ObjectFile *Obj = Sym.getObject();
85 section_iterator SecI(Obj->section_begin());
86 if (error_code EC = Sym.getSection(SecI))
87 return EC;
88
89 if (SecI == Obj->section_end()) {
90 Result = UnknownAddressOrSize;
91 return object_error::success;
92 }
93
94 uint64_t SectionAddress;
95 if (error_code EC = SecI->getAddress(SectionAddress))
96 return EC;
97
98 Result = Address - SectionAddress;
99 return object_error::success;
72100 }
73101
74102 ObjectImage *RuntimeDyldImpl::loadObject(ObjectImage *InputObject) {
124152 if (SymType == object::SymbolRef::ST_Function ||
125153 SymType == object::SymbolRef::ST_Data ||
126154 SymType == object::SymbolRef::ST_Unknown) {
127 uint64_t FileOffset;
155 uint64_t SectOffset;
128156 StringRef SectionData;
129157 bool IsCode;
130158 section_iterator SI = Obj->end_sections();
131 Check(I->getFileOffset(FileOffset));
159 Check(getOffset(*I, SectOffset));
132160 Check(I->getSection(SI));
133161 if (SI == Obj->end_sections())
134162 continue;
135163 Check(SI->getContents(SectionData));
136164 Check(SI->isText(IsCode));
137 const uint8_t *SymPtr =
138 (const uint8_t *)Obj->getData().data() + (uintptr_t)FileOffset;
139 uintptr_t SectOffset =
140 (uintptr_t)(SymPtr - (const uint8_t *)SectionData.begin());
141165 unsigned SectionID =
142166 findOrEmitSection(*Obj, *SI, IsCode, LocalSections);
143167 LocalSymbols[Name.data()] = SymbolLoc(SectionID, SectOffset);
144 DEBUG(dbgs() << "\tFileOffset: " << format("%p", (uintptr_t)FileOffset)
145 << " flags: " << Flags << " SID: " << SectionID
146 << " Offset: " << format("%p", SectOffset));
168 DEBUG(dbgs() << "\tOffset: " << format("%p", (uintptr_t)SectOffset)
169 << " flags: " << Flags << " SID: " << SectionID);
147170 GlobalSymbolTable[Name] = SymbolLoc(SectionID, SectOffset);
148171 }
149172 }
183183 return ret;
184184 }
185185
186 uint64_t LLVMGetSymbolFileOffset(LLVMSymbolIteratorRef SI) {
187 uint64_t ret;
188 if (error_code ec = (*unwrap(SI))->getFileOffset(ret))
189 report_fatal_error(ec.message());
190 return ret;
191 }
192
193186 uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI) {
194187 uint64_t ret;
195188 if (error_code ec = (*unwrap(SI))->getSize(ret))
7171 while (!LLVMIsSymbolIteratorAtEnd(O, sym)) {
7272
7373 LLVMMoveToContainingSection(sect, sym);
74 printf("%s @0x%08" PRIx64 "/0x%08" PRIx64 " +%" PRIu64 " (%s)\n",
75 LLVMGetSymbolName(sym), LLVMGetSymbolAddress(sym),
76 LLVMGetSymbolFileOffset(sym), LLVMGetSymbolSize(sym),
74 printf("%s @0x%08" PRIx64 " +%" PRIu64 " (%s)\n", LLVMGetSymbolName(sym),
75 LLVMGetSymbolAddress(sym), LLVMGetSymbolSize(sym),
7776 LLVMGetSectionName(sect));
7877
7978 LLVMMoveToNextSymbol(sym);