Ghidra is a software reverse engineering (SRE) framework
GP-3707 revised and implemented missing RISCV ELF relocations. Corrected ElfRelocation to maintain signed addend value.
ghidra1065e5b01e8b6
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/elf/ElfRelocation.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/elf/ElfRelocation.javaindex cd8a3c5284..8f0e0a5972 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/elf/ElfRelocation.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/elf/ElfRelocation.java@@ -85,7 +85,7 @@ public class ElfRelocation implements StructConverter {private long r_offset;private long r_info;- private long r_addend;+ private long r_addend; // signed-valueprivate boolean hasAddend;private boolean is32bit;@@ -116,7 +116,7 @@ public class ElfRelocation implements StructConverter {* @param withAddend true if if RELA entry with addend, else false* @param r_offset The offset for the entry* @param r_info The info value for the entry- * @param r_addend The addend for the entry+ * @param r_addend The signed-addend for the entry (32-bit addends should be signed-extended to 64-bits)* @return ELF relocation object* @throws IOException if an IO or parse error occurs*/@@ -193,7 +193,8 @@ public class ElfRelocation implements StructConverter {* @param withAddend true if if RELA entry with addend, else false* @param offset The offset for the entry (r_offset)* @param info The info value for the entry (r_info)- * @param addend The addend for the entry (r_addend)+ * @param addend The signed-addend (r_addend) for the entry (32-bit addends should+ * be signed-extended to 64-bits)* @throws IOException if an IO or parse error occurs*/protected void initElfRelocation(ElfHeader elfHeader, int relocationTableIndex,@@ -205,16 +206,13 @@ public class ElfRelocation implements StructConverter {if (is32bit) {this.r_offset = Integer.toUnsignedLong((int) offset);this.r_info = Integer.toUnsignedLong((int) info);- if (hasAddend) {- this.r_addend = Integer.toUnsignedLong((int) addend);- }}else {this.r_offset = offset;this.r_info = info;- if (hasAddend) {- this.r_addend = addend;- }+ }+ if (hasAddend) {+ this.r_addend = addend;}}@@ -223,7 +221,7 @@ public class ElfRelocation implements StructConverter {this.r_offset = Integer.toUnsignedLong(reader.readNextInt());this.r_info = Integer.toUnsignedLong(reader.readNextInt());if (hasAddend) {- r_addend = Integer.toUnsignedLong(reader.readNextInt());+ r_addend = reader.readNextInt();}}else {@@ -307,10 +305,13 @@ public class ElfRelocation implements StructConverter {}/**- * This member specifies a constant addend used to compute+ * This member specifies the RELA signed-constant addend used to compute* the value to be stored into the relocatable field. This- * value will be 0 for REL entries which do not supply an addend.- * @return a constant addend+ * value will be 0 for REL entries which do not supply an addend and may+ * rely on an implicit addend stored at the relocation offset.+ * See {@link #hasAddend()} which is true for RELA / Elf_Rela and false+ * for REL / Elf_Rel relocations.+ * @return addend as 64-bit signed constant*/public long getAddend() {return r_addend;diff --git a/Ghidra/Processors/RISCV/src/main/java/ghidra/app/util/bin/format/elf/relocation/RISCV_ElfRelocationContext.java b/Ghidra/Processors/RISCV/src/main/java/ghidra/app/util/bin/format/elf/relocation/RISCV_ElfRelocationContext.javanew file mode 100644index 0000000000..a1a453f546--- /dev/null+++ b/Ghidra/Processors/RISCV/src/main/java/ghidra/app/util/bin/format/elf/relocation/RISCV_ElfRelocationContext.java@@ -0,0 +1,83 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.app.util.bin.format.elf.relocation;++import java.util.*;++import ghidra.app.util.bin.format.elf.*;+import ghidra.program.model.address.Address;++class RISCV_ElfRelocationContext extends ElfRelocationContext {++ protected RISCV_ElfRelocationContext(ElfRelocationHandler handler, ElfLoadHelper loadHelper,+ Map<ElfSymbol, Address> symbolMap) {+ super(handler, loadHelper, symbolMap);+ }++ /**+ * <code>OffsetComparator</code> provides ability to compare a Long ElfSymbol offset value with an+ * ElfRelocation object's relocation offset.+ */+ private static class OffsetComparator implements Comparator<Object> {++ public static final OffsetComparator INSTANCE = new OffsetComparator();++ @Override+ public int compare(Object o1, Object o2) {+ if (o1 instanceof Long) {+ return -compare(o2, o1);+ }+ ElfRelocation rel = (ElfRelocation) o1;+ long relOffset = rel.getOffset();+ long offset = (Long) o2;+ if (relOffset == offset) {+ return 0;+ }+ return Long.compareUnsigned(relOffset, offset);+ }++ }++ /**+ * Find the HI20 relocation whose offset matches the value of of the specified symbol.+ * @param hi20Symbol ELF symbol which corresponds to HI20 relocation+ * @return matching relocation or null if not found+ */+ ElfRelocation getHi20Relocation(ElfSymbol hi20Symbol) {++ Long symValue = hi20Symbol.getValue();++ // Search for first relocation within table whose offset matches the specified hi20Symbol value+ ElfRelocation[] relocations = relocationTable.getRelocations();+ int relIndex = Arrays.binarySearch(relocations, symValue, OffsetComparator.INSTANCE);+ if (relIndex < 0) {+ return null; // relocation not found+ }+ // back-up in the event there is more than one matching relocation offset+ while (relIndex > 0 && relocations[relIndex - 1].getOffset() == symValue) {+ --relIndex;+ }+ // look for hi20 relocation+ while (relIndex < relocations.length && relocations[relIndex - 1].getOffset() == symValue) {+ int type = relocations[relIndex].getType();+ if ((type == RISCV_ElfRelocationConstants.R_RISCV_PCREL_HI20) ||+ (type == RISCV_ElfRelocationConstants.R_RISCV_GOT_HI20)) {+ return relocations[relIndex];+ }+ }+ return null;+ }+}diff --git a/Ghidra/Processors/RISCV/src/main/java/ghidra/app/util/bin/format/elf/relocation/RISCV_ElfRelocationHandler.java b/Ghidra/Processors/RISCV/src/main/java/ghidra/app/util/bin/format/elf/relocation/RISCV_ElfRelocationHandler.javaindex 52c3d57542..8fda8c2861 100644--- a/Ghidra/Processors/RISCV/src/main/java/ghidra/app/util/bin/format/elf/relocation/RISCV_ElfRelocationHandler.java+++ b/Ghidra/Processors/RISCV/src/main/java/ghidra/app/util/bin/format/elf/relocation/RISCV_ElfRelocationHandler.java@@ -15,15 +15,15 @@*/package ghidra.app.util.bin.format.elf.relocation;-import java.util.Iterator;+import java.util.Map;import ghidra.app.util.bin.format.elf.*;-import ghidra.program.model.address.*;+import ghidra.program.model.address.Address;import ghidra.program.model.listing.Program;import ghidra.program.model.mem.Memory;import ghidra.program.model.mem.MemoryAccessException;-import ghidra.program.model.reloc.*;import ghidra.program.model.reloc.Relocation.Status;+import ghidra.program.model.reloc.RelocationResult;import ghidra.util.exception.NotFoundException;/**@@ -52,6 +52,12 @@ public class RISCV_ElfRelocationHandler extends ElfRelocationHandler {return elf.e_machine() == ElfConstants.EM_RISCV;}+ @Override+ public RISCV_ElfRelocationContext createRelocationContext(ElfLoadHelper loadHelper,+ Map<ElfSymbol, Address> symbolMap) {+ return new RISCV_ElfRelocationContext(this, loadHelper, symbolMap);+ }+/*** Get the adjusted 20 high bits of a 32 bit target. The lower 12 bits will* be found in a later instruction, using a sign-extended signed addition. If those@@ -81,64 +87,50 @@ public class RISCV_ElfRelocationHandler extends ElfRelocationHandler {/*** PC relative relocations like R_RISCV_PCREL_LO12_I find their target indirectly,* using their symbolValue to locate the address of the matching R_RISCV_PCREL_HI20- * or R_RISCV_GOT_HI20.- * That *HI20 relocation's symbol value points to the actual target.- * This function attempts to locate that actual target by querying Ghidra's Relocation- * and Symbol tables. There can be more than one relocation assigned to a given address,- * so we need to search.- *- * Note that this function probably belongs within ElfRelocationContext, but we have no- * published strategy for integration testing that class.- *- * @return the relocation symbol value associated with the linked relocation type.+ * or R_RISCV_GOT_HI20. The HI20 relocation's symbol identifies the actual target.+ * @param elfRelocationContext ELF relocation context for RISCV+ * @param hi20Symbol symbol which identifies a HI20 relocation offset+ * @param relocAddrOffsetAdj relocation offset adjustment to be used when computing+ * actual address offet within the target program.+ * @return the 32-bit HI20 relative offset value or 0 if HI20 relocation not found*/- static int getSymbolValueIndirect(ElfRelocationContext elfRelocationContext, int hi20Addr) {+ private static int getSymbolValueIndirect(ElfRelocationContext elfRelocationContext,+ ElfSymbol hi20Symbol, long relocAddrOffsetAdj) {- int target;- // Get the relevant Ghidra tables- Program program = elfRelocationContext.getProgram();- AddressSpace space = program.getAddressFactory().getDefaultAddressSpace();- RelocationTable relocationTable = program.getRelocationTable();-- // get the possible address of R_RISCV_PCREL_HI20 relocation holding the target address- Address hi20Address = program.getAddressFactory().getAddress(space.getSpaceID(), hi20Addr);-- // we need an address set with one holding a single address to retrieve multiple relocations- AddressSet relocationAddressSet = new AddressSet(hi20Address);- // get any relocations at this address - hopefully R_RISCV_PCREL_HI20 and likely R_RISCV_RELAX- Iterator<Relocation> relocs = relocationTable.getRelocations(relocationAddressSet);- // search the relocations for a R_RISCV_PCREL_HI20 relocation- while (relocs.hasNext()) {- Relocation rel = relocs.next();- // there may be other valid relocation types to process- if ((rel.getType() == RISCV_ElfRelocationConstants.R_RISCV_PCREL_HI20) ||- (rel.getType() == RISCV_ElfRelocationConstants.R_RISCV_GOT_HI20)) {- int refSymbolIndex = (int) rel.getValues()[0];-// System.out.println("Matching PCREL_HI20 value is 0x" + Long.toHexString(refSymbolIndex));- // Note that an elf symbol index is not the same thing as a regular symbol index.- ElfSymbol elfSym = elfRelocationContext.getSymbol(refSymbolIndex);- int targetOffset = (int) elfRelocationContext.getSymbolValue(elfSym);-// System.out.println(-// "PCREL_HI20 Symbol \"" + elfRelocationContext.getSymbolName(refSymbolIndex) +-// "\" found with offset 0x" + Long.toHexString(targetOffset));- // compute the target offset from the referred auipc instruction- target = targetOffset - hi20Addr;-// System.out.println("PCREL_HI20 Symbol location is 0x" + Long.toHexString(target));- return target;- }+ RISCV_ElfRelocationContext relocContext = (RISCV_ElfRelocationContext) elfRelocationContext;+ ElfRelocation hi20Reloc = relocContext.getHi20Relocation(hi20Symbol);+ if (hi20Reloc == null) {+ return 0;}- return 0;++ int symIndex = hi20Reloc.getSymbolIndex();+ ElfSymbol sym = elfRelocationContext.getSymbol(symIndex);+ long symOffset = elfRelocationContext.getSymbolValue(sym);++ // must apply HI20 addend to symbol offset+ long targetOffset = symOffset + hi20Reloc.getAddend();++ // must adjust to account for image-base+ long hi20RelocOffset = hi20Reloc.getOffset() + relocAddrOffsetAdj;++ // TODO: should we perform range check for 64-bit case?+ return (int) (targetOffset - hi20RelocOffset);}@Overridepublic RelocationResult relocate(ElfRelocationContext elfRelocationContext,- ElfRelocation relocation,- Address relocationAddress) throws MemoryAccessException, NotFoundException {+ ElfRelocation relocation, Address relocationAddress)+ throws MemoryAccessException, NotFoundException {ElfHeader elf = elfRelocationContext.getElfHeader();if (!canRelocate(elf)) {return RelocationResult.FAILURE;}+ if (!relocation.hasAddend()) {+ // Implementation only supports Elf_Rela relocations for RISCV+ return RelocationResult.UNSUPPORTED;+ }+Program program = elfRelocationContext.getProgram();Memory memory = program.getMemory();boolean is32 = elf.is32Bit();@@ -147,8 +139,7 @@ public class RISCV_ElfRelocationHandler extends ElfRelocationHandler {return RelocationResult.SKIPPED;}- long addend = relocation.hasAddend() ? relocation.getAddend()- : is32 ? memory.getInt(relocationAddress) : memory.getLong(relocationAddress);+ long addend = relocation.getAddend();long offset = relocationAddress.getOffset();long base = elfRelocationContext.getImageBaseWordAdjustmentOffset();@@ -267,7 +258,7 @@ public class RISCV_ElfRelocationHandler extends ElfRelocationHandler {target = (int) (addend + symbolValue - offset);value32 =((target & 0x01e) << 7) | ((target & 0x0800) >> 4) | ((target & 0x03e0) << 20) |- ((target & 0x1000) << 19) | memory.getInt(relocationAddress);+ ((target & 0x1000) << 19) | (memory.getInt(relocationAddress) & 0x1fff07f);memory.setInt(relocationAddress, value32);break;@@ -276,7 +267,7 @@ public class RISCV_ElfRelocationHandler extends ElfRelocationHandler {target = (int) (addend + symbolValue - offset);value32 =(target & 0xff000) | ((target & 0x00800) << 9) | ((target & 0x007fe) << 20) |- ((target & 0x100000) << 11) | memory.getInt(relocationAddress);+ ((target & 0x100000) << 11) | (memory.getInt(relocationAddress) & 0xfff);memory.setInt(relocationAddress, value32);break;@@ -288,9 +279,9 @@ public class RISCV_ElfRelocationHandler extends ElfRelocationHandler {// PC-relative call MACRO call,tail (auipc+jalr pair)target = (int) (addend + symbolValue - offset);memory.setInt(relocationAddress,- getHi20(target) | memory.getInt(relocationAddress));+ getHi20(target) | (memory.getInt(relocationAddress) & 0xfff));memory.setInt(relocationAddress.add(4),- (getLo12(target) << 20) | memory.getInt(relocationAddress.add(4)));+ (getLo12(target) << 20) | (memory.getInt(relocationAddress.add(4)) & 0xfffff));byteLength = 8;break;@@ -312,18 +303,21 @@ public class RISCV_ElfRelocationHandler extends ElfRelocationHandler {// PC-relative, not tested on 32 bit objectstarget = (int) (addend + symbolValue - offset);memory.setInt(relocationAddress,- getHi20(target) | memory.getInt(relocationAddress));+ getHi20(target) | (memory.getInt(relocationAddress) & 0xfff));break;case RISCV_ElfRelocationConstants.R_RISCV_PCREL_LO12_I:// PC-relative reference %pcrel_lo(symbol) (I-Type), relative to the cited pc_rel_hi20- target = getSymbolValueIndirect(elfRelocationContext, (int) symbolValue);+ target = getSymbolValueIndirect(elfRelocationContext, sym,+ relocationAddress.getOffset() - relocation.getOffset());if (target == 0) {- markAsWarning(program, relocationAddress, "R_RISCV_PCREL_LO12_I", symbolName,- symbolIndex, "TODO, needs support ", elfRelocationContext.getLog());- return RelocationResult.UNSUPPORTED;+ markAsError(program, relocationAddress, type, symbolName,+ "Failed to locate HI20 relocation for R_RISCV_PCREL_LO12_I",+ elfRelocationContext.getLog());+ return RelocationResult.FAILURE;}- value32 = ((target & 0x00000fff) << 20) | memory.getInt(relocationAddress);+ value32 =+ ((target & 0x00000fff) << 20) | (memory.getInt(relocationAddress) & 0xfffff);memory.setInt(relocationAddress, value32);break;@@ -331,29 +325,32 @@ public class RISCV_ElfRelocationHandler extends ElfRelocationHandler {// PC-relative reference %pcrel_lo(symbol) (S-Type)// S-type immediates split the 12 bit value into separate 7 bit and 5 bit fields.// Warning: untested!- target = getSymbolValueIndirect(elfRelocationContext, (int) symbolValue);+ target = getSymbolValueIndirect(elfRelocationContext, sym,+ relocationAddress.getOffset() - relocation.getOffset());if (target == 0) {- markAsWarning(program, relocationAddress, "R_RISCV_PCREL_LO12_I", symbolName,- symbolIndex,- "TODO, needs support ", elfRelocationContext.getLog());- return RelocationResult.UNSUPPORTED;+ markAsError(program, relocationAddress, type, symbolName,+ "Failed to locate HI20 relocation for R_RISCV_PCREL_LO12_S",+ elfRelocationContext.getLog());+ return RelocationResult.FAILURE;}value32 = ((target & 0x000007f) << 25) | (target & 0x00000f80) |- memory.getInt(relocationAddress);+ (memory.getInt(relocationAddress) & 0x1fff07f);memory.setInt(relocationAddress, value32);break;case RISCV_ElfRelocationConstants.R_RISCV_HI20:// Absolute address %hi(symbol) (U-Type)value32 =- (int) ((symbolValue + 0x800) & 0xfffff000) | memory.getInt(relocationAddress);+ (int) ((symbolValue + 0x800) & 0xfffff000) |+ (memory.getInt(relocationAddress) & 0xfff);memory.setInt(relocationAddress, value32);break;case RISCV_ElfRelocationConstants.R_RISCV_LO12_I:// Absolute address %lo(symbol) (I-Type)value32 =- ((int) (symbolValue & 0x00000fff) << 20) | memory.getInt(relocationAddress);+ ((int) (symbolValue & 0x00000fff) << 20) |+ (memory.getInt(relocationAddress) & 0xfffff);memory.setInt(relocationAddress, value32);break;@@ -361,7 +358,7 @@ public class RISCV_ElfRelocationHandler extends ElfRelocationHandler {// Absolute address %lo(symbol) (S-Type)value32 = (int) (symbolValue & 0x00000fff);value32 = ((value32 & 0x1f) << 7) | ((value32 & 0xfe0) << 20) |- memory.getInt(relocationAddress);+ (memory.getInt(relocationAddress) & 0x1fff07f);memory.setInt(relocationAddress, value32);break;@@ -391,11 +388,8 @@ public class RISCV_ElfRelocationHandler extends ElfRelocationHandler {case RISCV_ElfRelocationConstants.R_RISCV_ADD8:// 8-bit label addition word8 = old + S + A- markAsWarning(program, relocationAddress, "R_RISCV_ADD8", symbolName, symbolIndex,- "TODO, needs support ", elfRelocationContext.getLog());value8 = memory.getByte(relocationAddress);- value8 += (byte) symbolValue;- value8 += (byte) addend;+ value8 += (byte) (symbolValue + addend);memory.setByte(relocationAddress, value8);byteLength = 1;break;@@ -403,8 +397,7 @@ public class RISCV_ElfRelocationHandler extends ElfRelocationHandler {case RISCV_ElfRelocationConstants.R_RISCV_ADD16:// 16-bit label addition word16 = old + S + Avalue16 = memory.getShort(relocationAddress);- value16 += (short) symbolValue;- value16 += (short) addend;+ value16 += (short) (symbolValue + addend);memory.setShort(relocationAddress, value16);byteLength = 2;break;@@ -412,16 +405,14 @@ public class RISCV_ElfRelocationHandler extends ElfRelocationHandler {case RISCV_ElfRelocationConstants.R_RISCV_ADD32:// 32-bit label addition word32 = old + S + Avalue32 = memory.getInt(relocationAddress);- value32 += (int) symbolValue;- value32 += (int) addend;+ value32 += (int) (symbolValue + addend);memory.setInt(relocationAddress, value32);break;case RISCV_ElfRelocationConstants.R_RISCV_ADD64:// 64-bit label addition word64 = old + S + Avalue64 = memory.getLong(relocationAddress);- value64 += symbolValue;- value64 += addend;+ value64 += (symbolValue + addend);memory.setLong(relocationAddress, value64);byteLength = 8;break;@@ -429,8 +420,7 @@ public class RISCV_ElfRelocationHandler extends ElfRelocationHandler {case RISCV_ElfRelocationConstants.R_RISCV_SUB8:// 8-bit label subtraction word8 = old - S - Avalue8 = memory.getByte(relocationAddress);- value8 -= (byte) symbolValue;- value8 -= (byte) addend;+ value8 -= (byte) (symbolValue + addend);memory.setByte(relocationAddress, value8);byteLength = 1;break;@@ -438,8 +428,7 @@ public class RISCV_ElfRelocationHandler extends ElfRelocationHandler {case RISCV_ElfRelocationConstants.R_RISCV_SUB16:// 16-bit label subtraction word16 = old - S - Avalue16 = memory.getShort(relocationAddress);- value16 -= (short) symbolValue;- value16 -= (short) addend;+ value16 -= (short) (symbolValue + addend);memory.setShort(relocationAddress, value16);byteLength = 2;break;@@ -447,16 +436,14 @@ public class RISCV_ElfRelocationHandler extends ElfRelocationHandler {case RISCV_ElfRelocationConstants.R_RISCV_SUB32:// 32-bit label subtraction word32 = old - S - Avalue32 = memory.getInt(relocationAddress);- value32 -= (int) symbolValue;- value32 -= (int) addend;+ value32 -= (int) (symbolValue + addend);memory.setInt(relocationAddress, value32);break;case RISCV_ElfRelocationConstants.R_RISCV_SUB64:// 64-bit label subtraction word64 = old - S - Avalue64 = memory.getLong(relocationAddress);- value64 -= symbolValue;- value64 -= addend;+ value64 -= (symbolValue + addend);memory.setLong(relocationAddress, value64);byteLength = 8;break;@@ -545,40 +532,38 @@ public class RISCV_ElfRelocationHandler extends ElfRelocationHandler {return RelocationResult.SKIPPED;case RISCV_ElfRelocationConstants.R_RISCV_SUB6:- // Local label subtraction- markAsWarning(program, relocationAddress, "R_RISCV_SUB6", symbolName, symbolIndex,- "TODO, needs support ", elfRelocationContext.getLog());- return RelocationResult.UNSUPPORTED;+ int loc8 = memory.getByte(relocationAddress);+ value8 = (byte) (symbolValue + addend);+ value8 = (byte) ((loc8 & 0xc0) | (((loc8 & 0x3f) - value8) & 0x3f));+ memory.setByte(relocationAddress, value8);+ byteLength = 1;+ break;case RISCV_ElfRelocationConstants.R_RISCV_SET6:- // Local label subtraction- markAsWarning(program, relocationAddress, "R_RISCV_SET6", symbolName, symbolIndex,- "TODO, needs support ", elfRelocationContext.getLog());- return RelocationResult.UNSUPPORTED;+ loc8 = memory.getByte(relocationAddress);+ value8 = (byte) (symbolValue + addend);+ value8 = (byte) ((loc8 & 0xc0) | (value8 & 0x3f));+ memory.setByte(relocationAddress, value8);+ byteLength = 1;+ break;case RISCV_ElfRelocationConstants.R_RISCV_SET8:- // Local label subtraction- markAsWarning(program, relocationAddress, "R_RISCV_SET8", symbolName, symbolIndex,- "TODO, needs support ", elfRelocationContext.getLog());- return RelocationResult.UNSUPPORTED;+ value8 = (byte) (symbolValue + addend);+ memory.setByte(relocationAddress, value8);+ byteLength = 1;+ break;case RISCV_ElfRelocationConstants.R_RISCV_SET16:- // Local label subtraction- markAsWarning(program, relocationAddress, "R_RISCV_SET16", symbolName, symbolIndex,- "TODO, needs support ", elfRelocationContext.getLog());- return RelocationResult.UNSUPPORTED;-- case RISCV_ElfRelocationConstants.R_RISCV_SET32:- // Local label subtraction- markAsWarning(program, relocationAddress, "R_RISCV_SET32", symbolName, symbolIndex,- "TODO, needs support ", elfRelocationContext.getLog());- return RelocationResult.UNSUPPORTED;+ value16 = (short) (symbolValue + addend);+ memory.setShort(relocationAddress, value8);+ byteLength = 2;+ break;case RISCV_ElfRelocationConstants.R_RISCV_32_PCREL:- // 32-bit PC relative- markAsWarning(program, relocationAddress, "R_RISCV_32_PCREL", symbolName,- symbolIndex, "TODO, needs support ", elfRelocationContext.getLog());- return RelocationResult.UNSUPPORTED;+ case RISCV_ElfRelocationConstants.R_RISCV_SET32:+ value32 = (int) (symbolValue + addend);+ memory.setInt(relocationAddress, value8);+ break;default:// 58-191 Reserved Reserved for future standard use