llvm.org GIT mirror llvm / ab6b4cf
Expose getRel and getRela to reduce code duplication. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241266 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 5 years ago
2 changed file(s) with 13 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
246246 return *Sec;
247247 }
248248
249 const Elf_Rel *getRel(DataRefImpl Rel) const;
250 const Elf_Rela *getRela(DataRefImpl Rela) const;
251
252249 const Elf_Sym *toELFSymIter(DataRefImpl Sym) const {
253250 return reinterpret_cast(Sym.p & ~uintptr_t(1));
254251 }
302299
303300 public:
304301 ELFObjectFile(MemoryBufferRef Object, std::error_code &EC);
302
303 const Elf_Rel *getRel(DataRefImpl Rel) const;
304 const Elf_Rela *getRela(DataRefImpl Rela) const;
305305
306306 const Elf_Sym *getSymbol(DataRefImpl Symb) const;
307307
297297 }
298298
299299 template
300 static const typename ELFObjectFile::Elf_Rel *
301 getRel(const ELFFile &EF, DataRefImpl Rel) {
302 typedef typename ELFObjectFile::Elf_Rel Elf_Rel;
303 return EF.template getEntry(Rel.d.a, Rel.d.b);
304 }
305
306 template
307 static const typename ELFObjectFile::Elf_Rela *
308 getRela(const ELFFile &EF, DataRefImpl Rela) {
309 typedef typename ELFObjectFile::Elf_Rela Elf_Rela;
310 return EF.template getEntry(Rela.d.a, Rela.d.b);
311 }
312
313 template
314300 static std::error_code getRelocationValueString(const ELFObjectFile *Obj,
315301 DataRefImpl Rel,
316302 SmallVectorImpl &Result) {
317303 typedef typename ELFObjectFile::Elf_Sym Elf_Sym;
318304 typedef typename ELFObjectFile::Elf_Shdr Elf_Shdr;
305 typedef typename ELFObjectFile::Elf_Rel Elf_Rel;
306 typedef typename ELFObjectFile::Elf_Rela Elf_Rela;
307
319308 const ELFFile &EF = *Obj->getELFFile();
320309
321310 ErrorOr SecOrErr = EF.getSection(Rel.d.a);
343332 default:
344333 return object_error::parse_failed;
345334 case ELF::SHT_REL: {
346 type = getRel(EF, Rel)->getType(EF.isMips64EL());
347 symbol_index = getRel(EF, Rel)->getSymbol(EF.isMips64EL());
335 const Elf_Rel *ERel = Obj->getRel(Rel);
336 type = ERel->getType(EF.isMips64EL());
337 symbol_index = ERel->getSymbol(EF.isMips64EL());
348338 // TODO: Read implicit addend from section data.
349339 break;
350340 }
351341 case ELF::SHT_RELA: {
352 type = getRela(EF, Rel)->getType(EF.isMips64EL());
353 symbol_index = getRela(EF, Rel)->getSymbol(EF.isMips64EL());
354 addend = getRela(EF, Rel)->r_addend;
342 const Elf_Rela *ERela = Obj->getRela(Rel);
343 type = ERela->getType(EF.isMips64EL());
344 symbol_index = ERela->getSymbol(EF.isMips64EL());
345 addend = ERela->r_addend;
355346 break;
356347 }
357348 }