llvm.org GIT mirror llvm / 167957f
Change getRelocationAdditionalInfo to be ELF only. It was only implemented for ELF where it collected the Addend, so this patch also renames it to getRelocationAddend. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181502 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 7 years ago
10 changed file(s) with 65 addition(s) and 59 deletion(s). Raw diff Collapse all Expand all
148148 uint64_t &Res) const;
149149 virtual error_code getRelocationTypeName(DataRefImpl Rel,
150150 SmallVectorImpl &Result) const;
151 virtual error_code getRelocationAdditionalInfo(DataRefImpl Rel,
152 int64_t &Res) const;
153151 virtual error_code getRelocationValueString(DataRefImpl Rel,
154152 SmallVectorImpl &Result) const;
155153
676676 error_code getSymbolVersion(SymbolRef Symb, StringRef &Version,
677677 bool &IsDefault) const;
678678 uint64_t getSymbolIndex(const Elf_Sym *sym) const;
679 error_code getRelocationAddend(DataRefImpl Rel, int64_t &Res) const;
679680 protected:
680681 virtual error_code getSymbolNext(DataRefImpl Symb, SymbolRef &Res) const;
681682 virtual error_code getSymbolName(DataRefImpl Symb, StringRef &Res) const;
724725 uint64_t &Res) const;
725726 virtual error_code getRelocationTypeName(DataRefImpl Rel,
726727 SmallVectorImpl &Result) const;
727 virtual error_code getRelocationAdditionalInfo(DataRefImpl Rel,
728 int64_t &Res) const;
729728 virtual error_code getRelocationValueString(DataRefImpl Rel,
730729 SmallVectorImpl &Result) const;
731730
22262225 }
22272226
22282227 template
2229 error_code ELFObjectFile::getRelocationAdditionalInfo(
2228 error_code ELFObjectFile::getRelocationAddend(
22302229 DataRefImpl Rel, int64_t &Result) const {
22312230 const Elf_Shdr *sec = getSection(Rel.w.b);
22322231 switch (sec->sh_type) {
29482947 return object_error::success;
29492948 }
29502949
2950 /// FIXME: Maybe we should have a base ElfObjectFile that is not a template
2951 /// and make these member functions?
2952 static inline error_code getELFRelocationAddend(const RelocationRef R,
2953 int64_t &Addend) {
2954 const ObjectFile *Obj = R.getObjectFile();
2955 DataRefImpl DRI = R.getRawDataRefImpl();
2956 // Little-endian 32-bit
2957 if (const ELFObjectFile > *ELFObj =
2958 dyn_cast > >(Obj))
2959 return ELFObj->getRelocationAddend(DRI, Addend);
2960
2961 // Big-endian 32-bit
2962 if (const ELFObjectFile > *ELFObj =
2963 dyn_cast > >(Obj))
2964 return ELFObj->getRelocationAddend(DRI, Addend);
2965
2966 // Little-endian 64-bit
2967 if (const ELFObjectFile > *ELFObj =
2968 dyn_cast > >(Obj))
2969 return ELFObj->getRelocationAddend(DRI, Addend);
2970
2971 // Big-endian 64-bit
2972 if (const ELFObjectFile > *ELFObj =
2973 dyn_cast > >(Obj))
2974 return ELFObj->getRelocationAddend(DRI, Addend);
2975
2976 llvm_unreachable("Object passed to getELFRelocationAddend() is not ELF");
2977 }
2978
29512979 /// This is a generic interface for retrieving GNU symbol version
29522980 /// information from an ELFObjectFile.
29532981 static inline error_code GetELFSymbolVersion(const ObjectFile *Obj,
7575 virtual error_code getRelocationType(DataRefImpl Rel, uint64_t &Res) const;
7676 virtual error_code getRelocationTypeName(DataRefImpl Rel,
7777 SmallVectorImpl &Result) const;
78 virtual error_code getRelocationAdditionalInfo(DataRefImpl Rel,
79 int64_t &Res) const;
8078 virtual error_code getRelocationValueString(DataRefImpl Rel,
8179 SmallVectorImpl &Result) const;
8280 virtual error_code getRelocationHidden(DataRefImpl Rel, bool &Result) const;
118118 ///
119119 /// This is for display purposes only.
120120 error_code getTypeName(SmallVectorImpl &Result) const;
121 error_code getAdditionalInfo(int64_t &Result) const;
122121
123122 /// @brief Get a string that represents the calculation of the value of this
124123 /// relocation.
127126 error_code getValueString(SmallVectorImpl &Result) const;
128127
129128 DataRefImpl getRawDataRefImpl() const;
129 const ObjectFile *getObjectFile() const;
130130 };
131131 typedef content_iterator relocation_iterator;
132132
341341 uint64_t &Res) const = 0;
342342 virtual error_code getRelocationTypeName(DataRefImpl Rel,
343343 SmallVectorImpl &Result) const = 0;
344 virtual error_code getRelocationAdditionalInfo(DataRefImpl Rel,
345 int64_t &Res) const = 0;
346344 virtual error_code getRelocationValueString(DataRefImpl Rel,
347345 SmallVectorImpl &Result) const = 0;
348346 virtual error_code getRelocationHidden(DataRefImpl Rel, bool &Result) const {
578576 return OwningObject->getRelocationTypeName(RelocationPimpl, Result);
579577 }
580578
581 inline error_code RelocationRef::getAdditionalInfo(int64_t &Result) const {
582 return OwningObject->getRelocationAdditionalInfo(RelocationPimpl, Result);
583 }
584
585579 inline error_code RelocationRef::getValueString(SmallVectorImpl &Result)
586580 const {
587581 return OwningObject->getRelocationValueString(RelocationPimpl, Result);
593587
594588 inline DataRefImpl RelocationRef::getRawDataRefImpl() const {
595589 return RelocationPimpl;
590 }
591
592 inline const ObjectFile *RelocationRef::getObjectFile() const {
593 return OwningObject;
596594 }
597595
598596 // Inline function definitions.
1717
1818 #include "llvm/ADT/StringRef.h"
1919 #include "llvm/Object/ObjectFile.h"
20 #include "llvm/Object/ELF.h"
2021 #include "llvm/Support/Debug.h"
2122 #include "llvm/Support/ELF.h"
2223 #include "llvm/Support/raw_ostream.h"
122123 StringRef FileFormat;
123124 bool HasError;
124125
126 int64_t getAddend(RelocationRef R) {
127 int64_t Addend;
128 getELFRelocationAddend(R, Addend);
129 return Addend;
130 }
131
125132 /// Operations
126133
127134 /// 386-ELF
132139 // Ideally the Addend here will be the addend in the data for
133140 // the relocation. It's not actually the case for Rel relocations.
134141 RelocToApply visitELF_386_32(RelocationRef R, uint64_t Value) {
135 int64_t Addend;
136 R.getAdditionalInfo(Addend);
142 int64_t Addend = getAddend(R);
137143 return RelocToApply(Value + Addend, 4);
138144 }
139145
140146 RelocToApply visitELF_386_PC32(RelocationRef R, uint64_t Value,
141147 uint64_t SecAddr) {
142 int64_t Addend;
143 R.getAdditionalInfo(Addend);
148 int64_t Addend = getAddend(R);
144149 uint64_t Address;
145150 R.getOffset(Address);
146151 return RelocToApply(Value + Addend - Address, 4);
151156 return RelocToApply(0, 0);
152157 }
153158 RelocToApply visitELF_X86_64_64(RelocationRef R, uint64_t Value) {
154 int64_t Addend;
155 R.getAdditionalInfo(Addend);
159 int64_t Addend = getAddend(R);
156160 return RelocToApply(Value + Addend, 8);
157161 }
158162 RelocToApply visitELF_X86_64_PC32(RelocationRef R, uint64_t Value,
159163 uint64_t SecAddr) {
160 int64_t Addend;
161 R.getAdditionalInfo(Addend);
164 int64_t Addend = getAddend(R);
162165 uint64_t Address;
163166 R.getOffset(Address);
164167 return RelocToApply(Value + Addend - Address, 4);
165168 }
166169 RelocToApply visitELF_X86_64_32(RelocationRef R, uint64_t Value) {
167 int64_t Addend;
168 R.getAdditionalInfo(Addend);
170 int64_t Addend = getAddend(R);
169171 uint32_t Res = (Value + Addend) & 0xFFFFFFFF;
170172 return RelocToApply(Res, 4);
171173 }
172174 RelocToApply visitELF_X86_64_32S(RelocationRef R, uint64_t Value) {
173 int64_t Addend;
174 R.getAdditionalInfo(Addend);
175 int64_t Addend = getAddend(R);
175176 int32_t Res = (Value + Addend) & 0xFFFFFFFF;
176177 return RelocToApply(Res, 4);
177178 }
178179
179180 /// PPC64 ELF
180181 RelocToApply visitELF_PPC64_ADDR32(RelocationRef R, uint64_t Value) {
181 int64_t Addend;
182 R.getAdditionalInfo(Addend);
182 int64_t Addend = getAddend(R);
183183 uint32_t Res = (Value + Addend) & 0xFFFFFFFF;
184184 return RelocToApply(Res, 4);
185185 }
186186
187187 /// MIPS ELF
188188 RelocToApply visitELF_MIPS_32(RelocationRef R, uint64_t Value) {
189 int64_t Addend;
190 R.getAdditionalInfo(Addend);
189 int64_t Addend = getAddend(R);
191190 uint32_t Res = (Value + Addend) & 0xFFFFFFFF;
192191 return RelocToApply(Res, 4);
193192 }
194193
195194 // AArch64 ELF
196195 RelocToApply visitELF_AARCH64_ABS32(RelocationRef R, uint64_t Value) {
197 int64_t Addend;
198 R.getAdditionalInfo(Addend);
196 int64_t Addend = getAddend(R);
199197 int64_t Res = Value + Addend;
200198
201199 // Overflow check allows for both signed and unsigned interpretation.
206204 }
207205
208206 RelocToApply visitELF_AARCH64_ABS64(RelocationRef R, uint64_t Value) {
209 int64_t Addend;
210 R.getAdditionalInfo(Addend);
207 int64_t Addend = getAddend(R);
211208 return RelocToApply(Value + Addend, 8);
212209 }
213210
214211 // SystemZ ELF
215212 RelocToApply visitELF_390_32(RelocationRef R, uint64_t Value) {
216 int64_t Addend;
217 R.getAdditionalInfo(Addend);
213 int64_t Addend = getAddend(R);
218214 int64_t Res = Value + Addend;
219215
220216 // Overflow check allows for both signed and unsigned interpretation.
225221 }
226222
227223 RelocToApply visitELF_390_64(RelocationRef R, uint64_t Value) {
228 int64_t Addend;
229 R.getAdditionalInfo(Addend);
224 int64_t Addend = getAddend(R);
230225 return RelocToApply(Value + Addend, 8);
231226 }
232227 };
518518
519519 SymbolRef TargetSymbol;
520520 uint64_t TargetSymbolOffset;
521 int64_t TargetAdditionalInfo;
522521 check(i->getSymbol(TargetSymbol));
523522 check(i->getOffset(TargetSymbolOffset));
524 check(i->getAdditionalInfo(TargetAdditionalInfo));
523 int64_t Addend;
524 check(getELFRelocationAddend(*i, Addend));
525525
526526 i = i.increment(err);
527527 if (i == e)
543543 section_iterator tsi(Obj.end_sections());
544544 check(TargetSymbol.getSection(tsi));
545545 Rel.SectionID = findOrEmitSection(Obj, (*tsi), true, LocalSections);
546 Rel.Addend = (intptr_t)TargetAdditionalInfo;
546 Rel.Addend = (intptr_t)Addend;
547547 return;
548548 }
549549 }
741741 uint64_t RelType;
742742 Check(RelI.getType(RelType));
743743 int64_t Addend;
744 Check(RelI.getAdditionalInfo(Addend));
744 Check(getELFRelocationAddend(RelI, Addend));
745745 SymbolRef Symbol;
746746 Check(RelI.getSymbol(Symbol));
747747
797797
798798 #undef LLVM_COFF_SWITCH_RELOC_TYPE_NAME
799799
800 error_code COFFObjectFile::getRelocationAdditionalInfo(DataRefImpl Rel,
801 int64_t &Res) const {
802 Res = 0;
803 return object_error::success;
804 }
805800 error_code COFFObjectFile::getRelocationValueString(DataRefImpl Rel,
806801 SmallVectorImpl &Result) const {
807802 const coff_relocation *reloc = toRel(Rel);
985985 break;
986986 }
987987 Result.append(res.begin(), res.end());
988 return object_error::success;
989 }
990
991 error_code MachOObjectFile::getRelocationAdditionalInfo(DataRefImpl Rel,
992 int64_t &Res) const {
993 Res = 0;
994988 return object_error::success;
995989 }
996990
66 // CHECK-NEXT: Offset: 0x4018F8
77 // CHECK-NEXT: Type: R_X86_64_JUMP_SLOT (7)
88 // CHECK-NEXT: Symbol: __libc_start_main
9 // CHECK-NEXT: Info: 0x0
9 // CHECK-NEXT: Addend: 0x0
1010 // CHECK-NEXT: }
1111 // CHECK-NEXT: Relocation {
1212 // CHECK-NEXT: Offset: 0x401900
1313 // CHECK-NEXT: Type: R_X86_64_JUMP_SLOT (7)
1414 // CHECK-NEXT: Symbol: puts
15 // CHECK-NEXT: Info: 0x0
15 // CHECK-NEXT: Addend: 0x0
1616 // CHECK-NEXT: }
1717 // CHECK-NEXT: }
578578 uint64_t Offset;
579579 uint64_t RelocType;
580580 SmallString<32> RelocName;
581 int64_t Info;
581 int64_t Addend;
582582 StringRef SymbolName;
583583 SymbolRef Symbol;
584584 if (Obj->getElfHeader()->e_type == ELF::ET_REL){
588588 }
589589 if (error(RelI->getType(RelocType))) return;
590590 if (error(RelI->getTypeName(RelocName))) return;
591 if (error(RelI->getAdditionalInfo(Info))) return;
591 if (error(getELFRelocationAddend(*RelI, Addend))) return;
592592 if (error(RelI->getSymbol(Symbol))) return;
593593 if (error(Symbol.getName(SymbolName))) return;
594594
597597 W.printHex("Offset", Offset);
598598 W.printNumber("Type", RelocName, RelocType);
599599 W.printString("Symbol", SymbolName.size() > 0 ? SymbolName : "-");
600 W.printHex("Info", Info);
600 W.printHex("Addend", Addend);
601601 } else {
602602 raw_ostream& OS = W.startLine();
603603 OS << W.hex(Offset)
604604 << " " << RelocName
605605 << " " << (SymbolName.size() > 0 ? SymbolName : "-")
606 << " " << W.hex(Info)
606 << " " << W.hex(Addend)
607607 << "\n";
608608 }
609609 }