@@ -85,7 +85,7 @@ public class ElfRelocation implements StructConverter {
85
85
86
86
private long r_offset ;
87
87
private long r_info ;
88
- private long r_addend ;
88
+ private long r_addend ; // signed-value
89
89
90
90
private boolean hasAddend ;
91
91
private boolean is32bit ;
@@ -116,7 +116,7 @@ static ElfRelocation createElfRelocation(BinaryReader reader,
116
116
* @param withAddend true if if RELA entry with addend, else false
117
117
* @param r_offset The offset for the entry
118
118
* @param r_info The info value for the entry
119
- * @param r_addend The addend for the entry
119
+ * @param r_addend The signed- addend for the entry (32-bit addends should be signed-extended to 64-bits)
120
120
* @return ELF relocation object
121
121
* @throws IOException if an IO or parse error occurs
122
122
*/
@@ -193,7 +193,8 @@ protected void initElfRelocation(BinaryReader reader, ElfHeader elfHeader,
193
193
* @param withAddend true if if RELA entry with addend, else false
194
194
* @param offset The offset for the entry (r_offset)
195
195
* @param info The info value for the entry (r_info)
196
- * @param addend The addend for the entry (r_addend)
196
+ * @param addend The signed-addend (r_addend) for the entry (32-bit addends should
197
+ * be signed-extended to 64-bits)
197
198
* @throws IOException if an IO or parse error occurs
198
199
*/
199
200
protected void initElfRelocation (ElfHeader elfHeader , int relocationTableIndex ,
@@ -205,16 +206,13 @@ protected void initElfRelocation(ElfHeader elfHeader, int relocationTableIndex,
205
206
if (is32bit ) {
206
207
this .r_offset = Integer .toUnsignedLong ((int ) offset );
207
208
this .r_info = Integer .toUnsignedLong ((int ) info );
208
- if (hasAddend ) {
209
- this .r_addend = Integer .toUnsignedLong ((int ) addend );
210
- }
211
209
}
212
210
else {
213
211
this .r_offset = offset ;
214
212
this .r_info = info ;
215
- if ( hasAddend ) {
216
- this . r_addend = addend ;
217
- }
213
+ }
214
+ if ( hasAddend ) {
215
+ this . r_addend = addend ;
218
216
}
219
217
}
220
218
@@ -223,7 +221,7 @@ private void readEntryData(BinaryReader reader) throws IOException {
223
221
this .r_offset = Integer .toUnsignedLong (reader .readNextInt ());
224
222
this .r_info = Integer .toUnsignedLong (reader .readNextInt ());
225
223
if (hasAddend ) {
226
- r_addend = Integer . toUnsignedLong ( reader .readNextInt () );
224
+ r_addend = reader .readNextInt ();
227
225
}
228
226
}
229
227
else {
@@ -307,10 +305,13 @@ public long getRelocationInfo() {
307
305
}
308
306
309
307
/**
310
- * This member specifies a constant addend used to compute
308
+ * This member specifies the RELA signed- constant addend used to compute
311
309
* the value to be stored into the relocatable field. This
312
- * value will be 0 for REL entries which do not supply an addend.
313
- * @return a constant addend
310
+ * value will be 0 for REL entries which do not supply an addend and may
311
+ * rely on an implicit addend stored at the relocation offset.
312
+ * See {@link #hasAddend()} which is true for RELA / Elf_Rela and false
313
+ * for REL / Elf_Rel relocations.
314
+ * @return addend as 64-bit signed constant
314
315
*/
315
316
public long getAddend () {
316
317
return r_addend ;
0 commit comments