llvm.org GIT mirror llvm / e850907
[DWARF] - Cleanup relocations proccessing. RelocAddrMap was a pair of <width, address>, where width is relocation size (4/8/x, x < 8), and width field was never used in code. Relocations proccessing loop had checks for width field. Does not look like DWARF parser should do that. There is probably no much sense to validate relocations during proccessing them in parser. Patch removes relocation's width relative code from DWARFContext. Differential revision: https://reviews.llvm.org/D33194 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303251 91177308-0d34-0410-b5e6-96231b3b80d8 George Rimar 3 years ago
2 changed file(s) with 24 addition(s) and 42 deletion(s). Raw diff Collapse all Expand all
1616 namespace llvm {
1717
1818 struct RelocAddrEntry {
19 uint8_t Width;
2019 int64_t Value;
2120 };
2221
10851085 continue;
10861086 }
10871087
1088 if (Section.relocation_begin() == Section.relocation_end())
1089 continue;
1090
10881091 std::map AddrCache;
1089 if (Section.relocation_begin() != Section.relocation_end()) {
1090 uint64_t SectionSize = RelocatedSection->getSize();
1091 for (const RelocationRef &Reloc : Section.relocations()) {
1092 // FIXME: it's not clear how to correctly handle scattered
1093 // relocations.
1094 if (isRelocScattered(Obj, Reloc))
1095 continue;
1096
1097 Expected SymAddrOrErr =
1098 getSymbolAddress(Obj, Reloc, L, AddrCache);
1099 if (!SymAddrOrErr) {
1100 errs() << toString(SymAddrOrErr.takeError()) << '\n';
1101 continue;
1102 }
1103
1104 object::RelocVisitor V(Obj);
1105 object::RelocToApply R(V.visit(Reloc.getType(), Reloc, *SymAddrOrErr));
1106 if (V.error()) {
1107 SmallString<32> Name;
1108 Reloc.getTypeName(Name);
1109 errs() << "error: failed to compute relocation: "
1110 << Name << "\n";
1111 continue;
1112 }
1113 uint64_t Address = Reloc.getOffset();
1114 if (Address + R.Width > SectionSize) {
1115 errs() << "error: " << R.Width << "-byte relocation starting "
1116 << Address << " bytes into section " << name << " which is "
1117 << SectionSize << " bytes long.\n";
1118 continue;
1119 }
1120 if (R.Width > 8) {
1121 errs() << "error: can't handle a relocation of more than 8 bytes at "
1122 "a time.\n";
1123 continue;
1124 }
1125 DEBUG(dbgs() << "Writing " << format("%p", R.Value)
1126 << " at " << format("%p", Address)
1127 << " with width " << format("%d", R.Width)
1128 << "\n");
1129 Map->insert({Address, {(uint8_t)R.Width, R.Value}});
1092 for (const RelocationRef &Reloc : Section.relocations()) {
1093 // FIXME: it's not clear how to correctly handle scattered
1094 // relocations.
1095 if (isRelocScattered(Obj, Reloc))
1096 continue;
1097
1098 Expected SymAddrOrErr =
1099 getSymbolAddress(Obj, Reloc, L, AddrCache);
1100 if (!SymAddrOrErr) {
1101 errs() << toString(SymAddrOrErr.takeError()) << '\n';
1102 continue;
11301103 }
1104
1105 object::RelocVisitor V(Obj);
1106 object::RelocToApply R(V.visit(Reloc.getType(), Reloc, *SymAddrOrErr));
1107 if (V.error()) {
1108 SmallString<32> Name;
1109 Reloc.getTypeName(Name);
1110 errs() << "error: failed to compute relocation: " << Name << "\n";
1111 continue;
1112 }
1113 Map->insert({Reloc.getOffset(), {R.Value}});
11311114 }
11321115 }
11331116 }